forked from EVOgeek/Vmeda.Online
		
	MOBILE-3811 resource: Remove mimetype icons from resource only on 4.0+
This partially reverts commit 96b172c42ca216aacc986502eb628e5a911d0671.
This commit is contained in:
		
							parent
							
								
									8b67def43c
								
							
						
					
					
						commit
						82419c3f50
					
				@ -23,6 +23,7 @@ import { CoreConstants, ModPurpose } 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 { CoreCourseModuleData } from '@features/course/services/course-helper';
 | 
					import { CoreCourseModuleData } from '@features/course/services/course-helper';
 | 
				
			||||||
 | 
					import { CoreIonicColorNames } from '@singletons/colors';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Handler to support forum modules.
 | 
					 * Handler to support forum modules.
 | 
				
			||||||
@ -58,7 +59,7 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
 | 
				
			|||||||
        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) {
 | 
				
			||||||
            data.extraBadgeColor = '';
 | 
					            data.extraBadgeColor = undefined;
 | 
				
			||||||
            const match = />(\d+)[^<]+/.exec(module.afterlink);
 | 
					            const match = />(\d+)[^<]+/.exec(module.afterlink);
 | 
				
			||||||
            data.extraBadge = match ? Translate.instant('addon.mod_forum.unreadpostsnumber', { $a : match[1] }) : '';
 | 
					            data.extraBadge = match ? Translate.instant('addon.mod_forum.unreadpostsnumber', { $a : match[1] }) : '';
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
@ -112,7 +113,7 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        data.extraBadge = Translate.instant('core.loading');
 | 
					        data.extraBadge = Translate.instant('core.loading');
 | 
				
			||||||
        data.extraBadgeColor = 'light';
 | 
					        data.extraBadgeColor = CoreIonicColorNames.DARK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await CoreUtils.ignoreErrors(AddonModForum.invalidateForumData(courseId));
 | 
					        await CoreUtils.ignoreErrors(AddonModForum.invalidateForumData(courseId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -120,7 +121,7 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
 | 
				
			|||||||
            // Handle unread posts.
 | 
					            // Handle unread posts.
 | 
				
			||||||
            const forum = await AddonModForum.getForum(courseId, moduleId, { siteId });
 | 
					            const forum = await AddonModForum.getForum(courseId, moduleId, { siteId });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            data.extraBadgeColor = '';
 | 
					            data.extraBadgeColor = undefined;
 | 
				
			||||||
            data.extraBadge = forum.unreadpostscount
 | 
					            data.extraBadge = forum.unreadpostscount
 | 
				
			||||||
                ? Translate.instant(
 | 
					                ? Translate.instant(
 | 
				
			||||||
                    'addon.mod_forum.unreadpostsnumber',
 | 
					                    'addon.mod_forum.unreadpostsnumber',
 | 
				
			||||||
@ -129,7 +130,7 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
 | 
				
			|||||||
                : '';
 | 
					                : '';
 | 
				
			||||||
        } catch {
 | 
					        } catch {
 | 
				
			||||||
            // Ignore errors.
 | 
					            // Ignore errors.
 | 
				
			||||||
            data.extraBadgeColor = '';
 | 
					            data.extraBadgeColor = undefined;
 | 
				
			||||||
            data.extraBadge = '';
 | 
					            data.extraBadge = '';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@ import { CoreCourseModuleData } 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';
 | 
				
			||||||
import { CoreFileHelper } from '@services/file-helper';
 | 
					import { CoreFileHelper } from '@services/file-helper';
 | 
				
			||||||
 | 
					import { CoreSites } from '@services/sites';
 | 
				
			||||||
import { CoreMimetypeUtils } from '@services/utils/mimetype';
 | 
					import { CoreMimetypeUtils } from '@services/utils/mimetype';
 | 
				
			||||||
import { CoreTextUtils } from '@services/utils/text';
 | 
					import { CoreTextUtils } from '@services/utils/text';
 | 
				
			||||||
import { CoreTimeUtils } from '@services/utils/time';
 | 
					import { CoreTimeUtils } from '@services/utils/time';
 | 
				
			||||||
@ -95,7 +96,14 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.getResourceData(module, courseId, handlerData).then((extra) => {
 | 
					        this.getResourceData(module, courseId, handlerData).then((extra) => {
 | 
				
			||||||
            handlerData.extraBadge = extra;
 | 
					            handlerData.extraBadge = extra;
 | 
				
			||||||
            handlerData.extraBadgeColor = '';
 | 
					
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }).catch(() => {
 | 
				
			||||||
 | 
					            // Ignore errors.
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.getIconSrc(module).then((icon) => {
 | 
				
			||||||
 | 
					            handlerData.icon = icon;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }).catch(() => {
 | 
					        }).catch(() => {
 | 
				
			||||||
@ -214,6 +222,36 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
 | 
				
			|||||||
        return extra.join(' ');
 | 
					        return extra.join(' ');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @inheritdoc
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    async getIconSrc(module?: CoreCourseModuleData): Promise<string | undefined> {
 | 
				
			||||||
 | 
					        if (!module) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.0')) {
 | 
				
			||||||
 | 
					            return await CoreCourse.getModuleIconSrc(module.modname, module.modicon);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let mimetypeIcon = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (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
 | 
					     * @inheritdoc
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,7 @@ import { CoreSites } from '@services/sites';
 | 
				
			|||||||
import { makeSingleton } from '@singletons';
 | 
					import { makeSingleton } from '@singletons';
 | 
				
			||||||
import { CoreCourseModuleData } from './course-helper';
 | 
					import { CoreCourseModuleData } from './course-helper';
 | 
				
			||||||
import { CoreNavigationOptions } from '@services/navigator';
 | 
					import { CoreNavigationOptions } from '@services/navigator';
 | 
				
			||||||
 | 
					import { CoreIonicColorNames } from '@singletons/colors';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Interface that all course module handlers must implement.
 | 
					 * Interface that all course module handlers must implement.
 | 
				
			||||||
@ -146,7 +147,7 @@ export interface CoreCourseModuleHandlerData {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The color of the extra badge. Default: primary.
 | 
					     * The color of the extra badge. Default: primary.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    extraBadgeColor?: string;
 | 
					    extraBadgeColor?: CoreIonicColorNames;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Whether to display a button to download/refresh the module if it's downloadable.
 | 
					     * Whether to display a button to download/refresh the module if it's downloadable.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user