MOBILE-4038 icon: Revert getModuleIconSrc to sync

Reverted from 1c0a86d045
main
Noel De Martin 2022-06-09 13:19:22 +02:00
parent e7bd014848
commit 8dd0ef41a1
17 changed files with 48 additions and 54 deletions

View File

@ -54,15 +54,15 @@ export class AddonBlockRecentlyAccessedItemsProvider {
const cmIds: number[] = []; const cmIds: number[] = [];
items = await Promise.all(items.map(async (item) => { items = items.map((item) => {
const modicon = item.icon && CoreDomUtils.getHTMLElementAttribute(item.icon, 'src'); 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'); item.iconTitle = item.icon && CoreDomUtils.getHTMLElementAttribute(item.icon, 'title');
cmIds.push(item.cmid); cmIds.push(item.cmid);
return item; return item;
})); });
// Check if the viewed module should be updated for each activity. // Check if the viewed module should be updated for each activity.
const lastViewedMap = await CoreCourse.getCertainModulesViewed(cmIds, site.getId()); const lastViewedMap = await CoreCourse.getCertainModulesViewed(cmIds, site.getId());

View File

@ -49,12 +49,12 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
/** /**
* @inheritdoc * @inheritdoc
*/ */
async ngOnChanges(changes: {[name: string]: SimpleChange}): Promise<void> { ngOnChanges(changes: {[name: string]: SimpleChange}): void {
this.showCourse = !this.course; this.showCourse = !this.course;
if (changes.events || changes.from || changes.to) { if (changes.events || changes.from || changes.to) {
if (this.events) { if (this.events) {
const filteredEvents = await this.filterEventsByTime(); const filteredEvents = this.filterEventsByTime();
this.empty = !filteredEvents || filteredEvents.length <= 0; this.empty = !filteredEvents || filteredEvents.length <= 0;
const eventsByDay: Record<number, AddonBlockTimelineEvent[]> = {}; const eventsByDay: Record<number, AddonBlockTimelineEvent[]> = {};
@ -88,7 +88,7 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
* *
* @return Filtered events. * @return Filtered events.
*/ */
protected async filterEventsByTime(): Promise<AddonBlockTimelineEvent[]> { protected filterEventsByTime(): AddonBlockTimelineEvent[] {
const start = AddonBlockTimeline.getDayStart(this.from); const start = AddonBlockTimeline.getDayStart(this.from);
const end = this.to !== undefined const end = this.to !== undefined
? AddonBlockTimeline.getDayStart(this.to) ? AddonBlockTimeline.getDayStart(this.to)
@ -97,7 +97,7 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
const now = CoreTimeUtils.timestamp(); const now = CoreTimeUtils.timestamp();
const midnight = AddonBlockTimeline.getDayStart(); 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)) { if (start > event.timesort || (end && event.timesort >= end)) {
return false; 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. // 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). // This means if filtering by overdue, some events fetched might not be required (eg if due later today).
return (!this.overdue || event.overdue); return (!this.overdue || event.overdue);
}).map(async (event) => { }).map((event) => {
event.iconUrl = await CoreCourse.getModuleIconSrc(event.icon.component); event.iconUrl = CoreCourse.getModuleIconSrc(event.icon.component);
event.modulename = event.modulename || event.icon.component; event.modulename = event.modulename || event.icon.component;
event.iconTitle = CoreCourse.translateModuleName(event.modulename); event.iconTitle = CoreCourse.translateModuleName(event.modulename);
return event; return event;
})); });
} }
/** /**

View File

@ -529,9 +529,7 @@ class AddonCalendarMonthSlidesItemsManagerSource extends CoreSwipeSlidesDynamicI
day.eventsFormated = day.eventsFormated || []; day.eventsFormated = day.eventsFormated || [];
day.filteredEvents = day.filteredEvents || []; day.filteredEvents = day.filteredEvents || [];
// Format online events. // Format online events.
const onlineEventsFormatted = await Promise.all( const onlineEventsFormatted = day.events.map((event) => AddonCalendarHelper.formatEventData(event));
day.events.map(async (event) => AddonCalendarHelper.formatEventData(event)),
);
day.eventsFormated = day.eventsFormated.concat(onlineEventsFormatted); day.eventsFormated = day.eventsFormated.concat(onlineEventsFormatted);

View File

@ -165,7 +165,7 @@ export class AddonCalendarUpcomingEventsComponent implements OnInit, DoCheck, On
async fetchEvents(): Promise<void> { async fetchEvents(): Promise<void> {
// Don't pass courseId and categoryId, we'll filter them locally. // Don't pass courseId and categoryId, we'll filter them locally.
const result = await AddonCalendar.getUpcomingEvents(); 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. // Merge the online events with offline data.
this.events = this.mergeEvents(); this.events = this.mergeEvents();
// Filter events by course. // Filter events by course.

View File

@ -669,9 +669,7 @@ class AddonCalendarDaySlidesItemsManagerSource extends CoreSwipeSlidesDynamicIte
try { try {
// Don't pass courseId and categoryId, we'll filter them locally. // 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()); result = await AddonCalendar.getDayEvents(day.moment.year(), day.moment.month() + 1, day.moment.date());
preloadedDay.onlineEvents = await Promise.all( preloadedDay.onlineEvents = result.events.map((event) => AddonCalendarHelper.formatEventData(event));
result.events.map((event) => AddonCalendarHelper.formatEventData(event)),
);
} catch (error) { } catch (error) {
// Allow navigating to non-cached days in offline (behave as if using emergency cache). // Allow navigating to non-cached days in offline (behave as if using emergency cache).
if (CoreNetwork.isOnline()) { if (CoreNetwork.isOnline()) {

View File

@ -198,7 +198,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
// Get the event data. // Get the event data.
if (this.eventId >= 0) { if (this.eventId >= 0) {
const event = await AddonCalendar.getEventById(this.eventId); const event = await AddonCalendar.getEventById(this.eventId);
this.event = await AddonCalendarHelper.formatEventData(event); this.event = AddonCalendarHelper.formatEventData(event);
} }
try { try {

View File

@ -164,9 +164,9 @@ export class AddonCalendarHelperProvider {
* *
* @param event Event to format. * @param event Event to format.
*/ */
async formatEventData( formatEventData(
event: AddonCalendarEvent | AddonCalendarEventBase | AddonCalendarGetEventsEvent, event: AddonCalendarEvent | AddonCalendarEventBase | AddonCalendarGetEventsEvent,
): Promise<AddonCalendarEventToDisplay> { ): AddonCalendarEventToDisplay {
const eventFormatted: AddonCalendarEventToDisplay = { const eventFormatted: AddonCalendarEventToDisplay = {
...event, ...event,
@ -181,7 +181,7 @@ export class AddonCalendarHelperProvider {
}; };
if (event.modulename) { if (event.modulename) {
eventFormatted.eventIcon = await CoreCourse.getModuleIconSrc(event.modulename); eventFormatted.eventIcon = CoreCourse.getModuleIconSrc(event.modulename);
eventFormatted.moduleIcon = eventFormatted.eventIcon; eventFormatted.moduleIcon = eventFormatted.eventIcon;
eventFormatted.iconTitle = CoreCourse.translateModuleName(event.modulename); eventFormatted.iconTitle = CoreCourse.translateModuleName(event.modulename);
} }

View File

@ -46,7 +46,7 @@ export class AddonModLabelModuleHandlerService extends CoreModuleHandlerBase imp
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getData(module: CoreCourseModuleData): Promise<CoreCourseModuleHandlerData> { getData(module: CoreCourseModuleData): CoreCourseModuleHandlerData {
// Remove the description from the module so it isn't rendered twice. // Remove the description from the module so it isn't rendered twice.
const title = module.description || ''; const title = module.description || '';
module.description = ''; module.description = '';

View File

@ -104,13 +104,11 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
// Ignore errors. // Ignore errors.
}); });
this.getIconSrc(module).then((icon) => { try {
handlerData.icon = icon; handlerData.icon = this.getIconSrc(module);
} catch {
return;
}).catch(() => {
// Ignore errors. // Ignore errors.
}); }
return handlerData; return handlerData;
} }
@ -227,13 +225,13 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getIconSrc(module?: CoreCourseModuleData): Promise<string | undefined> { getIconSrc(module?: CoreCourseModuleData): string | undefined {
if (!module) { if (!module) {
return; return;
} }
if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.0')) { if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.0')) {
return await CoreCourse.getModuleIconSrc(module.modname, module.modicon); return CoreCourse.getModuleIconSrc(module.modname, module.modicon);
} }
let mimetypeIcon = ''; let mimetypeIcon = '';
@ -251,7 +249,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
mimetypeIcon = CoreMimetypeUtils.getFileIcon(file.filename || ''); mimetypeIcon = CoreMimetypeUtils.getFileIcon(file.filename || '');
} }
return await CoreCourse.getModuleIconSrc(module.modname, module.modicon, mimetypeIcon); return CoreCourse.getModuleIconSrc(module.modname, module.modicon, mimetypeIcon);
} }
/** /**

View File

@ -55,7 +55,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getData(module: CoreCourseModuleData): Promise<CoreCourseModuleHandlerData> { getData(module: CoreCourseModuleData): CoreCourseModuleHandlerData {
/** /**
* Open the URL. * Open the URL.
@ -80,7 +80,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
}; };
const handlerData: CoreCourseModuleHandlerData = { const handlerData: CoreCourseModuleHandlerData = {
icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), icon: CoreCourse.getModuleIconSrc(module.modname, module.modicon),
title: module.name, title: module.name,
class: 'addon-mod_url-handler', class: 'addon-mod_url-handler',
showDownloadButton: false, 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) { if (!handlerData.buttons) {
return; return;
} }
@ -120,7 +120,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
const icon = AddonModUrl.guessIcon(module.contents[0].fileurl); const icon = AddonModUrl.guessIcon(module.contents[0].fileurl);
// Calculate the icon to use. // 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; return;

View File

@ -34,14 +34,14 @@ export class CoreModuleHandlerBase implements Partial<CoreCourseModuleHandler> {
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getData( getData(
module: CoreCourseModuleData, module: CoreCourseModuleData,
courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
sectionId?: 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 forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<CoreCourseModuleHandlerData> { ): Promise<CoreCourseModuleHandlerData> | CoreCourseModuleHandlerData {
return { return {
icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), icon: CoreCourse.getModuleIconSrc(module.modname, module.modicon),
title: module.name, title: module.name,
class: 'addon-mod_' + module.modname + '-handler', class: 'addon-mod_' + module.modname + '-handler',
showDownloadButton: true, showDownloadButton: true,

View File

@ -783,7 +783,7 @@ export class CoreCourseProvider {
* @param modicon The mod icon string to use in case we are not using a core activity. * @param modicon The mod icon string to use in case we are not using a core activity.
* @return The IMG src. * @return The IMG src.
*/ */
async getModuleIconSrc(moduleName: string, modicon?: string, mimetypeIcon = ''): Promise<string> { getModuleIconSrc(moduleName: string, modicon?: string, mimetypeIcon = ''): string {
if (mimetypeIcon) { if (mimetypeIcon) {
return mimetypeIcon; return mimetypeIcon;
} }

View File

@ -41,12 +41,12 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler {
/** /**
* @inheritdoc * @inheritdoc
*/ */
async getData( getData(
module: CoreCourseModuleData, module: CoreCourseModuleData,
): Promise<CoreCourseModuleHandlerData> { ): CoreCourseModuleHandlerData {
// Return the default data. // Return the default data.
const defaultData: CoreCourseModuleHandlerData = { const defaultData: CoreCourseModuleHandlerData = {
icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), icon: CoreCourse.getModuleIconSrc(module.modname, module.modicon),
title: module.name, title: module.name,
class: 'core-course-default-handler core-course-module-' + module.modname + '-handler', class: 'core-course-default-handler core-course-module-' + module.modname + '-handler',
action: async (event: Event, module: CoreCourseModuleData, courseId: number, options?: CoreNavigationOptions) => { action: async (event: Event, module: CoreCourseModuleData, courseId: number, options?: CoreNavigationOptions) => {

View File

@ -391,7 +391,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
async getModuleIconSrc(modname: string, modicon?: string, module?: CoreCourseModuleData): Promise<string> { async getModuleIconSrc(modname: string, modicon?: string, module?: CoreCourseModuleData): Promise<string> {
const icon = await this.executeFunctionOnEnabled<Promise<string>>(modname, 'getIconSrc', [module]); const icon = await this.executeFunctionOnEnabled<Promise<string>>(modname, 'getIconSrc', [module]);
return icon || await CoreCourse.getModuleIconSrc(modname, modicon) || ''; return icon || CoreCourse.getModuleIconSrc(modname, modicon) || '';
} }
/** /**

View File

@ -191,7 +191,7 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy {
*/ */
private async fetchGrades(): Promise<void> { private async fetchGrades(): Promise<void> {
const table = await CoreGrades.getCourseGradesTable(this.courseId, this.userId); 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.title = formattedTable.rows[0]?.gradeitem ?? Translate.instant('core.grades.grades');
this.columns = formattedTable.columns; this.columns = formattedTable.columns;

View File

@ -98,7 +98,7 @@ export class CoreGradesHelperProvider {
* @param tableRow JSON object representing row of grades table data. * @param tableRow JSON object representing row of grades table data.
* @return Formatted row object. * @return Formatted row object.
*/ */
protected async formatGradeRowForTable(tableRow: CoreGradesTableRow): Promise<CoreGradesFormattedTableRow> { protected formatGradeRowForTable(tableRow: CoreGradesTableRow): CoreGradesFormattedTableRow {
const row: CoreGradesFormattedTableRow = {}; const row: CoreGradesFormattedTableRow = {};
for (let name in tableRow) { for (let name in tableRow) {
const column: CoreGradesTableColumn = tableRow[name]; const column: CoreGradesTableColumn = tableRow[name];
@ -116,7 +116,7 @@ export class CoreGradesHelperProvider {
row.colspan = itemNameColumn.colspan; row.colspan = itemNameColumn.colspan;
row.rowspan = tableRow.leader?.rowspan || 1; 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('leveleven') < 0 ? 'odd' : 'even';
row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : ''; row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : '';
row.rowclass += itemNameColumn.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : ''; 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. * @param table JSON object representing a table with data.
* @return Formatted HTML table. * @return Formatted HTML table.
*/ */
async formatGradesTable(table: CoreGradesTable): Promise<CoreGradesFormattedTable> { formatGradesTable(table: CoreGradesTable): CoreGradesFormattedTable {
const maxDepth = table.maxdepth; const maxDepth = table.maxdepth;
const formatted: CoreGradesFormattedTable = { const formatted: CoreGradesFormattedTable = {
columns: [], columns: [],
@ -202,7 +202,7 @@ export class CoreGradesHelperProvider {
feedback: false, feedback: false,
contributiontocoursetotal: 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. // Get a row with some info.
let normalRow = formatted.rows.find( let normalRow = formatted.rows.find(
@ -474,7 +474,7 @@ export class CoreGradesHelperProvider {
// Find href containing "/mod/xxx/xxx.php". // Find href containing "/mod/xxx/xxx.php".
const regex = /href="([^"]*\/mod\/[^"|^/]*\/[^"|^.]*\.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) { if (row.itemname && row.itemname.content) {
const matches = row.itemname.content.match(regex); const matches = row.itemname.content.match(regex);
@ -486,7 +486,7 @@ export class CoreGradesHelperProvider {
} }
return false; 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. * @param text HTML where the image will be rendered.
* @return Row object with the image. * @return Row object with the image.
*/ */
protected async setRowIcon<T extends CoreGradesFormattedRowCommonData>(row: T, text: string): Promise<T> { protected setRowIcon<T extends CoreGradesFormattedRowCommonData>(row: T, text: string): T {
text = text.replace('%2F', '/').replace('%2f', '/'); text = text.replace('%2F', '/').replace('%2f', '/');
if (text.indexOf('/agg_mean') > -1) { if (text.indexOf('/agg_mean') > -1) {
row.itemtype = 'agg_mean'; row.itemtype = 'agg_mean';
@ -621,7 +621,7 @@ export class CoreGradesHelperProvider {
row.itemtype = 'mod'; row.itemtype = 'mod';
row.itemmodule = module[1]; row.itemmodule = module[1];
row.iconAlt = CoreCourse.translateModuleName(row.itemmodule) || ''; row.iconAlt = CoreCourse.translateModuleName(row.itemmodule) || '';
row.image = await CoreCourse.getModuleIconSrc( row.image = CoreCourse.getModuleIconSrc(
module[1], module[1],
CoreDomUtils.convertToElement(text).querySelector('img')?.getAttribute('src') ?? undefined, CoreDomUtils.convertToElement(text).querySelector('img')?.getAttribute('src') ?? undefined,
); );

View File

@ -76,7 +76,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp
module.description = ''; module.description = '';
return { return {
icon: await CoreCourse.getModuleIconSrc(module.modname, icon), icon: CoreCourse.getModuleIconSrc(module.modname, icon),
title: title || '', title: title || '',
a11yTitle: '', a11yTitle: '',
class: this.handlerSchema.displaydata?.class, class: this.handlerSchema.displaydata?.class,
@ -87,7 +87,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp
const showDowloadButton = this.handlerSchema.downloadbutton; const showDowloadButton = this.handlerSchema.downloadbutton;
const handlerData: CoreCourseModuleHandlerData = { const handlerData: CoreCourseModuleHandlerData = {
title: module.name, title: module.name,
icon: await CoreCourse.getModuleIconSrc(module.modname, icon), icon: CoreCourse.getModuleIconSrc(module.modname, icon),
class: this.handlerSchema.displaydata?.class, class: this.handlerSchema.displaydata?.class,
showDownloadButton: showDowloadButton !== undefined ? showDowloadButton : hasOffline, showDownloadButton: showDowloadButton !== undefined ? showDowloadButton : hasOffline,
}; };