MOBILE-4724 core: Move showOperationModals to CoreLoadings

main
Dani Palou 2025-01-13 08:32:20 +01:00
parent c2a500976d
commit 9e006424f6
7 changed files with 45 additions and 26 deletions

View File

@ -69,7 +69,7 @@ jobs:
cat circular-dependencies cat circular-dependencies
lines=$(cat circular-dependencies | wc -l) lines=$(cat circular-dependencies | wc -l)
echo "Total circular dependencies: $lines" echo "Total circular dependencies: $lines"
test $lines -eq 90 test $lines -eq 93
- name: JavaScript code compatibility - name: JavaScript code compatibility
run: | run: |
npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn" npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn"

View File

@ -26,12 +26,12 @@ import {
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrl } from '@singletons/url'; import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@singletons/utils'; import { CoreUtils } from '@singletons/utils';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CorePromiseUtils } from '@singletons/promise-utils'; import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreAlerts } from '@services/overlays/alerts'; import { CoreAlerts } from '@services/overlays/alerts';
import { CoreLoadings } from '@services/overlays/loadings';
@Component({ @Component({
selector: 'page-addon-mod-forum-search', selector: 'page-addon-mod-forum-search',
@ -104,7 +104,7 @@ export class AddonModForumSearchPage implements OnInit {
return; return;
} }
await CoreDomUtils.showOperationModals('core.searching', true, async () => { await CoreLoadings.showOperationModals('core.searching', true, async () => {
await this.resultsSource.reload(); await this.resultsSource.reload();
await CorePromiseUtils.ignoreErrors( await CorePromiseUtils.ignoreErrors(
CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()), CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()),

View File

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
import { Component, OnInit, OnDestroy, AfterViewInit, ViewChild } from '@angular/core'; 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 { CoreSearchGlobalSearchResultsSource } from '@features/search/classes/global-search-results-source';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@singletons/utils'; 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 { CoreSearchBoxComponent } from '@features/search/components/search-box/search-box';
import { CoreModals } from '@services/overlays/modals'; import { CoreModals } from '@services/overlays/modals';
import { CorePromiseUtils } from '@singletons/promise-utils'; import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreLoadings } from '@services/overlays/loadings';
@Component({ @Component({
selector: 'page-core-search-global-search', selector: 'page-core-search-global-search',
@ -103,7 +103,7 @@ export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy, AfterViewI
return; return;
} }
await CoreDomUtils.showOperationModals('core.searching', true, async () => { await CoreLoadings.showOperationModals('core.searching', true, async () => {
await this.resultsSource.reload(); await this.resultsSource.reload();
await CorePromiseUtils.ignoreErrors( await CorePromiseUtils.ignoreErrors(
CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()), 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()) { 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());
} }
} }

View File

@ -29,10 +29,10 @@ import { CoreFile } from '@services/file';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CorePlatform } from '@services/platform'; import { CorePlatform } from '@services/platform';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreToasts, ToastDuration } from '@services/overlays/toasts'; import { CoreToasts, ToastDuration } from '@services/overlays/toasts';
import { CoreText } from '@singletons/text'; import { CoreText } from '@singletons/text';
import { CoreAlerts } from '@services/overlays/alerts'; import { CoreAlerts } from '@services/overlays/alerts';
import { CoreLoadings } from '@services/overlays/loadings';
/** /**
* Page that displays the developer options. * Page that displays the developer options.
@ -225,7 +225,7 @@ export class CoreSettingsDevPage implements OnInit {
* Invalidate app caches. * Invalidate app caches.
*/ */
async invalidateCaches(): Promise<void> { async invalidateCaches(): Promise<void> {
const success = await CoreDomUtils.showOperationModals('Invalidating caches', false, async () => { const success = await CoreLoadings.showOperationModals('Invalidating caches', false, async () => {
await CoreCacheManager.invalidate(); await CoreCacheManager.invalidate();
return true; return true;

View File

@ -71,8 +71,7 @@ export class CoreAlertsService {
confirm<T>(message: string, options: CoreAlertsConfirmOptions = {}): Promise<T> { confirm<T>(message: string, options: CoreAlertsConfirmOptions = {}): Promise<T> {
return new Promise<T>((resolve, reject): void => { return new Promise<T>((resolve, reject): void => {
const { okText, cancelText, ...alertOptions } = options; const { okText, cancelText, ...alertOptions } = options;
const buttons = [
(<AlertOptions> alertOptions).buttons = [
{ {
text: cancelText || Translate.instant('core.cancel'), text: cancelText || Translate.instant('core.cancel'),
role: 'cancel', role: 'cancel',
@ -88,11 +87,17 @@ export class CoreAlertsService {
}, },
]; ];
let cssClass = alertOptions.cssClass || '';
if (!alertOptions.header) { 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) { if (!alertOptions.header) {
options.cssClass = (options.cssClass || '') + ' core-nohead'; alertOptions.cssClass = (alertOptions.cssClass || '') + ' core-nohead';
} }
this.show(options); this.show(alertOptions);
}); });
} }

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreIonLoadingElement } from '@classes/ion-loading'; import { CoreIonLoadingElement } from '@classes/ion-loading';
import { Translate, makeSingleton } from '@singletons'; import { Translate, makeSingleton } from '@singletons';
import { CoreAlerts } from './alerts';
/** /**
* Handles application loading. * Handles application loading.
@ -60,6 +61,28 @@ export class CoreLoadingsService {
return loading; 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<T>(text: string, needsTranslate: boolean, operation: () => Promise<T>): Promise<T | null> {
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. * Pauses the active loading modal.
*/ */

View File

@ -794,19 +794,10 @@ export class CoreDomUtilsProvider {
* @param needsTranslate Whether the 'text' needs to be translated. * @param needsTranslate Whether the 'text' needs to be translated.
* @param operation Operation. * @param operation Operation.
* @returns Operation result. * @returns Operation result.
* @deprecated since 5.0. Use CoreLoadings.showOperationModals instead.
*/ */
async showOperationModals<T>(text: string, needsTranslate: boolean, operation: () => Promise<T>): Promise<T | null> { async showOperationModals<T>(text: string, needsTranslate: boolean, operation: () => Promise<T>): Promise<T | null> {
const modal = await CoreLoadings.show(text, needsTranslate); return CoreLoadings.showOperationModals(text, needsTranslate, operation);
try {
return await operation();
} catch (error) {
CoreAlerts.showError(error);
return null;
} finally {
modal.dismiss();
}
} }
/** /**