MOBILE-4724 core: Move showOperationModals to CoreLoadings
This commit is contained in:
		
							parent
							
								
									c2a500976d
								
							
						
					
					
						commit
						9e006424f6
					
				
							
								
								
									
										2
									
								
								.github/workflows/testing.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/testing.yml
									
									
									
									
										vendored
									
									
								
							@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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()),
 | 
			
		||||
 | 
			
		||||
@ -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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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<void> {
 | 
			
		||||
        const success = await CoreDomUtils.showOperationModals('Invalidating caches', false, async () => {
 | 
			
		||||
        const success = await CoreLoadings.showOperationModals('Invalidating caches', false, async () => {
 | 
			
		||||
            await CoreCacheManager.invalidate();
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
@ -71,8 +71,7 @@ export class CoreAlertsService {
 | 
			
		||||
    confirm<T>(message: string, options: CoreAlertsConfirmOptions = {}): Promise<T> {
 | 
			
		||||
        return new Promise<T>((resolve, reject): void => {
 | 
			
		||||
            const { okText, cancelText, ...alertOptions } = options;
 | 
			
		||||
 | 
			
		||||
            (<AlertOptions> 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);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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<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.
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
@ -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<T>(text: string, needsTranslate: boolean, operation: () => Promise<T>): Promise<T | null> {
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user