MOBILE-2748 mod: Use more specific type on module handlers

main
Pau Ferrer Ocaña 2021-09-22 14:25:02 +02:00
parent 1c0a86d045
commit aa8c6136de
8 changed files with 26 additions and 27 deletions

View File

@ -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<CoreCourseModuleHandlerData> {
async getData(module: CoreCourseModule, courseId: number): Promise<CoreCourseModuleHandlerData> {
const data = await super.getData(module, courseId);
if ('afterlink' in module && !!module.afterlink) {

View File

@ -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<CoreCourseModuleHandlerData> {
async getData(module: CoreCourseModule): Promise<CoreCourseModuleHandlerData> {
// Remove the description from the module so it isn't rendered twice.
const title = module.description || '';
module.description = '';

View File

@ -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<void> {

View File

@ -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<boolean> {
protected async hideOpenButton(module: CoreCourseModule, courseId: number): Promise<boolean> {
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<AddonResourceHandlerData> {
@ -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;

View File

@ -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<CoreCourseModuleHandlerData> {
async getData(module: CoreCourseModule, courseId: number): Promise<CoreCourseModuleHandlerData> {
/**
* 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<boolean> {
protected async hideLinkButton(module: CoreCourseModule, courseId: number): Promise<boolean> {
try {
const contents = await CoreCourse.getModuleContents(module, courseId, undefined, false, false, undefined, this.modName);

View File

@ -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<CoreCourseModuleHandler> {
* @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<CoreCourseModuleHandlerData> {
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,

View File

@ -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<CoreCourseModuleHandlerData> {
// 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) => {

View File

@ -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<CoreCourseModu
*/
async getModuleDataFor(
modname: string,
module: CoreCourseAnyModuleData,
module: CoreCourseModule,
courseId: number,
sectionId?: number,
forCoursePage?: boolean,