diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 546d1db53..d51c2f17f 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -69,7 +69,7 @@ jobs: cat circular-dependencies lines=$(cat circular-dependencies | wc -l) echo "Total circular dependencies: $lines" - test $lines -eq 90 + test $lines -eq 93 - name: JavaScript code compatibility run: | npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn" diff --git a/src/addons/mod/forum/pages/search/search.ts b/src/addons/mod/forum/pages/search/search.ts index 24abb8c17..a79612d0b 100644 --- a/src/addons/mod/forum/pages/search/search.ts +++ b/src/addons/mod/forum/pages/search/search.ts @@ -26,12 +26,12 @@ import { import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; -import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrl } from '@singletons/url'; import { CoreUtils } from '@singletons/utils'; import { Translate } from '@singletons'; import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreAlerts } from '@services/overlays/alerts'; +import { CoreLoadings } from '@services/overlays/loadings'; @Component({ selector: 'page-addon-mod-forum-search', @@ -104,7 +104,7 @@ export class AddonModForumSearchPage implements OnInit { return; } - await CoreDomUtils.showOperationModals('core.searching', true, async () => { + await CoreLoadings.showOperationModals('core.searching', true, async () => { await this.resultsSource.reload(); await CorePromiseUtils.ignoreErrors( CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()), diff --git a/src/core/features/search/pages/global-search/global-search.ts b/src/core/features/search/pages/global-search/global-search.ts index 2e05b430f..b00dfb355 100644 --- a/src/core/features/search/pages/global-search/global-search.ts +++ b/src/core/features/search/pages/global-search/global-search.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Component, OnInit, OnDestroy, AfterViewInit, ViewChild } from '@angular/core'; -import { CoreDomUtils } from '@services/utils/dom'; import { CoreSearchGlobalSearchResultsSource } from '@features/search/classes/global-search-results-source'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@singletons/utils'; @@ -31,6 +30,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreSearchBoxComponent } from '@features/search/components/search-box/search-box'; import { CoreModals } from '@services/overlays/modals'; import { CorePromiseUtils } from '@singletons/promise-utils'; +import { CoreLoadings } from '@services/overlays/loadings'; @Component({ selector: 'page-core-search-global-search', @@ -103,7 +103,7 @@ export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy, AfterViewI return; } - await CoreDomUtils.showOperationModals('core.searching', true, async () => { + await CoreLoadings.showOperationModals('core.searching', true, async () => { await this.resultsSource.reload(); await CorePromiseUtils.ignoreErrors( CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()), @@ -150,7 +150,7 @@ export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy, AfterViewI }); if (!this.resultsSource.hasEmptyQuery() && this.resultsSource.isDirty()) { - await CoreDomUtils.showOperationModals('core.searching', true, () => this.resultsSource.reload()); + await CoreLoadings.showOperationModals('core.searching', true, () => this.resultsSource.reload()); } } diff --git a/src/core/features/settings/pages/dev/dev.ts b/src/core/features/settings/pages/dev/dev.ts index bf8a017e2..ecc05f8e9 100644 --- a/src/core/features/settings/pages/dev/dev.ts +++ b/src/core/features/settings/pages/dev/dev.ts @@ -29,10 +29,10 @@ import { CoreFile } from '@services/file'; import { CoreNavigator } from '@services/navigator'; import { CorePlatform } from '@services/platform'; import { CoreSites } from '@services/sites'; -import { CoreDomUtils } from '@services/utils/dom'; import { CoreToasts, ToastDuration } from '@services/overlays/toasts'; import { CoreText } from '@singletons/text'; import { CoreAlerts } from '@services/overlays/alerts'; +import { CoreLoadings } from '@services/overlays/loadings'; /** * Page that displays the developer options. @@ -225,7 +225,7 @@ export class CoreSettingsDevPage implements OnInit { * Invalidate app caches. */ async invalidateCaches(): Promise { - const success = await CoreDomUtils.showOperationModals('Invalidating caches', false, async () => { + const success = await CoreLoadings.showOperationModals('Invalidating caches', false, async () => { await CoreCacheManager.invalidate(); return true; diff --git a/src/core/services/overlays/alerts.ts b/src/core/services/overlays/alerts.ts index 338388b8a..9223a357a 100644 --- a/src/core/services/overlays/alerts.ts +++ b/src/core/services/overlays/alerts.ts @@ -71,8 +71,7 @@ export class CoreAlertsService { confirm(message: string, options: CoreAlertsConfirmOptions = {}): Promise { return new Promise((resolve, reject): void => { const { okText, cancelText, ...alertOptions } = options; - - ( alertOptions).buttons = [ + const buttons = [ { text: cancelText || Translate.instant('core.cancel'), role: 'cancel', @@ -88,11 +87,17 @@ export class CoreAlertsService { }, ]; + let cssClass = alertOptions.cssClass || ''; if (!alertOptions.header) { - options.cssClass = (options.cssClass || '') + ' core-nohead'; + cssClass = cssClass + ' core-nohead'; } - this.show(options); + this.show({ + ...alertOptions, + message, + buttons, + cssClass, + }); }); } @@ -129,11 +134,11 @@ export class CoreAlertsService { }, ]; - if (!options.header) { - options.cssClass = (options.cssClass || '') + ' core-nohead'; + if (!alertOptions.header) { + alertOptions.cssClass = (alertOptions.cssClass || '') + ' core-nohead'; } - this.show(options); + this.show(alertOptions); }); } diff --git a/src/core/services/overlays/loadings.ts b/src/core/services/overlays/loadings.ts index a5d3c8007..ea3bdae4b 100644 --- a/src/core/services/overlays/loadings.ts +++ b/src/core/services/overlays/loadings.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreIonLoadingElement } from '@classes/ion-loading'; import { Translate, makeSingleton } from '@singletons'; +import { CoreAlerts } from './alerts'; /** * Handles application loading. @@ -60,6 +61,28 @@ export class CoreLoadingsService { return loading; } + /** + * Show a loading modal whilst an operation is running, and an error modal if it fails. + * + * @param text Loading dialog text. + * @param needsTranslate Whether the 'text' needs to be translated. + * @param operation Operation. + * @returns Operation result. + */ + async showOperationModals(text: string, needsTranslate: boolean, operation: () => Promise): Promise { + const modal = await this.show(text, needsTranslate); + + try { + return await operation(); + } catch (error) { + CoreAlerts.showError(error); + + return null; + } finally { + modal.dismiss(); + } + } + /** * Pauses the active loading modal. */ diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 2b2149717..51e55a30e 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -794,19 +794,10 @@ export class CoreDomUtilsProvider { * @param needsTranslate Whether the 'text' needs to be translated. * @param operation Operation. * @returns Operation result. + * @deprecated since 5.0. Use CoreLoadings.showOperationModals instead. */ async showOperationModals(text: string, needsTranslate: boolean, operation: () => Promise): Promise { - const modal = await CoreLoadings.show(text, needsTranslate); - - try { - return await operation(); - } catch (error) { - CoreAlerts.showError(error); - - return null; - } finally { - modal.dismiss(); - } + return CoreLoadings.showOperationModals(text, needsTranslate, operation); } /**