MOBILE-3810 module: Fix getIconSrc on course module handler
parent
56e51e9e60
commit
8a3ae5e081
|
@ -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 } from '@features/course/services/course';
|
||||
import { CoreCourse, CoreCourseWSModule } 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';
|
||||
|
@ -226,6 +226,32 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async getIconSrc(module?: CoreCourseWSModule): Promise<string | undefined> {
|
||||
if (!module) {
|
||||
return;
|
||||
}
|
||||
let mimetypeIcon = '';
|
||||
|
||||
if ('contentsinfo' in module && module.contentsinfo) {
|
||||
// No need to use the list of files.
|
||||
const mimetype = module.contentsinfo.mimetypes[0];
|
||||
if (mimetype) {
|
||||
mimetypeIcon = CoreMimetypeUtils.getMimetypeIcon(mimetype);
|
||||
}
|
||||
|
||||
} else if (module.contents && module.contents[0]) {
|
||||
const files = module.contents;
|
||||
const file = files[0];
|
||||
|
||||
mimetypeIcon = CoreMimetypeUtils.getFileIcon(file.filename || '');
|
||||
}
|
||||
|
||||
return await CoreCourse.getModuleIconSrc(module.modname, module.modicon, mimetypeIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import { Component, Input, OnChanges, OnInit, SimpleChange } from '@angular/core';
|
||||
import { CoreCourse } from '@features/course/services/course';
|
||||
|
||||
const assetsPath = 'assets/img/mod/';
|
||||
const assetsPath = 'assets/img/';
|
||||
const fallbackModName = 'external-tool';
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ export class CoreModIconComponent implements OnInit, OnChanges {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ngOnChanges(changes: { [name: string]: SimpleChange }): void {
|
||||
if (changes && changes.modicon && changes.modicon.previousValue) {
|
||||
if (changes && changes.modicon && changes.modicon.previousValue !== undefined) {
|
||||
this.setIcon();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,9 +80,10 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler {
|
|||
/**
|
||||
* Get the icon src for the module.
|
||||
*
|
||||
* @param module: Module to get the icon from.
|
||||
* @return The icon src.
|
||||
*/
|
||||
getIconSrc?(module: CoreCourseWSModule): Promise<string> | string | undefined;
|
||||
getIconSrc?(module?: CoreCourseWSModule): Promise<string | undefined> | string | undefined;
|
||||
|
||||
/**
|
||||
* Check if this type of module supports a certain feature.
|
||||
|
@ -343,10 +344,11 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
|
|||
*
|
||||
* @param modname The name of the module type.
|
||||
* @param modicon The mod icon string.
|
||||
* @param module The module to use.
|
||||
* @return Promise resolved with the icon src.
|
||||
*/
|
||||
async getModuleIconSrc(modname: string, modicon?: string): Promise<string> {
|
||||
const icon = await this.executeFunctionOnEnabled<Promise<string>>(modname, 'getIconSrc');
|
||||
async getModuleIconSrc(modname: string, modicon?: string, module?: CoreCourseWSModule): Promise<string> {
|
||||
const icon = await this.executeFunctionOnEnabled<Promise<string>>(modname, 'getIconSrc', [module]);
|
||||
|
||||
return icon || await CoreCourse.getModuleIconSrc(modname, modicon) || '';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue