MOBILE-2795 calendar: Hide imposible options in events reminders
This commit is contained in:
		
							parent
							
								
									49615641af
								
							
						
					
					
						commit
						8cafbfdd9f
					
				| @ -52,19 +52,19 @@ | ||||
|             </ion-card-content> | ||||
|         </ion-card> | ||||
| 
 | ||||
|         <ion-card list *ngIf="notificationsEnabled"> | ||||
|         <ion-card list *ngIf="notificationsEnabled && event.timestart - 600 > currentTime"> | ||||
|             <ion-item> | ||||
|                 <ion-label>{{ 'addon.calendar.notifications' | translate }}</ion-label> | ||||
|                 <ion-select [(ngModel)]="notificationTime" (ionChange)="updateNotificationTime($event)" interface="action-sheet"> | ||||
|                     <ion-option value="-1">{{ 'core.defaultvalue' | translate :{$a: defaultTimeReadable} }}</ion-option> | ||||
|                     <ion-option value="-1" *ngIf="event.timestart - defaultTime > currentTime">{{ 'core.defaultvalue' | translate :{$a: defaultTimeReadable} }}</ion-option> | ||||
|                     <ion-option value="0">{{ 'core.settings.disabled' | translate }}</ion-option> | ||||
|                     <ion-option value="10">{{ 600 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="30">{{ 1800 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="60">{{ 3600 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="120">{{ 7200 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="360">{{ 21600 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="720">{{ 43200 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="1440">{{ 86400 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="30" *ngIf="event.timestart - 1800 > currentTime">{{ 1800 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="60" *ngIf="event.timestart - 3600 > currentTime">{{ 3600 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="120" *ngIf="event.timestart - 7200 > currentTime">{{ 7200 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="360" *ngIf="event.timestart - 21600 > currentTime">{{ 21600 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="720" *ngIf="event.timestart - 43200 > currentTime">{{ 43200 | coreDuration }}</ion-option> | ||||
|                     <ion-option value="1440" *ngIf="event.timestart - 86400 > currentTime">{{ 86400 | coreDuration }}</ion-option> | ||||
|                 </ion-select> | ||||
|             </ion-item> | ||||
|         </ion-card> | ||||
|  | ||||
| @ -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. | ||||
|      * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user