Merge pull request #1650 from crazyserver/MOBILE-2779

MOBILE-2779 course: Display the icon of unsupported activities
main
Juan Leyva 2018-12-10 17:05:57 +01:00 committed by GitHub
commit 6276a888a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 59 additions and 33 deletions

View File

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

View File

@ -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;
});

View File

@ -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,

View File

@ -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,

View File

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

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

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

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -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);
}
});

View File

@ -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,

View File

@ -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,

View File

@ -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';
}

View File

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

View File

@ -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);
}
/**

View File

@ -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="([^"]*)"/);

View File

@ -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.
*