Skip to content

Commit cc24b2c

Browse files
committed
MOBILE-3833 mycourses: Display side blocks in my courses
1 parent b0f0900 commit cc24b2c

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

src/core/features/block/components/side-blocks-button/side-blocks-button.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy {
3333

3434
@Input() contextLevel!: string;
3535
@Input() instanceId!: number;
36+
@Input() myDashboardPage?: string;
3637

3738
userTour: CoreUserTourDirectiveOptions = {
3839
id: 'side-blocks-button',
@@ -69,6 +70,7 @@ export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy {
6970
componentProps: {
7071
contextLevel: this.contextLevel,
7172
instanceId: this.instanceId,
73+
myDashboardPage: this.myDashboardPage,
7274
},
7375
});
7476
}

src/core/features/block/components/side-blocks/side-blocks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class CoreBlockSideBlocksComponent implements OnInit {
3434

3535
@Input() contextLevel!: string;
3636
@Input() instanceId!: number;
37+
@Input() myDashboardPage?: string;
3738

3839
@ViewChildren(CoreBlockComponent) blocksComponents?: QueryList<CoreBlockComponent>;
3940

@@ -83,7 +84,7 @@ export class CoreBlockSideBlocksComponent implements OnInit {
8384
if (this.contextLevel === 'course') {
8485
this.blocks = await CoreBlockHelper.getCourseBlocks(this.instanceId);
8586
} else {
86-
const blocks = await CoreCoursesDashboard.getDashboardBlocks();
87+
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, undefined, this.myDashboardPage);
8788

8889
this.blocks = blocks.sideBlocks;
8990
}

src/core/features/courses/pages/my/my.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ <h2 class="big">{{ 'core.courses.mycourses' | translate }}</h2>
4949
<core-block *ngIf="loadedBlock?.visible" [block]="loadedBlock" contextLevel="user" [instanceId]="userId"></core-block>
5050
</ion-list>
5151

52+
<core-block-side-blocks-button slot="fixed" *ngIf="hasSideBlocks" contextLevel="user" [instanceId]="userId"
53+
[myDashboardPage]="myPageCourses">
54+
</core-block-side-blocks-button>
55+
5256
<core-empty-box *ngIf="!loadedBlock" icon="fas-cubes" [message]="'core.course.nocontentavailable' | translate">
5357
</core-empty-box>
5458
</core-loading>

src/core/features/courses/pages/my/my.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
4242
loadedBlock?: Partial<CoreCourseBlock>;
4343
myOverviewBlock?: AddonBlockMyOverviewComponent;
4444
loaded = false;
45+
myPageCourses = CoreCoursesDashboardProvider.MY_PAGE_COURSES;
46+
hasSideBlocks = false;
4547

4648
protected updateSiteObserver: CoreEventObserver;
4749

@@ -79,9 +81,11 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
7981

8082
if (available && !disabled) {
8183
try {
82-
const blocks = await CoreCoursesDashboard.getDashboardBlocksFromWS(CoreCoursesDashboardProvider.MY_PAGE_COURSES);
84+
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, undefined, this.myPageCourses);
8385

84-
this.loadedBlock = blocks.find((block) => block.name == 'myoverview');
86+
// My overview block should always be in main blocks, but check side blocks too just in case.
87+
this.loadedBlock = blocks.mainBlocks.concat(blocks.sideBlocks).find((block) => block.name == 'myoverview');
88+
this.hasSideBlocks = blocks.sideBlocks.length > 0;
8589

8690
await CoreUtils.nextTicks(2);
8791

src/core/features/courses/services/dashboard.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,15 @@ export class CoreCoursesDashboardProvider {
9292
*
9393
* @param userId User ID. Default, current user.
9494
* @param siteId Site ID. If not defined, current site.
95+
* @param myPage What my page to return blocks of. Default MY_PAGE_DEFAULT.
9596
* @return Promise resolved with the list of blocks.
9697
*/
97-
async getDashboardBlocks(userId?: number, siteId?: string): Promise<CoreCoursesDashboardBlocks> {
98-
const blocks = await this.getDashboardBlocksFromWS(CoreCoursesDashboardProvider.MY_PAGE_DEFAULT, userId, siteId);
98+
async getDashboardBlocks(
99+
userId?: number,
100+
siteId?: string,
101+
myPage = CoreCoursesDashboardProvider.MY_PAGE_DEFAULT,
102+
): Promise<CoreCoursesDashboardBlocks> {
103+
const blocks = await this.getDashboardBlocksFromWS(myPage, userId, siteId);
99104

100105
let mainBlocks: CoreCourseBlock[] = [];
101106
let sideBlocks: CoreCourseBlock[] = [];

0 commit comments

Comments
 (0)