From ad5fc0b1b7160db2bfeee6606c2154b258568a9c Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 12 Apr 2023 12:50:28 +0200 Subject: [PATCH] MOBILE-4308 core: Apply no filter to complex icons --- .../mod/resource/services/handlers/module.ts | 9 ++++++++ .../mod/url/services/handlers/module.ts | 23 +++++++++++-------- src/core/components/mod-icon/mod-icon.ts | 20 ++++++++-------- .../features/grades/pages/course/course.html | 3 +-- .../grades/pages/course/course.page.ts | 9 -------- .../features/grades/services/grades-helper.ts | 2 -- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/addons/mod/resource/services/handlers/module.ts b/src/addons/mod/resource/services/handlers/module.ts index 369195644..bd4a543ff 100644 --- a/src/addons/mod/resource/services/handlers/module.ts +++ b/src/addons/mod/resource/services/handlers/module.ts @@ -258,5 +258,14 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase return AddonModResourceIndexComponent; } + /** + * @inheritdoc + */ + iconIsShape(module?: CoreCourseModuleData | undefined, modicon?: string | undefined): boolean | undefined { + const iconUrl = module?.modicon ?? modicon; + + return !iconUrl?.startsWith('assets/img/files/'); + } + } export const AddonModResourceModuleHandler = makeSingleton(AddonModResourceModuleHandlerService); diff --git a/src/addons/mod/url/services/handlers/module.ts b/src/addons/mod/url/services/handlers/module.ts index fae5d0d57..60c044bf8 100644 --- a/src/addons/mod/url/services/handlers/module.ts +++ b/src/addons/mod/url/services/handlers/module.ts @@ -55,7 +55,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple /** * @inheritdoc */ - getData(module: CoreCourseModuleData): CoreCourseModuleHandlerData { + async getData(module: CoreCourseModuleData): Promise { /** * Open the URL. @@ -109,11 +109,9 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple }], }; - this.hideLinkButton(module).then((hideButton) => { - if (!handlerData.buttons) { - return; - } + const hideButton = await CoreUtils.ignoreErrors(this.hideLinkButton(module)); + if (handlerData.buttons && hideButton !== undefined) { handlerData.buttons[0].hidden = hideButton; if (module.contents && module.contents[0]) { @@ -122,11 +120,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple // Calculate the icon to use. handlerData.icon = CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon); } - - return; - }).catch(() => { - // Ignore errors. - }); + } return handlerData; } @@ -193,5 +187,14 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple return this.shouldOpenLink(module); } + /** + * @inheritdoc + */ + iconIsShape(module?: CoreCourseModuleData | undefined, modicon?: string | undefined): boolean | undefined { + const iconUrl = module?.modicon ?? modicon; + + return !iconUrl?.startsWith('assets/img/files/'); + } + } export const AddonModUrlModuleHandler = makeSingleton(AddonModUrlModuleHandlerService); diff --git a/src/core/components/mod-icon/mod-icon.ts b/src/core/components/mod-icon/mod-icon.ts index 6cb43d41a..29bec0fb9 100644 --- a/src/core/components/mod-icon/mod-icon.ts +++ b/src/core/components/mod-icon/mod-icon.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CoreConstants, ModPurpose } from '@/core/constants'; -import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChange } from '@angular/core'; +import { Component, ElementRef, Input, OnChanges, OnInit, SimpleChange } from '@angular/core'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreSites } from '@services/sites'; @@ -35,13 +35,11 @@ export class CoreModIconComponent implements OnInit, OnChanges { @Input() fallbackTranslation = ''; // Fallback translation string if cannot auto translate. @Input() componentId?: number; // Component Id for external icons. @Input() modicon?: string; // Module icon url or local url. - @Input() noFilter?: boolean; // Whether to disable filters. @Input() showAlt = true; // Show alt otherwise it's only presentation icon. @Input() purpose: ModPurpose = ModPurpose.MOD_PURPOSE_OTHER; // Purpose of the module. - @Output() failedLoading = new EventEmitter(); - icon = ''; + noFilter = false; modNameTranslated = ''; isLocalUrl = true; linkIconWithComponent = false; @@ -81,22 +79,22 @@ export class CoreModIconComponent implements OnInit, OnChanges { } } - this.setIcon(); + await this.setIcon(); } /** * @inheritdoc */ - ngOnChanges(changes: { [name: string]: SimpleChange }): void { + async ngOnChanges(changes: { [name: string]: SimpleChange }): Promise { if (changes && changes.modicon && changes.modicon.previousValue !== undefined) { - this.setIcon(); + await this.setIcon(); } } /** * Set icon. */ - setIcon(): void { + async setIcon(): Promise { this.icon = this.modicon || this.icon; this.isLocalUrl = this.icon.startsWith(assetsPath); @@ -108,6 +106,9 @@ export class CoreModIconComponent implements OnInit, OnChanges { !!this.componentId && !this.isLocalUrl && !this.icon.match('/theme/image.php/[^/]+/' + this.modname + '/[-0-9]*/'); + + const iconIsShape = await CoreCourseModuleDelegate.moduleIconIsShape(this.modname, this.icon); + this.noFilter = iconIsShape === false; } /** @@ -126,8 +127,7 @@ export class CoreModIconComponent implements OnInit, OnChanges { } this.icon = path + moduleName + '.svg'; - - this.failedLoading.emit(); + this.noFilter = false; } } diff --git a/src/core/features/grades/pages/course/course.html b/src/core/features/grades/pages/course/course.html index 44236689c..70cc02b61 100644 --- a/src/core/features/grades/pages/course/course.html +++ b/src/core/features/grades/pages/course/course.html @@ -48,8 +48,7 @@ + [modname]="row.itemmodule"> diff --git a/src/core/features/grades/pages/course/course.page.ts b/src/core/features/grades/pages/course/course.page.ts index 508d99488..c70adc1a8 100644 --- a/src/core/features/grades/pages/course/course.page.ts +++ b/src/core/features/grades/pages/course/course.page.ts @@ -239,13 +239,4 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { infiniteComplete && infiniteComplete(); } - /** - * Handle row image failed loading. - * - * @param row Row data. - */ - failedLoadingRowImage(row: CoreGradesFormattedTableRow): void { - delete row.imageIsShape; - } - } diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index 60e9aa9e4..05f78ddf2 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -693,7 +693,6 @@ export class CoreGradesHelperProvider { row.itemmodule = modname; row.iconAlt = CoreCourse.translateModuleName(row.itemmodule) || ''; row.image = await CoreCourseModuleDelegate.getModuleIconSrc(modname, modicon); - row.imageIsShape = await CoreCourseModuleDelegate.moduleIconIsShape(modname, modicon); } } else { if (row.rowspan && row.rowspan > 1) { @@ -806,7 +805,6 @@ export type CoreGradesFormattedRowCommonData = { rowclass?: string; itemtype?: string; image?: string; - imageIsShape?: boolean; itemmodule?: string; iconAlt?: string; rowspan?: number;