From dcf33d4fc198b410a5779fc50d262d1745d2f039 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 28 Nov 2019 16:40:53 +0100 Subject: [PATCH 1/4] MOBILE-3235 blocks: Fix activities block outside of course context level --- .../components/activitymodules/activitymodules.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts index 566ddc0b8..512e93b52 100644 --- a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts +++ b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts @@ -18,6 +18,7 @@ import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component'; import { CoreConstants } from '@core/constants'; import { TranslateService } from '@ngx-translate/core'; +import { CoreSitesProvider } from '@providers/sites'; /** * Component to render an "activity modules" block. @@ -36,7 +37,8 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i protected fetchContentDefaultError = 'Error getting activity modules data.'; constructor(injector: Injector, protected courseProvider: CoreCourseProvider, - protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate) { + protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate, + protected sitesProvider: CoreSitesProvider) { super(injector, 'AddonBlockActivityModulesComponent'); } @@ -63,8 +65,11 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i * @return Promise resolved when done. */ protected fetchContent(): Promise { - return this.courseProvider.getSections(this.instanceId, false, true).then((sections) => { + const courseId = this.contextLevel === 'course' + ? this.instanceId + : this.sitesProvider.getCurrentSiteHomeId(); + return this.courseProvider.getSections(courseId, false, true).then((sections) => { this.entries = []; const archetypes = {}, From 46cc61cc016afe0aa2b86058d298640ef2f22368 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 28 Nov 2019 17:18:13 +0100 Subject: [PATCH 2/4] MOBILE-3235 core: Add enumeration defining available context levels --- .../activitymodules/activitymodules.ts | 24 +++++++++++++------ src/core/constants.ts | 12 ++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts index 512e93b52..adc6e9173 100644 --- a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts +++ b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts @@ -16,7 +16,7 @@ import { Component, OnInit, Injector, Input } from '@angular/core'; import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component'; -import { CoreConstants } from '@core/constants'; +import { CoreConstants, ContextLevel } from '@core/constants'; import { TranslateService } from '@ngx-translate/core'; import { CoreSitesProvider } from '@providers/sites'; @@ -29,7 +29,7 @@ import { CoreSitesProvider } from '@providers/sites'; }) export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent implements OnInit { @Input() block: any; // The block to render. - @Input() contextLevel: string; // The context where the block will be used. + @Input() contextLevel: ContextLevel; // The context where the block will be used. @Input() instanceId: number; // The instance ID associated with the context level. entries: any[] = []; @@ -65,11 +65,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i * @return Promise resolved when done. */ protected fetchContent(): Promise { - const courseId = this.contextLevel === 'course' - ? this.instanceId - : this.sitesProvider.getCurrentSiteHomeId(); - - return this.courseProvider.getSections(courseId, false, true).then((sections) => { + return this.courseProvider.getSections(this.getCourseId(), false, true).then((sections) => { this.entries = []; const archetypes = {}, @@ -127,4 +123,18 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i } }); } + + /** + * Obtain the appropiate course id for the block. + * + * @return Course id. + */ + protected getCourseId(): number { + switch (this.contextLevel) { + case ContextLevel.Course: + return this.instanceId; + default: + return this.sitesProvider.getCurrentSiteHomeId(); + } + } } diff --git a/src/core/constants.ts b/src/core/constants.ts index de6898658..ac5a28de1 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -12,6 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +/** + * Context levels enumeration. + */ +export const enum ContextLevel { + System = 'system', + User = 'user', + Category = 'category', + Course = 'course', + ActivityModule = 'module', + Block = 'block', +} + /** * Static class to contain all the core constants. */ From 31c4595bbdf7f4a35c6420e526ee6f207e6329b1 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 2 Dec 2019 11:17:24 +0100 Subject: [PATCH 3/4] MOBILE-3235 core: Rename ContextLevel enum keys --- .../components/activitymodules/activitymodules.ts | 2 +- src/core/constants.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts index adc6e9173..b46a9b366 100644 --- a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts +++ b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts @@ -131,7 +131,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i */ protected getCourseId(): number { switch (this.contextLevel) { - case ContextLevel.Course: + case ContextLevel.COURSE: return this.instanceId; default: return this.sitesProvider.getCurrentSiteHomeId(); diff --git a/src/core/constants.ts b/src/core/constants.ts index ac5a28de1..65c666882 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -16,12 +16,12 @@ * Context levels enumeration. */ export const enum ContextLevel { - System = 'system', - User = 'user', - Category = 'category', - Course = 'course', - ActivityModule = 'module', - Block = 'block', + SYSTEM = 'system', + USER = 'user', + COURSECAT = 'category', + COURSE = 'course', + MODULE = 'module', + BLOCK = 'block', } /** From cf4331bc89d4e9ee558b238861161c5c9395b14f Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 2 Dec 2019 13:21:51 +0100 Subject: [PATCH 4/4] MOBILE-3235 core: Rename 'category' context level to 'coursecat' Renamed in order to remain consistent with the LMS. --- src/addon/calendar/pages/event/event.html | 2 +- src/addon/calendar/providers/helper.ts | 2 +- src/core/constants.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/addon/calendar/pages/event/event.html b/src/addon/calendar/pages/event/event.html index 704a23bec..63f53e1e6 100644 --- a/src/addon/calendar/pages/event/event.html +++ b/src/addon/calendar/pages/event/event.html @@ -60,7 +60,7 @@

{{ 'core.category' | translate}}

-

+

{{ 'core.description' | translate}}

diff --git a/src/addon/calendar/providers/helper.ts b/src/addon/calendar/providers/helper.ts index 976c21431..a6bed59b5 100644 --- a/src/addon/calendar/providers/helper.ts +++ b/src/addon/calendar/providers/helper.ts @@ -144,7 +144,7 @@ export class AddonCalendarHelperProvider { courseId = e.course ? e.course.id : e.courseid; if (categoryId > 0) { - e.contextLevel = 'category'; + e.contextLevel = 'coursecat'; e.contextInstanceId = categoryId; } else if (courseId > 0) { e.contextLevel = 'course'; diff --git a/src/core/constants.ts b/src/core/constants.ts index 65c666882..c9784ccc3 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -18,7 +18,7 @@ export const enum ContextLevel { SYSTEM = 'system', USER = 'user', - COURSECAT = 'category', + COURSECAT = 'coursecat', COURSE = 'course', MODULE = 'module', BLOCK = 'block',