MOBILE-4653 reminders: Move reminders constants
parent
efd364f285
commit
966edb8beb
|
@ -40,7 +40,7 @@ import { CoreError } from '@classes/errors/error';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CanLeave } from '@guards/can-leave';
|
import { CanLeave } from '@guards/can-leave';
|
||||||
import { CoreForms } from '@singletons/form';
|
import { CoreForms } from '@singletons/form';
|
||||||
import { CoreReminders, CoreRemindersService, CoreRemindersUnits } from '@features/reminders/services/reminders';
|
import { CoreReminders, CoreRemindersService } from '@features/reminders/services/reminders';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import {
|
import {
|
||||||
ADDON_CALENDAR_COMPONENT,
|
ADDON_CALENDAR_COMPONENT,
|
||||||
|
@ -52,6 +52,7 @@ import {
|
||||||
import { ContextLevel } from '@/core/constants';
|
import { ContextLevel } from '@/core/constants';
|
||||||
import { CorePopovers } from '@services/popovers';
|
import { CorePopovers } from '@services/popovers';
|
||||||
import { CoreLoadings } from '@services/loadings';
|
import { CoreLoadings } from '@services/loadings';
|
||||||
|
import { REMINDERS_DISABLED, CoreRemindersUnits } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays a form to create/edit an event.
|
* Page that displays a form to create/edit an event.
|
||||||
|
@ -621,7 +622,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
|
|
||||||
// Check if default reminders are enabled.
|
// Check if default reminders are enabled.
|
||||||
const defaultTime = await CoreReminders.getDefaultNotificationTime(this.currentSite.getId());
|
const defaultTime = await CoreReminders.getDefaultNotificationTime(this.currentSite.getId());
|
||||||
if (defaultTime === CoreRemindersService.DISABLED) {
|
if (defaultTime === REMINDERS_DISABLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import { CoreConstants } from '@/core/constants';
|
||||||
import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker';
|
import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker';
|
||||||
import { AddonCalendarEventsSource } from '@addons/calendar/classes/events-source';
|
import { AddonCalendarEventsSource } from '@addons/calendar/classes/events-source';
|
||||||
import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager';
|
import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager';
|
||||||
import { CoreReminders, CoreRemindersService } from '@features/reminders/services/reminders';
|
import { CoreReminders } from '@features/reminders/services/reminders';
|
||||||
import { CoreLocalNotifications } from '@services/local-notifications';
|
import { CoreLocalNotifications } from '@services/local-notifications';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import { CoreConfig } from '@services/config';
|
import { CoreConfig } from '@services/config';
|
||||||
|
@ -54,6 +54,7 @@ import {
|
||||||
ADDON_CALENDAR_NEW_EVENT_EVENT,
|
ADDON_CALENDAR_NEW_EVENT_EVENT,
|
||||||
ADDON_CALENDAR_UNDELETED_EVENT_EVENT,
|
ADDON_CALENDAR_UNDELETED_EVENT_EVENT,
|
||||||
} from '@addons/calendar/constants';
|
} from '@addons/calendar/constants';
|
||||||
|
import { REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays a single calendar event.
|
* Page that displays a single calendar event.
|
||||||
|
@ -146,7 +147,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reload reminders if default notification time changes.
|
// Reload reminders if default notification time changes.
|
||||||
this.defaultTimeChangedObserver = CoreEvents.on(CoreRemindersService.DEFAULT_NOTIFICATION_TIME_CHANGED, () => {
|
this.defaultTimeChangedObserver = CoreEvents.on(REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED, () => {
|
||||||
this.loadReminders();
|
this.loadReminders();
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
CoreReminders,
|
CoreReminders,
|
||||||
CoreRemindersService,
|
CoreRemindersService,
|
||||||
} from '@features/reminders/services/reminders';
|
} from '@features/reminders/services/reminders';
|
||||||
|
import { REMINDERS_DISABLED } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the calendar settings.
|
* Page that displays the calendar settings.
|
||||||
|
@ -67,7 +68,7 @@ export class AddonCalendarSettingsPage implements OnInit {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await CoreReminders.setDefaultNotificationTime(reminderTime.timeBefore ?? CoreRemindersService.DISABLED);
|
await CoreReminders.setDefaultNotificationTime(reminderTime.timeBefore ?? REMINDERS_DISABLED);
|
||||||
this.updateDefaultTimeLabel();
|
this.updateDefaultTimeLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ import {
|
||||||
AddonCalendarEventType,
|
AddonCalendarEventType,
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
import { AddonCalendarSyncInvalidateEvent } from './calendar-sync';
|
import { AddonCalendarSyncInvalidateEvent } from './calendar-sync';
|
||||||
|
import { REMINDERS_DISABLED, REMINDERS_DEFAULT_REMINDER_TIMEBEFORE } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that provides some features regarding lists of courses and categories.
|
* Service that provides some features regarding lists of courses and categories.
|
||||||
|
@ -314,7 +315,7 @@ export class AddonCalendarHelperProvider {
|
||||||
const defaultTime = await CoreReminders.getDefaultNotificationTime(siteId);
|
const defaultTime = await CoreReminders.getDefaultNotificationTime(siteId);
|
||||||
let defaultLabel: string | undefined;
|
let defaultLabel: string | undefined;
|
||||||
|
|
||||||
if (defaultTime > CoreRemindersService.DISABLED) {
|
if (defaultTime > REMINDERS_DISABLED) {
|
||||||
const data = CoreRemindersService.convertSecondsToValueAndUnit(defaultTime);
|
const data = CoreRemindersService.convertSecondsToValueAndUnit(defaultTime);
|
||||||
defaultLabel = CoreReminders.getUnitValueLabel(data.value, data.unit, true);
|
defaultLabel = CoreReminders.getUnitValueLabel(data.value, data.unit, true);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +325,7 @@ export class AddonCalendarHelperProvider {
|
||||||
id: reminder.id,
|
id: reminder.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (reminder.timebefore === CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE) {
|
if (reminder.timebefore === REMINDERS_DEFAULT_REMINDER_TIMEBEFORE) {
|
||||||
// Default time. Check if default notifications are disabled.
|
// Default time. Check if default notifications are disabled.
|
||||||
if (defaultLabel !== undefined) {
|
if (defaultLabel !== undefined) {
|
||||||
formatted.label = defaultLabel;
|
formatted.label = defaultLabel;
|
||||||
|
|
|
@ -41,7 +41,6 @@ import {
|
||||||
CoreReminderData,
|
CoreReminderData,
|
||||||
CoreReminders,
|
CoreReminders,
|
||||||
CoreRemindersPushNotificationData,
|
CoreRemindersPushNotificationData,
|
||||||
CoreRemindersService,
|
|
||||||
} from '@features/reminders/services/reminders';
|
} from '@features/reminders/services/reminders';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||||
|
@ -60,6 +59,7 @@ import {
|
||||||
ADDON_CALENDAR_UNDELETED_EVENT_EVENT,
|
ADDON_CALENDAR_UNDELETED_EVENT_EVENT,
|
||||||
AddonCalendarEventType,
|
AddonCalendarEventType,
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
|
import { REMINDERS_DEFAULT_REMINDER_TIMEBEFORE } from '@features/reminders/constants';
|
||||||
import { AddonCalendarFilter } from './calendar-helper';
|
import { AddonCalendarFilter } from './calendar-helper';
|
||||||
|
|
||||||
declare module '@singletons/events' {
|
declare module '@singletons/events' {
|
||||||
|
@ -685,7 +685,7 @@ export class AddonCalendarProvider {
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
|
||||||
timebefore = timebefore ?? CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE;
|
timebefore = timebefore ?? REMINDERS_DEFAULT_REMINDER_TIMEBEFORE;
|
||||||
|
|
||||||
const previousReminders = await CoreReminders.getReminders({
|
const previousReminders = await CoreReminders.getReminders({
|
||||||
instanceId: event.id,
|
instanceId: event.id,
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
import { ADDON_CALENDAR_EVENTS_TABLE, AddonCalendarEventType } from '@addons/calendar/constants';
|
import { ADDON_CALENDAR_EVENTS_TABLE, AddonCalendarEventType } from '@addons/calendar/constants';
|
||||||
import { SQLiteDB } from '@classes/sqlitedb';
|
import { SQLiteDB } from '@classes/sqlitedb';
|
||||||
import { CoreRemindersService, CoreReminders } from '@features/reminders/services/reminders';
|
import { REMINDERS_DISABLED } from '@features/reminders/constants';
|
||||||
|
import { CoreReminders } from '@features/reminders/services/reminders';
|
||||||
import { CoreConfig } from '@services/config';
|
import { CoreConfig } from '@services/config';
|
||||||
import { CoreSiteSchema } from '@services/sites';
|
import { CoreSiteSchema } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
@ -201,7 +202,7 @@ const migrateDefaultTime = async (siteId: string, convertToSeconds = false): Pro
|
||||||
await CoreUtils.ignoreErrors(CoreConfig.delete(key));
|
await CoreUtils.ignoreErrors(CoreConfig.delete(key));
|
||||||
|
|
||||||
if (defaultTime <= 0) {
|
if (defaultTime <= 0) {
|
||||||
defaultTime = CoreRemindersService.DISABLED;
|
defaultTime = REMINDERS_DISABLED;
|
||||||
} else if (convertToSeconds) {
|
} else if (convertToSeconds) {
|
||||||
// Convert from minutes to seconds.
|
// Convert from minutes to seconds.
|
||||||
defaultTime = defaultTime * 60;
|
defaultTime = defaultTime * 60;
|
||||||
|
|
|
@ -12,12 +12,13 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreReminderData, CoreReminders, CoreRemindersService } from '@features/reminders/services/reminders';
|
import { CoreReminderData, CoreReminders } from '@features/reminders/services/reminders';
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { CorePopovers } from '@services/popovers';
|
import { CorePopovers } from '@services/popovers';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreTimeUtils } from '@services/utils/time';
|
import { CoreTimeUtils } from '@services/utils/time';
|
||||||
import { CoreToasts } from '@services/toasts';
|
import { CoreToasts } from '@services/toasts';
|
||||||
|
import { REMINDERS_DISABLED } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that displays a button to set a reminder.
|
* Component that displays a button to set a reminder.
|
||||||
|
@ -128,7 +129,7 @@ export class CoreRemindersSetButtonComponent implements OnInit {
|
||||||
type: this.type,
|
type: this.type,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (timebefore === undefined || timebefore === CoreRemindersService.DISABLED) {
|
if (timebefore === undefined || timebefore === REMINDERS_DISABLED) {
|
||||||
this.setTimebefore(undefined);
|
this.setTimebefore(undefined);
|
||||||
CoreToasts.show({
|
CoreToasts.show({
|
||||||
message: 'core.reminders.reminderunset',
|
message: 'core.reminders.reminderunset',
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import { CoreSharedModule } from '@/core/shared.module';
|
import { CoreSharedModule } from '@/core/shared.module';
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { CoreRemindersUnits } from '@features/reminders/services/reminders';
|
import { CoreRemindersUnits } from '@features/reminders/constants';
|
||||||
import { PopoverController } from '@singletons';
|
import { PopoverController } from '@singletons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,13 +16,13 @@ import { Component, Input, OnInit } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
CoreReminders,
|
CoreReminders,
|
||||||
CoreRemindersService,
|
CoreRemindersService,
|
||||||
CoreRemindersUnits,
|
|
||||||
CoreReminderValueAndUnit,
|
CoreReminderValueAndUnit,
|
||||||
} from '@features/reminders/services/reminders';
|
} from '@features/reminders/services/reminders';
|
||||||
import { CorePopovers } from '@services/popovers';
|
import { CorePopovers } from '@services/popovers';
|
||||||
import { CoreWait } from '@singletons/wait';
|
import { CoreWait } from '@singletons/wait';
|
||||||
import { PopoverController } from '@singletons';
|
import { PopoverController } from '@singletons';
|
||||||
import { CoreSharedModule } from '@/core/shared.module';
|
import { CoreSharedModule } from '@/core/shared.module';
|
||||||
|
import { CoreRemindersUnits, REMINDERS_DISABLED } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component is meant to display a popover with the reminder options.
|
* This component is meant to display a popover with the reminder options.
|
||||||
|
@ -88,7 +88,7 @@ export class CoreRemindersSetReminderMenuComponent implements OnInit {
|
||||||
});
|
});
|
||||||
|
|
||||||
const initialValue = CoreRemindersService.convertSecondsToValueAndUnit(this.initialValue);
|
const initialValue = CoreRemindersService.convertSecondsToValueAndUnit(this.initialValue);
|
||||||
if (initialValue.value === CoreRemindersService.DISABLED) {
|
if (initialValue.value === REMINDERS_DISABLED) {
|
||||||
this.currentValue = 'disabled';
|
this.currentValue = 'disabled';
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { CoreConstants } from '@/core/constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Units to set a reminder.
|
||||||
|
*/
|
||||||
|
export enum CoreRemindersUnits {
|
||||||
|
MINUTE = CoreConstants.SECONDS_MINUTE,
|
||||||
|
HOUR = CoreConstants.SECONDS_HOUR,
|
||||||
|
DAY = CoreConstants.SECONDS_DAY,
|
||||||
|
WEEK = CoreConstants.SECONDS_WEEK,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const REMINDERS_UNITS_LABELS = {
|
||||||
|
single: {
|
||||||
|
[CoreRemindersUnits.MINUTE]: 'core.minute',
|
||||||
|
[CoreRemindersUnits.HOUR]: 'core.hour',
|
||||||
|
[CoreRemindersUnits.DAY]: 'core.day',
|
||||||
|
[CoreRemindersUnits.WEEK]: 'core.week',
|
||||||
|
},
|
||||||
|
multi: {
|
||||||
|
[CoreRemindersUnits.MINUTE]: 'core.minutes',
|
||||||
|
[CoreRemindersUnits.HOUR]: 'core.hours',
|
||||||
|
[CoreRemindersUnits.DAY]: 'core.days',
|
||||||
|
[CoreRemindersUnits.WEEK]: 'core.weeks',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const REMINDERS_DEFAULT_REMINDER_TIMEBEFORE = -1;
|
||||||
|
export const REMINDERS_DISABLED = -1;
|
||||||
|
|
||||||
|
export const REMINDERS_DEFAULT_NOTIFICATION_TIME_SETTING = 'CoreRemindersDefaultNotification';
|
||||||
|
export const REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED = 'CoreRemindersDefaultNotificationChangedEvent';
|
|
@ -16,8 +16,9 @@ import { ADDON_CALENDAR_COMPONENT, ADDON_CALENDAR_EVENTS_TABLE } from '@addons/c
|
||||||
import { SQLiteDB } from '@classes/sqlitedb';
|
import { SQLiteDB } from '@classes/sqlitedb';
|
||||||
import { CoreSiteSchema } from '@services/sites';
|
import { CoreSiteSchema } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreReminderData, CoreRemindersService } from '../reminders';
|
import { CoreReminderData } from '../reminders';
|
||||||
import { AddonCalendarEventDBRecord } from '@addons/calendar/services/database/calendar';
|
import { AddonCalendarEventDBRecord } from '@addons/calendar/services/database/calendar';
|
||||||
|
import { REMINDERS_DEFAULT_REMINDER_TIMEBEFORE } from '@features/reminders/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database variables for CoreRemindersService service.
|
* Database variables for CoreRemindersService service.
|
||||||
|
@ -113,7 +114,7 @@ const migrateFromCalendarRemindersV1 = async (db: SQLiteDB): Promise<void> => {
|
||||||
|
|
||||||
if (!reminderTime || reminderTime === -1) {
|
if (!reminderTime || reminderTime === -1) {
|
||||||
// Default reminder.
|
// Default reminder.
|
||||||
reminderTime = CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE;
|
reminderTime = REMINDERS_DEFAULT_REMINDER_TIMEBEFORE;
|
||||||
} else if (reminderTime > event.timestart) {
|
} else if (reminderTime > event.timestart) {
|
||||||
// Reminder is after the event, ignore it.
|
// Reminder is after the event, ignore it.
|
||||||
return;
|
return;
|
||||||
|
@ -165,7 +166,7 @@ const migrateFromCalendarRemindersV2 = async (db: SQLiteDB): Promise<void> => {
|
||||||
}
|
}
|
||||||
const event = events[record.eventid];
|
const event = events[record.eventid];
|
||||||
|
|
||||||
const reminderTime = record.time || CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE;
|
const reminderTime = record.time || REMINDERS_DEFAULT_REMINDER_TIMEBEFORE;
|
||||||
|
|
||||||
if (uniqueReminder[record.eventid] === undefined) {
|
if (uniqueReminder[record.eventid] === undefined) {
|
||||||
uniqueReminder[record.eventid] = [];
|
uniqueReminder[record.eventid] = [];
|
||||||
|
|
|
@ -27,31 +27,14 @@ import { lazyMap, LazyMap } from '@/core/utils/lazy-map';
|
||||||
import { CoreDatabaseTable } from '@classes/database/database-table';
|
import { CoreDatabaseTable } from '@classes/database/database-table';
|
||||||
import { asyncInstance, AsyncInstance } from '@/core/utils/async-instance';
|
import { asyncInstance, AsyncInstance } from '@/core/utils/async-instance';
|
||||||
import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-proxy';
|
import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-proxy';
|
||||||
|
import {
|
||||||
/**
|
CoreRemindersUnits,
|
||||||
* Units to set a reminder.
|
REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED,
|
||||||
*/
|
REMINDERS_DEFAULT_NOTIFICATION_TIME_SETTING,
|
||||||
export enum CoreRemindersUnits {
|
REMINDERS_DEFAULT_REMINDER_TIMEBEFORE,
|
||||||
MINUTE = CoreConstants.SECONDS_MINUTE,
|
REMINDERS_DISABLED,
|
||||||
HOUR = CoreConstants.SECONDS_HOUR,
|
REMINDERS_UNITS_LABELS,
|
||||||
DAY = CoreConstants.SECONDS_DAY,
|
} from '../constants';
|
||||||
WEEK = CoreConstants.SECONDS_WEEK,
|
|
||||||
}
|
|
||||||
|
|
||||||
const REMINDER_UNITS_LABELS = {
|
|
||||||
single: {
|
|
||||||
[CoreRemindersUnits.MINUTE]: 'core.minute',
|
|
||||||
[CoreRemindersUnits.HOUR]: 'core.hour',
|
|
||||||
[CoreRemindersUnits.DAY]: 'core.day',
|
|
||||||
[CoreRemindersUnits.WEEK]: 'core.week',
|
|
||||||
},
|
|
||||||
multi: {
|
|
||||||
[CoreRemindersUnits.MINUTE]: 'core.minutes',
|
|
||||||
[CoreRemindersUnits.HOUR]: 'core.hours',
|
|
||||||
[CoreRemindersUnits.DAY]: 'core.days',
|
|
||||||
[CoreRemindersUnits.WEEK]: 'core.weeks',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to handle reminders.
|
* Service to handle reminders.
|
||||||
|
@ -59,11 +42,23 @@ const REMINDER_UNITS_LABELS = {
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreRemindersService {
|
export class CoreRemindersService {
|
||||||
|
|
||||||
static readonly DEFAULT_REMINDER_TIMEBEFORE = -1;
|
/**
|
||||||
static readonly DISABLED = -1;
|
* @deprecated since 5.0. Use REMINDERS_DEFAULT_REMINDER_TIMEBEFORE instead.
|
||||||
|
*/
|
||||||
|
static readonly DEFAULT_REMINDER_TIMEBEFORE = REMINDERS_DEFAULT_REMINDER_TIMEBEFORE;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use REMINDERS_DISABLED instead.
|
||||||
|
*/
|
||||||
|
static readonly DISABLED = REMINDERS_DISABLED;
|
||||||
|
|
||||||
static readonly DEFAULT_NOTIFICATION_TIME_SETTING = 'CoreRemindersDefaultNotification';
|
/**
|
||||||
static readonly DEFAULT_NOTIFICATION_TIME_CHANGED = 'CoreRemindersDefaultNotificationChangedEvent';
|
* @deprecated since 5.0. Use REMINDERS_DEFAULT_NOTIFICATION_TIME_SETTING instead.
|
||||||
|
*/
|
||||||
|
static readonly DEFAULT_NOTIFICATION_TIME_SETTING = REMINDERS_DEFAULT_NOTIFICATION_TIME_SETTING;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED instead.
|
||||||
|
*/
|
||||||
|
static readonly DEFAULT_NOTIFICATION_TIME_CHANGED = REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED;
|
||||||
|
|
||||||
protected remindersTables: LazyMap<AsyncInstance<CoreDatabaseTable<CoreReminderDBRecord>>>;
|
protected remindersTables: LazyMap<AsyncInstance<CoreDatabaseTable<CoreReminderDBRecord>>>;
|
||||||
|
|
||||||
|
@ -91,7 +86,7 @@ export class CoreRemindersService {
|
||||||
|
|
||||||
this.scheduleAllNotifications();
|
this.scheduleAllNotifications();
|
||||||
|
|
||||||
CoreEvents.on(CoreRemindersService.DEFAULT_NOTIFICATION_TIME_CHANGED, async (data) => {
|
CoreEvents.on(REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED, async (data) => {
|
||||||
const site = await CoreSites.getSite(data.siteId);
|
const site = await CoreSites.getSite(data.siteId);
|
||||||
const siteId = site.getId();
|
const siteId = site.getId();
|
||||||
|
|
||||||
|
@ -215,7 +210,7 @@ export class CoreRemindersService {
|
||||||
protected async getRemindersWithDefaultTime(siteId?: string): Promise<CoreReminderDBRecord[]> {
|
protected async getRemindersWithDefaultTime(siteId?: string): Promise<CoreReminderDBRecord[]> {
|
||||||
siteId ??= CoreSites.getCurrentSiteId();
|
siteId ??= CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
return this.remindersTables[siteId].getMany({ timebefore: CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE }, {
|
return this.remindersTables[siteId].getMany({ timebefore: REMINDERS_DEFAULT_REMINDER_TIMEBEFORE }, {
|
||||||
sorting: [
|
sorting: [
|
||||||
{ time: 'asc' },
|
{ time: 'asc' },
|
||||||
],
|
],
|
||||||
|
@ -294,11 +289,11 @@ export class CoreRemindersService {
|
||||||
|
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
const timebefore = reminder.timebefore === CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE
|
const timebefore = reminder.timebefore === REMINDERS_DEFAULT_REMINDER_TIMEBEFORE
|
||||||
? await this.getDefaultNotificationTime(siteId)
|
? await this.getDefaultNotificationTime(siteId)
|
||||||
: reminder.timebefore;
|
: reminder.timebefore;
|
||||||
|
|
||||||
if (timebefore === CoreRemindersService.DISABLED) {
|
if (timebefore === REMINDERS_DISABLED) {
|
||||||
// Notification disabled. Cancel.
|
// Notification disabled. Cancel.
|
||||||
return this.cancelReminder(reminder.id, reminder.component, siteId);
|
return this.cancelReminder(reminder.id, reminder.component, siteId);
|
||||||
}
|
}
|
||||||
|
@ -364,7 +359,7 @@ export class CoreRemindersService {
|
||||||
* @returns Translated label.
|
* @returns Translated label.
|
||||||
*/
|
*/
|
||||||
getUnitValueLabel(value: number, unit: CoreRemindersUnits, addDefaultLabel = false): string {
|
getUnitValueLabel(value: number, unit: CoreRemindersUnits, addDefaultLabel = false): string {
|
||||||
if (value === CoreRemindersService.DISABLED) {
|
if (value === REMINDERS_DISABLED) {
|
||||||
return Translate.instant('core.settings.disabled');
|
return Translate.instant('core.settings.disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,8 +368,8 @@ export class CoreRemindersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const unitsLabel = value === 1 ?
|
const unitsLabel = value === 1 ?
|
||||||
REMINDER_UNITS_LABELS.single[unit] :
|
REMINDERS_UNITS_LABELS.single[unit] :
|
||||||
REMINDER_UNITS_LABELS.multi[unit];
|
REMINDERS_UNITS_LABELS.multi[unit];
|
||||||
|
|
||||||
const label = Translate.instant('core.reminders.timebefore', {
|
const label = Translate.instant('core.reminders.timebefore', {
|
||||||
units: Translate.instant(unitsLabel),
|
units: Translate.instant(unitsLabel),
|
||||||
|
@ -397,7 +392,7 @@ export class CoreRemindersService {
|
||||||
static convertSecondsToValueAndUnit(seconds?: number): CoreReminderValueAndUnit {
|
static convertSecondsToValueAndUnit(seconds?: number): CoreReminderValueAndUnit {
|
||||||
if (seconds === undefined || seconds < 0) {
|
if (seconds === undefined || seconds < 0) {
|
||||||
return {
|
return {
|
||||||
value: CoreRemindersService.DISABLED,
|
value: REMINDERS_DISABLED,
|
||||||
unit: CoreRemindersUnits.MINUTE,
|
unit: CoreRemindersUnits.MINUTE,
|
||||||
};
|
};
|
||||||
} else if (seconds === 0) {
|
} else if (seconds === 0) {
|
||||||
|
@ -437,7 +432,7 @@ export class CoreRemindersService {
|
||||||
async getDefaultNotificationTime(siteId?: string): Promise<number> {
|
async getDefaultNotificationTime(siteId?: string): Promise<number> {
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
const key = CoreRemindersService.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
const key = REMINDERS_DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
||||||
|
|
||||||
return CoreConfig.get(key, CoreConstants.CONFIG.calendarreminderdefaultvalue || 3600);
|
return CoreConfig.get(key, CoreConstants.CONFIG.calendarreminderdefaultvalue || 3600);
|
||||||
}
|
}
|
||||||
|
@ -452,11 +447,11 @@ export class CoreRemindersService {
|
||||||
async setDefaultNotificationTime(time: number, siteId?: string): Promise<void> {
|
async setDefaultNotificationTime(time: number, siteId?: string): Promise<void> {
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
const key = CoreRemindersService.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
const key = REMINDERS_DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
||||||
|
|
||||||
await CoreConfig.set(key, time);
|
await CoreConfig.set(key, time);
|
||||||
|
|
||||||
CoreEvents.trigger(CoreRemindersService.DEFAULT_NOTIFICATION_TIME_CHANGED, { time }, siteId);
|
CoreEvents.trigger(REMINDERS_DEFAULT_NOTIFICATION_TIME_CHANGED, { time }, siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue