MOBILE-2791 core: Prevent repeated alerts
parent
35163f473c
commit
02a7f39080
|
@ -24,6 +24,7 @@ import { CoreAppProvider } from '../app';
|
||||||
import { CoreConfigProvider } from '../config';
|
import { CoreConfigProvider } from '../config';
|
||||||
import { CoreUrlUtilsProvider } from './url';
|
import { CoreUrlUtilsProvider } from './url';
|
||||||
import { CoreConstants } from '@core/constants';
|
import { CoreConstants } from '@core/constants';
|
||||||
|
import { Md5 } from 'ts-md5/dist/md5';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "Utils" service with helper functions for UI, DOM elements and HTML code.
|
* "Utils" service with helper functions for UI, DOM elements and HTML code.
|
||||||
|
@ -41,6 +42,7 @@ export class CoreDomUtilsProvider {
|
||||||
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
|
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
|
||||||
protected lastInstanceId = 0;
|
protected lastInstanceId = 0;
|
||||||
protected debugDisplay = false; // Whether to display debug messages. Store it in a variable to make it synchronous.
|
protected debugDisplay = false; // Whether to display debug messages. Store it in a variable to make it synchronous.
|
||||||
|
protected displayedAlerts = {}; // To prevent duplicated alerts.
|
||||||
|
|
||||||
constructor(private translate: TranslateService, private loadingCtrl: LoadingController, private toastCtrl: ToastController,
|
constructor(private translate: TranslateService, private loadingCtrl: LoadingController, private toastCtrl: ToastController,
|
||||||
private alertCtrl: AlertController, private textUtils: CoreTextUtilsProvider, private appProvider: CoreAppProvider,
|
private alertCtrl: AlertController, private textUtils: CoreTextUtilsProvider, private appProvider: CoreAppProvider,
|
||||||
|
@ -898,6 +900,12 @@ export class CoreDomUtilsProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
return promise.then((message) => {
|
return promise.then((message) => {
|
||||||
|
const alertId = <string> Md5.hashAsciiStr((title || '') + '#' + (message || ''));
|
||||||
|
|
||||||
|
if (this.displayedAlerts[alertId]) {
|
||||||
|
// There's already an alert with the same message and title. Return it.
|
||||||
|
return this.displayedAlerts[alertId];
|
||||||
|
}
|
||||||
|
|
||||||
const alert = this.alertCtrl.create({
|
const alert = this.alertCtrl.create({
|
||||||
title: title,
|
title: title,
|
||||||
|
@ -913,6 +921,13 @@ export class CoreDomUtilsProvider {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Store the alert and remove it when dismissed.
|
||||||
|
this.displayedAlerts[alertId] = alert;
|
||||||
|
|
||||||
|
alert.onDidDismiss(() => {
|
||||||
|
delete this.displayedAlerts[alertId];
|
||||||
|
});
|
||||||
|
|
||||||
if (autocloseTime > 0) {
|
if (autocloseTime > 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
alert.dismiss();
|
alert.dismiss();
|
||||||
|
|
Loading…
Reference in New Issue