MOBILE-4031 core: Create config values for Toast duration
parent
ee64090001
commit
a611ac64d0
|
@ -104,5 +104,10 @@
|
||||||
},
|
},
|
||||||
"wsrequestqueuelimit": 10,
|
"wsrequestqueuelimit": 10,
|
||||||
"wsrequestqueuedelay": 100,
|
"wsrequestqueuedelay": 100,
|
||||||
"calendarreminderdefaultvalue": 3600
|
"calendarreminderdefaultvalue": 3600,
|
||||||
|
"toastDurations": {
|
||||||
|
"short": 2000,
|
||||||
|
"long": 3500,
|
||||||
|
"sticky": 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import { AddonCalendarOffline } from '../../services/calendar-offline';
|
||||||
import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider } from '../../services/calendar-sync';
|
import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider } from '../../services/calendar-sync';
|
||||||
import { CoreNetwork } from '@services/network';
|
import { CoreNetwork } from '@services/network';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreLocalNotifications } from '@services/local-notifications';
|
import { CoreLocalNotifications } from '@services/local-notifications';
|
||||||
|
@ -556,7 +556,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlineEventDeleted || this.event.id < 0) {
|
if (onlineEventDeleted || this.event.id < 0) {
|
||||||
CoreDomUtils.showToast('addon.calendar.eventcalendareventdeleted', true, 3000);
|
CoreDomUtils.showToast('addon.calendar.eventcalendareventdeleted', true, ToastDuration.LONG);
|
||||||
|
|
||||||
// Event deleted, close the view.
|
// Event deleted, close the view.
|
||||||
CoreNavigator.back();
|
CoreNavigator.back();
|
||||||
|
@ -611,7 +611,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.deleted && data.deleted.indexOf(this.eventId) != -1) {
|
if (data.deleted && data.deleted.indexOf(this.eventId) != -1) {
|
||||||
CoreDomUtils.showToast('addon.calendar.eventcalendareventdeleted', true, 3000);
|
CoreDomUtils.showToast('addon.calendar.eventcalendareventdeleted', true, ToastDuration.LONG);
|
||||||
|
|
||||||
// Event was deleted, close the view.
|
// Event was deleted, close the view.
|
||||||
CoreNavigator.back();
|
CoreNavigator.back();
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { CanLeave } from '@guards/can-leave';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreSync } from '@services/sync';
|
import { CoreSync } from '@services/sync';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreFormFields, CoreForms } from '@singletons/form';
|
import { CoreFormFields, CoreForms } from '@singletons/form';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
|
@ -467,7 +467,7 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy, CanLeave {
|
||||||
async timeUp(): Promise<void> {
|
async timeUp(): Promise<void> {
|
||||||
this.timeUpToast = await CoreDomUtils.showToastWithOptions({
|
this.timeUpToast = await CoreDomUtils.showToastWithOptions({
|
||||||
message: Translate.instant('addon.mod_assign.caneditsubmission'),
|
message: Translate.instant('addon.mod_assign.caneditsubmission'),
|
||||||
duration: 0,
|
duration: ToastDuration.STICKY,
|
||||||
buttons: [Translate.instant('core.dismiss')],
|
buttons: [Translate.instant('core.dismiss')],
|
||||||
cssClass: 'core-danger-toast',
|
cssClass: 'core-danger-toast',
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fi
|
||||||
import { CoreRatingOffline } from '@features/rating/services/rating-offline';
|
import { CoreRatingOffline } from '@features/rating/services/rating-offline';
|
||||||
import { FileEntry } from '@ionic-native/file/ngx';
|
import { FileEntry } from '@ionic-native/file/ngx';
|
||||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreFormFields } from '@singletons/form';
|
import { CoreFormFields } from '@singletons/form';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
@ -173,7 +173,11 @@ export class AddonModDataHelperProvider {
|
||||||
|
|
||||||
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, siteId);
|
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, siteId);
|
||||||
|
|
||||||
CoreDomUtils.showToast(approve ? 'addon.mod_data.recordapproved' : 'addon.mod_data.recorddisapproved', true, 3000);
|
CoreDomUtils.showToast(
|
||||||
|
approve ? 'addon.mod_data.recordapproved' : 'addon.mod_data.recorddisapproved',
|
||||||
|
true,
|
||||||
|
ToastDuration.LONG,
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore error, it was already displayed.
|
// Ignore error, it was already displayed.
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -725,7 +729,7 @@ export class AddonModDataHelperProvider {
|
||||||
|
|
||||||
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId, entryId, deleted: true }, siteId);
|
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId, entryId, deleted: true }, siteId);
|
||||||
|
|
||||||
CoreDomUtils.showToast('addon.mod_data.recorddeleted', true, 3000);
|
CoreDomUtils.showToast('addon.mod_data.recorddeleted', true, ToastDuration.LONG);
|
||||||
|
|
||||||
modal.dismiss();
|
modal.dismiss();
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { AddonNotes, AddonNotesPublishState } from '@addons/notes/services/notes
|
||||||
import { Component, ViewChild, ElementRef, Input } from '@angular/core';
|
import { Component, ViewChild, ElementRef, Input } from '@angular/core';
|
||||||
import { CoreApp } from '@services/app';
|
import { CoreApp } from '@services/app';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreForms } from '@singletons/form';
|
import { CoreForms } from '@singletons/form';
|
||||||
import { ModalController } from '@singletons';
|
import { ModalController } from '@singletons';
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ export class AddonNotesAddComponent {
|
||||||
CoreForms.triggerFormSubmittedEvent(this.formElement, sent, CoreSites.getCurrentSiteId());
|
CoreForms.triggerFormSubmittedEvent(this.formElement, sent, CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
ModalController.dismiss(<AddonNotesAddModalReturn>{ type: this.type, sent: true }).finally(() => {
|
ModalController.dismiss(<AddonNotesAddModalReturn>{ type: this.type, sent: true }).finally(() => {
|
||||||
CoreDomUtils.showToast(sent ? 'addon.notes.eventnotecreated' : 'core.datastoredoffline', true, 3000);
|
CoreDomUtils.showToast(sent ? 'addon.notes.eventnotecreated' : 'core.datastoredoffline', true, ToastDuration.LONG);
|
||||||
});
|
});
|
||||||
} catch (error){
|
} catch (error){
|
||||||
CoreDomUtils.showErrorModal(error);
|
CoreDomUtils.showErrorModal(error);
|
||||||
|
|
|
@ -23,7 +23,7 @@ import { CoreUser, CoreUserProfile } from '@features/user/services/user';
|
||||||
import { IonContent, IonRefresher } from '@ionic/angular';
|
import { IonContent, IonRefresher } from '@ionic/angular';
|
||||||
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 { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
|
@ -232,7 +232,7 @@ export class AddonNotesListPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
this.refreshNotes(false);
|
this.refreshNotes(false);
|
||||||
|
|
||||||
CoreDomUtils.showToast('addon.notes.eventnotedeleted', true, 3000);
|
CoreDomUtils.showToast('addon.notes.eventnotedeleted', true, ToastDuration.LONG);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'Delete note failed.');
|
CoreDomUtils.showErrorModalDefault(error, 'Delete note failed.');
|
||||||
|
|
|
@ -29,7 +29,7 @@ import {
|
||||||
CoreWSUploadFileResult,
|
CoreWSUploadFileResult,
|
||||||
CoreWSPreSetsSplitRequest,
|
CoreWSPreSetsSplitRequest,
|
||||||
} from '@services/ws';
|
} from '@services/ws';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreTimeUtils } from '@services/utils/time';
|
import { CoreTimeUtils } from '@services/utils/time';
|
||||||
import { CoreUrlUtils, CoreUrlParams } from '@services/utils/url';
|
import { CoreUrlUtils, CoreUrlParams } from '@services/utils/url';
|
||||||
|
@ -572,7 +572,7 @@ export class CoreSite {
|
||||||
|
|
||||||
if (wsPreSets.cleanUnicode && CoreTextUtils.hasUnicodeData(data)) {
|
if (wsPreSets.cleanUnicode && CoreTextUtils.hasUnicodeData(data)) {
|
||||||
// Data will be cleaned, notify the user.
|
// Data will be cleaned, notify the user.
|
||||||
CoreDomUtils.showToast('core.unicodenotsupported', true, 3000);
|
CoreDomUtils.showToast('core.unicodenotsupported', true, ToastDuration.LONG);
|
||||||
} else {
|
} else {
|
||||||
// No need to clean data in this call.
|
// No need to clean data in this call.
|
||||||
wsPreSets.cleanUnicode = false;
|
wsPreSets.cleanUnicode = false;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import { ContextLevel, CoreConstants } from '@/core/constants';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { NgZone, Translate } from '@singletons';
|
import { NgZone, Translate } from '@singletons';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { CoreUser } from '@features/user/services/user';
|
import { CoreUser } from '@features/user/services/user';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
|
@ -319,7 +319,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
|
||||||
CoreDomUtils.showToast(
|
CoreDomUtils.showToast(
|
||||||
commentsResponse ? 'core.comments.eventcommentcreated' : 'core.datastoredoffline',
|
commentsResponse ? 'core.comments.eventcommentcreated' : 'core.datastoredoffline',
|
||||||
true,
|
true,
|
||||||
3000,
|
ToastDuration.LONG,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (commentsResponse) {
|
if (commentsResponse) {
|
||||||
|
@ -417,7 +417,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
this.invalidateComments();
|
this.invalidateComments();
|
||||||
|
|
||||||
CoreDomUtils.showToast('core.comments.eventcommentdeleted', true, 3000);
|
CoreDomUtils.showToast('core.comments.eventcommentdeleted', true, ToastDuration.LONG);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'Delete comment failed.');
|
CoreDomUtils.showErrorModalDefault(error, 'Delete comment failed.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import {
|
||||||
} from '@features/rating/services/rating';
|
} from '@features/rating/services/rating';
|
||||||
import { CoreRatingOffline } from '@features/rating/services/rating-offline';
|
import { CoreRatingOffline } from '@features/rating/services/rating-offline';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils, ToastDuration } from '@services/utils/dom';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ export class CoreRatingRateComponent implements OnChanges, OnDestroy {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response === undefined) {
|
if (response === undefined) {
|
||||||
CoreDomUtils.showToast('core.datastoredoffline', true, 3000);
|
CoreDomUtils.showToast('core.datastoredoffline', true, ToastDuration.LONG);
|
||||||
} else {
|
} else {
|
||||||
this.onUpdate.emit();
|
this.onUpdate.emit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1614,23 +1614,19 @@ export class CoreDomUtilsProvider {
|
||||||
async showToast(
|
async showToast(
|
||||||
text: string,
|
text: string,
|
||||||
needsTranslate?: boolean,
|
needsTranslate?: boolean,
|
||||||
duration: number = 2000,
|
duration: ToastDuration | number = ToastDuration.SHORT,
|
||||||
cssClass: string = '',
|
cssClass: string = '',
|
||||||
): Promise<HTMLIonToastElement> {
|
): Promise<HTMLIonToastElement> {
|
||||||
if (needsTranslate) {
|
if (needsTranslate) {
|
||||||
text = Translate.instant(text);
|
text = Translate.instant(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
const loader = await ToastController.create({
|
return this.showToastWithOptions({
|
||||||
message: text,
|
message: text,
|
||||||
duration: duration,
|
duration: duration,
|
||||||
position: 'bottom',
|
position: 'bottom',
|
||||||
cssClass: cssClass,
|
cssClass: cssClass,
|
||||||
});
|
});
|
||||||
|
|
||||||
await loader.present();
|
|
||||||
|
|
||||||
return loader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1639,12 +1635,15 @@ export class CoreDomUtilsProvider {
|
||||||
* @param options Options.
|
* @param options Options.
|
||||||
* @return Promise resolved with Toast instance.
|
* @return Promise resolved with Toast instance.
|
||||||
*/
|
*/
|
||||||
async showToastWithOptions(options: ToastOptions): Promise<HTMLIonToastElement> {
|
async showToastWithOptions(options: ShowToastOptions): Promise<HTMLIonToastElement> {
|
||||||
// Set some default values.
|
// Convert some values and set default values.
|
||||||
options.duration = options.duration ?? 2000;
|
const toastOptions: ToastOptions = {
|
||||||
options.position = options.position ?? 'bottom';
|
...options,
|
||||||
|
duration: CoreConstants.CONFIG.toastDurations[options.duration] ?? options.duration ?? 2000,
|
||||||
|
position: options.position ?? 'bottom',
|
||||||
|
};
|
||||||
|
|
||||||
const loader = await ToastController.create(options);
|
const loader = await ToastController.create(toastOptions);
|
||||||
|
|
||||||
await loader.present();
|
await loader.present();
|
||||||
|
|
||||||
|
@ -2130,3 +2129,19 @@ export enum VerticalPoint {
|
||||||
MID = 'mid',
|
MID = 'mid',
|
||||||
BOTTOM = 'bottom',
|
BOTTOM = 'bottom',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toast duration.
|
||||||
|
*/
|
||||||
|
export enum ToastDuration {
|
||||||
|
LONG = 'long',
|
||||||
|
SHORT = 'short',
|
||||||
|
STICKY = 'sticky',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for showToastWithOptions.
|
||||||
|
*/
|
||||||
|
export type ShowToastOptions = Omit<ToastOptions, 'duration'> & {
|
||||||
|
duration: ToastDuration | number;
|
||||||
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { CoreSitesDemoSiteData } from '@services/sites';
|
||||||
import { OpenFileAction } from '@services/utils/utils';
|
import { OpenFileAction } from '@services/utils/utils';
|
||||||
import { CoreLoginSiteSelectorListMethod } from '@features/login/services/login-helper';
|
import { CoreLoginSiteSelectorListMethod } from '@features/login/services/login-helper';
|
||||||
import { CoreDatabaseConfiguration } from '@classes/database/database-table';
|
import { CoreDatabaseConfiguration } from '@classes/database/database-table';
|
||||||
|
import { ToastDuration } from '@services/utils/dom';
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
|
||||||
|
@ -69,4 +70,5 @@ export interface EnvironmentConfig {
|
||||||
calendarreminderdefaultvalue: number; // Initial value for default reminders (in seconds). User can change it later.
|
calendarreminderdefaultvalue: number; // Initial value for default reminders (in seconds). User can change it later.
|
||||||
removeaccountonlogout?: boolean; // True to remove the account when the user clicks logout. Doesn't affect switch account.
|
removeaccountonlogout?: boolean; // True to remove the account when the user clicks logout. Doesn't affect switch account.
|
||||||
uselegacycompletion?: boolean; // Whether to use legacy completion by default in all course formats.
|
uselegacycompletion?: boolean; // Whether to use legacy completion by default in all course formats.
|
||||||
|
toastDurations: Record<ToastDuration, number>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue