From 831ae1789cc7287a16033677a88fcbfe1ee0b73e Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 28 Mar 2022 14:23:40 +0200 Subject: [PATCH] MOBILE-3833 blocks: Fix side-blocks contexts --- .../block/calendarupcoming/services/block-handler.ts | 11 ++++++----- .../side-blocks-button/side-blocks-button.ts | 6 ++++-- .../block/components/side-blocks/side-blocks.html | 2 +- .../block/components/side-blocks/side-blocks.ts | 11 ++++++----- .../components/course-format/course-format.html | 3 ++- .../core-course-format-single-activity.html | 2 +- .../features/courses/pages/dashboard/dashboard.html | 3 ++- src/core/features/sitehome/pages/index/index.html | 2 +- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/addons/block/calendarupcoming/services/block-handler.ts b/src/addons/block/calendarupcoming/services/block-handler.ts index 2201a1c32..ee59a8ed0 100644 --- a/src/addons/block/calendarupcoming/services/block-handler.ts +++ b/src/addons/block/calendarupcoming/services/block-handler.ts @@ -20,6 +20,7 @@ import { CoreCourseBlock } from '@features/course/services/course'; import { Params } from '@angular/router'; import { makeSingleton } from '@singletons'; import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu'; +import { CoreSites } from '@services/sites'; /** * Block handler. @@ -39,8 +40,11 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl * @return Data or promise resolved with the data. */ getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData { - const linkParams: Params = contextLevel == 'course' ? { courseId: instanceId } : {}; - linkParams.upcoming = true; + const linkParams: Params = { upcoming: true }; + + if (contextLevel == 'course' && instanceId !== CoreSites.getCurrentSiteHomeId()) { + linkParams.courseId = instanceId; + } return { title: 'addon.block_calendarupcoming.pluginname', @@ -48,9 +52,6 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl component: CoreBlockOnlyTitleComponent, link: AddonCalendarMainMenuHandlerService.PAGE_NAME, linkParams: linkParams, - navOptions: { - preferCurrentTab: false, - }, }; } diff --git a/src/core/features/block/components/side-blocks-button/side-blocks-button.ts b/src/core/features/block/components/side-blocks-button/side-blocks-button.ts index e748b67aa..3bec41f02 100644 --- a/src/core/features/block/components/side-blocks-button/side-blocks-button.ts +++ b/src/core/features/block/components/side-blocks-button/side-blocks-button.ts @@ -30,7 +30,8 @@ import { CoreBlockSideBlocksComponent } from '../side-blocks/side-blocks'; }) export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy { - @Input() courseId!: number; + @Input() contextLevel!: string; + @Input() instanceId!: number; @ViewChild('button', { read: ElementRef }) button?: ElementRef; protected element: HTMLElement; @@ -54,7 +55,8 @@ export class CoreBlockSideBlocksButtonComponent implements OnInit, OnDestroy { CoreDomUtils.openSideModal({ component: CoreBlockSideBlocksComponent, componentProps: { - courseId: this.courseId, + contextLevel: this.contextLevel, + instanceId: this.instanceId, }, }); } diff --git a/src/core/features/block/components/side-blocks/side-blocks.html b/src/core/features/block/components/side-blocks/side-blocks.html index 91fee4e1e..d9a0d3473 100644 --- a/src/core/features/block/components/side-blocks/side-blocks.html +++ b/src/core/features/block/components/side-blocks/side-blocks.html @@ -14,7 +14,7 @@ - + diff --git a/src/core/features/block/components/side-blocks/side-blocks.ts b/src/core/features/block/components/side-blocks/side-blocks.ts index b44b32557..56624490f 100644 --- a/src/core/features/block/components/side-blocks/side-blocks.ts +++ b/src/core/features/block/components/side-blocks/side-blocks.ts @@ -32,7 +32,8 @@ import { CoreCoursesDashboard } from '@features/courses/services/dashboard'; }) export class CoreBlockSideBlocksComponent implements OnInit { - @Input() courseId?: number; + @Input() contextLevel!: string; + @Input() instanceId!: number; @ViewChildren(CoreBlockComponent) blocksComponents?: QueryList; @@ -56,8 +57,8 @@ export class CoreBlockSideBlocksComponent implements OnInit { async invalidateBlocks(): Promise { const promises: Promise[] = []; - if (this.courseId) { - promises.push(CoreCourse.invalidateCourseBlocks(this.courseId)); + if (this.contextLevel === 'course') { + promises.push(CoreCourse.invalidateCourseBlocks(this.instanceId)); } else { promises.push(CoreCoursesDashboard.invalidateDashboardBlocks()); } @@ -79,8 +80,8 @@ export class CoreBlockSideBlocksComponent implements OnInit { */ async loadContent(): Promise { try { - if (this.courseId) { - this.blocks = await CoreBlockHelper.getCourseBlocks(this.courseId); + if (this.contextLevel === 'course') { + this.blocks = await CoreBlockHelper.getCourseBlocks(this.instanceId); } else { const blocks = await CoreCoursesDashboard.getDashboardBlocks(); diff --git a/src/core/features/course/components/course-format/course-format.html b/src/core/features/course/components/course-format/course-format.html index 2d8cd3391..3afda6fd4 100644 --- a/src/core/features/course/components/course-format/course-format.html +++ b/src/core/features/course/components/course-format/course-format.html @@ -44,7 +44,8 @@ - + diff --git a/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html b/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html index 1e960e8a8..d5c1692c3 100644 --- a/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html +++ b/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html @@ -2,5 +2,5 @@ - + diff --git a/src/core/features/courses/pages/dashboard/dashboard.html b/src/core/features/courses/pages/dashboard/dashboard.html index 38dc1f17e..ee62e3917 100644 --- a/src/core/features/courses/pages/dashboard/dashboard.html +++ b/src/core/features/courses/pages/dashboard/dashboard.html @@ -15,7 +15,8 @@ - + + diff --git a/src/core/features/sitehome/pages/index/index.html b/src/core/features/sitehome/pages/index/index.html index f7c3d0856..b780c5565 100644 --- a/src/core/features/sitehome/pages/index/index.html +++ b/src/core/features/sitehome/pages/index/index.html @@ -45,7 +45,7 @@ - +