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 { CoreUtils } from '@services/utils/utils';
|
||||
import { IonRefresher } from '@ionic/angular';
|
||||
import { CoreCoursesDashboard } from '@features/courses/services/dashboard';
|
||||
|
||||
/**
|
||||
* Component that displays the list of side blocks.
|
||||
|
@ -30,7 +31,7 @@ import { IonRefresher } from '@ionic/angular';
|
|||
})
|
||||
export class CoreBlockSideBlocksComponent implements OnInit {
|
||||
|
||||
@Input() courseId!: number;
|
||||
@Input() courseId?: number;
|
||||
@Input() downloadEnabled = false;
|
||||
|
||||
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
|
||||
|
@ -55,8 +56,10 @@ export class CoreBlockSideBlocksComponent implements OnInit {
|
|||
async invalidateBlocks(): Promise<void> {
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
if (CoreBlockHelper.canGetCourseBlocks()) {
|
||||
if (this.courseId) {
|
||||
promises.push(CoreCourse.invalidateCourseBlocks(this.courseId));
|
||||
} else {
|
||||
promises.push(CoreCoursesDashboard.invalidateDashboardBlocks());
|
||||
}
|
||||
|
||||
// Invalidate the blocks.
|
||||
|
@ -76,7 +79,13 @@ export class CoreBlockSideBlocksComponent implements OnInit {
|
|||
*/
|
||||
async loadContent(): Promise<void> {
|
||||
try {
|
||||
this.blocks = await CoreBlockHelper.getCourseBlocks(this.courseId);
|
||||
if (this.courseId) {
|
||||
this.blocks = await CoreBlockHelper.getCourseBlocks(this.courseId);
|
||||
} else {
|
||||
const blocks = await CoreCoursesDashboard.getDashboardBlocks();
|
||||
|
||||
this.blocks = blocks.sideBlocks;
|
||||
}
|
||||
} catch (error) {
|
||||
CoreDomUtils.showErrorModal(error);
|
||||
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
</ion-button>
|
||||
<core-context-menu>
|
||||
<core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000"
|
||||
[content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload()"
|
||||
iconAction="toggle" [(toggle)]="downloadEnabled"></core-context-menu-item>
|
||||
<core-context-menu-item [priority]="500"
|
||||
[content]="'addon.storagemanager.managestorage' | translate"
|
||||
[content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload()" iconAction="toggle"
|
||||
[(toggle)]="downloadEnabled"></core-context-menu-item>
|
||||
<core-context-menu-item [priority]="500" [content]="'addon.storagemanager.managestorage' | translate"
|
||||
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
|
||||
</core-context-menu>
|
||||
</core-navbar-buttons>
|
||||
|
@ -20,11 +19,13 @@
|
|||
<ion-list>
|
||||
<ng-container *ngFor="let block of blocks">
|
||||
<core-block *ngIf="block.visible" [block]="block" contextLevel="user" [instanceId]="userId"
|
||||
[extraData]="{'downloadEnabled': downloadEnabled}"></core-block>
|
||||
[extraData]="{'downloadEnabled': downloadEnabled}"></core-block>
|
||||
</ng-container>
|
||||
</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-loading>
|
||||
</ion-content>
|
||||
|
|
|
@ -23,6 +23,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
|||
import { CoreCourseBlock } from '@features/course/services/course';
|
||||
import { CoreBlockComponent } from '@features/block/components/block/block';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreBlockDelegate } from '@features/block/services/block-delegate';
|
||||
|
||||
/**
|
||||
* Page that displays the dashboard page.
|
||||
|
@ -36,6 +37,7 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
|
|||
|
||||
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
|
||||
|
||||
hasSideBlocks = false;
|
||||
searchEnabled = false;
|
||||
downloadEnabled = false;
|
||||
downloadCourseEnabled = false;
|
||||
|
@ -88,7 +90,11 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
|
|||
this.userId = CoreSites.getCurrentSiteUserId();
|
||||
|
||||
try {
|
||||
this.blocks = await CoreCoursesDashboard.getDashboardBlocks();
|
||||
const blocks = await CoreCoursesDashboard.getDashboardBlocks();
|
||||
|
||||
this.blocks = blocks.mainBlocks;
|
||||
|
||||
this.hasSideBlocks = CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks);
|
||||
} catch (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 siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with the list of blocks.
|
||||
* @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 params: CoreBlockGetDashboardBlocksWSParams = {
|
||||
|
@ -63,6 +63,44 @@ export class CoreCoursesDashboardProvider {
|
|||
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.
|
||||
*
|
||||
|
@ -122,6 +160,11 @@ export class CoreCoursesDashboardProvider {
|
|||
|
||||
export const CoreCoursesDashboard = makeSingleton(CoreCoursesDashboardProvider);
|
||||
|
||||
export type CoreCoursesDashboardBlocks = {
|
||||
mainBlocks: CoreCourseBlock[];
|
||||
sideBlocks: CoreCourseBlock[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Params of core_block_get_dashboard_blocks WS.
|
||||
*/
|
||||
|
|
|
@ -68,7 +68,7 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler
|
|||
if (dashboardAvailable && blocksEnabled) {
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue