parent
e7bd014848
commit
8dd0ef41a1
|
@ -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());
|
||||
|
|
|
@ -49,12 +49,12 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async ngOnChanges(changes: {[name: string]: SimpleChange}): Promise<void> {
|
||||
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<number, AddonBlockTimelineEvent[]> = {};
|
||||
|
@ -88,7 +88,7 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
|
|||
*
|
||||
* @return Filtered events.
|
||||
*/
|
||||
protected async filterEventsByTime(): Promise<AddonBlockTimelineEvent[]> {
|
||||
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;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ export class AddonCalendarUpcomingEventsComponent implements OnInit, DoCheck, On
|
|||
async fetchEvents(): Promise<void> {
|
||||
// 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.
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -164,9 +164,9 @@ export class AddonCalendarHelperProvider {
|
|||
*
|
||||
* @param event Event to format.
|
||||
*/
|
||||
async formatEventData(
|
||||
formatEventData(
|
||||
event: AddonCalendarEvent | AddonCalendarEventBase | AddonCalendarGetEventsEvent,
|
||||
): Promise<AddonCalendarEventToDisplay> {
|
||||
): 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);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ export class AddonModLabelModuleHandlerService extends CoreModuleHandlerBase imp
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async getData(module: CoreCourseModuleData): Promise<CoreCourseModuleHandlerData> {
|
||||
getData(module: CoreCourseModuleData): CoreCourseModuleHandlerData {
|
||||
// Remove the description from the module so it isn't rendered twice.
|
||||
const title = module.description || '';
|
||||
module.description = '';
|
||||
|
|
|
@ -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<string | undefined> {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,7 +55,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async getData(module: CoreCourseModuleData): Promise<CoreCourseModuleHandlerData> {
|
||||
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;
|
||||
|
|
|
@ -34,14 +34,14 @@ export class CoreModuleHandlerBase implements Partial<CoreCourseModuleHandler> {
|
|||
/**
|
||||
* @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<CoreCourseModuleHandlerData> {
|
||||
): Promise<CoreCourseModuleHandlerData> | 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,
|
||||
|
|
|
@ -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<string> {
|
||||
getModuleIconSrc(moduleName: string, modicon?: string, mimetypeIcon = ''): string {
|
||||
if (mimetypeIcon) {
|
||||
return mimetypeIcon;
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async getData(
|
||||
getData(
|
||||
module: CoreCourseModuleData,
|
||||
): Promise<CoreCourseModuleHandlerData> {
|
||||
): 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) => {
|
||||
|
|
|
@ -391,7 +391,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
|
|||
async getModuleIconSrc(modname: string, modicon?: string, module?: CoreCourseModuleData): Promise<string> {
|
||||
const icon = await this.executeFunctionOnEnabled<Promise<string>>(modname, 'getIconSrc', [module]);
|
||||
|
||||
return icon || await CoreCourse.getModuleIconSrc(modname, modicon) || '';
|
||||
return icon || CoreCourse.getModuleIconSrc(modname, modicon) || '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -191,7 +191,7 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy {
|
|||
*/
|
||||
private async fetchGrades(): Promise<void> {
|
||||
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;
|
||||
|
|
|
@ -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<CoreGradesFormattedTableRow> {
|
||||
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<CoreGradesFormattedTable> {
|
||||
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<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', '/');
|
||||
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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue