From 8cafbfdd9f55e7a44b1b3e05599c52376dc6e848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 10 Jan 2019 10:34:26 +0100 Subject: [PATCH] MOBILE-2795 calendar: Hide imposible options in events reminders --- src/addon/calendar/pages/event/event.html | 16 +++++++-------- src/addon/calendar/pages/event/event.ts | 25 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/addon/calendar/pages/event/event.html b/src/addon/calendar/pages/event/event.html index c8de82b17..f863e1243 100644 --- a/src/addon/calendar/pages/event/event.html +++ b/src/addon/calendar/pages/event/event.html @@ -52,19 +52,19 @@ - + {{ 'addon.calendar.notifications' | translate }} - {{ 'core.defaultvalue' | translate :{$a: defaultTimeReadable} }} + {{ 'core.defaultvalue' | translate :{$a: defaultTimeReadable} }} {{ 'core.settings.disabled' | translate }} {{ 600 | coreDuration }} - {{ 1800 | coreDuration }} - {{ 3600 | coreDuration }} - {{ 7200 | coreDuration }} - {{ 21600 | coreDuration }} - {{ 43200 | coreDuration }} - {{ 86400 | coreDuration }} + {{ 1800 | coreDuration }} + {{ 3600 | coreDuration }} + {{ 7200 | coreDuration }} + {{ 21600 | coreDuration }} + {{ 43200 | coreDuration }} + {{ 86400 | coreDuration }} diff --git a/src/addon/calendar/pages/event/event.ts b/src/addon/calendar/pages/event/event.ts index f8e3dec31..e20a61877 100644 --- a/src/addon/calendar/pages/event/event.ts +++ b/src/addon/calendar/pages/event/event.ts @@ -48,12 +48,14 @@ export class AddonCalendarEventPage { notificationsEnabled = false; moduleUrl = ''; categoryPath = ''; + currentTime: number; + defaultTime: number; constructor(private translate: TranslateService, private calendarProvider: AddonCalendarProvider, navParams: NavParams, - private domUtils: CoreDomUtilsProvider, private coursesProvider: CoreCoursesProvider, timeUtils: CoreTimeUtilsProvider, + private domUtils: CoreDomUtilsProvider, private coursesProvider: CoreCoursesProvider, private calendarHelper: AddonCalendarHelperProvider, private sitesProvider: CoreSitesProvider, localNotificationsProvider: CoreLocalNotificationsProvider, private courseProvider: CoreCourseProvider, - private textUtils: CoreTextUtilsProvider) { + private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider) { this.eventId = navParams.get('id'); this.notificationsEnabled = localNotificationsProvider.isAvailable(); @@ -61,9 +63,12 @@ export class AddonCalendarEventPage { if (this.notificationsEnabled) { this.calendarProvider.getEventNotificationTimeOption(this.eventId).then((notificationTime) => { this.notificationTime = notificationTime; + this.loadNotificationTime(); }); this.calendarProvider.getDefaultNotificationTime().then((defaultTime) => { + this.defaultTime = defaultTime * 60; + this.loadNotificationTime(); if (defaultTime === 0) { // Disabled by default. this.defaultTimeReadable = this.translate.instant('core.settings.disabled'); @@ -111,6 +116,9 @@ export class AddonCalendarEventPage { this.calendarHelper.formatEventData(event); this.event = event; + this.currentTime = this.timeUtils.timestamp(); + this.loadNotificationTime(); + // Reset some of the calculated data. this.categoryPath = ''; this.courseName = ''; @@ -178,6 +186,19 @@ export class AddonCalendarEventPage { }); } + /** + * Loads notification time by discarding options not in the list. + */ + loadNotificationTime(): void { + if (typeof this.notificationTime != 'undefined') { + if (this.notificationTime > 0 && this.event.timestart - this.notificationTime * 60 < this.currentTime) { + this.notificationTime = 0; + } else if (this.notificationTime < 0 && this.event.timestart - this.defaultTime < this.currentTime) { + this.notificationTime = 0; + } + } + } + /** * Refresh the event. *