MOBILE-3087 calendar: Support repeateditall setting

main
Dani Palou 2019-06-27 12:34:08 +02:00
parent 649ad7a1a2
commit 12ce9f63b5
7 changed files with 81 additions and 20 deletions

View File

@ -96,6 +96,7 @@
"addon.calendar.errorloadevents": "local_moodlemobileapp", "addon.calendar.errorloadevents": "local_moodlemobileapp",
"addon.calendar.eventduration": "calendar", "addon.calendar.eventduration": "calendar",
"addon.calendar.eventendtime": "calendar", "addon.calendar.eventendtime": "calendar",
"addon.calendar.eventkind": "calendar",
"addon.calendar.eventname": "calendar", "addon.calendar.eventname": "calendar",
"addon.calendar.eventstarttime": "calendar", "addon.calendar.eventstarttime": "calendar",
"addon.calendar.eventtype": "calendar", "addon.calendar.eventtype": "calendar",
@ -106,6 +107,9 @@
"addon.calendar.noevents": "local_moodlemobileapp", "addon.calendar.noevents": "local_moodlemobileapp",
"addon.calendar.nopermissiontoupdatecalendar": "error", "addon.calendar.nopermissiontoupdatecalendar": "error",
"addon.calendar.reminders": "local_moodlemobileapp", "addon.calendar.reminders": "local_moodlemobileapp",
"addon.calendar.repeatedevents": "calendar",
"addon.calendar.repeateditall": "calendar",
"addon.calendar.repeateditthis": "calendar",
"addon.calendar.repeatevent": "calendar", "addon.calendar.repeatevent": "calendar",
"addon.calendar.repeatweeksl": "calendar", "addon.calendar.repeatweeksl": "calendar",
"addon.calendar.setnewreminder": "local_moodlemobileapp", "addon.calendar.setnewreminder": "local_moodlemobileapp",

View File

@ -12,6 +12,7 @@
"errorloadevents": "Error loading events.", "errorloadevents": "Error loading events.",
"eventduration": "Duration", "eventduration": "Duration",
"eventendtime": "End time", "eventendtime": "End time",
"eventkind": "Type of event",
"eventname": "Event title", "eventname": "Event title",
"eventstarttime": "Start time", "eventstarttime": "Start time",
"eventtype": "Event type", "eventtype": "Event type",
@ -22,6 +23,9 @@
"noevents": "There are no events", "noevents": "There are no events",
"nopermissiontoupdatecalendar": "Sorry, but you do not have permission to update the calendar event", "nopermissiontoupdatecalendar": "Sorry, but you do not have permission to update the calendar event",
"reminders": "Reminders", "reminders": "Reminders",
"repeatedevents": "Repeated events",
"repeateditall": "Also apply changes to the other {{$a}} events in this repeat series",
"repeateditthis": "Apply changes to this event only",
"repeatevent": "Repeat this event", "repeatevent": "Repeat this event",
"repeatweeksl": "Repeat weekly, creating altogether", "repeatweeksl": "Repeat weekly, creating altogether",
"setnewreminder": "Set a new reminder", "setnewreminder": "Set a new reminder",

View File

@ -26,7 +26,7 @@
<!-- Type. --> <!-- Type. -->
<ion-item text-wrap class="addon-calendar-eventtype-container"> <ion-item text-wrap class="addon-calendar-eventtype-container">
<ion-label id="addon-calendar-eventtype-label"><h2 [core-mark-required]="true">{{ 'addon.calendar.eventtype' | translate }}</h2></ion-label> <ion-label id="addon-calendar-eventtype-label"><h2 [core-mark-required]="true">{{ 'addon.calendar.eventkind' | translate }}</h2></ion-label>
<ion-select [formControlName]="'eventtype'" aria-labelledby="addon-calendar-eventtype-label" interface="action-sheet" [disabled]="eventTypes.length == 1"> <ion-select [formControlName]="'eventtype'" aria-labelledby="addon-calendar-eventtype-label" interface="action-sheet" [disabled]="eventTypes.length == 1">
<ion-option *ngFor="let type of eventTypes" [value]="type.value">{{ type.name | translate }}</ion-option> <ion-option *ngFor="let type of eventTypes" [value]="type.value">{{ type.name | translate }}</ion-option>
</ion-select> </ion-select>
@ -96,8 +96,8 @@
</ion-item> </ion-item>
<!-- Duration. --> <!-- Duration. -->
<div text-wrap radio-group [formControlName]="'duration'" class="addon-calendar-duration-container"> <div text-wrap radio-group [formControlName]="'duration'" class="addon-calendar-radio-container">
<ion-item class="addon-calendar-duration-title"><h2>{{ 'addon.calendar.eventduration' | translate }}</h2></ion-item> <ion-item class="addon-calendar-radio-title"><h2>{{ 'addon.calendar.eventduration' | translate }}</h2></ion-item>
<ion-item> <ion-item>
<ion-label>{{ 'addon.calendar.durationnone' | translate }}</ion-label> <ion-label>{{ 'addon.calendar.durationnone' | translate }}</ion-label>
<ion-radio [value]="0"></ion-radio> <ion-radio [value]="0"></ion-radio>
@ -118,15 +118,30 @@
</ion-item> </ion-item>
</div> </div>
<!-- Repeat. --> <!-- Repeat (for new events). -->
<ion-item text-wrap> <ng-container *ngIf="!eventId || eventId < 0">
<ion-label><h2>{{ 'addon.calendar.repeatevent' | translate }}</h2></ion-label> <ion-item text-wrap>
<ion-checkbox item-end [formControlName]="'repeat'"></ion-checkbox> <ion-label><h2>{{ 'addon.calendar.repeatevent' | translate }}</h2></ion-label>
</ion-item> <ion-checkbox item-end [formControlName]="'repeat'"></ion-checkbox>
<ion-item text-wrap *ngIf="eventForm.controls.repeat.value"> </ion-item>
<ion-label stacked><h2>{{ 'addon.calendar.repeatweeksl' | translate }}</h2></ion-label> <ion-item text-wrap *ngIf="eventForm.controls.repeat.value">
<ion-input type="number" name="repeats" [formControlName]="'repeats'"></ion-input> <ion-label stacked><h2>{{ 'addon.calendar.repeatweeksl' | translate }}</h2></ion-label>
</ion-item> <ion-input type="number" name="repeats" [formControlName]="'repeats'"></ion-input>
</ion-item>
</ng-container>
<!-- Apply to all events or just this one (editing repeated events). -->
<div *ngIf="event && event.repeatid" text-wrap radio-group [formControlName]="'repeateditall'" class="addon-calendar-radio-container">
<ion-item class="addon-calendar-radio-title"><h2>{{ 'addon.calendar.repeatedevents' | translate }}</h2></ion-item>
<ion-item>
<ion-label>{{ 'addon.calendar.repeateditall' | translate:{$a: event.othereventscount} }}</ion-label>
<ion-radio [value]="1"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{ 'addon.calendar.repeateditthis' | translate }}</ion-label>
<ion-radio [value]="0"></ion-radio>
</ion-item>
</div>
</ng-container> </ng-container>
<ion-item> <ion-item>

View File

@ -1,5 +1,5 @@
ion-app.app-root page-addon-calendar-edit-event { ion-app.app-root page-addon-calendar-edit-event {
.addon-calendar-duration-container ion-item:not(.addon-calendar-duration-title) { .addon-calendar-radio-container ion-item:not(.addon-calendar-radio-title) {
&.item-ios { &.item-ios {
@include padding-horizontal($item-ios-padding-start * 2, null); @include padding-horizontal($item-ios-padding-start * 2, null);

View File

@ -57,6 +57,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
courseGroupSet = false; courseGroupSet = false;
advanced = false; advanced = false;
errors: any; errors: any;
event: any; // The event object (when editing an event).
// Form variables. // Form variables.
eventForm: FormGroup; eventForm: FormGroup;
@ -72,6 +73,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
protected showAll: boolean; protected showAll: boolean;
protected isDestroyed = false; protected isDestroyed = false;
protected error = false; protected error = false;
protected gotEventData = false;
constructor(navParams: NavParams, constructor(navParams: NavParams,
private navCtrl: NavController, private navCtrl: NavController,
@ -126,6 +128,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
this.eventForm.addControl('timedurationminutes', this.fb.control('')); this.eventForm.addControl('timedurationminutes', this.fb.control(''));
this.eventForm.addControl('repeat', this.fb.control(false)); this.eventForm.addControl('repeat', this.fb.control(false));
this.eventForm.addControl('repeats', this.fb.control('1')); this.eventForm.addControl('repeats', this.fb.control('1'));
this.eventForm.addControl('repeateditall', this.fb.control(1));
} }
/** /**
@ -164,7 +167,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
return Promise.reject(this.translate.instant('addon.calendar.nopermissiontoupdatecalendar')); return Promise.reject(this.translate.instant('addon.calendar.nopermissiontoupdatecalendar'));
} }
if (this.eventId && !refresh) { if (this.eventId && !this.gotEventData) {
// Editing an event, get the event data. Wait for sync first. // Editing an event, get the event data. Wait for sync first.
promises.push(this.calendarSync.waitForSync(AddonCalendarSyncProvider.SYNC_ID).then(() => { promises.push(this.calendarSync.waitForSync(AddonCalendarSyncProvider.SYNC_ID).then(() => {
@ -173,20 +176,35 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
this.syncProvider.blockOperation(AddonCalendarProvider.COMPONENT, this.eventId); this.syncProvider.blockOperation(AddonCalendarProvider.COMPONENT, this.eventId);
} }
const promises = [];
// Get the event offline data if there's any. // Get the event offline data if there's any.
return this.calendarOffline.getEvent(this.eventId).then((event) => { promises.push(this.calendarOffline.getEvent(this.eventId).then((event) => {
this.hasOffline = true; this.hasOffline = true;
return event; return event;
}).catch(() => { }).catch(() => {
// No offline data. // No offline data.
this.hasOffline = false; this.hasOffline = false;
}));
if (this.eventId > 0) {
// It's an online event. get its data from server.
promises.push(this.calendarProvider.getEventById(this.eventId).then((event) => {
this.event = event;
if (event && event.repeatid) {
event.othereventscount = event.eventcount ? event.eventcount - 1 : '';
}
return event;
}));
}
return Promise.all(promises).then((result) => {
this.gotEventData = true;
const event = result[0] || result[1]; // Use offline data first.
if (this.eventId > 0) {
// It's an online event. get its data from server.
return this.calendarProvider.getEventById(this.eventId);
}
}).then((event) => {
if (event) { if (event) {
// Load the data in the form. // Load the data in the form.
this.eventForm.controls.name.setValue(event.name); this.eventForm.controls.name.setValue(event.name);
@ -204,6 +222,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
this.eventForm.controls.timedurationminutes.setValue(event.timedurationminutes || ''); this.eventForm.controls.timedurationminutes.setValue(event.timedurationminutes || '');
this.eventForm.controls.repeat.setValue(!!event.repeat); this.eventForm.controls.repeat.setValue(!!event.repeat);
this.eventForm.controls.repeats.setValue(event.repeats || '1'); this.eventForm.controls.repeats.setValue(event.repeats || '1');
this.eventForm.controls.repeateditall.setValue(event.repeateditall || 1);
} }
}); });
})); }));
@ -394,6 +413,11 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
data.repeats = formData.repeats; data.repeats = formData.repeats;
} }
if (this.event && this.event.repeatid) {
data.repeatid = this.event.repeatid;
data.repeateditall = formData.repeateditall;
}
// Send the data. // Send the data.
const modal = this.domUtils.showModalLoading('core.sending', true); const modal = this.domUtils.showModalLoading('core.sending', true);

View File

@ -94,6 +94,14 @@ export class AddonCalendarOfflineProvider {
name: 'repeats', name: 'repeats',
type: 'TEXT', type: 'TEXT',
}, },
{
name: 'repeatid',
type: 'INTEGER',
},
{
name: 'repeateditall',
type: 'INTEGER',
},
{ {
name: 'userid', name: 'userid',
type: 'INTEGER', type: 'INTEGER',
@ -202,6 +210,8 @@ export class AddonCalendarOfflineProvider {
timedurationminutes: data.timedurationminutes, timedurationminutes: data.timedurationminutes,
repeat: data.repeat ? 1 : 0, repeat: data.repeat ? 1 : 0,
repeats: data.repeats, repeats: data.repeats,
repeatid: data.repeatid,
repeateditall: data.repeateditall ? 1 : 0,
timecreated: timeCreated, timecreated: timeCreated,
userid: site.getUserId() userid: site.getUserId()
}; };

View File

@ -96,6 +96,7 @@
"addon.calendar.errorloadevents": "Error loading events.", "addon.calendar.errorloadevents": "Error loading events.",
"addon.calendar.eventduration": "Duration", "addon.calendar.eventduration": "Duration",
"addon.calendar.eventendtime": "End time", "addon.calendar.eventendtime": "End time",
"addon.calendar.eventkind": "Type of event",
"addon.calendar.eventname": "Event title", "addon.calendar.eventname": "Event title",
"addon.calendar.eventstarttime": "Start time", "addon.calendar.eventstarttime": "Start time",
"addon.calendar.eventtype": "Event type", "addon.calendar.eventtype": "Event type",
@ -106,6 +107,9 @@
"addon.calendar.noevents": "There are no events", "addon.calendar.noevents": "There are no events",
"addon.calendar.nopermissiontoupdatecalendar": "Sorry, but you do not have permission to update the calendar event", "addon.calendar.nopermissiontoupdatecalendar": "Sorry, but you do not have permission to update the calendar event",
"addon.calendar.reminders": "Reminders", "addon.calendar.reminders": "Reminders",
"addon.calendar.repeatedevents": "Repeated events",
"addon.calendar.repeateditall": "Also apply changes to the other {{$a}} events in this repeat series",
"addon.calendar.repeateditthis": "Apply changes to this event only",
"addon.calendar.repeatevent": "Repeat this event", "addon.calendar.repeatevent": "Repeat this event",
"addon.calendar.repeatweeksl": "Repeat weekly, creating altogether", "addon.calendar.repeatweeksl": "Repeat weekly, creating altogether",
"addon.calendar.setnewreminder": "Set a new reminder", "addon.calendar.setnewreminder": "Set a new reminder",