diff --git a/src/addons/calendar/components/calendar/addon-calendar-calendar.html b/src/addons/calendar/components/calendar/addon-calendar-calendar.html index 21d0bc83d..b355dd1e5 100644 --- a/src/addons/calendar/components/calendar/addon-calendar-calendar.html +++ b/src/addons/calendar/components/calendar/addon-calendar-calendar.html @@ -93,7 +93,7 @@ </div> </ng-container> <p *ngIf="day.filteredEvents.length > 4" class="addon-calendar-day-more"> - <b>{{ 'core.nummore' | translate:{$a: day.filteredEvents.length - 3} }}</b> + <strong>{{ 'core.nummore' | translate:{$a: day.filteredEvents.length - 3} }}</strong> </p> </div> </ion-col> diff --git a/src/addons/calendar/services/calendar-helper.ts b/src/addons/calendar/services/calendar-helper.ts index 95366cf1a..09b58b831 100644 --- a/src/addons/calendar/services/calendar-helper.ts +++ b/src/addons/calendar/services/calendar-helper.ts @@ -661,7 +661,7 @@ export class AddonCalendarHelperProvider { const finalPromises: Promise<unknown>[] =[AddonCalendar.invalidateAllUpcomingEvents()]; // Fetch months and days. - fetchTimestarts.map((fetchTime) => { + fetchTimestarts.forEach((fetchTime) => { const day = moment(fetchTime * 1000); const monthId = this.getMonthId(day); @@ -697,7 +697,7 @@ export class AddonCalendarHelperProvider { }); // Invalidate months and days. - invalidateTimestarts.map((fetchTime) => { + invalidateTimestarts.forEach((fetchTime) => { const day = moment(fetchTime * 1000); const monthId = this.getMonthId(day); diff --git a/src/addons/calendar/services/calendar.ts b/src/addons/calendar/services/calendar.ts index 155861284..5e0f7e811 100644 --- a/src/addons/calendar/services/calendar.ts +++ b/src/addons/calendar/services/calendar.ts @@ -529,7 +529,7 @@ export class AddonCalendarProvider { // Convert the array to an object. const result = {}; if (response.allowedeventtypes) { - response.allowedeventtypes.map((type) => { + response.allowedeventtypes.forEach((type) => { result[type] = true; }); } diff --git a/src/addons/messages/pages/discussion/discussion.html b/src/addons/messages/pages/discussion/discussion.html index f5c3e8dba..d0c876da3 100644 --- a/src/addons/messages/pages/discussion/discussion.html +++ b/src/addons/messages/pages/discussion/discussion.html @@ -65,7 +65,7 @@ <ng-container *ngIf="isSelf && !canLoadMore"> <p class="ion-text-center">{{ 'addon.messages.selfconversation' | translate }}</p> - <p class="ion-text-center"><i>{{ 'addon.messages.selfconversationdefaultmessage' | translate }}</i></p> + <p class="ion-text-center"><em>{{ 'addon.messages.selfconversationdefaultmessage' | translate }}</em></p> </ng-container> <h2 class="sr-only">{{ title }}</h2> diff --git a/src/addons/mod/assign/classes/submissions-source.ts b/src/addons/mod/assign/classes/submissions-source.ts index 8a5ef3441..273867191 100644 --- a/src/addons/mod/assign/classes/submissions-source.ts +++ b/src/addons/mod/assign/classes/submissions-source.ts @@ -126,7 +126,7 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc CoreSites.getCurrentSiteId(), ); } - } catch (error) { + } catch { // Ignore errors, probably user is offline or sync is blocked. } } diff --git a/src/addons/mod/assign/components/submission/submission.ts b/src/addons/mod/assign/components/submission/submission.ts index 7e040d205..d38e423ac 100644 --- a/src/addons/mod/assign/components/submission/submission.ts +++ b/src/addons/mod/assign/components/submission/submission.ts @@ -525,7 +525,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can submitId: this.submitId, }, this.siteId); } - } catch (error) { + } catch { // Ignore errors, probably user is offline or sync is blocked. } } diff --git a/src/addons/mod/assign/services/assign.ts b/src/addons/mod/assign/services/assign.ts index 2b313ceaa..c09110175 100644 --- a/src/addons/mod/assign/services/assign.ts +++ b/src/addons/mod/assign/services/assign.ts @@ -565,7 +565,7 @@ export class AddonModAssignProvider { }; try { - return this.getSubmissionStatus(assign.id, newOptions); + return await this.getSubmissionStatus(assign.id, newOptions); } catch { // Error, return the first result even if it doesn't have the user submission. return response; diff --git a/src/addons/mod/chat/pages/chat/chat.ts b/src/addons/mod/chat/pages/chat/chat.ts index 0fce55789..76a53a6a4 100644 --- a/src/addons/mod/chat/pages/chat/chat.ts +++ b/src/addons/mod/chat/pages/chat/chat.ts @@ -220,7 +220,7 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { } return id; - } catch (error) { + } catch { // Ignore errors. return id; } diff --git a/src/addons/mod/chat/services/chat-helper.ts b/src/addons/mod/chat/services/chat-helper.ts index 2f4f6e02d..5ec95bdaa 100644 --- a/src/addons/mod/chat/services/chat-helper.ts +++ b/src/addons/mod/chat/services/chat-helper.ts @@ -66,7 +66,9 @@ export class AddonModChatHelperProvider { if (!formattedMessage.special && formattedMessage.message.match(patternTo)) { const matches = formattedMessage.message.match(patternTo); - formattedMessage.message = `<i><b>${Translate.instant('addon.mod_chat.saidto')} </b>${matches![1]}</i>: ${matches![2]}`; + formattedMessage.message = `<em> + <strong>${Translate.instant('addon.mod_chat.saidto')} </strong> + ${matches![1]}</em>: ${matches![2]}`; } formattedMessage.showUserData = this.showUserData(currentUserId, message, prevMessage); diff --git a/src/addons/mod/data/services/data-helper.ts b/src/addons/mod/data/services/data-helper.ts index 6993f0210..258b15bf2 100644 --- a/src/addons/mod/data/services/data-helper.ts +++ b/src/addons/mod/data/services/data-helper.ts @@ -723,7 +723,7 @@ export class AddonModDataHelperProvider { try { await AddonModData.invalidateEntryData(dataId, entryId, siteId); await AddonModData.invalidateEntriesData(dataId, siteId); - } catch (error) { + } catch { // Ignore errors. } diff --git a/src/addons/mod/data/services/data.ts b/src/addons/mod/data/services/data.ts index dde8919c8..09275a88a 100644 --- a/src/addons/mod/data/services/data.ts +++ b/src/addons/mod/data/services/data.ts @@ -987,7 +987,7 @@ export class AddonModDataProvider { options.groupId = options.groupId || 0; options.sort = options.sort || 0; - options.order || options.order || 'DESC'; + options.order = options.order || 'DESC'; options.page = options.page || 0; options.perPage = options.perPage || AddonModDataProvider.PER_PAGE; options.readingStrategy = options.readingStrategy || CoreSitesReadingStrategy.PREFER_NETWORK; diff --git a/src/addons/mod/feedback/pages/attempt/attempt.ts b/src/addons/mod/feedback/pages/attempt/attempt.ts index e8981da89..c83b91289 100644 --- a/src/addons/mod/feedback/pages/attempt/attempt.ts +++ b/src/addons/mod/feedback/pages/attempt/attempt.ts @@ -66,9 +66,9 @@ export class AddonModFeedbackAttemptPage implements OnInit, OnDestroy { /** * @inheritdoc */ - ngOnInit(): void { + async ngOnInit(): Promise<void> { try { - this.attempts.start(); + await this.attempts.start(); } catch (error) { CoreDomUtils.showErrorModal(error); diff --git a/src/addons/mod/forum/classes/forum-discussions-source.ts b/src/addons/mod/forum/classes/forum-discussions-source.ts index f525f4d02..49b12fa60 100644 --- a/src/addons/mod/forum/classes/forum-discussions-source.ts +++ b/src/addons/mod/forum/classes/forum-discussions-source.ts @@ -292,7 +292,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource discussion.userfullname = user.fullname; discussion.userpictureurl = user.profileimageurl; - } catch (error) { + } catch { // Ignore errors. } }); diff --git a/src/addons/mod/forum/pages/discussion/discussion.page.ts b/src/addons/mod/forum/pages/discussion/discussion.page.ts index 6556402dd..dafc9525d 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.page.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.page.ts @@ -358,7 +358,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes // Not set, use default sort. // @TODO add fallback to $CFG->forum_displaymode. } - } catch (error) { + } catch { // Ignore errors. } } @@ -511,7 +511,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes } await Promise.all(promises); - } catch (error) { + } catch { // Ignore errors. } diff --git a/src/addons/mod/glossary/components/index/index.ts b/src/addons/mod/glossary/components/index/index.ts index 36595994c..523c6ffa2 100644 --- a/src/addons/mod/glossary/components/index/index.ts +++ b/src/addons/mod/glossary/components/index/index.ts @@ -474,7 +474,7 @@ class AddonModGlossaryEntriesManager extends CoreListItemsManager<AddonModGlossa await AddonModGlossary.logView(glossary.id, viewMode, glossary.name); CoreCourse.checkModuleCompletion(this.page.courseId, this.page.module.completiondata); - } catch (error) { + } catch { // Ignore errors. } } diff --git a/src/addons/mod/glossary/services/glossary.ts b/src/addons/mod/glossary/services/glossary.ts index f85c300de..53ef5b21f 100644 --- a/src/addons/mod/glossary/services/glossary.ts +++ b/src/addons/mod/glossary/services/glossary.ts @@ -663,13 +663,12 @@ export class AddonModGlossaryProvider { // No more pages and the entry wasn't found. Reject. throw new CoreError('Entry not found.'); - }; + } /** * Performs the whole fetch of the entries using the proper function and arguments. * * @param fetchFunction Function to fetch. - * @param fetchArguments Arguments to call the fetching. * @param options Other options. * @return Promise resolved with all entrries. */ @@ -682,7 +681,7 @@ export class AddonModGlossaryProvider { const entries: AddonModGlossaryEntry[] = []; const fetchMoreEntries = async (): Promise<AddonModGlossaryEntry[]> => { - const result = await fetchFunction({ + const result = fetchFunction({ from: entries.length, ...options, // Include all options. }); @@ -915,7 +914,14 @@ export class AddonModGlossaryProvider { try { // Try to add it in online. - return this.addEntryOnline(glossaryId, concept, definition, entryOptions, <number> attachments, otherOptions.siteId); + return await this.addEntryOnline( + glossaryId, + concept, + definition, + entryOptions, + <number> attachments, + otherOptions.siteId, + ); } catch (error) { if (otherOptions.allowOffline && !CoreUtils.isWebServiceError(error)) { // Couldn't connect to server, store in offline. diff --git a/src/addons/mod/h5pactivity/components/index/index.ts b/src/addons/mod/h5pactivity/components/index/index.ts index b1808e316..74e0277b2 100644 --- a/src/addons/mod/h5pactivity/components/index/index.ts +++ b/src/addons/mod/h5pactivity/components/index/index.ts @@ -459,7 +459,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv try { // Invalidate attempts. await AddonModH5PActivity.invalidateUserAttempts(this.h5pActivity.id, undefined, this.siteId); - } catch (error) { + } catch { // Ignore errors. } diff --git a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts index 3b3727a2b..552568111 100644 --- a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts +++ b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts @@ -119,7 +119,7 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit { try { this.user = await CoreUser.getProfile(this.attempt.userid, this.courseId, true); - } catch (error) { + } catch { // Ignore errors. } } diff --git a/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts b/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts index bb95f9fcb..c0864d3ec 100644 --- a/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts +++ b/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts @@ -133,7 +133,7 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit { protected async fetchUserProfile(): Promise<void> { try { this.user = await CoreUser.getProfile(this.userId, this.courseId, true); - } catch (error) { + } catch { // Ignore errors. } } diff --git a/src/addons/mod/lesson/services/handlers/prefetch.ts b/src/addons/mod/lesson/services/handlers/prefetch.ts index 4d87bf1ce..011b47b40 100644 --- a/src/addons/mod/lesson/services/handlers/prefetch.ts +++ b/src/addons/mod/lesson/services/handlers/prefetch.ts @@ -143,7 +143,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref if (password) { try { - return this.validatePassword(lessonId, accessInfo, password, options); + return await this.validatePassword(lessonId, accessInfo, password, options); } catch { // Error validating it. } @@ -320,7 +320,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref * @param lesson Lesson. * @param password Password (if needed). * @param retake Retake to prefetch. - * @param options Options. + * @param modOptions Options. * @return Promise resolved when done. */ protected async prefetchPlayData( @@ -364,12 +364,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref const promises = pages.map(async (data) => { // Check if any page has a RANDOMBRANCH jump. if (!hasRandomBranch) { - for (let i = 0; i < data.jumps.length; i++) { - if (data.jumps[i] == AddonModLessonProvider.LESSON_RANDOMBRANCH) { - hasRandomBranch = true; - break; - } - } + hasRandomBranch = data.jumps.some((jump) => jump === AddonModLessonProvider.LESSON_RANDOMBRANCH); } // Get the page data. We don't pass accessInfo because we don't need to calculate the offline data. @@ -499,8 +494,8 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref * Validate the password. * * @param lessonId Lesson ID. - * @param info Lesson access info. - * @param pwd Password to check. + * @param accessInfo Lesson access info. + * @param password Password to check. * @param options Other options. * @return Promise resolved when done. */ diff --git a/src/addons/mod/lti/services/lti-helper.ts b/src/addons/mod/lti/services/lti-helper.ts index dcb3ac154..b23cda06a 100644 --- a/src/addons/mod/lti/services/lti-helper.ts +++ b/src/addons/mod/lti/services/lti-helper.ts @@ -118,7 +118,7 @@ export class AddonModLtiHelperProvider { await AddonModLti.logView(ltiId, name, siteId); CoreCourse.checkModuleCompletion(courseId, module.completiondata); - } catch (error) { + } catch { // Ignore errors. } } diff --git a/src/addons/mod/wiki/components/index/addon-mod-wiki-index.html b/src/addons/mod/wiki/components/index/addon-mod-wiki-index.html index 56336ba50..c6e278efb 100644 --- a/src/addons/mod/wiki/components/index/addon-mod-wiki-index.html +++ b/src/addons/mod/wiki/components/index/addon-mod-wiki-index.html @@ -65,7 +65,7 @@ </article> <div class="ion-margin-top" *ngIf="tagsEnabled && tags.length > 0"> - <b>{{ 'core.tag.tags' | translate }}:</b> + <strong>{{ 'core.tag.tags' | translate }}:</strong> <core-tag-list [tags]="tags"></core-tag-list> </div> </div> diff --git a/src/addons/mod/wiki/services/wiki.ts b/src/addons/mod/wiki/services/wiki.ts index d83357c88..32180ffb9 100644 --- a/src/addons/mod/wiki/services/wiki.ts +++ b/src/addons/mod/wiki/services/wiki.ts @@ -723,7 +723,7 @@ export class AddonModWikiProvider { try { // Try to create it in online. - return this.newPageOnline(title, content, options); + return await this.newPageOnline(title, content, options); } catch (error) { if (CoreUtils.isWebServiceError(error)) { // The WebService has thrown an error, this means that the page cannot be added. diff --git a/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts b/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts index 26d9b61c1..78b028706 100644 --- a/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts +++ b/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts @@ -119,7 +119,7 @@ export class AddonModWorkshopAssessmentStrategyComponent implements OnInit, OnDe // Load Weights selector. if (this.edit && this.access.canallocate) { - this.weights; + this.weights = []; for (let i = 16; i >= 0; i--) { this.weights[i] = i; } @@ -347,8 +347,6 @@ export class AddonModWorkshopAssessmentStrategyComponent implements OnInit, OnDe this.workshop.course, assessmentData, ); - - gradeUpdated = false; } else { // Try to send it to server. diff --git a/src/core/components/icon/icon.scss b/src/core/components/icon/icon.scss index 097de22a6..cc3176c14 100644 --- a/src/core/components/icon/icon.scss +++ b/src/core/components/icon/icon.scss @@ -8,7 +8,6 @@ :host-context(ion-item.md) ion-icon { &[slot] { - font-size: 1.6em; color: rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.54); font-size: 24px; margin-top: 12px; diff --git a/src/core/features/block/classes/base-block-component.ts b/src/core/features/block/classes/base-block-component.ts index b73e0e517..58d3878ab 100644 --- a/src/core/features/block/classes/base-block-component.ts +++ b/src/core/features/block/classes/base-block-component.ts @@ -52,10 +52,8 @@ export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockCompon */ async ngOnInit(): Promise<void> { if (this.block.configs && this.block.configs.length > 0) { - this.block.configs.map((config) => { + this.block.configs.forEach((config) => { config.value = CoreTextUtils.parseJSON(config.value); - - return config; }); this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name'); diff --git a/src/core/features/courses/services/handlers/course-link.ts b/src/core/features/courses/services/handlers/course-link.ts index 5c7347844..0bd9d0229 100644 --- a/src/core/features/courses/services/handlers/course-link.ts +++ b/src/core/features/courses/services/handlers/course-link.ts @@ -47,13 +47,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler } /** - * Get the list of actions for a link (url). - * - * @param siteIds List of sites the URL belongs to. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return List of (or promise resolved with list of) actions. + * @inheritdoc */ getActions( siteIds: string[], @@ -103,17 +97,10 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler } /** - * Check if the handler is enabled for a certain site (site + user) and a URL. - * If not defined, defaults to true. - * - * @param siteId The site ID. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return Whether the handler is enabled for the URL and site. + * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params, courseId?: number): Promise<boolean> { - courseId = parseInt(params.id, 10); + async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> { + const courseId = parseInt(params.id, 10); if (!courseId) { return false; @@ -333,7 +320,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler await CoreUtils.wait(5000); - return await this.waitForEnrolled(courseId); + return this.waitForEnrolled(courseId); } } diff --git a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts index 44a06bb56..ac0ceebf9 100644 --- a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts +++ b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts @@ -973,7 +973,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit, this.showMessage('core.editor.textrecovered', this.RESTORE_MESSAGE_CLEAR_TIME); } } - } catch (error) { + } catch { // Ignore errors, shouldn't happen. } } diff --git a/src/core/features/editor/services/editor-offline.ts b/src/core/features/editor/services/editor-offline.ts index 810893090..0025f84e4 100644 --- a/src/core/features/editor/services/editor-offline.ts +++ b/src/core/features/editor/services/editor-offline.ts @@ -56,7 +56,7 @@ export class CoreEditorOfflineProvider { const params = this.fixDraftPrimaryData(contextLevel, contextInstanceId, elementId, extraParams); await db.deleteRecords(DRAFT_TABLE, params); - } catch (error) { + } catch { // Ignore errors, probably no draft stored. } } @@ -149,12 +149,12 @@ export class CoreEditorOfflineProvider { } await db.insertRecord(DRAFT_TABLE, entry); - } catch (error) { + } catch { // Ignore errors saving the draft. It shouldn't happen. } return entry; - } catch (error) { + } catch { // No draft stored. Store an empty draft to save the pageinstance. await this.saveDraft( contextLevel, diff --git a/src/core/features/fileuploader/services/fileuploader-helper.ts b/src/core/features/fileuploader/services/fileuploader-helper.ts index 6f160a070..ab401b17c 100644 --- a/src/core/features/fileuploader/services/fileuploader-helper.ts +++ b/src/core/features/fileuploader/services/fileuploader-helper.ts @@ -812,7 +812,7 @@ export class CoreFileUploaderHelperProvider { file = await CoreFile.getFileObjectFromFileEntry(fileEntry); size = file.size; - } catch (error) { + } catch { // Ignore failures. } } diff --git a/src/core/features/grades/services/handlers/report-link.ts b/src/core/features/grades/services/handlers/report-link.ts index 1efed0df7..a6457e3a9 100644 --- a/src/core/features/grades/services/handlers/report-link.ts +++ b/src/core/features/grades/services/handlers/report-link.ts @@ -30,14 +30,7 @@ export class CoreGradesReportLinkHandlerService extends CoreContentLinksHandlerB pattern = /\/grade\/report(\/user)?\/index.php/; /** - * Get the list of actions for a link (url). - * - * @param siteIds List of sites the URL belongs to. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @param data Extra data to handle the URL. - * @return List of (or promise resolved with list of) actions. + * @inheritdoc */ getActions( siteIds: string[], @@ -60,14 +53,7 @@ export class CoreGradesReportLinkHandlerService extends CoreContentLinksHandlerB } /** - * Check if the handler is enabled for a certain site (site + user) and a URL. - * If not defined, defaults to true. - * - * @param siteId The site ID. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return Whether the handler is enabled for the URL and site. + * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record<string, string>, courseId?: number): Promise<boolean> { if (!courseId && !params.id) { diff --git a/src/core/features/grades/services/handlers/user-link.ts b/src/core/features/grades/services/handlers/user-link.ts index 1f1ba4008..b3fd56690 100644 --- a/src/core/features/grades/services/handlers/user-link.ts +++ b/src/core/features/grades/services/handlers/user-link.ts @@ -30,14 +30,7 @@ export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBas pattern = /\/course\/user\.php.*[?&]mode=grade/; /** - * Get the list of actions for a link (url). - * - * @param siteIds List of sites the URL belongs to. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @param data Extra data to handle the URL. - * @return List of (or promise resolved with list of) actions. + * @inheritdoc */ getActions( siteIds: string[], @@ -60,14 +53,7 @@ export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBas } /** - * Check if the handler is enabled for a certain site (site + user) and a URL. - * If not defined, defaults to true. - * - * @param siteId The site ID. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return Whether the handler is enabled for the URL and site. + * @inheritdoc */ async isEnabled(siteId: string, url: string, params: Record<string, string>, courseId?: number): Promise<boolean> { if (!courseId && !params.id) { diff --git a/src/core/features/h5p/classes/content-validator.ts b/src/core/features/h5p/classes/content-validator.ts index 20c2cb69b..b2861a8f0 100644 --- a/src/core/features/h5p/classes/content-validator.ts +++ b/src/core/features/h5p/classes/content-validator.ts @@ -191,7 +191,7 @@ export class CoreH5PContentValidator { /** * Validate given value against number semantics. * - * @param num Number to validate. + * @param value Number to validate. * @param semantics Semantics. * @return Validated number. */ @@ -497,9 +497,7 @@ export class CoreH5PContentValidator { let validateFunction: undefined | ((...args: unknown[]) => unknown); let field: CoreH5PSemantics | undefined; - for (let i = 0; i < semantics.fields.length; i++) { - field = semantics.fields[i]; - + for (const field of semantics.fields) { if (field.name == key) { if (semantics.optional) { field.optional = true; @@ -778,8 +776,7 @@ export class CoreH5PContentValidator { if (matches && matches.length > 1) { if (allowedStyles && attrName === 'style') { // Allow certain styles. - for (let i = 0; i < allowedStyles.length; i++) { - const pattern = allowedStyles[i]; + for (const pattern of allowedStyles) { if (matches[1].match(pattern)) { // All patterns are start to end patterns, and CKEditor adds one span per style. attrArray.push('style="' + matches[1] + '"'); @@ -1122,7 +1119,7 @@ export class CoreH5PContentValidator { }, ]; - return this.metadataSemantics!; + return this.metadataSemantics; } /** @@ -1266,7 +1263,7 @@ export class CoreH5PContentValidator { ], }; - return this.copyrightSemantics!; + return this.copyrightSemantics; } /** diff --git a/src/core/features/h5p/classes/core.ts b/src/core/features/h5p/classes/core.ts index 8c50ea5eb..e77c7c752 100644 --- a/src/core/features/h5p/classes/core.ts +++ b/src/core/features/h5p/classes/core.ts @@ -292,7 +292,7 @@ export class CoreH5PCore { // Update library usage. try { await this.h5pFramework.deleteLibraryUsage(content.id, siteId); - } catch (error) { + } catch { // Ignore errors. } diff --git a/src/core/features/h5p/classes/file-storage.ts b/src/core/features/h5p/classes/file-storage.ts index 5bbab236d..598e4a404 100644 --- a/src/core/features/h5p/classes/file-storage.ts +++ b/src/core/features/h5p/classes/file-storage.ts @@ -229,7 +229,7 @@ export class CoreH5PFileStorage { try { // Delete the index.html. await this.deleteContentIndex(entry.foldername, site.getId()); - } catch (error) { + } catch { // Ignore errors. } }); @@ -463,7 +463,7 @@ export class CoreH5PFileStorage { // Delete existing library version. try { await CoreFile.removeDir(folderPath); - } catch (error) { + } catch { // Ignore errors, maybe it doesn't exist. } diff --git a/src/core/features/h5p/classes/helper.ts b/src/core/features/h5p/classes/helper.ts index d418fa615..126ee649f 100644 --- a/src/core/features/h5p/classes/helper.ts +++ b/src/core/features/h5p/classes/helper.ts @@ -223,7 +223,7 @@ export class CoreH5PHelper { // Remove tmp folder. try { await CoreFile.removeDir(destFolder); - } catch (error) { + } catch { // Ignore errors, it will be deleted eventually. } } diff --git a/src/core/features/h5p/classes/validator.ts b/src/core/features/h5p/classes/validator.ts index edc952aa2..7eca0f96f 100644 --- a/src/core/features/h5p/classes/validator.ts +++ b/src/core/features/h5p/classes/validator.ts @@ -273,7 +273,7 @@ export class CoreH5PValidator { const parts = entry.name.split('.'); // The language code is in parts[0]. langIndex[parts[0]] = langFileData; - } catch (error) { + } catch { // Ignore this language. } })); diff --git a/src/core/features/h5p/components/h5p-player/h5p-player.ts b/src/core/features/h5p/components/h5p-player/h5p-player.ts index dfc86f0b4..2d727e8af 100644 --- a/src/core/features/h5p/components/h5p-player/h5p-player.ts +++ b/src/core/features/h5p/components/h5p-player/h5p-player.ts @@ -47,7 +47,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { canDownload$ = new BehaviorSubject(false); calculating$ = new BehaviorSubject(true); displayOptions?: CoreH5PDisplayOptions; - urlParams?: {[name: string]: string}; + urlParams: {[name: string]: string} = {}; protected site: CoreSite; protected siteId: string; @@ -60,7 +60,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { ) { this.logger = CoreLogger.getInstance('CoreH5PPlayerComponent'); - this.site = CoreSites.getCurrentSite()!; + this.site = CoreSites.getRequiredCurrentSite(); this.siteId = this.site.getId(); this.siteCanDownload = this.site.canDownloadFiles() && !CoreH5P.isOfflineDisabledInSite(); } @@ -100,7 +100,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { // Download the package in background if the size is low. try { - this.attemptDownloadInBg(); + await this.attemptDownloadInBg(); } catch (error) { this.logger.error('Error downloading H5P in background', error); } @@ -120,12 +120,12 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { try { // Get the file size and ask the user to confirm. - const size = await CorePluginFileDelegate.getFileSize({ fileurl: this.urlParams!.url }, this.siteId); + const size = await CorePluginFileDelegate.getFileSize({ fileurl: this.urlParams.url }, this.siteId); await CoreDomUtils.confirmDownloadSize({ size: size, total: true }); // User confirmed, add to the queue. - await CoreFilepool.addToQueueByUrl(this.siteId, this.urlParams!.url, this.component, this.componentId); + await CoreFilepool.addToQueueByUrl(this.siteId, this.urlParams.url, this.component, this.componentId); } catch (error) { if (CoreDomUtils.isCanceledError(error)) { @@ -191,7 +191,6 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { /** * Calculate state of the file. * - * @param fileUrl The H5P file URL. * @return Promise resolved when done. */ protected async calculateState(): Promise<void> { @@ -199,7 +198,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { // Get the status of the file. try { - const state = await CoreFilepool.getFileStateByUrl(this.siteId, this.urlParams!.url); + const state = await CoreFilepool.getFileStateByUrl(this.siteId, this.urlParams.url); this.canDownload$.next(true); this.state = state; diff --git a/src/core/features/login/components/site-help/site-help.html b/src/core/features/login/components/site-help/site-help.html index 10242b5cd..502818a75 100644 --- a/src/core/features/login/components/site-help/site-help.html +++ b/src/core/features/login/components/site-help/site-help.html @@ -14,7 +14,7 @@ <ion-list> <ion-item class="ion-text-wrap"> <ion-label> - <h2><b>{{ 'core.login.faqcannotfindmysitequestion' | translate }}</b></h2> + <h2><strong>{{ 'core.login.faqcannotfindmysitequestion' | translate }}</strong></h2> </ion-label> </ion-item> <ion-item class="ion-text-wrap"> @@ -24,7 +24,7 @@ </ion-item> <ion-item class="ion-text-wrap"> <ion-label> - <h2><b>{{ 'core.login.faqwhatisurlquestion' | translate }}</b></h2> + <h2><strong>{{ 'core.login.faqwhatisurlquestion' | translate }}</strong></h2> </ion-label> </ion-item> <ion-item class="ion-text-wrap core-login-faqwhatisurlanswer"> @@ -34,7 +34,7 @@ </ion-item> <ion-item class="ion-text-wrap"> <ion-label> - <h2><b>{{ 'core.login.faqcannotconnectquestion' | translate }}</b></h2> + <h2><strong>{{ 'core.login.faqcannotconnectquestion' | translate }}</strong></h2> </ion-label> </ion-item> <ion-item class="ion-text-wrap"> @@ -44,7 +44,7 @@ </ion-item> <ion-item class="ion-text-wrap"> <ion-label> - <h2><b>{{ 'core.login.faqsetupsitequestion' | translate }}</b></h2> + <h2><strong>{{ 'core.login.faqsetupsitequestion' | translate }}</strong></h2> </ion-label> </ion-item> <ion-item class="ion-text-wrap"> @@ -57,7 +57,7 @@ </ion-item> <ion-item class="ion-text-wrap"> <ion-label> - <h2><b>{{ 'core.login.faqtestappquestion' | translate }}</b></h2> + <h2><strong>{{ 'core.login.faqtestappquestion' | translate }}</strong></h2> </ion-label> </ion-item> <ion-item class="ion-text-wrap"> @@ -67,7 +67,7 @@ </ion-item> <ion-item class="ion-text-wrap" *ngIf="canScanQR"> <ion-label> - <h2><b>{{ 'core.login.faqwhereisqrcode' | translate }}</b></h2> + <h2><strong>{{ 'core.login.faqwhereisqrcode' | translate }}</strong></h2> </ion-label> </ion-item> <ion-item class="ion-text-wrap core-login-faqwhereisqrcodeanswer" *ngIf="canScanQR"> diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index 902fbd16c..bd7df5d05 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -360,7 +360,7 @@ export class CoreLoginSitePage implements OnInit { params: pageParams, }); } - } catch (error) { + } catch { // Ignore errors. } } @@ -546,7 +546,7 @@ export class CoreLoginSitePage implements OnInit { }, }); } - } catch (error) { + } catch { // Ignore errors. } finally { modal.dismiss(); diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 366ae942d..927db6168 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -625,14 +625,11 @@ export class CorePushNotificationsProvider { const total = counters.reduce((previous, counter) => previous + counter, 0); - if (!CorePlatform.isMobile()) { - // Browser doesn't have an app badge, stop. - return total; + if (CorePlatform.isMobile()) { + // Set the app badge on mobile. + await Badge.set(total); } - // Set the app badge. - await Badge.set(total); - return total; } diff --git a/src/core/features/rating/services/rating.ts b/src/core/features/rating/services/rating.ts index fa401c826..6a6d6bc7b 100644 --- a/src/core/features/rating/services/rating.ts +++ b/src/core/features/rating/services/rating.ts @@ -404,17 +404,15 @@ export class CoreRatingProvider { true, )); + const ratingsResults = await Promise.all(promises); + if (!site.isVersionGreaterEqualThan([' 3.6.5', '3.7.1', '3.8'])) { - promises.map((promise) => promise.then(async (ratings) => { - const userIds = ratings.map((rating: CoreRatingItemRating) => rating.userid); + const ratings: CoreRatingItemRating[] = [].concat.apply([], ratingsResults); - await CoreUser.prefetchProfiles(userIds, courseId, site.id); + const userIds = ratings.map((rating) => rating.userid); - return; - })); + await CoreUser.prefetchProfiles(userIds, courseId, site.id); } - - await Promise.all(promises); } /** diff --git a/src/core/features/sitehome/services/handlers/index-link.ts b/src/core/features/sitehome/services/handlers/index-link.ts index ebe42ecb3..58e7cc299 100644 --- a/src/core/features/sitehome/services/handlers/index-link.ts +++ b/src/core/features/sitehome/services/handlers/index-link.ts @@ -53,8 +53,9 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Record<string, string>, courseId?: number): Promise<boolean> { - courseId = parseInt(params.id, 10); + async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> { + const courseId = parseInt(params.id, 10); + if (!courseId) { return url.includes('index.php'); } diff --git a/src/core/features/user/pages/about/about.scss b/src/core/features/user/pages/about/about.scss index 1ed9a0b9f..8edaa46ad 100644 --- a/src/core/features/user/pages/about/about.scss +++ b/src/core/features/user/pages/about/about.scss @@ -16,12 +16,12 @@ .contact-status { width: 24px !important; height: 24px !important; - right: calc(50% - 12px - var(--core-avatar-size) / 2) !important; + right: calc(50% - 12px - var(--core-avatar-size) / 2) !important; } .edit-avatar { position: absolute; - right: calc(50% - 15px - var(--core-avatar-size) / 2); + right: calc(50% - 15px - var(--core-avatar-size) / 2); bottom: -12px; :host-context([dir="rtl"]) & { diff --git a/src/core/features/user/pages/profile/profile.scss b/src/core/features/user/pages/profile/profile.scss index 41723e265..0265d7694 100644 --- a/src/core/features/user/pages/profile/profile.scss +++ b/src/core/features/user/pages/profile/profile.scss @@ -16,7 +16,7 @@ .contact-status { width: 24px !important; height: 24px !important; - right: calc(50% - 12px - var(--core-avatar-size) / 2) !important; + right: calc(50% - 12px - var(--core-avatar-size) / 2) !important; } } } diff --git a/src/core/features/user/services/handlers/profile-link.ts b/src/core/features/user/services/handlers/profile-link.ts index b7eb0ad5b..a4b6ce399 100644 --- a/src/core/features/user/services/handlers/profile-link.ts +++ b/src/core/features/user/services/handlers/profile-link.ts @@ -30,21 +30,12 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa pattern = /((\/user\/view\.php)|(\/user\/profile\.php)).*([?&]id=\d+)/; /** - * Get the list of actions for a link (url). - * - * @param siteIds List of sites the URL belongs to. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @param data Extra data to handle the URL. - * @return List of (or promise resolved with list of) actions. + * @inheritdoc */ getActions( siteIds: string[], url: string, params: Record<string, string>, - courseId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars - data?: unknown, // eslint-disable-line @typescript-eslint/no-unused-vars ): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { return [{ action: (siteId): void => { @@ -59,17 +50,9 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa } /** - * Check if the handler is enabled for a certain site (site + user) and a URL. - * If not defined, defaults to true. - * - * @param siteId The site ID. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return Whether the handler is enabled for the URL and site. + * @inheritdoc */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async isEnabled(siteId: string, url: string, params: Record<string, string>, courseId?: number): Promise<boolean> { + async isEnabled(siteId: string, url: string): Promise<boolean> { return url.indexOf('/grade/report/') == -1; } diff --git a/src/core/features/user/services/user-profile-field-delegate.ts b/src/core/features/user/services/user-profile-field-delegate.ts index 0432a8ea0..6a5b2c284 100644 --- a/src/core/features/user/services/user-profile-field-delegate.ts +++ b/src/core/features/user/services/user-profile-field-delegate.ts @@ -181,7 +181,7 @@ export class CoreUserProfileFieldDelegateService extends CoreDelegate<CoreUserPr if (data) { result.push(data); } - } catch (error) { + } catch { // Ignore errors. } })); diff --git a/src/core/pipes/format-date.ts b/src/core/pipes/format-date.ts index 2e49d275a..84a0e91d8 100644 --- a/src/core/pipes/format-date.ts +++ b/src/core/pipes/format-date.ts @@ -43,7 +43,7 @@ export class CoreFormatDatePipe implements PipeTransform { timestamp = timestamp || Date.now(); format = format || 'strftimedaydatetime'; - if (typeof timestamp == 'string') { + if (typeof timestamp === 'string') { // Convert the value to a number. const numberTimestamp = parseInt(timestamp, 10); if (isNaN(numberTimestamp)) { @@ -55,7 +55,7 @@ export class CoreFormatDatePipe implements PipeTransform { } // Add "core." if needed. - if (format.indexOf('strf') == 0 || format.indexOf('df') == 0) { + if (format.indexOf('strf') === 0 || format.indexOf('df') === 0) { format = 'core.' + format; } diff --git a/src/core/services/file.ts b/src/core/services/file.ts index 0d8c96388..85580f311 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -1205,7 +1205,7 @@ export class CoreFileProvider { }); await Promise.all(promises); - } catch (error) { + } catch { // Ignore errors, maybe it doesn't exist. } } diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index d954aff62..fbe4a2e2b 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -1467,7 +1467,7 @@ export class CoreFilepoolProvider { const fileSize = await CoreFile.getFileSize(file.path); size += fileSize; - } catch (error) { + } catch { // Ignore failures, maybe some file was deleted. } })); diff --git a/src/core/services/plugin-file-delegate.ts b/src/core/services/plugin-file-delegate.ts index cf5602af8..4839be2fb 100644 --- a/src/core/services/plugin-file-delegate.ts +++ b/src/core/services/plugin-file-delegate.ts @@ -200,10 +200,8 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa if (handler && handler.getFileSize) { try { - const size = handler.getFileSize(downloadableFile, siteId); - - return size; - } catch (error) { + return await handler.getFileSize(downloadableFile, siteId); + } catch { // Ignore errors. } } diff --git a/src/core/services/utils/mimetype.ts b/src/core/services/utils/mimetype.ts index d8e4610ed..c9fdd1fa1 100644 --- a/src/core/services/utils/mimetype.ts +++ b/src/core/services/utils/mimetype.ts @@ -302,14 +302,12 @@ export class CoreMimetypeUtilsProvider { */ guessExtensionFromUrl(fileUrl: string): string | undefined { const split = fileUrl.split('.'); - let candidate; - let extension; - let position; + let extension: string | undefined; if (split.length > 1) { - candidate = split[split.length - 1].toLowerCase(); + let candidate = split[split.length - 1].toLowerCase(); // Remove params if any. - position = candidate.indexOf('?'); + let position = candidate.indexOf('?'); if (position > -1) { candidate = candidate.substring(0, position); } @@ -343,7 +341,7 @@ export class CoreMimetypeUtilsProvider { */ getFileExtension(filename: string): string | undefined { const dot = filename.lastIndexOf('.'); - let ext; + let ext: string | undefined; if (dot > -1) { ext = filename.substring(dot + 1).toLowerCase(); @@ -582,11 +580,10 @@ export class CoreMimetypeUtilsProvider { */ removeExtension(path: string): string { const position = path.lastIndexOf('.'); - let extension; if (position > -1) { // Check extension corresponds to a mimetype to know if it's valid. - extension = path.substring(position + 1).toLowerCase(); + const extension = path.substring(position + 1).toLowerCase(); if (this.getMimeType(extension) !== undefined) { return path.substring(0, position); // Remove extension. } diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 6c024c41a..265a8c889 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -741,7 +741,7 @@ export class CoreTextUtilsProvider { * @returns Treated text. */ replaceArguments(text: string, replacements: Record<string, string> = {}, encoding?: 'uri'): string { - let match; + let match: RegExpMatchArray | null = null; while ((match = text.match(/\{\{([^}]+)\}\}/))) { const argument = match[1].trim(); @@ -829,7 +829,7 @@ export class CoreTextUtilsProvider { /** * Replace @@PLUGINFILE@@ wildcards with the real URL in a text. * - * @param Text to treat. + * @param text to treat. * @param files Files to extract the pluginfile URL from. They need to have the URL in a url or fileurl attribute. * @return Treated text. */ @@ -847,8 +847,10 @@ export class CoreTextUtilsProvider { /** * Restore original draftfile URLs. * - * @param text Text to treat, including pluginfile URLs. - * @param replaceMap Map of the replacements that were done. + * @param siteUrl Site URL. + * @param treatedText Treated text with replacements. + * @param originalText Original text. + * @param files List of files to search and replace. * @return Treated text. */ restoreDraftfileUrls(siteUrl: string, treatedText: string, originalText: string, files: CoreWSFile[]): string { @@ -1053,7 +1055,6 @@ export class CoreTextUtilsProvider { * * @param title Title of the new state. * @param content Content of the text to be expanded. - * @param component Component to link the embedded files to. * @param options Options. * @return Promise resolved when the modal is displayed. */ diff --git a/src/core/services/utils/time.ts b/src/core/services/utils/time.ts index bbc4a3e19..e664bb5b8 100644 --- a/src/core/services/utils/time.ts +++ b/src/core/services/utils/time.ts @@ -170,7 +170,7 @@ export class CoreTimeUtilsProvider { /** * Converts a number of seconds into a short human readable format: minutes and seconds, in fromat: 3' 27''. * - * @param seconds Seconds + * @param duration Seconds * @return Short human readable text. * @deprecated since app 4.0. Use CoreTime.formatTimeShort instead. */ diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts index 282a1c4fc..15ef3c685 100644 --- a/src/core/services/utils/url.ts +++ b/src/core/services/utils/url.ts @@ -544,7 +544,7 @@ export class CoreUrlUtilsProvider { url = url.replace(/\/webservice\/pluginfile\.php\//, '/pluginfile.php/'); // Make sure the URL doesn't contain the token. - url.replace(/([?&])token=[^&]*&?/, '$1'); + url = url.replace(/([?&])token=[^&]*&?/, '$1'); return url; } diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index d593de260..58431922a 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -486,7 +486,7 @@ export class CoreUtilsProvider { * @param ...args All the params sent after checkAll will be passed to isEnabledFn. * @return Promise resolved with the list of enabled sites. */ - filterEnabledSites<P extends unknown[]>( + async filterEnabledSites<P extends unknown[]>( siteIds: string[], isEnabledFn: (siteId, ...args: P) => boolean | Promise<boolean>, checkAll?: boolean, @@ -507,16 +507,14 @@ export class CoreUtilsProvider { } } - return this.allPromises(promises).catch(() => { - // Ignore errors. - }).then(() => { - if (!checkAll) { - // Checking 1 was enough, so it will either return all the sites or none. - return enabledSites.length ? siteIds : []; - } else { - return enabledSites; - } - }); + await CoreUtils.ignoreErrors(this.allPromises(promises)); + + if (!checkAll) { + // Checking 1 was enough, so it will either return all the sites or none. + return enabledSites.length ? siteIds : []; + } else { + return enabledSites; + } } /** @@ -639,21 +637,21 @@ export class CoreUtilsProvider { * * @return Promise resolved with the list of countries. */ - getCountryList(): Promise<Record<string, string>> { + async getCountryList(): Promise<Record<string, string>> { // Get the keys of the countries. - return this.getCountryKeysList().then((keys) => { - // Now get the code and the translated name. - const countries = {}; + const keys = await this.getCountryKeysList(); - keys.forEach((key) => { - if (key.indexOf('assets.countries.') === 0) { - const code = key.replace('assets.countries.', ''); - countries[code] = Translate.instant(key); - } - }); + // Now get the code and the translated name. + const countries: Record<string, string> = {}; - return countries; + keys.forEach((key) => { + if (key.indexOf('assets.countries.') === 0) { + const code = key.replace('assets.countries.', ''); + countries[code] = Translate.instant(key); + } }); + + return countries; } /** @@ -661,18 +659,14 @@ export class CoreUtilsProvider { * * @return Promise resolved with the list of countries. */ - getCountryListSorted(): Promise<CoreCountry[]> { + async getCountryListSorted(): Promise<CoreCountry[]> { // Get the keys of the countries. - return this.getCountryList().then((countries) => { - // Sort translations. - const sortedCountries: { code: string; name: string }[] = []; + const countries = await this.getCountryList(); - Object.keys(countries).sort((a, b) => countries[a].localeCompare(countries[b])).forEach((key) => { - sortedCountries.push({ code: key, name: countries[key] }); - }); - - return sortedCountries; - }); + // Sort translations. + return Object.keys(countries) + .sort((a, b) => countries[a].localeCompare(countries[b])) + .map((code) => ({ code, name: countries[code] })); } /** @@ -680,11 +674,13 @@ export class CoreUtilsProvider { * * @return Promise resolved with the countries list. Rejected if not translated. */ - protected getCountryKeysList(): Promise<string[]> { + protected async getCountryKeysList(): Promise<string[]> { // It's possible that the current language isn't translated, so try with default language first. const defaultLang = CoreLang.getDefaultLanguage(); - return this.getCountryKeysListForLanguage(defaultLang).catch(() => { + try { + return await this.getCountryKeysListForLanguage(defaultLang); + } catch { // Not translated, try to use the fallback language. const fallbackLang = CoreLang.getFallbackLanguage(); @@ -693,8 +689,8 @@ export class CoreUtilsProvider { throw new Error('Countries not found.'); } - return this.getCountryKeysListForLanguage(fallbackLang); - }); + return await this.getCountryKeysListForLanguage(fallbackLang); + } } /** @@ -732,17 +728,19 @@ export class CoreUtilsProvider { * @param url The URL of the file. * @return Promise resolved with the mimetype. */ - getMimeTypeFromUrl(url: string): Promise<string> { + async getMimeTypeFromUrl(url: string): Promise<string> { // First check if it can be guessed from the URL. const extension = CoreMimetypeUtils.guessExtensionFromUrl(url); - const mimetype = extension && CoreMimetypeUtils.getMimeType(extension); + let mimetype = extension && CoreMimetypeUtils.getMimeType(extension); if (mimetype) { - return Promise.resolve(mimetype); + return mimetype; } // Can't be guessed, get the remote mimetype. - return CoreWS.getRemoteFileMimeType(url).then(mimetype => mimetype || ''); + mimetype = await CoreWS.getRemoteFileMimeType(url); + + return mimetype || ''; } /** @@ -772,7 +770,7 @@ export class CoreUtilsProvider { /** * Check if an unknown value is a FileEntry. * - * @param value Value to check. + * @param file Object to check. * @return Type guard indicating if the file is a FileEntry. */ valueIsFileEntry(file: unknown): file is FileEntry { @@ -1029,7 +1027,7 @@ export class CoreUtilsProvider { this.iabInstance = InAppBrowser.create(url, '_blank', options); if (CorePlatform.isMobile()) { - let loadStopSubscription; + let loadStopSubscription: Subscription | undefined; const loadStartUrls: string[] = []; // Trigger global events when a url is loaded or the window is closed. This is to make it work like in Ionic 1. @@ -1720,7 +1718,7 @@ export class CoreUtilsProvider { * Ignore errors from a promise. * * @param promise Promise to ignore errors. - * @param fallbackResult Value to return if the promise is rejected. + * @param fallback Value to return if the promise is rejected. * @return Promise with ignored errors, resolving to the fallback result if provided. */ async ignoreErrors<Result>(promise: Promise<Result>): Promise<Result | undefined>;