MOBILE-2748 mod: Use more specific type on module handlers
parent
1c0a86d045
commit
aa8c6136de
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
import { Injectable, Type } from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
import { AddonModForum, AddonModForumProvider } from '../forum';
|
import { AddonModForum, AddonModForumProvider } from '../forum';
|
||||||
import { CoreCourseAnyModuleData } from '@features/course/services/course';
|
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
@ -23,6 +22,7 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { AddonModForumIndexComponent } from '../../components/index';
|
import { AddonModForumIndexComponent } from '../../components/index';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
||||||
|
import { CoreCourseModule } from '@features/course/services/course-helper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to support forum modules.
|
* Handler to support forum modules.
|
||||||
|
@ -53,7 +53,7 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async getData(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreCourseModuleHandlerData> {
|
async getData(module: CoreCourseModule, courseId: number): Promise<CoreCourseModuleHandlerData> {
|
||||||
const data = await super.getData(module, courseId);
|
const data = await super.getData(module, courseId);
|
||||||
|
|
||||||
if ('afterlink' in module && !!module.afterlink) {
|
if ('afterlink' in module && !!module.afterlink) {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
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 { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ export class AddonModLabelModuleHandlerService extends CoreModuleHandlerBase imp
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @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.
|
// Remove the description from the module so it isn't rendered twice.
|
||||||
const title = module.description || '';
|
const title = module.description || '';
|
||||||
module.description = '';
|
module.description = '';
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { Injectable, Type } from '@angular/core';
|
||||||
|
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
|
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 { CoreCourseModule } from '@features/course/services/course-helper';
|
||||||
import { CoreApp } from '@services/app';
|
import { CoreApp } from '@services/app';
|
||||||
import { CoreFilepool } from '@services/filepool';
|
import { CoreFilepool } from '@services/filepool';
|
||||||
|
@ -55,7 +54,7 @@ export class AddonModLtiModuleHandlerService extends CoreModuleHandlerBase imple
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async getData(
|
async getData(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
sectionId?: number,
|
sectionId?: number,
|
||||||
forCoursePage?: boolean,
|
forCoursePage?: boolean,
|
||||||
|
@ -87,7 +86,7 @@ export class AddonModLtiModuleHandlerService extends CoreModuleHandlerBase imple
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected async loadCustomIcon(
|
protected async loadCustomIcon(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
handlerData: CoreCourseModuleHandlerData,
|
handlerData: CoreCourseModuleHandlerData,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { Injectable, Type } from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
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 { CoreCourseModule } from '@features/course/services/course-helper';
|
||||||
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
|
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
|
||||||
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
|
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
|
||||||
|
@ -64,7 +64,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async getData(
|
async getData(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
sectionId?: number,
|
sectionId?: number,
|
||||||
forCoursePage?: boolean,
|
forCoursePage?: boolean,
|
||||||
|
@ -94,7 +94,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
|
||||||
}];
|
}];
|
||||||
|
|
||||||
this.getResourceData(module, courseId, handlerData).then((data) => {
|
this.getResourceData(module, courseId, handlerData).then((data) => {
|
||||||
handlerData.icon = data.icon;
|
handlerData.icon = handlerData.icon || data.icon;
|
||||||
handlerData.extraBadge = data.extra;
|
handlerData.extraBadge = data.extra;
|
||||||
handlerData.extraBadgeColor = 'light';
|
handlerData.extraBadgeColor = 'light';
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
|
||||||
* @param courseId The course ID.
|
* @param courseId The course ID.
|
||||||
* @return Resolved when done.
|
* @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) {
|
if (!('contentsinfo' in module) || !module.contentsinfo) {
|
||||||
await CoreCourse.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName);
|
await CoreCourse.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName);
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
|
||||||
* @return Resource data.
|
* @return Resource data.
|
||||||
*/
|
*/
|
||||||
protected async getResourceData(
|
protected async getResourceData(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
handlerData: CoreCourseModuleHandlerData,
|
handlerData: CoreCourseModuleHandlerData,
|
||||||
): Promise<AddonResourceHandlerData> {
|
): Promise<AddonResourceHandlerData> {
|
||||||
|
@ -233,7 +233,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
|
||||||
|
|
||||||
// No previously set, just set the icon.
|
// No previously set, just set the icon.
|
||||||
if (resourceData.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;
|
return resourceData;
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { CoreConstants } from '@/core/constants';
|
||||||
import { Injectable, Type } from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
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 { CoreCourseModule } from '@features/course/services/course-helper';
|
||||||
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
|
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
|
||||||
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
|
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
|
||||||
|
@ -54,7 +54,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async getData(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreCourseModuleHandlerData> {
|
async getData(module: CoreCourseModule, courseId: number): Promise<CoreCourseModuleHandlerData> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the URL.
|
* Open the URL.
|
||||||
|
@ -77,7 +77,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlerData: CoreCourseModuleHandlerData = {
|
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,
|
title: module.name,
|
||||||
class: 'addon-mod_url-handler',
|
class: 'addon-mod_url-handler',
|
||||||
showDownloadButton: false,
|
showDownloadButton: false,
|
||||||
|
@ -120,8 +120,8 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
|
||||||
|
|
||||||
if (module.contents && module.contents[0]) {
|
if (module.contents && module.contents[0]) {
|
||||||
// Calculate the icon to use.
|
// Calculate the icon to use.
|
||||||
handlerData.icon = AddonModUrl.guessIcon(module.contents[0].fileurl) ||
|
handlerData.icon = await CoreCourse.getModuleIconSrc(module.modname, module.modicon) ||
|
||||||
await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined);
|
AddonModUrl.guessIcon(module.contents[0].fileurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -139,7 +139,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
|
||||||
* @param courseId The course ID.
|
* @param courseId The course ID.
|
||||||
* @return Resolved when done.
|
* @return Resolved when done.
|
||||||
*/
|
*/
|
||||||
protected async hideLinkButton(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean> {
|
protected async hideLinkButton(module: CoreCourseModule, courseId: number): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const contents = await CoreCourse.getModuleContents(module, courseId, undefined, false, false, undefined, this.modName);
|
const contents = await CoreCourse.getModuleContents(module, courseId, undefined, false, false, undefined, this.modName);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
|
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
|
||||||
import { CoreCourse, CoreCourseAnyModuleData } from '../services/course';
|
import { CoreCourse } from '../services/course';
|
||||||
import { CoreCourseModule } from '../services/course-helper';
|
import { CoreCourseModule } from '../services/course-helper';
|
||||||
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../services/module-delegate';
|
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../services/module-delegate';
|
||||||
|
|
||||||
|
@ -35,13 +35,13 @@ export class CoreModuleHandlerBase implements Partial<CoreCourseModuleHandler> {
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async getData(
|
async getData(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
|
courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
sectionId?: 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
|
forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
): Promise<CoreCourseModuleHandlerData> {
|
): Promise<CoreCourseModuleHandlerData> {
|
||||||
return {
|
return {
|
||||||
icon: await CoreCourse.getModuleIconSrc(module.modname, 'modicon' in module ? module.modicon : undefined),
|
icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon),
|
||||||
title: module.name,
|
title: module.name,
|
||||||
class: 'addon-mod_' + module.modname + '-handler',
|
class: 'addon-mod_' + module.modname + '-handler',
|
||||||
showDownloadButton: true,
|
showDownloadButton: true,
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { Injectable, Type } from '@angular/core';
|
||||||
|
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../module-delegate';
|
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../module-delegate';
|
||||||
import { CoreCourse, CoreCourseAnyModuleData } from '../course';
|
import { CoreCourse } from '../course';
|
||||||
import { CoreCourseModule } from '../course-helper';
|
import { CoreCourseModule } from '../course-helper';
|
||||||
import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module';
|
import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module';
|
||||||
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
|
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
|
||||||
|
@ -42,11 +42,11 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler {
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async getData(
|
async getData(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
): Promise<CoreCourseModuleHandlerData> {
|
): Promise<CoreCourseModuleHandlerData> {
|
||||||
// Return the default data.
|
// Return the default data.
|
||||||
const defaultData: CoreCourseModuleHandlerData = {
|
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,
|
title: module.name,
|
||||||
class: 'core-course-default-handler core-course-module-' + module.modname + '-handler',
|
class: 'core-course-default-handler core-course-module-' + module.modname + '-handler',
|
||||||
action: (event: Event, module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions) => {
|
action: (event: Event, module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions) => {
|
||||||
|
|
|
@ -52,7 +52,7 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler {
|
||||||
* @return Data to render the module.
|
* @return Data to render the module.
|
||||||
*/
|
*/
|
||||||
getData(
|
getData(
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
sectionId?: number,
|
sectionId?: number,
|
||||||
forCoursePage?: boolean,
|
forCoursePage?: boolean,
|
||||||
|
@ -279,7 +279,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
|
||||||
*/
|
*/
|
||||||
async getModuleDataFor(
|
async getModuleDataFor(
|
||||||
modname: string,
|
modname: string,
|
||||||
module: CoreCourseAnyModuleData,
|
module: CoreCourseModule,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
sectionId?: number,
|
sectionId?: number,
|
||||||
forCoursePage?: boolean,
|
forCoursePage?: boolean,
|
||||||
|
|
Loading…
Reference in New Issue