Files
doneit-web/src/app/shared/agenda/new-event/new-event.component.ts
T

231 lines
5.9 KiB
TypeScript
Raw Normal View History

2021-02-24 09:14:58 +01:00
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { EventBody } from 'src/app/models/eventbody.model';
import { EventPerson } from 'src/app/models/eventperson.model';
import { EventsService } from 'src/app/services/events.service';
import { Event } from 'src/app/models/event.model';
import { ModalController } from '@ionic/angular';
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
import { SearchPage } from 'src/app/pages/search/search.page';
import { SearchDocument } from "src/app/models/search-document";
2021-02-24 09:14:58 +01:00
@Component({
selector: 'app-new-event',
templateUrl: './new-event.component.html',
styleUrls: ['./new-event.component.scss'],
})
2021-02-24 09:14:58 +01:00
export class NewEventPage implements OnInit {
2021-02-24 09:14:58 +01:00
eventBody: EventBody;
segment:string = "true";
@Input() profile:string;
@Input() selectedSegment: string;
@Input() selectedDate: Date;
2021-04-05 15:00:14 +01:00
@Input() taskParticipants: EventPerson[];
2021-04-07 15:13:31 +01:00
@Input() taskParticipantsCc: any = [];
@Output() setIntervenient = new EventEmitter<any>();
@Output() setIntervenientCC = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
@Input() postEvent: Event;
2021-02-24 09:14:58 +01:00
@Output() onAddEvent = new EventEmitter<any>();
2021-03-24 15:10:46 +01:00
@Output() openAttendeesComponent = new EventEmitter<any>();
2021-03-25 10:50:58 +01:00
@Output() clearContact = new EventEmitter<any>();
2021-03-25 15:18:12 +01:00
@Output() GoBackEditOrAdd = new EventEmitter<any>();
2021-03-25 15:51:19 +01:00
@Output() cloneAllmobileComponent = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
documents:SearchDocument[] = [];
2021-02-24 09:14:58 +01:00
minDate: string;
constructor(
private modalController: ModalController,
private eventService: EventsService,
) {}
2021-02-24 09:14:58 +01:00
ngOnInit() {
if(!this.restoreTemporaryData()){
this.postEvent = new Event();
this.eventBody = { BodyType : "1", Text : ""};
this.postEvent.Body = this.eventBody;
/* console.log(this.profile); */
2021-02-24 09:14:58 +01:00
let selectedStartdDate = this.selectedDate;
let selectedEndDate = new Date(this.selectedDate);
/* Set + 30minutes to seleted datetime */
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
this.minDate = this.selectedDate.toString();
if(this.selectedSegment != "Combinada"){
this.postEvent ={
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
2021-04-07 14:08:05 +01:00
CalendarName: '',
StartDate: selectedStartdDate,
EndDate: new Date(selectedEndDate),
EventType: 'Reunião',
Attendees: null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Categories: ['Reunião'],
HasAttachments: false,
};
}
else{
this.postEvent ={
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
CalendarName: 'Oficial',
StartDate: selectedStartdDate,
EndDate: new Date(selectedEndDate),
EventType: 'Reunião',
Attendees: null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Categories: ['Reunião'],
HasAttachments: false,
};
}
if(this.postEvent.Attendees != null) {
this.postEvent.Attendees.forEach(e =>{
if(e.IsRequired) {
this.taskParticipants.push(e);
} else {
this.taskParticipantsCc.push(e);
}
})
}
this.taskParticipants = removeDuplicate(this.taskParticipants);
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
this.setIntervenient.emit(this.taskParticipants);
this.setIntervenientCC.emit(this.taskParticipantsCc);
2021-02-24 09:14:58 +01:00
}
2021-02-24 09:14:58 +01:00
}
async getDoc(){
const modal = await this.modalController.create({
component: SearchPage,
cssClass: 'group-messages modal-desktop search-modal search-modal-to-desktop',
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect'
}
});
await modal.present();
modal.onDidDismiss().then((res)=>{
if(res){
const data = res.data;
this.documents.push(data.selected);
}
});
}
2021-02-24 09:14:58 +01:00
close(){
this.deleteTemporaryData();
2021-03-25 15:51:19 +01:00
this.cloneAllmobileComponent.emit();
2021-03-25 10:50:58 +01:00
this.clearContact.emit();
this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
2021-02-24 09:14:58 +01:00
}
2021-02-24 09:14:58 +01:00
save(){
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
2021-04-09 10:33:19 +01:00
if(this.profile=='mdgpr') {
2021-02-24 09:14:58 +01:00
this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).subscribe();
}
2021-04-09 10:33:19 +01:00
else if(this.profile=='pr') {
2021-02-24 09:14:58 +01:00
this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).subscribe();
}
this.deleteTemporaryData();
2021-03-25 10:50:58 +01:00
this.onAddEvent.emit(this.postEvent);
2021-03-25 15:18:12 +01:00
this.GoBackEditOrAdd.emit();
2021-04-07 15:13:31 +01:00
this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
2021-02-24 09:14:58 +01:00
}
2021-04-08 15:45:45 +01:00
async addParticipants() {
2021-04-09 10:33:19 +01:00
this.saveTemporaryData();
2021-04-08 15:45:45 +01:00
this.openAttendeesComponent.emit({
type: "intervenient"
});
this.clearContact.emit();
}
async addParticipantsCc() {
2021-04-09 10:33:19 +01:00
this.saveTemporaryData();
2021-04-08 15:45:45 +01:00
this.openAttendeesComponent.emit({
type: "CC"
});
this.clearContact.emit();
2021-03-24 15:10:46 +01:00
}
2021-02-24 09:14:58 +01:00
saveTemporaryData(){
window['temp.path:/home/agenda/new-event.component.ts'] = {
postEvent: this.postEvent,
eventBody: this.eventBody,
segment: this.segment
}
}
restoreTemporaryData(): boolean{
const restoredData = window['temp.path:/home/agenda/new-event.component.ts']
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData){
this.postEvent = restoredData.postEvent
this.eventBody = restoredData.eventBody
this.segment = restoredData.segment
return true;
} else {
return false;
}
}
deleteTemporaryData(){
window['temp.path:/home/agenda/new-event.component.ts'] = {}
}
2021-02-24 09:14:58 +01:00
}