diff --git a/src/addons/block/recentlyaccesseditems/services/recentlyaccesseditems.ts b/src/addons/block/recentlyaccesseditems/services/recentlyaccesseditems.ts index eaafaebec..1a1c3c65b 100644 --- a/src/addons/block/recentlyaccesseditems/services/recentlyaccesseditems.ts +++ b/src/addons/block/recentlyaccesseditems/services/recentlyaccesseditems.ts @@ -54,15 +54,15 @@ export class AddonBlockRecentlyAccessedItemsProvider { const cmIds: number[] = []; - items = await Promise.all(items.map(async (item) => { + items = items.map((item) => { const modicon = item.icon && CoreDomUtils.getHTMLElementAttribute(item.icon, 'src'); - item.iconUrl = await CoreCourse.getModuleIconSrc(item.modname, modicon || undefined); + item.iconUrl = CoreCourse.getModuleIconSrc(item.modname, modicon || undefined); item.iconTitle = item.icon && CoreDomUtils.getHTMLElementAttribute(item.icon, 'title'); cmIds.push(item.cmid); return item; - })); + }); // Check if the viewed module should be updated for each activity. const lastViewedMap = await CoreCourse.getCertainModulesViewed(cmIds, site.getId()); diff --git a/src/addons/block/timeline/components/events/events.ts b/src/addons/block/timeline/components/events/events.ts index bdebff829..368c010e8 100644 --- a/src/addons/block/timeline/components/events/events.ts +++ b/src/addons/block/timeline/components/events/events.ts @@ -49,12 +49,12 @@ export class AddonBlockTimelineEventsComponent implements OnChanges { /** * @inheritdoc */ - async ngOnChanges(changes: {[name: string]: SimpleChange}): Promise { + ngOnChanges(changes: {[name: string]: SimpleChange}): void { this.showCourse = !this.course; if (changes.events || changes.from || changes.to) { if (this.events) { - const filteredEvents = await this.filterEventsByTime(); + const filteredEvents = this.filterEventsByTime(); this.empty = !filteredEvents || filteredEvents.length <= 0; const eventsByDay: Record = {}; @@ -88,7 +88,7 @@ export class AddonBlockTimelineEventsComponent implements OnChanges { * * @return Filtered events. */ - protected async filterEventsByTime(): Promise { + protected filterEventsByTime(): AddonBlockTimelineEvent[] { const start = AddonBlockTimeline.getDayStart(this.from); const end = this.to !== undefined ? AddonBlockTimeline.getDayStart(this.to) @@ -97,7 +97,7 @@ export class AddonBlockTimelineEventsComponent implements OnChanges { const now = CoreTimeUtils.timestamp(); const midnight = AddonBlockTimeline.getDayStart(); - return await Promise.all(this.events.filter((event) => { + return this.events.filter((event) => { if (start > event.timesort || (end && event.timesort >= end)) { return false; } @@ -114,13 +114,13 @@ export class AddonBlockTimelineEventsComponent implements OnChanges { // When filtering by overdue, we fetch all events due today, in case any have elapsed already and are overdue. // This means if filtering by overdue, some events fetched might not be required (eg if due later today). return (!this.overdue || event.overdue); - }).map(async (event) => { - event.iconUrl = await CoreCourse.getModuleIconSrc(event.icon.component); + }).map((event) => { + event.iconUrl = CoreCourse.getModuleIconSrc(event.icon.component); event.modulename = event.modulename || event.icon.component; event.iconTitle = CoreCourse.translateModuleName(event.modulename); return event; - })); + }); } /** diff --git a/src/addons/calendar/components/calendar/calendar.ts b/src/addons/calendar/components/calendar/calendar.ts index 82a1fc81f..1ff4753a3 100644 --- a/src/addons/calendar/components/calendar/calendar.ts +++ b/src/addons/calendar/components/calendar/calendar.ts @@ -529,9 +529,7 @@ class AddonCalendarMonthSlidesItemsManagerSource extends CoreSwipeSlidesDynamicI day.eventsFormated = day.eventsFormated || []; day.filteredEvents = day.filteredEvents || []; // Format online events. - const onlineEventsFormatted = await Promise.all( - day.events.map(async (event) => AddonCalendarHelper.formatEventData(event)), - ); + const onlineEventsFormatted = day.events.map((event) => AddonCalendarHelper.formatEventData(event)); day.eventsFormated = day.eventsFormated.concat(onlineEventsFormatted); diff --git a/src/addons/calendar/components/upcoming-events/upcoming-events.ts b/src/addons/calendar/components/upcoming-events/upcoming-events.ts index 8740e28fa..2c28089ca 100644 --- a/src/addons/calendar/components/upcoming-events/upcoming-events.ts +++ b/src/addons/calendar/components/upcoming-events/upcoming-events.ts @@ -165,7 +165,7 @@ export class AddonCalendarUpcomingEventsComponent implements OnInit, DoCheck, On async fetchEvents(): Promise { // Don't pass courseId and categoryId, we'll filter them locally. const result = await AddonCalendar.getUpcomingEvents(); - this.onlineEvents = await Promise.all(result.events.map((event) => AddonCalendarHelper.formatEventData(event))); + this.onlineEvents = result.events.map((event) => AddonCalendarHelper.formatEventData(event)); // Merge the online events with offline data. this.events = this.mergeEvents(); // Filter events by course. diff --git a/src/addons/calendar/pages/day/day.page.ts b/src/addons/calendar/pages/day/day.page.ts index b7d63ed0e..eea350110 100644 --- a/src/addons/calendar/pages/day/day.page.ts +++ b/src/addons/calendar/pages/day/day.page.ts @@ -669,9 +669,7 @@ class AddonCalendarDaySlidesItemsManagerSource extends CoreSwipeSlidesDynamicIte try { // Don't pass courseId and categoryId, we'll filter them locally. result = await AddonCalendar.getDayEvents(day.moment.year(), day.moment.month() + 1, day.moment.date()); - preloadedDay.onlineEvents = await Promise.all( - result.events.map((event) => AddonCalendarHelper.formatEventData(event)), - ); + preloadedDay.onlineEvents = result.events.map((event) => AddonCalendarHelper.formatEventData(event)); } catch (error) { // Allow navigating to non-cached days in offline (behave as if using emergency cache). if (CoreNetwork.isOnline()) { diff --git a/src/addons/calendar/pages/event/event.page.ts b/src/addons/calendar/pages/event/event.page.ts index b448e9280..ac9a3ac11 100644 --- a/src/addons/calendar/pages/event/event.page.ts +++ b/src/addons/calendar/pages/event/event.page.ts @@ -198,7 +198,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { // Get the event data. if (this.eventId >= 0) { const event = await AddonCalendar.getEventById(this.eventId); - this.event = await AddonCalendarHelper.formatEventData(event); + this.event = AddonCalendarHelper.formatEventData(event); } try { diff --git a/src/addons/calendar/services/calendar-helper.ts b/src/addons/calendar/services/calendar-helper.ts index dce3c6fc5..378fd4ef5 100644 --- a/src/addons/calendar/services/calendar-helper.ts +++ b/src/addons/calendar/services/calendar-helper.ts @@ -164,9 +164,9 @@ export class AddonCalendarHelperProvider { * * @param event Event to format. */ - async formatEventData( + formatEventData( event: AddonCalendarEvent | AddonCalendarEventBase | AddonCalendarGetEventsEvent, - ): Promise { + ): AddonCalendarEventToDisplay { const eventFormatted: AddonCalendarEventToDisplay = { ...event, @@ -181,7 +181,7 @@ export class AddonCalendarHelperProvider { }; if (event.modulename) { - eventFormatted.eventIcon = await CoreCourse.getModuleIconSrc(event.modulename); + eventFormatted.eventIcon = CoreCourse.getModuleIconSrc(event.modulename); eventFormatted.moduleIcon = eventFormatted.eventIcon; eventFormatted.iconTitle = CoreCourse.translateModuleName(event.modulename); } diff --git a/src/addons/mod/label/services/handlers/module.ts b/src/addons/mod/label/services/handlers/module.ts index ec9ce00a2..23209a2d1 100644 --- a/src/addons/mod/label/services/handlers/module.ts +++ b/src/addons/mod/label/services/handlers/module.ts @@ -46,7 +46,7 @@ export class AddonModLabelModuleHandlerService extends CoreModuleHandlerBase imp /** * @inheritdoc */ - async getData(module: CoreCourseModuleData): Promise { + getData(module: CoreCourseModuleData): CoreCourseModuleHandlerData { // Remove the description from the module so it isn't rendered twice. const title = module.description || ''; module.description = ''; diff --git a/src/addons/mod/resource/services/handlers/module.ts b/src/addons/mod/resource/services/handlers/module.ts index c6f7e9e82..a67fe7926 100644 --- a/src/addons/mod/resource/services/handlers/module.ts +++ b/src/addons/mod/resource/services/handlers/module.ts @@ -104,13 +104,11 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase // Ignore errors. }); - this.getIconSrc(module).then((icon) => { - handlerData.icon = icon; - - return; - }).catch(() => { + try { + handlerData.icon = this.getIconSrc(module); + } catch { // Ignore errors. - }); + } return handlerData; } @@ -227,13 +225,13 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase /** * @inheritdoc */ - async getIconSrc(module?: CoreCourseModuleData): Promise { + getIconSrc(module?: CoreCourseModuleData): string | undefined { if (!module) { return; } if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.0')) { - return await CoreCourse.getModuleIconSrc(module.modname, module.modicon); + return CoreCourse.getModuleIconSrc(module.modname, module.modicon); } let mimetypeIcon = ''; @@ -251,7 +249,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase mimetypeIcon = CoreMimetypeUtils.getFileIcon(file.filename || ''); } - return await CoreCourse.getModuleIconSrc(module.modname, module.modicon, mimetypeIcon); + return CoreCourse.getModuleIconSrc(module.modname, module.modicon, mimetypeIcon); } /** diff --git a/src/addons/mod/url/services/handlers/module.ts b/src/addons/mod/url/services/handlers/module.ts index b9978c872..44d3895a0 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 */ - async getData(module: CoreCourseModuleData): Promise { + getData(module: CoreCourseModuleData): CoreCourseModuleHandlerData { /** * Open the URL. @@ -80,7 +80,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple }; const handlerData: CoreCourseModuleHandlerData = { - icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), + icon: CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'addon-mod_url-handler', showDownloadButton: false, @@ -109,7 +109,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple }], }; - this.hideLinkButton(module).then(async (hideButton) => { + this.hideLinkButton(module).then((hideButton) => { if (!handlerData.buttons) { return; } @@ -120,7 +120,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple const icon = AddonModUrl.guessIcon(module.contents[0].fileurl); // Calculate the icon to use. - handlerData.icon = await CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon); + handlerData.icon = CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon); } return; diff --git a/src/core/features/course/classes/module-base-handler.ts b/src/core/features/course/classes/module-base-handler.ts index 0950a8d2a..1bdceb16e 100644 --- a/src/core/features/course/classes/module-base-handler.ts +++ b/src/core/features/course/classes/module-base-handler.ts @@ -34,14 +34,14 @@ export class CoreModuleHandlerBase implements Partial { /** * @inheritdoc */ - async getData( + getData( module: CoreCourseModuleData, courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars sectionId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars - ): Promise { + ): Promise | CoreCourseModuleHandlerData { return { - icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), + icon: CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'addon-mod_' + module.modname + '-handler', showDownloadButton: true, diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 9ad406cd8..e58699c2a 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -783,7 +783,7 @@ export class CoreCourseProvider { * @param modicon The mod icon string to use in case we are not using a core activity. * @return The IMG src. */ - async getModuleIconSrc(moduleName: string, modicon?: string, mimetypeIcon = ''): Promise { + getModuleIconSrc(moduleName: string, modicon?: string, mimetypeIcon = ''): string { if (mimetypeIcon) { return mimetypeIcon; } diff --git a/src/core/features/course/services/handlers/default-module.ts b/src/core/features/course/services/handlers/default-module.ts index 13f40a844..3c25246f1 100644 --- a/src/core/features/course/services/handlers/default-module.ts +++ b/src/core/features/course/services/handlers/default-module.ts @@ -41,12 +41,12 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler { /** * @inheritdoc */ - async getData( + getData( module: CoreCourseModuleData, - ): Promise { + ): CoreCourseModuleHandlerData { // Return the default data. const defaultData: CoreCourseModuleHandlerData = { - icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), + icon: CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'core-course-default-handler core-course-module-' + module.modname + '-handler', action: async (event: Event, module: CoreCourseModuleData, courseId: number, options?: CoreNavigationOptions) => { diff --git a/src/core/features/course/services/module-delegate.ts b/src/core/features/course/services/module-delegate.ts index f2faeac31..89bcd8ec7 100644 --- a/src/core/features/course/services/module-delegate.ts +++ b/src/core/features/course/services/module-delegate.ts @@ -391,7 +391,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate { const icon = await this.executeFunctionOnEnabled>(modname, 'getIconSrc', [module]); - return icon || await CoreCourse.getModuleIconSrc(modname, modicon) || ''; + return icon || CoreCourse.getModuleIconSrc(modname, modicon) || ''; } /** diff --git a/src/core/features/grades/pages/course/course.page.ts b/src/core/features/grades/pages/course/course.page.ts index cdecf5322..f3d57d541 100644 --- a/src/core/features/grades/pages/course/course.page.ts +++ b/src/core/features/grades/pages/course/course.page.ts @@ -191,7 +191,7 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { */ private async fetchGrades(): Promise { const table = await CoreGrades.getCourseGradesTable(this.courseId, this.userId); - const formattedTable = await CoreGradesHelper.formatGradesTable(table); + const formattedTable = CoreGradesHelper.formatGradesTable(table); this.title = formattedTable.rows[0]?.gradeitem ?? Translate.instant('core.grades.grades'); this.columns = formattedTable.columns; diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index 1720fd445..b419aff25 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -98,7 +98,7 @@ export class CoreGradesHelperProvider { * @param tableRow JSON object representing row of grades table data. * @return Formatted row object. */ - protected async formatGradeRowForTable(tableRow: CoreGradesTableRow): Promise { + protected formatGradeRowForTable(tableRow: CoreGradesTableRow): CoreGradesFormattedTableRow { const row: CoreGradesFormattedTableRow = {}; for (let name in tableRow) { const column: CoreGradesTableColumn = tableRow[name]; @@ -116,7 +116,7 @@ export class CoreGradesHelperProvider { row.colspan = itemNameColumn.colspan; row.rowspan = tableRow.leader?.rowspan || 1; - await this.setRowIcon(row, content); + this.setRowIcon(row, content); row.rowclass = itemNameColumn.class.indexOf('leveleven') < 0 ? 'odd' : 'even'; row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : ''; row.rowclass += itemNameColumn.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : ''; @@ -182,7 +182,7 @@ export class CoreGradesHelperProvider { * @param table JSON object representing a table with data. * @return Formatted HTML table. */ - async formatGradesTable(table: CoreGradesTable): Promise { + formatGradesTable(table: CoreGradesTable): CoreGradesFormattedTable { const maxDepth = table.maxdepth; const formatted: CoreGradesFormattedTable = { columns: [], @@ -202,7 +202,7 @@ export class CoreGradesHelperProvider { feedback: false, contributiontocoursetotal: false, }; - formatted.rows = await Promise.all(table.tabledata.map(row => this.formatGradeRowForTable(row))); + formatted.rows = table.tabledata.map(row => this.formatGradeRowForTable(row)); // Get a row with some info. let normalRow = formatted.rows.find( @@ -474,7 +474,7 @@ export class CoreGradesHelperProvider { // Find href containing "/mod/xxx/xxx.php". const regex = /href="([^"]*\/mod\/[^"|^/]*\/[^"|^.]*\.php[^"]*)/; - return await Promise.all(table.tabledata.filter((row) => { + return table.tabledata.filter((row) => { if (row.itemname && row.itemname.content) { const matches = row.itemname.content.match(regex); @@ -486,7 +486,7 @@ export class CoreGradesHelperProvider { } return false; - }).map((row) => this.formatGradeRowForTable(row))); + }).map((row) => this.formatGradeRowForTable(row)); } /** @@ -589,7 +589,7 @@ export class CoreGradesHelperProvider { * @param text HTML where the image will be rendered. * @return Row object with the image. */ - protected async setRowIcon(row: T, text: string): Promise { + protected setRowIcon(row: T, text: string): T { text = text.replace('%2F', '/').replace('%2f', '/'); if (text.indexOf('/agg_mean') > -1) { row.itemtype = 'agg_mean'; @@ -621,7 +621,7 @@ export class CoreGradesHelperProvider { row.itemtype = 'mod'; row.itemmodule = module[1]; row.iconAlt = CoreCourse.translateModuleName(row.itemmodule) || ''; - row.image = await CoreCourse.getModuleIconSrc( + row.image = CoreCourse.getModuleIconSrc( module[1], CoreDomUtils.convertToElement(text).querySelector('img')?.getAttribute('src') ?? undefined, ); diff --git a/src/core/features/siteplugins/classes/handlers/module-handler.ts b/src/core/features/siteplugins/classes/handlers/module-handler.ts index 5b90fbee7..01ae7b0c9 100644 --- a/src/core/features/siteplugins/classes/handlers/module-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-handler.ts @@ -76,7 +76,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp module.description = ''; return { - icon: await CoreCourse.getModuleIconSrc(module.modname, icon), + icon: CoreCourse.getModuleIconSrc(module.modname, icon), title: title || '', a11yTitle: '', class: this.handlerSchema.displaydata?.class, @@ -87,7 +87,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp const showDowloadButton = this.handlerSchema.downloadbutton; const handlerData: CoreCourseModuleHandlerData = { title: module.name, - icon: await CoreCourse.getModuleIconSrc(module.modname, icon), + icon: CoreCourse.getModuleIconSrc(module.modname, icon), class: this.handlerSchema.displaydata?.class, showDownloadButton: showDowloadButton !== undefined ? showDowloadButton : hasOffline, };