MOBILE-3936 calendar: Move default reminder setting to reminders
parent
9f154a7bb6
commit
109d4bd2c5
|
@ -147,7 +147,6 @@
|
||||||
"addon.calendar.sunday": "calendar",
|
"addon.calendar.sunday": "calendar",
|
||||||
"addon.calendar.thu": "calendar",
|
"addon.calendar.thu": "calendar",
|
||||||
"addon.calendar.thursday": "calendar",
|
"addon.calendar.thursday": "calendar",
|
||||||
"addon.calendar.timebefore": "local_moodlemobileapp",
|
|
||||||
"addon.calendar.today": "calendar",
|
"addon.calendar.today": "calendar",
|
||||||
"addon.calendar.tomorrow": "calendar",
|
"addon.calendar.tomorrow": "calendar",
|
||||||
"addon.calendar.tue": "calendar",
|
"addon.calendar.tue": "calendar",
|
||||||
|
@ -161,7 +160,6 @@
|
||||||
"addon.calendar.typeopen": "calendar",
|
"addon.calendar.typeopen": "calendar",
|
||||||
"addon.calendar.typesite": "calendar",
|
"addon.calendar.typesite": "calendar",
|
||||||
"addon.calendar.typeuser": "calendar",
|
"addon.calendar.typeuser": "calendar",
|
||||||
"addon.calendar.units": "qtype_numerical",
|
|
||||||
"addon.calendar.upcomingevents": "calendar",
|
"addon.calendar.upcomingevents": "calendar",
|
||||||
"addon.calendar.userevents": "calendar",
|
"addon.calendar.userevents": "calendar",
|
||||||
"addon.calendar.wed": "calendar",
|
"addon.calendar.wed": "calendar",
|
||||||
|
@ -2150,6 +2148,15 @@
|
||||||
"core.rating.ratings": "rating",
|
"core.rating.ratings": "rating",
|
||||||
"core.redirectingtosite": "local_moodlemobileapp",
|
"core.redirectingtosite": "local_moodlemobileapp",
|
||||||
"core.refresh": "moodle",
|
"core.refresh": "moodle",
|
||||||
|
"core.reminders.atthetime": "local_moodlemobileapp",
|
||||||
|
"core.reminders.custom": "local_moodlemobileapp",
|
||||||
|
"core.reminders.customreminder": "local_moodlemobileapp",
|
||||||
|
"core.reminders.daybefore": "local_moodlemobileapp",
|
||||||
|
"core.reminders.daysbefore": "local_moodlemobileapp",
|
||||||
|
"core.reminders.delete": "moodle",
|
||||||
|
"core.reminders.setareminder": "local_moodlemobileapp",
|
||||||
|
"core.reminders.timebefore": "local_moodlemobileapp",
|
||||||
|
"core.reminders.units": "qtype_numerical",
|
||||||
"core.remove": "moodle",
|
"core.remove": "moodle",
|
||||||
"core.removefiles": "local_moodlemobileapp",
|
"core.removefiles": "local_moodlemobileapp",
|
||||||
"core.required": "moodle",
|
"core.required": "moodle",
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Reminders. Right now, only allow adding them here for new events. -->
|
<!-- Reminders. Right now, only allow adding them here for new events. -->
|
||||||
<ng-container *ngIf="notificationsEnabled && !eventId">
|
<ng-container *ngIf="remindersEnabled && !eventId">
|
||||||
<ion-item-divider class="addon-calendar-reminders-title">
|
<ion-item-divider class="addon-calendar-reminders-title">
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading">{{ 'addon.calendar.reminders' | translate }}</p>
|
<p class="item-heading">{{ 'addon.calendar.reminders' | translate }}</p>
|
||||||
|
|
|
@ -86,7 +86,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
descriptionControl: FormControl;
|
descriptionControl: FormControl;
|
||||||
|
|
||||||
// Reminders.
|
// Reminders.
|
||||||
notificationsEnabled = false;
|
remindersEnabled = false;
|
||||||
reminders: AddonCalendarEventCandidateReminder[] = [];
|
reminders: AddonCalendarEventCandidateReminder[] = [];
|
||||||
|
|
||||||
protected courseId!: number;
|
protected courseId!: number;
|
||||||
|
@ -101,7 +101,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
protected fb: FormBuilder,
|
protected fb: FormBuilder,
|
||||||
) {
|
) {
|
||||||
this.currentSite = CoreSites.getRequiredCurrentSite();
|
this.currentSite = CoreSites.getRequiredCurrentSite();
|
||||||
this.notificationsEnabled = CoreLocalNotifications.isAvailable();
|
this.remindersEnabled = CoreReminders.isEnabled();
|
||||||
this.errors = {
|
this.errors = {
|
||||||
required: Translate.instant('core.required'),
|
required: Translate.instant('core.required'),
|
||||||
};
|
};
|
||||||
|
@ -647,13 +647,13 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
*/
|
*/
|
||||||
protected async initReminders(): Promise<void> {
|
protected async initReminders(): Promise<void> {
|
||||||
// Don't init reminders when editing an event. Right now, only allow adding reminders for new events.
|
// Don't init reminders when editing an event. Right now, only allow adding reminders for new events.
|
||||||
if (!this.notificationsEnabled || this.eventId) {
|
if (!this.remindersEnabled || this.eventId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if default reminders are enabled.
|
// Check if default reminders are enabled.
|
||||||
const defaultTime = await AddonCalendar.getDefaultNotificationTime(this.currentSite.getId());
|
const defaultTime = await CoreReminders.getDefaultNotificationTime(this.currentSite.getId());
|
||||||
if (defaultTime === AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED) {
|
if (defaultTime === CoreRemindersService.DISABLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
<ion-card *ngIf="notificationsEnabled && event">
|
<ion-card *ngIf="remindersEnabled && event">
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<h2>{{ 'addon.calendar.reminders' | translate }}</h2>
|
<h2>{{ 'addon.calendar.reminders' | translate }}</h2>
|
||||||
|
|
|
@ -41,7 +41,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 } from '@features/reminders/services/reminders';
|
import { CoreReminders, CoreRemindersService } from '@features/reminders/services/reminders';
|
||||||
import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu';
|
import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
courseName = '';
|
courseName = '';
|
||||||
groupName?: string;
|
groupName?: string;
|
||||||
courseUrl = '';
|
courseUrl = '';
|
||||||
notificationsEnabled = false;
|
remindersEnabled = false;
|
||||||
moduleUrl = '';
|
moduleUrl = '';
|
||||||
categoryPath = '';
|
categoryPath = '';
|
||||||
currentTime = -1;
|
currentTime = -1;
|
||||||
|
@ -85,7 +85,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
constructor(
|
constructor(
|
||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
) {
|
) {
|
||||||
this.notificationsEnabled = CoreLocalNotifications.isAvailable();
|
this.remindersEnabled = CoreReminders.isEnabled();
|
||||||
this.siteHomeId = CoreSites.getCurrentSiteHomeId();
|
this.siteHomeId = CoreSites.getCurrentSiteHomeId();
|
||||||
this.currentSiteId = CoreSites.getCurrentSiteId();
|
this.currentSiteId = CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
|
@ -132,7 +132,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(AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_CHANGED, () => {
|
this.defaultTimeChangedObserver = CoreEvents.on(CoreRemindersService.DEFAULT_NOTIFICATION_TIME_CHANGED, () => {
|
||||||
this.loadReminders();
|
this.loadReminders();
|
||||||
}, this.currentSiteId);
|
}, this.currentSiteId);
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected async loadReminders(): Promise<void> {
|
protected async loadReminders(): Promise<void> {
|
||||||
if (!this.notificationsEnabled || !this.event) {
|
if (!this.remindersEnabled || !this.event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,18 +13,10 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import {
|
|
||||||
AddonCalendar,
|
|
||||||
AddonCalendarProvider,
|
|
||||||
} from '../../services/calendar';
|
|
||||||
import { CoreEvents } from '@singletons/events';
|
|
||||||
import { CoreSites } from '@services/sites';
|
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import {
|
import {
|
||||||
CoreReminders,
|
CoreReminders,
|
||||||
CoreRemindersService,
|
CoreRemindersService,
|
||||||
CoreRemindersUnits,
|
|
||||||
CoreReminderValueAndUnit,
|
|
||||||
} from '@features/reminders/services/reminders';
|
} from '@features/reminders/services/reminders';
|
||||||
import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu';
|
import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu';
|
||||||
|
|
||||||
|
@ -39,10 +31,7 @@ export class AddonCalendarSettingsPage implements OnInit {
|
||||||
|
|
||||||
defaultTimeLabel = '';
|
defaultTimeLabel = '';
|
||||||
|
|
||||||
protected defaultTime: CoreReminderValueAndUnit = {
|
protected defaultTime?: number;
|
||||||
value: 0,
|
|
||||||
unit: CoreRemindersUnits.MINUTE,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
@ -76,24 +65,18 @@ export class AddonCalendarSettingsPage implements OnInit {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await AddonCalendar.setDefaultNotificationTime(reminderTime.timeBefore);
|
await CoreReminders.setDefaultNotificationTime(reminderTime.timeBefore ?? CoreRemindersService.DISABLED);
|
||||||
this.updateDefaultTimeLabel();
|
this.updateDefaultTimeLabel();
|
||||||
|
|
||||||
CoreEvents.trigger(
|
|
||||||
AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_CHANGED,
|
|
||||||
{ time: reminderTime.timeBefore },
|
|
||||||
CoreSites.getCurrentSiteId(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update default time label.
|
* Update default time label.
|
||||||
*/
|
*/
|
||||||
async updateDefaultTimeLabel(): Promise<void> {
|
async updateDefaultTimeLabel(): Promise<void> {
|
||||||
const defaultTime = await AddonCalendar.getDefaultNotificationTime();
|
this.defaultTime = await CoreReminders.getDefaultNotificationTime();
|
||||||
|
|
||||||
this.defaultTime = CoreRemindersService.convertSecondsToValueAndUnit(defaultTime);
|
const defaultTime = CoreRemindersService.convertSecondsToValueAndUnit(this.defaultTime);
|
||||||
this.defaultTimeLabel = CoreReminders.getUnitValueLabel(this.defaultTime.value, this.defaultTime.unit);
|
this.defaultTimeLabel = CoreReminders.getUnitValueLabel(defaultTime.value, defaultTime.unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,10 +333,10 @@ export class AddonCalendarHelperProvider {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultTime = await AddonCalendar.getDefaultNotificationTime(siteId);
|
const defaultTime = await CoreReminders.getDefaultNotificationTime(siteId);
|
||||||
let defaultLabel: string | undefined;
|
let defaultLabel: string | undefined;
|
||||||
|
|
||||||
if (defaultTime > AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED) {
|
if (defaultTime > CoreRemindersService.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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import { SafeUrl } from '@angular/platform-browser';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { AddonCalendarFilter } from './calendar-helper';
|
import { AddonCalendarFilter } from './calendar-helper';
|
||||||
import { AddonCalendarSyncEvents, AddonCalendarSyncProvider } from './calendar-sync';
|
import { AddonCalendarSyncEvents, AddonCalendarSyncProvider } from './calendar-sync';
|
||||||
import { CoreEvents } from '@singletons/events';
|
|
||||||
import { CoreText } from '@singletons/text';
|
import { CoreText } from '@singletons/text';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import {
|
import {
|
||||||
|
@ -103,8 +102,7 @@ export class AddonCalendarProvider {
|
||||||
|
|
||||||
static readonly DAYS_INTERVAL = 30;
|
static readonly DAYS_INTERVAL = 30;
|
||||||
static readonly COMPONENT = 'AddonCalendarEvents';
|
static readonly COMPONENT = 'AddonCalendarEvents';
|
||||||
static readonly DEFAULT_NOTIFICATION_TIME_CHANGED = 'AddonCalendarDefaultNotificationTimeChangedEvent';
|
|
||||||
static readonly DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime';
|
|
||||||
static readonly STARTING_WEEK_DAY = 'addon_calendar_starting_week_day';
|
static readonly STARTING_WEEK_DAY = 'addon_calendar_starting_week_day';
|
||||||
static readonly NEW_EVENT_EVENT = 'addon_calendar_new_event';
|
static readonly NEW_EVENT_EVENT = 'addon_calendar_new_event';
|
||||||
static readonly NEW_EVENT_DISCARDED_EVENT = 'addon_calendar_new_event_discarded';
|
static readonly NEW_EVENT_DISCARDED_EVENT = 'addon_calendar_new_event_discarded';
|
||||||
|
@ -116,8 +114,6 @@ export class AddonCalendarProvider {
|
||||||
static readonly CALENDAR_TF_24 = '%H:%M'; // Calendar time in 24 hours format.
|
static readonly CALENDAR_TF_24 = '%H:%M'; // Calendar time in 24 hours format.
|
||||||
static readonly CALENDAR_TF_12 = '%I:%M %p'; // Calendar time in 12 hours format.
|
static readonly CALENDAR_TF_12 = '%I:%M %p'; // Calendar time in 12 hours format.
|
||||||
|
|
||||||
static readonly DEFAULT_NOTIFICATION_DISABLED = -1;
|
|
||||||
|
|
||||||
protected weekDays: AddonCalendarWeekDaysTranslationKeys[] = [
|
protected weekDays: AddonCalendarWeekDaysTranslationKeys[] = [
|
||||||
{
|
{
|
||||||
shortname: 'addon.calendar.sun',
|
shortname: 'addon.calendar.sun',
|
||||||
|
@ -293,7 +289,6 @@ export class AddonCalendarProvider {
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
async initialize(): Promise<void> {
|
async initialize(): Promise<void> {
|
||||||
|
|
||||||
CoreLocalNotifications.registerClick<CoreRemindersPushNotificationData>(
|
CoreLocalNotifications.registerClick<CoreRemindersPushNotificationData>(
|
||||||
AddonCalendarProvider.COMPONENT,
|
AddonCalendarProvider.COMPONENT,
|
||||||
async (notification) => {
|
async (notification) => {
|
||||||
|
@ -302,22 +297,6 @@ export class AddonCalendarProvider {
|
||||||
this.notificationClicked(notification);
|
this.notificationClicked(notification);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!CoreLocalNotifications.isAvailable()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CoreEvents.on(AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_CHANGED, async (data) => {
|
|
||||||
const site = await CoreSites.getSite(data.siteId);
|
|
||||||
const siteId = site.getId();
|
|
||||||
|
|
||||||
// Get all the events that have a default reminder.
|
|
||||||
const reminders = await CoreReminders.getRemindersWithDefaultTime(AddonCalendarProvider.COMPONENT, siteId);
|
|
||||||
|
|
||||||
// Reschedule all the default reminders.
|
|
||||||
reminders.forEach((reminder) =>
|
|
||||||
CoreReminders.scheduleNotification(reminder, siteId));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -602,13 +581,10 @@ export class AddonCalendarProvider {
|
||||||
*
|
*
|
||||||
* @param siteId ID of the site. If not defined, use current site.
|
* @param siteId ID of the site. If not defined, use current site.
|
||||||
* @return Promise resolved with the default time (in seconds).
|
* @return Promise resolved with the default time (in seconds).
|
||||||
|
* @deprecated since 4.1 Use CoreReminders.getDefaultNotificationTime instead.
|
||||||
*/
|
*/
|
||||||
async getDefaultNotificationTime(siteId?: string): Promise<number> {
|
async getDefaultNotificationTime(siteId?: string): Promise<number> {
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
return CoreReminders.getDefaultNotificationTime(siteId);
|
||||||
|
|
||||||
const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
|
||||||
|
|
||||||
return CoreConfig.get(key, CoreConstants.CONFIG.calendarreminderdefaultvalue || 3600);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1492,13 +1468,10 @@ export class AddonCalendarProvider {
|
||||||
* @param time New default time.
|
* @param time New default time.
|
||||||
* @param siteId ID of the site. If not defined, use current site.
|
* @param siteId ID of the site. If not defined, use current site.
|
||||||
* @return Promise resolved when stored.
|
* @return Promise resolved when stored.
|
||||||
|
* @deprecated since 4.1 Use CoreReminders.setDefaultNotificationTime.
|
||||||
*/
|
*/
|
||||||
async setDefaultNotificationTime(time: number, siteId?: string): Promise<void> {
|
async setDefaultNotificationTime(time: number, siteId?: string): Promise<void> {
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
await CoreReminders.setDefaultNotificationTime(time, siteId);
|
||||||
|
|
||||||
const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
|
||||||
|
|
||||||
await CoreConfig.set(key, time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,10 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { SQLiteDB } from '@classes/sqlitedb';
|
import { SQLiteDB } from '@classes/sqlitedb';
|
||||||
|
import { CoreRemindersService, 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';
|
||||||
import { AddonCalendar, AddonCalendarEventType, AddonCalendarProvider } from '../calendar';
|
import { AddonCalendarEventType } from '../calendar';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database variables for AddonCalendarProvider service.
|
* Database variables for AddonCalendarProvider service.
|
||||||
|
@ -180,20 +181,39 @@ export const CALENDAR_SITE_SCHEMA: CoreSiteSchema = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
async migrate(db: SQLiteDB, oldVersion: number, siteId: string): Promise<void> {
|
async migrate(db: SQLiteDB, oldVersion: number, siteId: string): Promise<void> {
|
||||||
if (oldVersion < 4) {
|
if (oldVersion < 5) {
|
||||||
// Migrate default notification time if it was changed.
|
await migrateDefaultTime(siteId, oldVersion < 4);
|
||||||
// Don't use getDefaultNotificationTime to be able to detect if the value was changed or not.
|
|
||||||
const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
|
||||||
const defaultTime = await CoreUtils.ignoreErrors(CoreConfig.get(key, null));
|
|
||||||
|
|
||||||
if (defaultTime) {
|
|
||||||
// Convert from minutes to seconds.
|
|
||||||
AddonCalendar.setDefaultNotificationTime(defaultTime * 60, siteId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migrate default notification time if it was changed.
|
||||||
|
* Don't use getDefaultNotificationTime to be able to detect if the value was changed or not.
|
||||||
|
*
|
||||||
|
* @param siteId Site ID to migrate.
|
||||||
|
* @param convertToSeconds If true, time will be converted to seconds.
|
||||||
|
*/
|
||||||
|
const migrateDefaultTime = async (siteId: string, convertToSeconds = false): Promise<void> => {
|
||||||
|
|
||||||
|
const key = 'mmaCalendarDefaultNotifTime#' + siteId;
|
||||||
|
try {
|
||||||
|
let defaultTime = await CoreConfig.get<number>(key);
|
||||||
|
await CoreUtils.ignoreErrors(CoreConfig.delete(key));
|
||||||
|
|
||||||
|
if (defaultTime <= 0) {
|
||||||
|
defaultTime = CoreRemindersService.DISABLED;
|
||||||
|
} else if (convertToSeconds) {
|
||||||
|
// Convert from minutes to seconds.
|
||||||
|
defaultTime = defaultTime * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreReminders.setDefaultNotificationTime(defaultTime, siteId);
|
||||||
|
} catch {
|
||||||
|
// Ignore errors, already migrated.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export type AddonCalendarEventDBRecord = {
|
export type AddonCalendarEventDBRecord = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
<ion-icon name="fas-check" *ngIf="currentValue === 'custom'" slot="end"></ion-icon>
|
<ion-icon name="fas-check" *ngIf="currentValue === 'custom'" slot="end"></ion-icon>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item *ngIf="noReminderLabel" button class="ion-text-wrap text-danger border-top" (click)="setReminder('disabled')"
|
<ion-item *ngIf="noReminderLabel" button class="ion-text-wrap text-danger border-top" (click)="disableReminder()" detail="false">
|
||||||
detail="false">
|
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading">{{ noReminderLabel | translate }}</p>
|
<p class="item-heading">{{ noReminderLabel | translate }}</p>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
|
|
|
@ -12,9 +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 { AddonCalendarProvider } from '@addons/calendar/services/calendar';
|
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { CoreReminders, CoreRemindersUnits, CoreReminderValueAndUnit } from '@features/reminders/services/reminders';
|
import {
|
||||||
|
CoreReminders,
|
||||||
|
CoreRemindersService,
|
||||||
|
CoreRemindersUnits,
|
||||||
|
CoreReminderValueAndUnit,
|
||||||
|
} from '@features/reminders/services/reminders';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { PopoverController } from '@singletons';
|
import { PopoverController } from '@singletons';
|
||||||
|
@ -29,7 +33,7 @@ import { CoreRemindersSetReminderCustomComponent } from '../set-reminder-custom/
|
||||||
})
|
})
|
||||||
export class CoreRemindersSetReminderMenuComponent implements OnInit {
|
export class CoreRemindersSetReminderMenuComponent implements OnInit {
|
||||||
|
|
||||||
@Input() initialValue?: CoreReminderValueAndUnit;
|
@Input() initialValue?: number;
|
||||||
@Input() noReminderLabel = '';
|
@Input() noReminderLabel = '';
|
||||||
|
|
||||||
currentValue = '0m';
|
currentValue = '0m';
|
||||||
|
@ -73,42 +77,34 @@ export class CoreRemindersSetReminderMenuComponent implements OnInit {
|
||||||
option.label = CoreReminders.getUnitValueLabel(option.value, option.unit);
|
option.label = CoreReminders.getUnitValueLabel(option.value, option.unit);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.initialValue) {
|
const initialValue = CoreRemindersService.convertSecondsToValueAndUnit(this.initialValue);
|
||||||
|
if (initialValue.value === CoreRemindersService.DISABLED) {
|
||||||
|
this.currentValue = 'disabled';
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.initialValue.value === AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED) {
|
|
||||||
this.currentValue = 'disabled';
|
|
||||||
} else {
|
|
||||||
// Search if it's one of the preset options.
|
// Search if it's one of the preset options.
|
||||||
const option = this.presetOptions.find(option =>
|
const option = this.presetOptions.find(option =>
|
||||||
option.value === this.initialValue?.value && option.unit === this.initialValue.unit);
|
option.value === initialValue?.value && option.unit === initialValue.unit);
|
||||||
|
|
||||||
if (option) {
|
if (option) {
|
||||||
this.currentValue = option.radioValue;
|
this.currentValue = option.radioValue;
|
||||||
} else {
|
} else {
|
||||||
// It's a custom value.
|
// It's a custom value.
|
||||||
this.currentValue = 'custom';
|
this.currentValue = 'custom';
|
||||||
this.customValue = this.initialValue.value;
|
this.customValue = initialValue.value;
|
||||||
this.customUnits = this.initialValue.unit;
|
this.customUnits = initialValue.unit;
|
||||||
this.customLabel = CoreReminders.getUnitValueLabel(this.customValue, this.customUnits);
|
this.customLabel = CoreReminders.getUnitValueLabel(this.customValue, this.customUnits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the reminder.
|
* Set the reminder.
|
||||||
*
|
*
|
||||||
* @param value Value to set.
|
* @param value Value to set.
|
||||||
*/
|
*/
|
||||||
setReminder(value: string): void {
|
setReminder(value?: string): void {
|
||||||
// Return it as an object because 0 means undefined if not.
|
|
||||||
if (value === 'disabled') {
|
|
||||||
PopoverController.dismiss({ timeBefore: AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED });
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const option = this.presetOptions.find(option => option.radioValue === value);
|
const option = this.presetOptions.find(option => option.radioValue === value);
|
||||||
if (!option) {
|
if (!option) {
|
||||||
return;
|
return;
|
||||||
|
@ -117,6 +113,13 @@ export class CoreRemindersSetReminderMenuComponent implements OnInit {
|
||||||
PopoverController.dismiss({ timeBefore: option.unit * option.value });
|
PopoverController.dismiss({ timeBefore: option.unit * option.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the reminder.
|
||||||
|
*/
|
||||||
|
disableReminder(): void {
|
||||||
|
PopoverController.dismiss({ timeBefore: undefined });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom value input clicked.
|
* Custom value input clicked.
|
||||||
*
|
*
|
||||||
|
|
|
@ -36,7 +36,7 @@ export const CORE_REMINDERS_SERVICES: Type<unknown>[] = [
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
multi: true,
|
multi: true,
|
||||||
useValue: async () => {
|
useValue: async () => {
|
||||||
CoreReminders.scheduleAllNotifications();
|
await CoreReminders.initialize();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
// 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 { AddonCalendar, AddonCalendarProvider } from '@addons/calendar/services/calendar';
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreLocalNotifications } from '@services/local-notifications';
|
import { CoreLocalNotifications } from '@services/local-notifications';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
@ -22,6 +21,8 @@ import { CoreReminderDBRecord, REMINDERS_TABLE } from './database/reminders';
|
||||||
import { ILocalNotification } from '@ionic-native/local-notifications';
|
import { ILocalNotification } from '@ionic-native/local-notifications';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
|
import { CoreConfig } from '@services/config';
|
||||||
|
import { CoreEvents } from '@singletons/events';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Units to set a reminder.
|
* Units to set a reminder.
|
||||||
|
@ -55,6 +56,35 @@ const REMINDER_UNITS_LABELS = {
|
||||||
export class CoreRemindersService {
|
export class CoreRemindersService {
|
||||||
|
|
||||||
static readonly DEFAULT_REMINDER_TIMEBEFORE = -1;
|
static readonly DEFAULT_REMINDER_TIMEBEFORE = -1;
|
||||||
|
static readonly DISABLED = -1;
|
||||||
|
|
||||||
|
static readonly DEFAULT_NOTIFICATION_TIME_SETTING = 'CoreRemindersDefaultNotification';
|
||||||
|
static readonly DEFAULT_NOTIFICATION_TIME_CHANGED = 'CoreRemindersDefaultNotificationChangedEvent';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the service.
|
||||||
|
*
|
||||||
|
* @return Promise resolved when done.
|
||||||
|
*/
|
||||||
|
async initialize(): Promise<void> {
|
||||||
|
if (!CoreLocalNotifications.isAvailable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scheduleAllNotifications();
|
||||||
|
|
||||||
|
CoreEvents.on(CoreRemindersService.DEFAULT_NOTIFICATION_TIME_CHANGED, async (data) => {
|
||||||
|
const site = await CoreSites.getSite(data.siteId);
|
||||||
|
const siteId = site.getId();
|
||||||
|
|
||||||
|
// Get all the events that have a default reminder.
|
||||||
|
const reminders = await this.getRemindersWithDefaultTime(siteId);
|
||||||
|
|
||||||
|
// Reschedule all the default reminders.
|
||||||
|
reminders.forEach((reminder) =>
|
||||||
|
this.scheduleNotification(reminder, siteId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if Reminders are enabled.
|
* Returns if Reminders are enabled.
|
||||||
|
@ -153,16 +183,15 @@ export class CoreRemindersService {
|
||||||
/**
|
/**
|
||||||
* Get all reminders of a component with default time.
|
* Get all reminders of a component with default time.
|
||||||
*
|
*
|
||||||
* @param component Component.
|
|
||||||
* @param siteId ID of the site the reminder belongs to. If not defined, use current site.
|
* @param siteId ID of the site the reminder belongs to. If not defined, use current site.
|
||||||
* @return Promise resolved when the reminder data is retrieved.
|
* @return Promise resolved when the reminder data is retrieved.
|
||||||
*/
|
*/
|
||||||
async getRemindersWithDefaultTime(component: string, siteId?: string): Promise<CoreReminderDBRecord[]> {
|
protected async getRemindersWithDefaultTime(siteId?: string): Promise<CoreReminderDBRecord[]> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
|
||||||
return site.getDb().getRecords<CoreReminderDBRecord>(
|
return site.getDb().getRecords<CoreReminderDBRecord>(
|
||||||
REMINDERS_TABLE,
|
REMINDERS_TABLE,
|
||||||
{ component, timebefore: CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE },
|
{ timebefore: CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE },
|
||||||
'time ASC',
|
'time ASC',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -241,10 +270,10 @@ export class CoreRemindersService {
|
||||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
const timebefore = reminder.timebefore === CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE
|
const timebefore = reminder.timebefore === CoreRemindersService.DEFAULT_REMINDER_TIMEBEFORE
|
||||||
? await AddonCalendar.getDefaultNotificationTime(siteId)
|
? await this.getDefaultNotificationTime(siteId)
|
||||||
: reminder.timebefore;
|
: reminder.timebefore;
|
||||||
|
|
||||||
if (timebefore === AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED) {
|
if (timebefore === CoreRemindersService.DISABLED) {
|
||||||
// Notification disabled. Cancel.
|
// Notification disabled. Cancel.
|
||||||
return this.cancelReminder(reminder.id, reminder.component, siteId);
|
return this.cancelReminder(reminder.id, reminder.component, siteId);
|
||||||
}
|
}
|
||||||
|
@ -309,8 +338,7 @@ export class CoreRemindersService {
|
||||||
* @return Translated label.
|
* @return Translated label.
|
||||||
*/
|
*/
|
||||||
getUnitValueLabel(value: number, unit: CoreRemindersUnits, addDefaultLabel = false): string {
|
getUnitValueLabel(value: number, unit: CoreRemindersUnits, addDefaultLabel = false): string {
|
||||||
if (value === AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED) {
|
if (value === CoreRemindersService.DISABLED) {
|
||||||
// TODO: It will need a migration of date to set 0 to -1 when needed.
|
|
||||||
return Translate.instant('core.settings.disabled');
|
return Translate.instant('core.settings.disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +371,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: AddonCalendarProvider.DEFAULT_NOTIFICATION_DISABLED,
|
value: CoreRemindersService.DISABLED,
|
||||||
unit: CoreRemindersUnits.MINUTE,
|
unit: CoreRemindersUnits.MINUTE,
|
||||||
};
|
};
|
||||||
} else if (seconds === 0) {
|
} else if (seconds === 0) {
|
||||||
|
@ -374,6 +402,37 @@ export class CoreRemindersService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the configured default notification time.
|
||||||
|
*
|
||||||
|
* @param siteId ID of the site. If not defined, use current site.
|
||||||
|
* @return Promise resolved with the default time (in seconds).
|
||||||
|
*/
|
||||||
|
async getDefaultNotificationTime(siteId?: string): Promise<number> {
|
||||||
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
|
const key = CoreRemindersService.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
||||||
|
|
||||||
|
return CoreConfig.get(key, CoreConstants.CONFIG.calendarreminderdefaultvalue || 3600);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default notification time.
|
||||||
|
*
|
||||||
|
* @param time New default time.
|
||||||
|
* @param siteId ID of the site. If not defined, use current site.
|
||||||
|
* @return Promise resolved when stored.
|
||||||
|
*/
|
||||||
|
async setDefaultNotificationTime(time: number, siteId?: string): Promise<void> {
|
||||||
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
|
const key = CoreRemindersService.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId;
|
||||||
|
|
||||||
|
await CoreConfig.set(key, time);
|
||||||
|
|
||||||
|
CoreEvents.trigger(CoreRemindersService.DEFAULT_NOTIFICATION_TIME_CHANGED, { time }, siteId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CoreReminders = makeSingleton(CoreRemindersService);
|
export const CoreReminders = makeSingleton(CoreRemindersService);
|
||||||
|
|
Loading…
Reference in New Issue