2021-01-29 09:45:27 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-07-02 11:19:52 +01:00
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
2021-06-29 10:50:05 +01:00
|
|
|
import { Router } from '@angular/router';
|
2021-06-08 15:59:06 +01:00
|
|
|
import { AlertController, AnimationController, ModalController, NavParams } from '@ionic/angular';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { Attachment } from 'src/app/models/attachment.model';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { EventBody } from 'src/app/models/eventbody.model';
|
|
|
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { EventsService } from 'src/app/services/events.service';
|
2021-06-15 15:09:20 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { Event } from '../../../models/event.model';
|
2021-06-15 15:28:03 +01:00
|
|
|
import { AttendeesPageModal } from '../../events/attendees/attendees.page';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { SearchPage } from '../../search/search.page';
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-event',
|
|
|
|
|
templateUrl: './edit-event.page.html',
|
|
|
|
|
styleUrls: ['./edit-event.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class EditEventPage implements OnInit {
|
|
|
|
|
|
2021-07-02 11:19:52 +01:00
|
|
|
Form: FormGroup;
|
|
|
|
|
validateFrom = false
|
2021-07-12 16:05:05 +01:00
|
|
|
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
|
|
|
|
public minDate = new Date().toISOString().slice(0,10)
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-01-31 01:40:19 +01:00
|
|
|
postEvent: Event;
|
|
|
|
|
isRecurring:string;
|
|
|
|
|
isEventEdited: boolean;
|
|
|
|
|
loadedEvent: Event;
|
|
|
|
|
eventBody: EventBody;
|
|
|
|
|
segment:string = "true";
|
|
|
|
|
profile:string;
|
|
|
|
|
eventAttendees: EventPerson[];
|
|
|
|
|
selectedSegment: string;
|
|
|
|
|
selectedDate: Date;
|
2021-06-29 10:50:05 +01:00
|
|
|
initCalendarName: string;
|
|
|
|
|
caller:string;
|
2021-07-08 21:31:14 +01:00
|
|
|
recurringTypes: any;
|
|
|
|
|
selectedRecurringType: any;
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
loadedEventAttachments: Attachment[] = [];
|
2021-04-06 11:28:46 +01:00
|
|
|
taskParticipants: any = [];
|
|
|
|
|
taskParticipantsCc: any = [];
|
|
|
|
|
adding: "intervenient" | "CC" = "intervenient";
|
|
|
|
|
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-09 13:57:31 +01:00
|
|
|
showAttendees = false;
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2021-01-31 01:40:19 +01:00
|
|
|
private navParams: NavParams,
|
|
|
|
|
private eventsService: EventsService,
|
|
|
|
|
public alertController: AlertController,
|
2021-04-23 10:35:53 +01:00
|
|
|
private attachmentsService: AttachmentsService,
|
2021-06-15 15:09:20 +01:00
|
|
|
private toastService: ToastService,
|
2021-06-29 10:50:05 +01:00
|
|
|
private router: Router,
|
2021-04-07 10:04:58 +01:00
|
|
|
) {
|
2021-07-01 11:26:45 +01:00
|
|
|
|
2021-07-08 13:20:54 +01:00
|
|
|
this.postEvent = new Event();
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isEventEdited = false;
|
2021-08-19 12:52:26 +01:00
|
|
|
this.postEvent.EventRecurrence = { Type:'-1', LastOccurrence:''};
|
2021-07-09 14:39:45 +01:00
|
|
|
this.postEvent = this.navParams.get('event');
|
2021-06-29 10:50:05 +01:00
|
|
|
this.caller = this.navParams.get('caller');
|
|
|
|
|
this.initCalendarName = this.postEvent.CalendarName;
|
2021-04-23 10:35:53 +01:00
|
|
|
|
2021-04-08 09:14:28 +01:00
|
|
|
if(this.postEvent){
|
2021-04-23 10:35:53 +01:00
|
|
|
if( this.postEvent.Body){
|
|
|
|
|
if(typeof(this.postEvent.Body.Text) == 'string'){
|
|
|
|
|
this.postEvent.Body.Text = this.postEvent.Body.Text.replace(/<[^>]+>/g, '');
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-08 09:14:28 +01:00
|
|
|
}
|
2021-04-06 11:28:46 +01:00
|
|
|
|
2021-05-06 13:32:54 +01:00
|
|
|
if(this.postEvent.Attendees == null) {
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipants = []
|
|
|
|
|
} else {
|
2021-04-08 13:39:48 +01:00
|
|
|
|
|
|
|
|
this.postEvent.Attendees.forEach(e =>{
|
|
|
|
|
if(e.IsRequired){
|
|
|
|
|
this.taskParticipants.push(e);
|
|
|
|
|
} else {
|
|
|
|
|
this.taskParticipantsCc.push(e);
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 10:01:43 +01:00
|
|
|
if(this.postEvent.IsRecurring == false) {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isRecurring = "Não se repete";
|
|
|
|
|
}
|
2021-04-12 10:01:43 +01:00
|
|
|
else {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isRecurring = "Repete";
|
|
|
|
|
}
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
this.getAttachments(this.postEvent.EventId);
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-01-31 01:40:19 +01:00
|
|
|
}
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-02-24 20:23:15 +01:00
|
|
|
window.onresize = (event) => {
|
|
|
|
|
// if not mobile remove all component
|
2021-05-06 13:32:54 +01:00
|
|
|
if( window.innerWidth >= 1024) {
|
2021-02-24 20:23:15 +01:00
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
2021-05-06 13:32:54 +01:00
|
|
|
}
|
2021-06-10 15:38:08 +01:00
|
|
|
if(window.innerWidth > 800){
|
|
|
|
|
this.showAttendees=true;
|
|
|
|
|
}
|
2021-07-08 13:20:54 +01:00
|
|
|
|
|
|
|
|
this.getRecurrenceTypes();
|
2021-07-12 11:20:08 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.selectedRecurringType = this.postEvent.EventRecurrence.Type.toString();
|
|
|
|
|
}, 500);
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-12 10:01:43 +01:00
|
|
|
close() {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.modalController.dismiss();
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-06-29 10:50:05 +01:00
|
|
|
goBack() {
|
|
|
|
|
console.log(this.caller);
|
|
|
|
|
this.router.navigate(['/home',this.caller]);
|
|
|
|
|
}
|
2021-04-08 13:39:48 +01:00
|
|
|
|
2021-07-08 13:20:54 +01:00
|
|
|
getRecurrenceTypes() {
|
|
|
|
|
this.eventsService.getRecurrenceTypes().subscribe(res=>{
|
|
|
|
|
console.log(res);
|
2021-07-08 21:31:14 +01:00
|
|
|
this.recurringTypes = res;
|
2021-07-08 13:20:54 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 11:20:08 +01:00
|
|
|
onSelectedRecurringChanged(ev?:any){
|
2021-07-08 21:31:14 +01:00
|
|
|
console.log(ev);
|
|
|
|
|
if(ev.length > 1){
|
|
|
|
|
console.log(ev.filter(data => data != '-1'));
|
|
|
|
|
this.selectedRecurringType = ev.filter(data => data != '-1');
|
|
|
|
|
}
|
|
|
|
|
if(ev.length == 0){
|
|
|
|
|
this.selectedRecurringType = "-1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 11:19:52 +01:00
|
|
|
|
|
|
|
|
runValidation() {
|
|
|
|
|
this.validateFrom = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
injectValidation() {
|
|
|
|
|
|
|
|
|
|
this.Form = new FormGroup({
|
|
|
|
|
Subject: new FormControl(this.postEvent.Subject, [
|
|
|
|
|
Validators.required,
|
|
|
|
|
// Validators.minLength(4)
|
|
|
|
|
]),
|
|
|
|
|
Location: new FormControl(this.postEvent.Location, [
|
|
|
|
|
Validators.required,
|
|
|
|
|
]),
|
|
|
|
|
CalendarName: new FormControl(this.postEvent.CalendarName, [
|
|
|
|
|
Validators.required
|
|
|
|
|
]),
|
2021-07-15 08:53:54 +01:00
|
|
|
Categories: new FormControl(this.postEvent.Category, [
|
2021-07-02 11:19:52 +01:00
|
|
|
Validators.required
|
|
|
|
|
]),
|
|
|
|
|
IsRecurring: new FormControl(this.postEvent.IsRecurring, [
|
|
|
|
|
Validators.required
|
|
|
|
|
]),
|
2021-07-16 23:16:55 +01:00
|
|
|
Date: new FormControl(new Date(this.postEvent.StartDate).getTime() < new Date(this.postEvent.EndDate).getTime()? 'ok': null,[
|
2021-07-13 16:02:14 +01:00
|
|
|
Validators.required
|
|
|
|
|
]),
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-07-13 16:02:14 +01:00
|
|
|
participantes: new FormControl(this.taskParticipants, [
|
|
|
|
|
Validators.required
|
|
|
|
|
]),
|
2021-07-02 11:19:52 +01:00
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-07-02 11:19:52 +01:00
|
|
|
|
2021-06-29 10:50:05 +01:00
|
|
|
save() {
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-07-02 11:19:52 +01:00
|
|
|
this.injectValidation()
|
|
|
|
|
this.runValidation()
|
|
|
|
|
|
2021-07-09 14:39:45 +01:00
|
|
|
if(this.Form.invalid) return false;
|
|
|
|
|
if(this.selectedRecurringType != '-1'){
|
|
|
|
|
this.postEvent.EventRecurrence.Type = this.selectedRecurringType;
|
|
|
|
|
}
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-08 13:39:48 +01:00
|
|
|
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc)
|
2021-07-16 23:16:55 +01:00
|
|
|
|
|
|
|
|
this.postEvent.EventRecurrence.Type = this.selectedRecurringType;
|
|
|
|
|
|
|
|
|
|
this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => {
|
|
|
|
|
if(this.initCalendarName != this.postEvent.CalendarName){
|
|
|
|
|
let body = {
|
|
|
|
|
"EventId": this.postEvent.EventId,
|
|
|
|
|
"CalendarDestinationName": this.postEvent.CalendarName,
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await this.eventsService.changeAgenda(body).toPromise();
|
|
|
|
|
} catch (error) {}
|
|
|
|
|
finally {
|
|
|
|
|
this.goBack();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
this.toastService.successMessage();
|
2021-06-29 10:50:05 +01:00
|
|
|
|
2021-07-16 23:16:55 +01:00
|
|
|
}, error => {
|
|
|
|
|
this.toastService.badRequest()
|
|
|
|
|
});
|
2021-05-24 16:49:25 +01:00
|
|
|
|
2021-07-16 23:16:55 +01:00
|
|
|
this.isEventEdited = true;
|
|
|
|
|
|
|
|
|
|
this.modalController.dismiss(this.isEventEdited);
|
2021-05-24 16:49:25 +01:00
|
|
|
|
|
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
this.saveDocument()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveDocument() {
|
|
|
|
|
|
|
|
|
|
this.loadedEventAttachments.forEach((e)=>{
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
const id: any = e.Id
|
|
|
|
|
const remove = e['remove']
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
if ( id == 'add') {
|
|
|
|
|
//data.selected
|
|
|
|
|
const DocumentToSave = {
|
|
|
|
|
SourceTitle: e.SourceName,
|
|
|
|
|
ParentId: this.postEvent.EventId,
|
|
|
|
|
Source: '1',
|
|
|
|
|
SourceId: e.SourceId,
|
|
|
|
|
ApplicationId: e.ApplicationId.toString(),
|
|
|
|
|
Id: '0',
|
|
|
|
|
Link: '',
|
|
|
|
|
SerialNumber: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.attachmentsService.setEventAttachmentById(DocumentToSave).subscribe(()=>{
|
|
|
|
|
this.getAttachments(this.postEvent.EventId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else if(remove) {
|
|
|
|
|
this.attachmentsService.deleteEventAttachmentById(e.Id).subscribe( res=> {})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 10:04:58 +01:00
|
|
|
async openAttendees() {
|
2021-06-10 15:38:08 +01:00
|
|
|
if(window.innerWidth > 801){
|
|
|
|
|
this.showAttendees=true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
const modal = await this.modalController.create({
|
2021-06-15 15:28:03 +01:00
|
|
|
component: AttendeesPageModal,
|
2021-06-10 15:38:08 +01:00
|
|
|
componentProps: {
|
|
|
|
|
adding: this.adding,
|
|
|
|
|
taskParticipants: this.taskParticipants,
|
|
|
|
|
taskParticipantsCc: this.taskParticipantsCc
|
|
|
|
|
},
|
2021-08-30 14:32:15 +01:00
|
|
|
cssClass: 'modal attendee modal-desktop',
|
2021-06-10 15:38:08 +01:00
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-06-10 15:38:08 +01:00
|
|
|
await modal.present();
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-06-10 15:38:08 +01:00
|
|
|
modal.onDidDismiss().then((data) => {
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-06-10 15:38:08 +01:00
|
|
|
if(data){
|
|
|
|
|
data = data['data'];
|
2021-05-04 15:44:48 +01:00
|
|
|
|
2021-06-10 15:38:08 +01:00
|
|
|
const newAttendees: EventPerson[] = data['taskParticipants'];
|
|
|
|
|
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
|
2021-05-04 15:44:48 +01:00
|
|
|
|
2021-08-30 14:32:15 +01:00
|
|
|
if(newAttendees.length) {
|
|
|
|
|
this.setIntervenient(newAttendees);
|
|
|
|
|
}
|
|
|
|
|
if(newAttendeesCC) {
|
|
|
|
|
this.setIntervenientCC(newAttendeesCC);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-05-04 15:44:48 +01:00
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
setIntervenient(data){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipants = data;
|
|
|
|
|
this.postEvent.Attendees = data;
|
|
|
|
|
}
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
setIntervenientCC(data){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipantsCc = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
addParticipants(){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.adding = 'intervenient'
|
2021-04-07 10:04:58 +01:00
|
|
|
this.openAttendees();
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
addParticipantsCC(){
|
2021-06-29 10:50:05 +01:00
|
|
|
this.adding = 'CC';
|
2021-04-07 10:04:58 +01:00
|
|
|
this.openAttendees();
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-04-08 13:39:48 +01:00
|
|
|
dynamicSetIntervenient({taskParticipants, taskParticipantsCc}){
|
|
|
|
|
this.taskParticipants = taskParticipants;
|
|
|
|
|
this.taskParticipantsCc = taskParticipantsCc;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
getAttachments(eventId: string){
|
|
|
|
|
this.attachmentsService.getAttachmentsById(eventId).subscribe(res=>{
|
|
|
|
|
this.loadedEventAttachments = res;
|
2021-07-13 12:05:17 +01:00
|
|
|
console.log('res', res);
|
2021-04-23 10:35:53 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
deleteAttachment(attachmentID: string, index) {
|
2021-04-23 10:35:53 +01:00
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
const id: any = this.loadedEventAttachments[index].Id
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
if(id == 'add') {
|
|
|
|
|
this.loadedEventAttachments = this.loadedEventAttachments.filter((e,i)=> i!=index)
|
|
|
|
|
} else {
|
|
|
|
|
this.loadedEventAttachments[index]['remove'] = true
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:05:17 +01:00
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getDoc() {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: SearchPage,
|
|
|
|
|
cssClass: 'modal-width-100-width-background modal',
|
|
|
|
|
componentProps: {
|
2021-04-30 14:12:45 +01:00
|
|
|
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
2021-05-03 17:24:48 +01:00
|
|
|
showSearchInput: true,
|
|
|
|
|
select: true,
|
2021-04-23 10:35:53 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
2021-07-09 12:35:11 +01:00
|
|
|
modal.onDidDismiss().then( async (res)=> {
|
|
|
|
|
if(res) {
|
2021-04-23 10:35:53 +01:00
|
|
|
const data = res.data;
|
2021-07-09 12:35:11 +01:00
|
|
|
|
|
|
|
|
const ApplicationIdDocumentToSave: any = {
|
|
|
|
|
SourceName: data.selected.Assunto,
|
2021-04-23 10:35:53 +01:00
|
|
|
ParentId: this.postEvent.EventId,
|
|
|
|
|
SourceId: data.selected.Id,
|
2021-07-09 12:35:11 +01:00
|
|
|
Stakeholders: false,
|
2021-04-23 10:35:53 +01:00
|
|
|
ApplicationId: data.selected.ApplicationType.toString(),
|
2021-07-09 12:35:11 +01:00
|
|
|
CreateDate: false,
|
|
|
|
|
// needed to attach this document
|
|
|
|
|
Id: 'add',
|
|
|
|
|
SourceTitle: data.selected.Assunto,
|
|
|
|
|
Source: '1',
|
2021-04-23 10:35:53 +01:00
|
|
|
Link: '',
|
|
|
|
|
SerialNumber: '',
|
2021-07-09 12:35:11 +01:00
|
|
|
}
|
2021-04-23 10:35:53 +01:00
|
|
|
|
2021-07-09 12:35:11 +01:00
|
|
|
console.log( this.loadedEventAttachments)
|
|
|
|
|
this.loadedEventAttachments.push(ApplicationIdDocumentToSave)
|
2021-04-23 10:35:53 +01:00
|
|
|
|
|
|
|
|
}
|
2021-07-09 12:35:11 +01:00
|
|
|
})
|
2021-04-23 10:35:53 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:05:17 +01:00
|
|
|
}
|