Files
doneit-web/src/app/shared/agenda/edit-event-to-approve/edit-event-to-approve.page.ts
T

452 lines
12 KiB
TypeScript
Raw Normal View History

2021-06-29 14:15:56 +01:00
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
2021-07-01 16:23:47 +01:00
import { FormControl, FormGroup, Validators } from '@angular/forms';
2021-06-30 10:24:23 +01:00
import { AlertController, ModalController } from '@ionic/angular';
2021-06-29 14:15:56 +01:00
import * as moment from 'moment';
import { Attachment } from 'src/app/models/attachment.model';
import { EventPerson } from 'src/app/models/eventperson.model';
import { SearchDocument } from 'src/app/models/search-document';
import { SearchPage } from 'src/app/pages/search/search.page';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { EventsService } from 'src/app/services/events.service';
import { ProcessesService } from 'src/app/services/processes.service';
import { ToastService } from 'src/app/services/toast.service';
2021-06-30 10:24:23 +01:00
import { NgxMatDateFormats } from '@angular-material-components/datetime-picker';
2021-06-30 16:11:07 +01:00
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
2021-06-29 14:15:56 +01:00
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
parse: {
dateInput: "YYYY-MMMM-DD HH:mm"
},
display: {
dateInput: "DD MMM YYYY H:mm",
monthYearLabel: "MMM YYYY",
dateA11yLabel: "LL",
monthYearA11yLabel: "MMMM YYYY"
}
}
@Component({
selector: 'app-edit-event-to-approve',
templateUrl: './edit-event-to-approve.page.html',
styleUrls: ['./edit-event-to-approve.page.scss'],
})
export class EditEventToApprovePage implements OnInit {
public date: any;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public minDate: any;
public maxDate: any;
public stepHour = 1;
public stepMinute = 5;
public stepSecond = 5;
public dateControlStart = new FormControl(moment("DD MM YYYY hh"));
public dateControlEnd = new FormControl(moment("DD MM YYYY hh"));
showLoader = false
get dateStart () {
return this.dateControlStart.value
}
get dateEnd () {
return this.dateControlEnd.value
}
@ViewChild('picker') picker: any;
@ViewChild('fim') fim: any;
@ViewChild('inicio') inicio: any;
@ViewChild('picker1') picker1: any;
loadedAttachments: Attachment[]= []
eventProcess = {
serialNumber: "",
taskStartDate: "",
workflowInstanceDataFields:{
Body: "",
IsRecurring: false,
ParticipantsList: [],
Agenda: '',
EndDate: '',
Location: '',
Subject: '',
InstanceId: '',
EventType: '',
StartDate: '',
MDEmail: '',
MDName: '',
IsAllDayEvent: '',
Message: ''
}
}
show = false
isRecurring:string;
isEventEdited: boolean;
profile:string;
eventAttendees: EventPerson[];
loadedEventAttachments: Attachment[];
adding: "intervenient" | "CC" = "intervenient";
showAttendees = false;
2021-06-30 09:45:56 +01:00
InstanceId: string;
2021-06-29 14:15:56 +01:00
2021-07-01 16:23:47 +01:00
Form: FormGroup;
validateFrom = false
2021-06-29 14:15:56 +01:00
@Output() openAttendeesComponent = new EventEmitter<any>();
@Output() clearContact = new EventEmitter<any>();
@Output() setIntervenient = new EventEmitter<any>();
@Output() setIntervenientCC = new EventEmitter<any>();
@Output() closeComponent = new EventEmitter<any>();
2021-06-30 09:45:56 +01:00
@Input() saveData: any;
2021-06-30 16:11:07 +01:00
@Input() serialNumber: string
@Input() taskParticipants: EventPerson[];
@Input() taskParticipantsCc: EventPerson[];
2021-06-30 09:45:56 +01:00
2021-06-29 14:15:56 +01:00
constructor(
private modalController: ModalController,
private eventsService: EventsService,
public alertController: AlertController,
private attachmentsService: AttachmentsService,
private processes:ProcessesService,
private toastService: ToastService,
) {
this.isEventEdited = false;
}
ngOnInit() {
2021-06-30 10:24:23 +01:00
2021-06-30 15:45:14 +01:00
if(this.restoreTemporaryData()){
this.setOtherData()
} else {
this.getTask();
2021-06-30 10:24:23 +01:00
2021-06-30 15:45:14 +01:00
}
2021-06-30 10:24:23 +01:00
2021-06-29 14:15:56 +01:00
}
async getTask() {
2021-06-30 15:45:14 +01:00
this.processes.GetTask(this.serialNumber).subscribe( result =>{
this.eventProcess = result
this.restoreDatepickerData()
2021-06-29 14:15:56 +01:00
// description
let body : any =this.eventProcess.workflowInstanceDataFields.Body.replace(/<[^>]+>/g, '')
this.eventProcess.workflowInstanceDataFields.Body = body
this.InstanceId = this.eventProcess.workflowInstanceDataFields.InstanceId
this.getAttachments()
2021-06-30 15:45:14 +01:00
this.setOtherData()
2021-06-30 11:59:57 +01:00
2021-06-30 15:45:14 +01:00
this.saveTemporaryData()
2021-06-29 14:15:56 +01:00
})
}
2021-06-30 15:45:14 +01:00
setOtherData() {
if(this.eventProcess.workflowInstanceDataFields.ParticipantsList) {
this.eventProcess.workflowInstanceDataFields.ParticipantsList.forEach(e => {
if(e.IsRequired) {
this.taskParticipants.push(e);
} else {
this.taskParticipantsCc.push(e);
}
})
}
2021-06-30 16:11:07 +01:00
this.taskParticipants = removeDuplicate(this.taskParticipants)
this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc)
2021-06-30 15:45:14 +01:00
if(this.eventProcess.workflowInstanceDataFields.IsRecurring == false) {
this.isRecurring = "Não se repete";
}
else {
this.isRecurring = "Repete";
}
this.InstanceId = this.eventProcess.workflowInstanceDataFields.InstanceId
this.getAttachments()
}
2021-06-29 14:15:56 +01:00
close() {
2021-06-30 11:59:57 +01:00
window['temp.path:/shared/agenda/edit-event-to-approve.ts'] = {}
2021-06-29 14:15:56 +01:00
this.closeComponent.emit();
/* this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
this.clearContact.emit(); */
//this.deleteTemporaryData();
}
2021-07-01 16:23:47 +01:00
runValidation() {
this.validateFrom = true
}
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.eventProcess.workflowInstanceDataFields.Subject, [
Validators.required,
// Validators.minLength(4)
]),
Location: new FormControl(this.eventProcess.workflowInstanceDataFields.Location, [
Validators.required,
]),
//CalendarName: new FormControl(this.postEvent.CalendarName),
// Categories: new FormControl(this.postEvent.Categories[0], [
// Validators.required
// ]),
dateStart: new FormControl(this.dateStart, [
Validators.required
]),
dateEnd: new FormControl(this.dateEnd, [
Validators.required
]),
// IsRecurring: new FormControl(this.postEvent.IsRecurring, [
// Validators.required
// ]),
2021-07-08 13:41:27 +01:00
participantes: new FormControl(this.taskParticipants, [
2021-07-08 13:57:08 +01:00
Validators.required
2021-07-01 16:23:47 +01:00
]),
})
}
2021-06-30 15:45:14 +01:00
save() {
2021-07-01 16:23:47 +01:00
this.injectValidation()
this.runValidation()
if(this.Form.invalid) return false
2021-06-29 14:15:56 +01:00
// set dates to eventProcess object
this.getDatepickerData()
2021-06-30 15:45:14 +01:00
this.taskParticipantsCc.forEach( e => {
2021-06-29 14:15:56 +01:00
e.IsRequired = false
})
this.eventProcess.workflowInstanceDataFields.ParticipantsList = this.taskParticipants.concat(this.taskParticipantsCc)
this.eventProcess.workflowInstanceDataFields.ParticipantsList.forEach(e=>{
if(e.hasOwnProperty('$type')) {
delete e.$type
}
})
const event: any = {
Agenda: this.eventProcess.workflowInstanceDataFields.Agenda,
Body: this.eventProcess.workflowInstanceDataFields.Body,
EndDate: this.eventProcess.workflowInstanceDataFields.EndDate,
EventType: this.eventProcess.workflowInstanceDataFields.EventType,
IsAllDayEvent: this.eventProcess.workflowInstanceDataFields.IsAllDayEvent,
IsRecurring: this.eventProcess.workflowInstanceDataFields.IsRecurring,
Location: this.eventProcess.workflowInstanceDataFields.Location,
Subject: this.eventProcess.workflowInstanceDataFields.Subject,
serialNumber: this.eventProcess.serialNumber,
StartDate: this.eventProcess.workflowInstanceDataFields.StartDate,
MDEmail: this.eventProcess.workflowInstanceDataFields.MDEmail,
MDName: this.eventProcess.workflowInstanceDataFields.MDName,
Message: this.eventProcess.workflowInstanceDataFields.Message,
ParticipantsList: this.eventProcess.workflowInstanceDataFields.ParticipantsList,
Private: false,
ReviewUserComment: ''
}
this.eventsService.postEventToApproveEdit(event).subscribe(()=>{
this.toastService.successMessage('Evento editado');
}, error =>{
this.toastService.badRequest('Evento não editado');
})
this.loadedAttachments.forEach((document:any)=>{
if(document['action'] == 'add') {
delete document.action
this.attachmentsService.setEventAttachmentById(document).subscribe(()=>{
this.toastService.successMessage();
}, error =>{
this.toastService.badRequest();
});
} else if(document['action'] == 'delete') {
delete document.action
this.attachmentsService.deleteEventAttachmentById(document.Id).subscribe( res=>{
this.toastService.successMessage()
}, error =>{
this.toastService.badRequest()
})
}
})
this.modalController.dismiss();
}
2021-06-30 10:24:23 +01:00
// setIntervenient(data){
// this.taskParticipants = data;
// this.postEvent.Attendees = data;
// }
2021-06-29 14:15:56 +01:00
2021-06-30 10:24:23 +01:00
// setIntervenientCC(data) {
// this.taskParticipantsCc = data;
// }
2021-06-29 14:15:56 +01:00
2021-06-30 10:24:23 +01:00
// addParticipants(){
// this.adding = 'intervenient'
2021-06-29 14:15:56 +01:00
2021-06-30 10:24:23 +01:00
// this.openAttendees();
// }
2021-06-29 14:15:56 +01:00
2021-06-30 10:24:23 +01:00
// addParticipantsCC(){
2021-06-29 14:15:56 +01:00
2021-06-30 10:24:23 +01:00
// this.adding = 'CC'
// this.openAttendees();
// }
2021-06-29 14:15:56 +01:00
2021-06-30 10:24:23 +01:00
dynamicSetIntervenient({taskParticipants, taskParticipantsCc}) {
2021-06-30 16:11:07 +01:00
this.taskParticipants = removeDuplicate(taskParticipants) ;
this.taskParticipantsCc = removeDuplicate(taskParticipantsCc) ;
2021-06-30 10:24:23 +01:00
}
2021-06-29 14:15:56 +01:00
2021-06-30 16:11:07 +01:00
async addParticipants() {
2021-06-29 14:15:56 +01:00
2021-06-30 16:11:07 +01:00
//this.saveTemporaryData();
2021-06-29 14:15:56 +01:00
2021-06-30 16:11:07 +01:00
this.openAttendeesComponent.emit({
type: "intervenient"
});
2021-06-29 14:15:56 +01:00
2021-06-30 16:11:07 +01:00
this.clearContact.emit();
}
2021-06-29 14:15:56 +01:00
async addParticipantsCC() {
this.openAttendeesComponent.emit({
type: "CC"
});
this.clearContact.emit();
}
saveTemporaryData() {
this.getDatepickerData()
2021-06-30 10:24:23 +01:00
window['temp.path:/shared/agenda/edit-event-to-approve.ts'] = {
eventProcess: this.eventProcess
2021-06-29 14:15:56 +01:00
}
}
2021-06-30 10:24:23 +01:00
restoreTemporaryData(): boolean {
const restoredData = window['temp.path:/shared/agenda/edit-event-to-approve.ts']
if(JSON.stringify(restoredData) != "{}" && undefined != restoredData) {
this.eventProcess = restoredData.eventProcess
// restore dater for date and hours picker
this.restoreDatepickerData()
return true;
} else {
return false;
}
}
2021-06-29 14:15:56 +01:00
async getAttachments() {
let result: any = await this.attachmentsService.getAttachmentsById(this.InstanceId).toPromise();
result.forEach((e)=>{
e.action = false
})
this.loadedAttachments = result
2021-06-30 10:24:23 +01:00
// console.log('this.loadedAttachments', this.loadedAttachments, result)
2021-06-29 14:15:56 +01:00
}
deleteAttachment(attachment: Attachment, index) {
this.loadedAttachments[index]['action'] = 'delete'
}
async getDoc() {
const modal = await this.modalController.create({
component: SearchPage,
cssClass: 'modal-width-100-width-background modal',
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
showSearchInput: true,
select: true,
}
});
await modal.present();
modal.onDidDismiss().then( async (res)=>{
if(res){
const data: SearchDocument = res.data.selected;
const DocumentToSave: any = {
SourceTitle: data.Assunto,
ParentId: this.InstanceId,
Source: '1',
SourceId: data.Id,
ApplicationId: data.ApplicationType.toString(),
Id: '',
Link: '',
SerialNumber: '',
action: 'add',
CreateDate: data.Data,
Data: data.Data,
Description: data.DocTypeDesc,
SourceName: data.Assunto,
Stakeholders: data.EntidadeOrganicaNome,
};
this.loadedAttachments.push(DocumentToSave)
console.log('push', DocumentToSave)
// await this.attachmentsService.setEventAttachmentById(DocumentToSave).subscribe(()=>{
// this.getAttachments();
// });
}
});
}
restoreDatepickerData() {
this.dateControlStart = new FormControl(moment(new Date(this.eventProcess.workflowInstanceDataFields.StartDate)));
this.dateControlEnd = new FormControl(moment(new Date(this.eventProcess.workflowInstanceDataFields.EndDate)));
}
getDatepickerData() {
this.eventProcess.workflowInstanceDataFields.StartDate = this.dateStart
this.eventProcess.workflowInstanceDataFields.EndDate = this.dateEnd
}
}