2021-01-29 09:45:27 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-01-29 14:13:31 +01:00
|
|
|
import { ModalController, NavParams } from '@ionic/angular';
|
2021-04-23 10:35:53 +01:00
|
|
|
import { EventAttachment } from 'src/app/models/attachment.model';
|
2021-01-29 14:13:31 +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 { SearchDocument } from 'src/app/models/search-document';
|
|
|
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
2021-01-29 14:13:31 +01:00
|
|
|
import { EventsService } from 'src/app/services/events.service';
|
2021-05-24 16:49:25 +01:00
|
|
|
import { BadRequestComponent } from 'src/app/shared/popover/bad-request/bad-request.component';
|
|
|
|
|
import { SuccessMessageComponent } from 'src/app/shared/popover/success-message/success-message.component';
|
2021-01-29 14:13:31 +01:00
|
|
|
import { Event } from '../../../models/event.model';
|
|
|
|
|
import { AttendeesPage } from '../../events/attendees/attendees.page';
|
2021-04-19 11:35:48 +01:00
|
|
|
import { SearchPage } from '../../search/search.page';
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-new-event',
|
|
|
|
|
templateUrl: './new-event.page.html',
|
|
|
|
|
styleUrls: ['./new-event.page.scss'],
|
|
|
|
|
})
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
export class NewEventPage implements OnInit {
|
2021-01-29 14:13:31 +01:00
|
|
|
postEvent: Event;
|
|
|
|
|
eventBody: EventBody;
|
|
|
|
|
segment:string = "true";
|
|
|
|
|
profile:string;
|
|
|
|
|
eventAttendees: EventPerson[];
|
|
|
|
|
selectedSegment: string;
|
|
|
|
|
selectedDate: Date;
|
|
|
|
|
minDate: string;
|
2021-01-29 09:45:27 +01:00
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
adding: "intervenient" | "CC";
|
|
|
|
|
|
|
|
|
|
taskParticipants: any = [];
|
|
|
|
|
taskParticipantsCc: any = [];
|
|
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
documents:SearchDocument[] = [];
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2021-01-29 14:13:31 +01:00
|
|
|
private navParams: NavParams,
|
|
|
|
|
private eventService: EventsService,
|
2021-04-23 10:35:53 +01:00
|
|
|
private attachmentsService: AttachmentsService
|
2021-01-29 14:13:31 +01:00
|
|
|
) {
|
|
|
|
|
this.postEvent = new Event();
|
|
|
|
|
this.eventBody = { BodyType : "1", Text : ""};
|
2021-04-07 11:52:28 +01:00
|
|
|
this.postEvent.Body = this.eventBody;
|
2021-01-29 14:13:31 +01:00
|
|
|
this.profile = this.navParams.get('profile');
|
|
|
|
|
|
|
|
|
|
this.selectedSegment = this.navParams.get('segment');
|
|
|
|
|
this.selectedDate = this.navParams.get('eventSelectedDate');
|
|
|
|
|
}
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-01-29 14:13:31 +01:00
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
/* console.log(this.profile); */
|
2021-01-29 14:13:31 +01:00
|
|
|
|
|
|
|
|
let selectedStartdDate = this.selectedDate;
|
|
|
|
|
let selectedEndDate = new Date(this.selectedDate);
|
|
|
|
|
/* Set + 30minutes to seleted datetime */
|
2021-01-29 15:55:49 +01:00
|
|
|
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
|
|
|
|
|
this.minDate = this.selectedDate.toString();
|
2021-01-29 14:13:31 +01:00
|
|
|
|
|
|
|
|
if(this.selectedSegment != "Combinada"){
|
|
|
|
|
this.postEvent ={
|
|
|
|
|
EventId: '',
|
|
|
|
|
Subject: '',
|
|
|
|
|
Body: this.eventBody,
|
|
|
|
|
Location: '',
|
|
|
|
|
CalendarId: '',
|
|
|
|
|
CalendarName: this.selectedSegment,
|
|
|
|
|
StartDate: selectedStartdDate,
|
|
|
|
|
EndDate: new Date(selectedEndDate),
|
|
|
|
|
EventType: 'Reunião',
|
|
|
|
|
Attendees: null,
|
|
|
|
|
IsMeeting: false,
|
|
|
|
|
IsRecurring: false,
|
|
|
|
|
AppointmentState: 0,
|
|
|
|
|
TimeZone: '',
|
|
|
|
|
Organizer: '',
|
2021-02-02 09:02:13 +01:00
|
|
|
Categories: ['Reunião'],
|
2021-01-29 14:13:31 +01:00
|
|
|
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: '',
|
2021-02-02 09:02:13 +01:00
|
|
|
Categories: ['Reunião'],
|
2021-01-29 14:13:31 +01:00
|
|
|
HasAttachments: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-02-24 20:23:15 +01:00
|
|
|
|
|
|
|
|
window.onresize = (event) => {
|
|
|
|
|
// if not mobile remove all component
|
|
|
|
|
if( window.innerWidth >= 1024){
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-05-06 13:32:54 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
|
|
|
|
close(){
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
2021-05-24 16:49:25 +01:00
|
|
|
|
2021-04-30 14:12:45 +01:00
|
|
|
async save() {
|
|
|
|
|
/* console.log(this.postEvent);
|
2021-04-07 11:52:28 +01:00
|
|
|
console.log(this.profile); */
|
2021-04-30 14:12:45 +01:00
|
|
|
|
2021-04-23 10:35:53 +01:00
|
|
|
if(this.documents.length >= 0) {
|
|
|
|
|
this.postEvent.HasAttachments = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let eventId: string;
|
2021-05-24 16:49:25 +01:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if(this.profile=='mdgpr') {
|
|
|
|
|
eventId = await this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).toPromise();
|
|
|
|
|
}
|
|
|
|
|
else if(this.profile=='pr'){
|
|
|
|
|
eventId = await this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).toPromise();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DocumentToSave: EventAttachment[] = this.documents.map((e) => {
|
|
|
|
|
return {
|
|
|
|
|
SourceTitle: e.Assunto,
|
|
|
|
|
ParentId: eventId,
|
|
|
|
|
Source: '1',
|
|
|
|
|
SourceId: e.Id,
|
|
|
|
|
ApplicationId: e.ApplicationType.toString(),
|
|
|
|
|
Id: '',
|
|
|
|
|
Link: '',
|
|
|
|
|
SerialNumber: ''
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await DocumentToSave.forEach( async (attachments, i) => {
|
|
|
|
|
try {
|
|
|
|
|
await this.attachmentsService.setEventAttachmentById(attachments).toPromise();
|
|
|
|
|
} catch(error) {
|
|
|
|
|
alert('document error')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.successMessage()
|
|
|
|
|
this.modalController.dismiss(this.postEvent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.badRequest()
|
2021-01-29 14:13:31 +01:00
|
|
|
}
|
2021-04-23 10:35:53 +01:00
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
}
|
2021-04-23 10:35:53 +01:00
|
|
|
|
|
|
|
|
|
2021-05-25 13:38:46 +01:00
|
|
|
async successMessage(message?: string) {
|
2021-05-24 16:49:25 +01:00
|
|
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: SuccessMessageComponent,
|
|
|
|
|
componentProps: {
|
2021-05-25 13:38:46 +01:00
|
|
|
message: message || 'Processo efetuado' ,
|
2021-05-24 16:49:25 +01:00
|
|
|
},
|
|
|
|
|
cssClass: 'modal modal-desktop'
|
2021-04-23 10:35:53 +01:00
|
|
|
});
|
|
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
modal.dismiss()
|
|
|
|
|
},3000)
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
async badRequest() {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: BadRequestComponent,
|
|
|
|
|
componentProps: {
|
|
|
|
|
message: 'Processo não realizado com sucesso',
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'modal modal-desktop'
|
|
|
|
|
});
|
2021-04-19 11:35:48 +01:00
|
|
|
|
2021-05-24 16:49:25 +01:00
|
|
|
modal.present()
|
|
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
modal.dismiss()
|
|
|
|
|
},3000)
|
|
|
|
|
}
|
2021-04-19 11:35:48 +01:00
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
async openAttendees() {
|
2021-05-04 15:44:48 +01:00
|
|
|
|
2021-01-29 14:13:31 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: AttendeesPage,
|
|
|
|
|
componentProps: {
|
2021-04-07 11:52:28 +01:00
|
|
|
eventAttendees: this.postEvent.Attendees,
|
|
|
|
|
adding: this.adding,
|
|
|
|
|
taskParticipants: this.taskParticipants
|
2021-01-29 14:13:31 +01:00
|
|
|
},
|
2021-04-16 14:32:22 +01:00
|
|
|
cssClass: 'attendee modal modal-desktop',
|
2021-01-29 14:13:31 +01:00
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss().then((data) => {
|
2021-04-07 11:52:28 +01:00
|
|
|
|
|
|
|
|
if(data){
|
|
|
|
|
data = data['data'];
|
|
|
|
|
|
|
|
|
|
const newAttendees: EventPerson[] = data['taskParticipants'];
|
|
|
|
|
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
|
|
|
|
|
|
|
|
|
|
this.setIntervenient(newAttendees);
|
|
|
|
|
this.setIntervenientCC(newAttendeesCC);
|
2021-01-29 14:13:31 +01:00
|
|
|
}
|
|
|
|
|
});
|
2021-04-07 11:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIntervenient(data){
|
|
|
|
|
this.taskParticipants = data;
|
|
|
|
|
this.postEvent.Attendees = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIntervenientCC(data){
|
|
|
|
|
this.taskParticipantsCc = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addParticipants(){
|
|
|
|
|
this.adding = 'intervenient'
|
|
|
|
|
this.openAttendees();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addParticipantsCC(){
|
|
|
|
|
this.adding = 'CC'
|
|
|
|
|
this.openAttendees();
|
|
|
|
|
}
|
2021-01-29 14:13:31 +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-29 15:25:14 +01:00
|
|
|
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
2021-04-30 14:12:45 +01:00
|
|
|
showSearchInput: true,
|
|
|
|
|
select: true
|
2021-04-23 10:35:53 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then((res)=>{
|
|
|
|
|
if(res){
|
|
|
|
|
const data = res.data;
|
|
|
|
|
this.documents.push(data.selected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeAttachment(index: number){
|
|
|
|
|
|
|
|
|
|
this.documents = this.documents.filter( (e, i) => index != i);
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-07 11:52:28 +01:00
|
|
|
}
|