From aa8c6136de59d2ce3a31a3ac922cdee3b18f8308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 22 Sep 2021 14:25:02 +0200 Subject: [PATCH] MOBILE-2748 mod: Use more specific type on module handlers --- src/addons/mod/forum/services/handlers/module.ts | 4 ++-- src/addons/mod/label/services/handlers/module.ts | 4 ++-- src/addons/mod/lti/services/handlers/module.ts | 5 ++--- src/addons/mod/resource/services/handlers/module.ts | 12 ++++++------ src/addons/mod/url/services/handlers/module.ts | 12 ++++++------ .../features/course/classes/module-base-handler.ts | 6 +++--- .../course/services/handlers/default-module.ts | 6 +++--- src/core/features/course/services/module-delegate.ts | 4 ++-- 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/addons/mod/forum/services/handlers/module.ts b/src/addons/mod/forum/services/handlers/module.ts index 7418879ca..98b81258b 100644 --- a/src/addons/mod/forum/services/handlers/module.ts +++ b/src/addons/mod/forum/services/handlers/module.ts @@ -14,7 +14,6 @@ import { Injectable, Type } from '@angular/core'; import { AddonModForum, AddonModForumProvider } from '../forum'; -import { CoreCourseAnyModuleData } from '@features/course/services/course'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; @@ -23,6 +22,7 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/ import { CoreConstants } from '@/core/constants'; import { AddonModForumIndexComponent } from '../../components/index'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; +import { CoreCourseModule } from '@features/course/services/course-helper'; /** * Handler to support forum modules. @@ -53,7 +53,7 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp /** * @inheritdoc */ - async getData(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getData(module: CoreCourseModule, courseId: number): Promise { const data = await super.getData(module, courseId); if ('afterlink' in module && !!module.afterlink) { diff --git a/src/addons/mod/label/services/handlers/module.ts b/src/addons/mod/label/services/handlers/module.ts index c51a15fa0..fe1306f3e 100644 --- a/src/addons/mod/label/services/handlers/module.ts +++ b/src/addons/mod/label/services/handlers/module.ts @@ -15,7 +15,7 @@ import { CoreConstants } from '@/core/constants'; import { Injectable } from '@angular/core'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; -import { CoreCourseWSModule } from '@features/course/services/course'; +import { CoreCourseModule } from '@features/course/services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; import { makeSingleton } from '@singletons'; @@ -44,7 +44,7 @@ export class AddonModLabelModuleHandlerService extends CoreModuleHandlerBase imp /** * @inheritdoc */ - async getData(module: CoreCourseWSModule): Promise { + async getData(module: CoreCourseModule): Promise { // Remove the description from the module so it isn't rendered twice. const title = module.description || ''; module.description = ''; diff --git a/src/addons/mod/lti/services/handlers/module.ts b/src/addons/mod/lti/services/handlers/module.ts index 79d1b90a1..6213d8c9a 100644 --- a/src/addons/mod/lti/services/handlers/module.ts +++ b/src/addons/mod/lti/services/handlers/module.ts @@ -16,7 +16,6 @@ import { Injectable, Type } from '@angular/core'; import { CoreConstants } from '@/core/constants'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; -import { CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourseModule } from '@features/course/services/course-helper'; import { CoreApp } from '@services/app'; import { CoreFilepool } from '@services/filepool'; @@ -55,7 +54,7 @@ export class AddonModLtiModuleHandlerService extends CoreModuleHandlerBase imple * @inheritdoc */ async getData( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, courseId: number, sectionId?: number, forCoursePage?: boolean, @@ -87,7 +86,7 @@ export class AddonModLtiModuleHandlerService extends CoreModuleHandlerBase imple * @return Promise resolved when done. */ protected async loadCustomIcon( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, courseId: number, handlerData: CoreCourseModuleHandlerData, ): Promise { diff --git a/src/addons/mod/resource/services/handlers/module.ts b/src/addons/mod/resource/services/handlers/module.ts index f9ed3f2c2..3c6030331 100644 --- a/src/addons/mod/resource/services/handlers/module.ts +++ b/src/addons/mod/resource/services/handlers/module.ts @@ -15,7 +15,7 @@ import { CoreConstants } from '@/core/constants'; import { Injectable, Type } from '@angular/core'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; -import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from '@features/course/services/course'; +import { CoreCourse, CoreCourseModuleContentFile } from '@features/course/services/course'; import { CoreCourseModule } from '@features/course/services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; @@ -64,7 +64,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase * @inheritdoc */ async getData( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, courseId: number, sectionId?: number, forCoursePage?: boolean, @@ -94,7 +94,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase }]; this.getResourceData(module, courseId, handlerData).then((data) => { - handlerData.icon = data.icon; + handlerData.icon = handlerData.icon || data.icon; handlerData.extraBadge = data.extra; handlerData.extraBadgeColor = 'light'; @@ -113,7 +113,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase * @param courseId The course ID. * @return Resolved when done. */ - protected async hideOpenButton(module: CoreCourseAnyModuleData, courseId: number): Promise { + protected async hideOpenButton(module: CoreCourseModule, courseId: number): Promise { if (!('contentsinfo' in module) || !module.contentsinfo) { await CoreCourse.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName); } @@ -131,7 +131,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase * @return Resource data. */ protected async getResourceData( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, courseId: number, handlerData: CoreCourseModuleHandlerData, ): Promise { @@ -233,7 +233,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase // No previously set, just set the icon. if (resourceData.icon == '') { - resourceData.icon = await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined); + resourceData.icon = await CoreCourse.getModuleIconSrc(module.modname, module.modicon); } return resourceData; diff --git a/src/addons/mod/url/services/handlers/module.ts b/src/addons/mod/url/services/handlers/module.ts index 94634f181..b1cdfaf9e 100644 --- a/src/addons/mod/url/services/handlers/module.ts +++ b/src/addons/mod/url/services/handlers/module.ts @@ -16,7 +16,7 @@ import { CoreConstants } from '@/core/constants'; import { Injectable, Type } from '@angular/core'; import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; -import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; +import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModule } from '@features/course/services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; @@ -54,7 +54,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple /** * @inheritdoc */ - async getData(module: CoreCourseAnyModuleData, courseId: number): Promise { + async getData(module: CoreCourseModule, courseId: number): Promise { /** * Open the URL. @@ -77,7 +77,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple }; const handlerData: CoreCourseModuleHandlerData = { - icon: await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined), + icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'addon-mod_url-handler', showDownloadButton: false, @@ -120,8 +120,8 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple if (module.contents && module.contents[0]) { // Calculate the icon to use. - handlerData.icon = AddonModUrl.guessIcon(module.contents[0].fileurl) || - await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined); + handlerData.icon = await CoreCourse.getModuleIconSrc(module.modname, module.modicon) || + AddonModUrl.guessIcon(module.contents[0].fileurl); } return; @@ -139,7 +139,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple * @param courseId The course ID. * @return Resolved when done. */ - protected async hideLinkButton(module: CoreCourseAnyModuleData, courseId: number): Promise { + protected async hideLinkButton(module: CoreCourseModule, courseId: number): Promise { try { const contents = await CoreCourse.getModuleContents(module, courseId, undefined, false, false, undefined, this.modName); diff --git a/src/core/features/course/classes/module-base-handler.ts b/src/core/features/course/classes/module-base-handler.ts index d44bc8238..f45aa6a53 100644 --- a/src/core/features/course/classes/module-base-handler.ts +++ b/src/core/features/course/classes/module-base-handler.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; -import { CoreCourse, CoreCourseAnyModuleData } from '../services/course'; +import { CoreCourse } from '../services/course'; import { CoreCourseModule } from '../services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../services/module-delegate'; @@ -35,13 +35,13 @@ export class CoreModuleHandlerBase implements Partial { * @inheritdoc */ async getData( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars sectionId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars ): Promise { return { - icon: await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined), + icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'addon-mod_' + module.modname + '-handler', showDownloadButton: true, diff --git a/src/core/features/course/services/handlers/default-module.ts b/src/core/features/course/services/handlers/default-module.ts index d6f7d9637..25bf41663 100644 --- a/src/core/features/course/services/handlers/default-module.ts +++ b/src/core/features/course/services/handlers/default-module.ts @@ -16,7 +16,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../module-delegate'; -import { CoreCourse, CoreCourseAnyModuleData } from '../course'; +import { CoreCourse } from '../course'; import { CoreCourseModule } from '../course-helper'; import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; @@ -42,11 +42,11 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler { * @inheritdoc */ async getData( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, ): Promise { // Return the default data. const defaultData: CoreCourseModuleHandlerData = { - icon: await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined), + icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'core-course-default-handler core-course-module-' + module.modname + '-handler', action: (event: Event, module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions) => { diff --git a/src/core/features/course/services/module-delegate.ts b/src/core/features/course/services/module-delegate.ts index e7165da57..9ff01b011 100644 --- a/src/core/features/course/services/module-delegate.ts +++ b/src/core/features/course/services/module-delegate.ts @@ -52,7 +52,7 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler { * @return Data to render the module. */ getData( - module: CoreCourseAnyModuleData, + module: CoreCourseModule, courseId: number, sectionId?: number, forCoursePage?: boolean, @@ -279,7 +279,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate