MOBILE-3833 mycourses: Display side blocks in my courses

main
Dani Palou 2022-04-22 12:38:05 +02:00
parent b0f090061b
commit cc24b2c7ff
5 changed files with 21 additions and 5 deletions

View File

@ -33,6 +33,7 @@ export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy {
@Input() contextLevel!: string;
@Input() instanceId!: number;
@Input() myDashboardPage?: string;
userTour: CoreUserTourDirectiveOptions = {
id: 'side-blocks-button',
@ -69,6 +70,7 @@ export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy {
componentProps: {
contextLevel: this.contextLevel,
instanceId: this.instanceId,
myDashboardPage: this.myDashboardPage,
},
});
}

View File

@ -34,6 +34,7 @@ export class CoreBlockSideBlocksComponent implements OnInit {
@Input() contextLevel!: string;
@Input() instanceId!: number;
@Input() myDashboardPage?: string;
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
@ -83,7 +84,7 @@ export class CoreBlockSideBlocksComponent implements OnInit {
if (this.contextLevel === 'course') {
this.blocks = await CoreBlockHelper.getCourseBlocks(this.instanceId);
} else {
const blocks = await CoreCoursesDashboard.getDashboardBlocks();
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, undefined, this.myDashboardPage);
this.blocks = blocks.sideBlocks;
}

View File

@ -49,6 +49,10 @@
<core-block *ngIf="loadedBlock?.visible" [block]="loadedBlock" contextLevel="user" [instanceId]="userId"></core-block>
</ion-list>
<core-block-side-blocks-button slot="fixed" *ngIf="hasSideBlocks" contextLevel="user" [instanceId]="userId"
[myDashboardPage]="myPageCourses">
</core-block-side-blocks-button>
<core-empty-box *ngIf="!loadedBlock" icon="fas-cubes" [message]="'core.course.nocontentavailable' | translate">
</core-empty-box>
</core-loading>

View File

@ -42,6 +42,8 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
loadedBlock?: Partial<CoreCourseBlock>;
myOverviewBlock?: AddonBlockMyOverviewComponent;
loaded = false;
myPageCourses = CoreCoursesDashboardProvider.MY_PAGE_COURSES;
hasSideBlocks = false;
protected updateSiteObserver: CoreEventObserver;
@ -79,9 +81,11 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
if (available && !disabled) {
try {
const blocks = await CoreCoursesDashboard.getDashboardBlocksFromWS(CoreCoursesDashboardProvider.MY_PAGE_COURSES);
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, undefined, this.myPageCourses);
this.loadedBlock = blocks.find((block) => block.name == 'myoverview');
// My overview block should always be in main blocks, but check side blocks too just in case.
this.loadedBlock = blocks.mainBlocks.concat(blocks.sideBlocks).find((block) => block.name == 'myoverview');
this.hasSideBlocks = blocks.sideBlocks.length > 0;
await CoreUtils.nextTicks(2);

View File

@ -92,10 +92,15 @@ export class CoreCoursesDashboardProvider {
*
* @param userId User ID. Default, current user.
* @param siteId Site ID. If not defined, current site.
* @param myPage What my page to return blocks of. Default MY_PAGE_DEFAULT.
* @return Promise resolved with the list of blocks.
*/
async getDashboardBlocks(userId?: number, siteId?: string): Promise<CoreCoursesDashboardBlocks> {
const blocks = await this.getDashboardBlocksFromWS(CoreCoursesDashboardProvider.MY_PAGE_DEFAULT, userId, siteId);
async getDashboardBlocks(
userId?: number,
siteId?: string,
myPage = CoreCoursesDashboardProvider.MY_PAGE_DEFAULT,
): Promise<CoreCoursesDashboardBlocks> {
const blocks = await this.getDashboardBlocksFromWS(myPage, userId, siteId);
let mainBlocks: CoreCourseBlock[] = [];
let sideBlocks: CoreCourseBlock[] = [];