diff --git a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts index 9e5519b4a..69a0122bb 100644 --- a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts +++ b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts @@ -68,7 +68,8 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i this.entries = []; - const archetypes = {}; + const archetypes = {}, + modIcons = {}; let modFullNames = {}; sections.forEach((section) => { @@ -98,6 +99,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i } else { modFullNames[mod.modname] = mod.modplural; } + modIcons[mod.modname] = mod.modicon; }); }); @@ -108,9 +110,9 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i let icon; if (modName === 'resources') { - icon = this.courseProvider.getModuleIconSrc('page'); + icon = this.courseProvider.getModuleIconSrc('page', modIcons['page']); } else { - icon = this.moduleDelegate.getModuleIconSrc(modName); + icon = this.moduleDelegate.getModuleIconSrc(modName, modIcons[modName]); } this.entries.push({ diff --git a/src/addon/block/recentlyaccesseditems/providers/recentlyaccesseditems.ts b/src/addon/block/recentlyaccesseditems/providers/recentlyaccesseditems.ts index e20e41b1f..f07f386d5 100644 --- a/src/addon/block/recentlyaccesseditems/providers/recentlyaccesseditems.ts +++ b/src/addon/block/recentlyaccesseditems/providers/recentlyaccesseditems.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSitesProvider } from '@providers/sites'; import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; /** * Service that provides some features regarding recently accessed items. @@ -23,7 +24,8 @@ import { CoreCourseProvider } from '@core/course/providers/course'; export class AddonBlockRecentlyAccessedItemsProvider { protected ROOT_CACHE_KEY = 'AddonBlockRecentlyAccessedItems:'; - constructor(private sitesProvider: CoreSitesProvider, private courseProvider: CoreCourseProvider) { } + constructor(private sitesProvider: CoreSitesProvider, private courseProvider: CoreCourseProvider, + private domUtils: CoreDomUtilsProvider) { } /** * Get cache key for get last accessed items value WS call. @@ -49,7 +51,8 @@ export class AddonBlockRecentlyAccessedItemsProvider { return site.read('block_recentlyaccesseditems_get_recent_items', undefined, preSets).then((items) => { return items.map((item) => { - item.iconUrl = this.courseProvider.getModuleIconSrc(item.modname); + const modicon = item.icon && this.domUtils.getHTMLElementAttribute(item.icon, 'src'); + item.iconUrl = this.courseProvider.getModuleIconSrc(item.modname, modicon); return item; }); diff --git a/src/addon/mod/assign/providers/module-handler.ts b/src/addon/mod/assign/providers/module-handler.ts index 5cd335bff..937aeeb1d 100644 --- a/src/addon/mod/assign/providers/module-handler.ts +++ b/src/addon/mod/assign/providers/module-handler.ts @@ -64,7 +64,7 @@ export class AddonModAssignModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('assign'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_assign-handler', showDownloadButton: true, diff --git a/src/addon/mod/book/providers/module-handler.ts b/src/addon/mod/book/providers/module-handler.ts index bffbf8038..a1b4c9af4 100644 --- a/src/addon/mod/book/providers/module-handler.ts +++ b/src/addon/mod/book/providers/module-handler.ts @@ -61,7 +61,7 @@ export class AddonModBookModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('book'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_book-handler', showDownloadButton: true, diff --git a/src/addon/mod/chat/providers/module-handler.ts b/src/addon/mod/chat/providers/module-handler.ts index 9b29145c0..e54d0fda2 100644 --- a/src/addon/mod/chat/providers/module-handler.ts +++ b/src/addon/mod/chat/providers/module-handler.ts @@ -59,7 +59,7 @@ export class AddonModChatModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('chat'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_chat-handler', action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { diff --git a/src/addon/mod/choice/providers/module-handler.ts b/src/addon/mod/choice/providers/module-handler.ts index f9a26b2b9..163b595a5 100644 --- a/src/addon/mod/choice/providers/module-handler.ts +++ b/src/addon/mod/choice/providers/module-handler.ts @@ -60,7 +60,7 @@ export class AddonModChoiceModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('choice'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_choice-handler', showDownloadButton: true, diff --git a/src/addon/mod/data/providers/module-handler.ts b/src/addon/mod/data/providers/module-handler.ts index 3fb8f5c7e..78cecd43b 100644 --- a/src/addon/mod/data/providers/module-handler.ts +++ b/src/addon/mod/data/providers/module-handler.ts @@ -63,7 +63,7 @@ export class AddonModDataModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('data'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_data-handler', showDownloadButton: true, diff --git a/src/addon/mod/feedback/providers/module-handler.ts b/src/addon/mod/feedback/providers/module-handler.ts index 26cc80e11..8da7e41d9 100644 --- a/src/addon/mod/feedback/providers/module-handler.ts +++ b/src/addon/mod/feedback/providers/module-handler.ts @@ -61,7 +61,7 @@ export class AddonModFeedbackModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('feedback'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_feedback-handler', showDownloadButton: true, diff --git a/src/addon/mod/folder/providers/module-handler.ts b/src/addon/mod/folder/providers/module-handler.ts index 125cf11b9..c17f6f0a2 100644 --- a/src/addon/mod/folder/providers/module-handler.ts +++ b/src/addon/mod/folder/providers/module-handler.ts @@ -60,7 +60,7 @@ export class AddonModFolderModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('folder'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_folder-handler', showDownloadButton: true, diff --git a/src/addon/mod/forum/providers/module-handler.ts b/src/addon/mod/forum/providers/module-handler.ts index 6a6d997ae..478ed249d 100644 --- a/src/addon/mod/forum/providers/module-handler.ts +++ b/src/addon/mod/forum/providers/module-handler.ts @@ -68,7 +68,7 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { const data: CoreCourseModuleHandlerData = { - icon: this.courseProvider.getModuleIconSrc('forum'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_forum-handler', showDownloadButton: true, diff --git a/src/addon/mod/glossary/providers/module-handler.ts b/src/addon/mod/glossary/providers/module-handler.ts index 99f3b3a33..5cfc21bd4 100644 --- a/src/addon/mod/glossary/providers/module-handler.ts +++ b/src/addon/mod/glossary/providers/module-handler.ts @@ -62,7 +62,7 @@ export class AddonModGlossaryModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('glossary'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_glossary-handler', showDownloadButton: true, diff --git a/src/addon/mod/imscp/providers/module-handler.ts b/src/addon/mod/imscp/providers/module-handler.ts index 6f581bdc1..d99d7ba76 100644 --- a/src/addon/mod/imscp/providers/module-handler.ts +++ b/src/addon/mod/imscp/providers/module-handler.ts @@ -61,7 +61,7 @@ export class AddonModImscpModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('imscp'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_imscp-handler', showDownloadButton: true, diff --git a/src/addon/mod/lesson/providers/module-handler.ts b/src/addon/mod/lesson/providers/module-handler.ts index db384d8bf..710578202 100644 --- a/src/addon/mod/lesson/providers/module-handler.ts +++ b/src/addon/mod/lesson/providers/module-handler.ts @@ -61,7 +61,7 @@ export class AddonModLessonModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('lesson'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_lesson-handler', showDownloadButton: true, diff --git a/src/addon/mod/lti/providers/module-handler.ts b/src/addon/mod/lti/providers/module-handler.ts index 5d623cc1b..85204e90e 100644 --- a/src/addon/mod/lti/providers/module-handler.ts +++ b/src/addon/mod/lti/providers/module-handler.ts @@ -71,7 +71,7 @@ export class AddonModLtiModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { const data: CoreCourseModuleHandlerData = { - icon: this.courseProvider.getModuleIconSrc('lti'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_lti-handler', action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { diff --git a/src/addon/mod/page/providers/module-handler.ts b/src/addon/mod/page/providers/module-handler.ts index dc5dd21ff..4a75ce269 100644 --- a/src/addon/mod/page/providers/module-handler.ts +++ b/src/addon/mod/page/providers/module-handler.ts @@ -61,7 +61,7 @@ export class AddonModPageModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('page'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_page-handler', showDownloadButton: true, diff --git a/src/addon/mod/quiz/providers/module-handler.ts b/src/addon/mod/quiz/providers/module-handler.ts index 3c4f27c60..9c821ec38 100644 --- a/src/addon/mod/quiz/providers/module-handler.ts +++ b/src/addon/mod/quiz/providers/module-handler.ts @@ -62,7 +62,7 @@ export class AddonModQuizModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('quiz'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_quiz-handler', showDownloadButton: true, diff --git a/src/addon/mod/resource/providers/module-handler.ts b/src/addon/mod/resource/providers/module-handler.ts index e6e9e6278..c29415ad7 100644 --- a/src/addon/mod/resource/providers/module-handler.ts +++ b/src/addon/mod/resource/providers/module-handler.ts @@ -78,7 +78,7 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { }; const handlerData: CoreCourseModuleHandlerData = { - icon: this.courseProvider.getModuleIconSrc(this.modName), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_resource-handler', showDownloadButton: true, @@ -162,6 +162,7 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { if (files && files.length) { const file = files[0]; + resourceData.icon = this.mimetypeUtils.getFileIcon(file.filename); if (options.showsize) { @@ -201,9 +202,8 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { } if (resourceData.icon == '') { - resourceData.icon = this.courseProvider.getModuleIconSrc(this.modName); + resourceData.icon = this.courseProvider.getModuleIconSrc(this.modName, module.modicon); } - resourceData.extra += extra.join(' '); return resourceData; diff --git a/src/addon/mod/scorm/providers/module-handler.ts b/src/addon/mod/scorm/providers/module-handler.ts index f5d2a649b..b096f7463 100644 --- a/src/addon/mod/scorm/providers/module-handler.ts +++ b/src/addon/mod/scorm/providers/module-handler.ts @@ -60,7 +60,7 @@ export class AddonModScormModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('scorm'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_scorm-handler', showDownloadButton: true, diff --git a/src/addon/mod/survey/providers/module-handler.ts b/src/addon/mod/survey/providers/module-handler.ts index cc84664c7..4725b6ea3 100644 --- a/src/addon/mod/survey/providers/module-handler.ts +++ b/src/addon/mod/survey/providers/module-handler.ts @@ -60,7 +60,7 @@ export class AddonModSurveyModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('survey'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_survey-handler', showDownloadButton: true, diff --git a/src/addon/mod/url/providers/module-handler.ts b/src/addon/mod/url/providers/module-handler.ts index 445c85b18..79c8c54f4 100644 --- a/src/addon/mod/url/providers/module-handler.ts +++ b/src/addon/mod/url/providers/module-handler.ts @@ -68,7 +68,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { // tslint:disable: no-this-assignment const handler = this; const handlerData = { - icon: this.courseProvider.getModuleIconSrc(this.modName), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_url-handler', showDownloadButton: false, @@ -122,7 +122,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { if (module.contents && module.contents[0]) { // Calculate the icon to use. handlerData.icon = this.urlProvider.guessIcon(module.contents[0].fileurl) || - this.courseProvider.getModuleIconSrc(this.modName); + this.courseProvider.getModuleIconSrc(this.modName, module.modicon); } }); diff --git a/src/addon/mod/wiki/providers/module-handler.ts b/src/addon/mod/wiki/providers/module-handler.ts index f36fc1bbb..72056f85b 100644 --- a/src/addon/mod/wiki/providers/module-handler.ts +++ b/src/addon/mod/wiki/providers/module-handler.ts @@ -61,7 +61,7 @@ export class AddonModWikiModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('wiki'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_wiki-handler', showDownloadButton: true, diff --git a/src/addon/mod/workshop/providers/module-handler.ts b/src/addon/mod/workshop/providers/module-handler.ts index 56ed78ded..11914daa9 100644 --- a/src/addon/mod/workshop/providers/module-handler.ts +++ b/src/addon/mod/workshop/providers/module-handler.ts @@ -60,7 +60,7 @@ export class AddonModWorkshopModuleHandler implements CoreCourseModuleHandler { */ getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { return { - icon: this.courseProvider.getModuleIconSrc('workshop'), + icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_workshop-handler', showDownloadButton: true, diff --git a/src/core/course/providers/course.ts b/src/core/course/providers/course.ts index c2660d101..f69b5063a 100644 --- a/src/core/course/providers/course.ts +++ b/src/core/course/providers/course.ts @@ -536,10 +536,18 @@ export class CoreCourseProvider { * Returns the source to a module icon. * * @param {string} moduleName The module name. + * @param {string} [modicon] The mod icon string to use in case we are not using a core activity. * @return {string} The IMG src. */ - getModuleIconSrc(moduleName: string): string { + getModuleIconSrc(moduleName: string, modicon?: string): string { + // @TODO: Check modicon url theme to apply other theme icons. + + // Use default icon on core themes. if (this.CORE_MODULES.indexOf(moduleName) < 0) { + if (modicon) { + return modicon; + } + moduleName = 'external-tool'; } diff --git a/src/core/course/providers/default-module.ts b/src/core/course/providers/default-module.ts index 04596a46e..f82e1b2d9 100644 --- a/src/core/course/providers/default-module.ts +++ b/src/core/course/providers/default-module.ts @@ -48,7 +48,7 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler { getData(module: any, courseId: number, sectionId: number): CoreCourseModuleHandlerData { // Return the default data. const defaultData: CoreCourseModuleHandlerData = { - icon: this.courseProvider.getModuleIconSrc(module.modname), + icon: this.courseProvider.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'core-course-default-handler core-course-module-' + module.modname + '-handler', action: (event: Event, navCtrl: NavController, module: any, courseId: number, options?: NavOptions): void => { diff --git a/src/core/course/providers/module-delegate.ts b/src/core/course/providers/module-delegate.ts index 52daed19e..f8d4aac72 100644 --- a/src/core/course/providers/module-delegate.ts +++ b/src/core/course/providers/module-delegate.ts @@ -313,10 +313,11 @@ export class CoreCourseModuleDelegate extends CoreDelegate { * Get the icon src for a certain type of module. * * @param {any} modname The name of the module type. + * @param {string} [modicon] The mod icon string. * @return {string} The icon src. */ - getModuleIconSrc(modname: string): string { - return this.executeFunctionOnEnabled(modname, 'getIconSrc') || this.courseProvider.getModuleIconSrc(modname); + getModuleIconSrc(modname: string, modicon?: string): string { + return this.executeFunctionOnEnabled(modname, 'getIconSrc') || this.courseProvider.getModuleIconSrc(modname, modicon); } /** diff --git a/src/core/grades/providers/helper.ts b/src/core/grades/providers/helper.ts index 7f2e5f4be..764d6ee7f 100644 --- a/src/core/grades/providers/helper.ts +++ b/src/core/grades/providers/helper.ts @@ -436,7 +436,8 @@ export class CoreGradesHelperProvider { if (typeof module[1] != 'undefined') { row['itemtype'] = 'mod'; row['itemmodule'] = module[1]; - row['image'] = this.courseProvider.getModuleIconSrc(module[1]); + row['image'] = this.courseProvider.getModuleIconSrc(module[1], + this.domUtils.convertToElement(text).querySelector('img').getAttribute('src')); } } else if (text.indexOf('src=') > -1) { const src = text.match(/src="([^"]*)"/); diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index 979a01980..320344365 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -346,6 +346,17 @@ export class CoreDomUtilsProvider { return data; } + /** + * Returns the attribute value of a string element. Only the first element will be selected. + * + * @param {string} html HTML element in string. + * @param {string} attribute Attribute to get. + * @return {string} Attribute value. + */ + getHTMLElementAttribute(html: string, attribute: string): string { + return this.convertToElement(html).children[0].getAttribute('src'); + } + /** * Returns height of an element. *