onActionBegin(args: ActionEventArgs): void {
var schedule;
//when an event is created
if (args.requestType === 'eventCreate') {
schedule = args.addedRecords;
this.addEvents(this.copyAppointment(schedule[0]));
console.log('event created !');
console.log('available schedules ->');
console.log(this.availableSchedules);
} else if (args.requestType === 'eventChange') {
// when an event is changed
schedule = args.changedRecords;
if (schedule[0].Guid != null) {
// if an recurrence exception is created
console.log('it is a recurrence exception with guid->' + schedule[0].Guid);
//this.addEvents(this.copyAppointment(schedule[0]));
this.updateEvents(this.copyAppointment(schedule[0]));
console.log('event updated !');
console.log('available schedules ->');
console.log(this.availableSchedules);
} else {
//normal updation
this.updateEvents(this.copyAppointment(schedule[0]));
console.log('event updated !');
console.log('available schedules ->');
console.log(this.availableSchedules);
}
} else if (args.requestType === 'eventRemove') {
// when an event is removed
schedule = args.deletedRecords;
this.deleteEvents(this.copyAppointment(schedule[0]));
console.log('event deleted !');
console.log('available schedules ->');
console.log(this.availableSchedules);
}
}
}
so whenever there is change i create an object of ScheduleData and copy all the changed or added or records into it as you can see
//for copying the record
copyAppointment(schedule) {
var appointment = new scheduleData();
appointment.Id = schedule.Id;
appointment.Subject = schedule.Subject;
appointment.StartTime = schedule.StartTime.toString();
appointment.EndTime = schedule.EndTime.toString();
appointment.IsAllDay = schedule.IsAllDay;
appointment.RecurrenceRule = schedule.RecurrenceRule;
appointment.RecurrenceException = schedule.RecurrenceException;
appointment.Guid = schedule.Guid;
if (schedule.RecurrenceRule != null && schedule.Guid == null) {
console.log('it is a recurrent event');
appointment.IsRecurrence = true;
} else if (schedule.RecurrenceRule != null && schedule.Guid != null) {
console.log('it is not a recurrent event');
appointment.IsRecurrence = false;
} else if (schedule.RecurrenceRule == null) {
console.log('it is not a recurrent event');
appointment.IsRecurrence = false;
}
return appointment;
}
after that i have some functions that performs the corresponding action to push it in another array which is of type ScheduleData
// for adding events into calendar schedules
addEvents(appointment: scheduleData) {
this.availableSchedules.push(appointment);
this.tutorAvailabilitySchedule.allAvailabilitySchedule = this.availableSchedules;
this.httpService.saveScheduleData(this.tutorAvailabilitySchedule).subscribe((res) => {});
}
// for updating events into calendar schedules
updateEvents(newAppointment: scheduleData) {
console.log(newAppointment);
let updateIndex = this.availableSchedules.findIndex((obj) => obj.Id == newAppointment.Id);
if (updateIndex == -1) {
console.log('item not present');
// this.addEvents(newAppointment);
this.availableSchedules.push(newAppointment);
} else {
this.availableSchedules[updateIndex] = newAppointment;
}
this.tutorAvailabilitySchedule.allAvailabilitySchedule = this.availableSchedules;
this.httpService.saveScheduleData(this.tutorAvailabilitySchedule).subscribe((res) => {
console.log(res);
});
}
//for deleting events into calendar schedules
deleteEvents(appointment: scheduleData) {
let deleteIndex = this.availableSchedules.findIndex((obj) => obj.Id == appointment.Id);
this.availableSchedules.splice(deleteIndex, 1);
this.tutorAvailabilitySchedule.allAvailabilitySchedule = this.availableSchedules;
this.httpService.saveScheduleData(this.tutorAvailabilitySchedule).subscribe((res) => {
console.log(res);
});
}
Now in these functions i send this array to backend which is in spring boot(java) and save it to database .
whenever i login again i retrieve this schedules Array which is of type scheduleData
i save it in the database like the same process above.
it works fine when i login again and view it.
but the problem arises when i edit an event of a particular date which is part of recurrence and extends its duration it displays fine
after login it displays the edits the whole chain and displays parent event along with edited event