MOBILE-3914 dashboard: Add side blocks on dashboard
parent
8cd89ead85
commit
0bfe870af1
|
@ -20,6 +20,7 @@ import { CoreBlockHelper } from '../../services/block-helper';
|
||||||
import { CoreBlockComponent } from '../block/block';
|
import { CoreBlockComponent } from '../block/block';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { IonRefresher } from '@ionic/angular';
|
import { IonRefresher } from '@ionic/angular';
|
||||||
|
import { CoreCoursesDashboard } from '@features/courses/services/dashboard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that displays the list of side blocks.
|
* Component that displays the list of side blocks.
|
||||||
|
@ -30,7 +31,7 @@ import { IonRefresher } from '@ionic/angular';
|
||||||
})
|
})
|
||||||
export class CoreBlockSideBlocksComponent implements OnInit {
|
export class CoreBlockSideBlocksComponent implements OnInit {
|
||||||
|
|
||||||
@Input() courseId!: number;
|
@Input() courseId?: number;
|
||||||
@Input() downloadEnabled = false;
|
@Input() downloadEnabled = false;
|
||||||
|
|
||||||
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
|
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
|
||||||
|
@ -55,8 +56,10 @@ export class CoreBlockSideBlocksComponent implements OnInit {
|
||||||
async invalidateBlocks(): Promise<void> {
|
async invalidateBlocks(): Promise<void> {
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
|
|
||||||
if (CoreBlockHelper.canGetCourseBlocks()) {
|
if (this.courseId) {
|
||||||
promises.push(CoreCourse.invalidateCourseBlocks(this.courseId));
|
promises.push(CoreCourse.invalidateCourseBlocks(this.courseId));
|
||||||
|
} else {
|
||||||
|
promises.push(CoreCoursesDashboard.invalidateDashboardBlocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalidate the blocks.
|
// Invalidate the blocks.
|
||||||
|
@ -76,7 +79,13 @@ export class CoreBlockSideBlocksComponent implements OnInit {
|
||||||
*/
|
*/
|
||||||
async loadContent(): Promise<void> {
|
async loadContent(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
if (this.courseId) {
|
||||||
this.blocks = await CoreBlockHelper.getCourseBlocks(this.courseId);
|
this.blocks = await CoreBlockHelper.getCourseBlocks(this.courseId);
|
||||||
|
} else {
|
||||||
|
const blocks = await CoreCoursesDashboard.getDashboardBlocks();
|
||||||
|
|
||||||
|
this.blocks = blocks.sideBlocks;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModal(error);
|
CoreDomUtils.showErrorModal(error);
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
</ion-button>
|
</ion-button>
|
||||||
<core-context-menu>
|
<core-context-menu>
|
||||||
<core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000"
|
<core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000"
|
||||||
[content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload()"
|
[content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload()" iconAction="toggle"
|
||||||
iconAction="toggle" [(toggle)]="downloadEnabled"></core-context-menu-item>
|
[(toggle)]="downloadEnabled"></core-context-menu-item>
|
||||||
<core-context-menu-item [priority]="500"
|
<core-context-menu-item [priority]="500" [content]="'addon.storagemanager.managestorage' | translate"
|
||||||
[content]="'addon.storagemanager.managestorage' | translate"
|
|
||||||
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
|
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
|
||||||
</core-context-menu>
|
</core-context-menu>
|
||||||
</core-navbar-buttons>
|
</core-navbar-buttons>
|
||||||
|
@ -24,7 +23,9 @@
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
<core-empty-box *ngIf="blocks.length == 0" icon="fas-th-large" [message]="'core.course.nocontentavailable' | translate">
|
<core-block-side-blocks-button *ngIf="hasSideBlocks" [downloadEnabled]="downloadEnabled"></core-block-side-blocks-button>
|
||||||
|
|
||||||
|
<core-empty-box *ngIf="blocks.length == 0" icon="fas-cubes" [message]="'core.course.nocontentavailable' | translate">
|
||||||
</core-empty-box>
|
</core-empty-box>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreCourseBlock } from '@features/course/services/course';
|
import { CoreCourseBlock } from '@features/course/services/course';
|
||||||
import { CoreBlockComponent } from '@features/block/components/block/block';
|
import { CoreBlockComponent } from '@features/block/components/block/block';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
|
import { CoreBlockDelegate } from '@features/block/services/block-delegate';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the dashboard page.
|
* Page that displays the dashboard page.
|
||||||
|
@ -36,6 +37,7 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
|
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
|
||||||
|
|
||||||
|
hasSideBlocks = false;
|
||||||
searchEnabled = false;
|
searchEnabled = false;
|
||||||
downloadEnabled = false;
|
downloadEnabled = false;
|
||||||
downloadCourseEnabled = false;
|
downloadCourseEnabled = false;
|
||||||
|
@ -88,7 +90,11 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
|
||||||
this.userId = CoreSites.getCurrentSiteUserId();
|
this.userId = CoreSites.getCurrentSiteUserId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.blocks = await CoreCoursesDashboard.getDashboardBlocks();
|
const blocks = await CoreCoursesDashboard.getDashboardBlocks();
|
||||||
|
|
||||||
|
this.blocks = blocks.mainBlocks;
|
||||||
|
|
||||||
|
this.hasSideBlocks = CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModal(error);
|
CoreDomUtils.showErrorModal(error);
|
||||||
|
|
||||||
|
|
|
@ -38,14 +38,14 @@ export class CoreCoursesDashboardProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get dashboard blocks.
|
* Get dashboard blocks from WS.
|
||||||
*
|
*
|
||||||
* @param userId User ID. Default, current user.
|
* @param userId User ID. Default, current user.
|
||||||
* @param siteId Site ID. If not defined, current site.
|
* @param siteId Site ID. If not defined, current site.
|
||||||
* @return Promise resolved with the list of blocks.
|
* @return Promise resolved with the list of blocks.
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
async getDashboardBlocks(userId?: number, siteId?: string): Promise<CoreCourseBlock[]> {
|
protected async getDashboardBlocksFromWS(userId?: number, siteId?: string): Promise<CoreCourseBlock[]> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
|
||||||
const params: CoreBlockGetDashboardBlocksWSParams = {
|
const params: CoreBlockGetDashboardBlocksWSParams = {
|
||||||
|
@ -63,6 +63,44 @@ export class CoreCoursesDashboardProvider {
|
||||||
return result.blocks || [];
|
return result.blocks || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get dashboard blocks.
|
||||||
|
*
|
||||||
|
* @param userId User ID. Default, current user.
|
||||||
|
* @param siteId Site ID. If not defined, current site.
|
||||||
|
* @return Promise resolved with the list of blocks.
|
||||||
|
*/
|
||||||
|
async getDashboardBlocks(userId?: number, siteId?: string): Promise<CoreCoursesDashboardBlocks> {
|
||||||
|
const blocks = await CoreCoursesDashboard.getDashboardBlocksFromWS(userId, siteId);
|
||||||
|
|
||||||
|
let mainBlocks: CoreCourseBlock[] = [];
|
||||||
|
let sideBlocks: CoreCourseBlock[] = [];
|
||||||
|
|
||||||
|
blocks.forEach((block) => {
|
||||||
|
if (block.region == 'content' || block.region == 'main') {
|
||||||
|
mainBlocks.push(block);
|
||||||
|
} else {
|
||||||
|
sideBlocks.push(block);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mainBlocks.length == 0) {
|
||||||
|
mainBlocks = [];
|
||||||
|
sideBlocks = [];
|
||||||
|
|
||||||
|
blocks.forEach((block) => {
|
||||||
|
if (block.region.match('side')) {
|
||||||
|
sideBlocks.push(block);
|
||||||
|
} else {
|
||||||
|
mainBlocks.push(block);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { mainBlocks, sideBlocks };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates dashboard blocks WS call.
|
* Invalidates dashboard blocks WS call.
|
||||||
*
|
*
|
||||||
|
@ -122,6 +160,11 @@ export class CoreCoursesDashboardProvider {
|
||||||
|
|
||||||
export const CoreCoursesDashboard = makeSingleton(CoreCoursesDashboardProvider);
|
export const CoreCoursesDashboard = makeSingleton(CoreCoursesDashboardProvider);
|
||||||
|
|
||||||
|
export type CoreCoursesDashboardBlocks = {
|
||||||
|
mainBlocks: CoreCourseBlock[];
|
||||||
|
sideBlocks: CoreCourseBlock[];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Params of core_block_get_dashboard_blocks WS.
|
* Params of core_block_get_dashboard_blocks WS.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -68,7 +68,7 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler
|
||||||
if (dashboardAvailable && blocksEnabled) {
|
if (dashboardAvailable && blocksEnabled) {
|
||||||
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, siteId);
|
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, siteId);
|
||||||
|
|
||||||
return CoreBlockDelegate.hasSupportedBlock(blocks);
|
return CoreBlockDelegate.hasSupportedBlock(blocks.mainBlocks) || CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if my overview is enabled. If it's enabled we will fake enabled blocks.
|
// Check if my overview is enabled. If it's enabled we will fake enabled blocks.
|
||||||
|
|
Loading…
Reference in New Issue