mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
save
This commit is contained in:
@@ -0,0 +1,426 @@
|
||||
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { AlertController, AnimationController, ModalController } from '@ionic/angular';
|
||||
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 { AttendeesPageModal } from 'src/app/pages/events/attendees/attendees.page';
|
||||
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';
|
||||
import { Event } from '../../../models/event.model';
|
||||
import { NgxMatDateFormats, NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker';
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@Input() serialNumber: string
|
||||
|
||||
|
||||
loadedAttachments: Attachment[]= []
|
||||
|
||||
eventProcess = {
|
||||
serialNumber: "",
|
||||
taskStartDate: "",
|
||||
workflowInstanceDataFields:{
|
||||
Body: "",
|
||||
IsRecurring: false,
|
||||
ParticipantsList: [],
|
||||
Agenda: '',
|
||||
EndDate: '',
|
||||
Location: '',
|
||||
Subject: '',
|
||||
InstanceId: '',
|
||||
EventType: '',
|
||||
StartDate: '',
|
||||
MDEmail: '',
|
||||
MDName: '',
|
||||
IsAllDayEvent: '',
|
||||
Message: ''
|
||||
}
|
||||
}
|
||||
|
||||
show = false
|
||||
|
||||
postEvent: Event;
|
||||
isRecurring:string;
|
||||
isEventEdited: boolean;
|
||||
segment:string = "true";
|
||||
profile:string;
|
||||
eventAttendees: EventPerson[];
|
||||
|
||||
loadedEventAttachments: Attachment[];
|
||||
taskParticipants: any = [];
|
||||
taskParticipantsCc: any = [];
|
||||
adding: "intervenient" | "CC" = "intervenient";
|
||||
|
||||
Location = ''
|
||||
|
||||
showAttendees = false;
|
||||
|
||||
InstanceId: string
|
||||
|
||||
@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>();
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
private eventsService: EventsService,
|
||||
public alertController: AlertController,
|
||||
private attachmentsService: AttachmentsService,
|
||||
private processes:ProcessesService,
|
||||
private animationController: AnimationController,
|
||||
private toastService: ToastService,
|
||||
) {
|
||||
|
||||
/* this.serialNumber = this.navParams.get('serialNumber'); */
|
||||
|
||||
this.isEventEdited = false;
|
||||
this.dateControlStart = new FormControl(moment(new Date()));
|
||||
this.dateControlEnd = new FormControl(moment(new Date()));
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getTask();
|
||||
console.log(this.serialNumber);
|
||||
}
|
||||
|
||||
async getTask() {
|
||||
console.log('this.eventProcess', this.eventProcess);
|
||||
|
||||
const result = await this.processes.GetTask(this.serialNumber).subscribe( result =>{
|
||||
this.eventProcess = result
|
||||
|
||||
this.restoreDatepickerData()
|
||||
|
||||
console.log(this.eventProcess.workflowInstanceDataFields.Subject)
|
||||
|
||||
// description
|
||||
let body : any =this.eventProcess.workflowInstanceDataFields.Body.replace(/<[^>]+>/g, '')
|
||||
this.eventProcess.workflowInstanceDataFields.Body = body
|
||||
this.Location = this.eventProcess.workflowInstanceDataFields.Location
|
||||
|
||||
this.InstanceId = this.eventProcess.workflowInstanceDataFields.InstanceId
|
||||
this.getAttachments()
|
||||
|
||||
if(this.eventProcess.workflowInstanceDataFields.IsRecurring == false) {
|
||||
this.isRecurring = "Não se repete";
|
||||
}
|
||||
else {
|
||||
this.isRecurring = "Repete";
|
||||
}
|
||||
|
||||
this.eventProcess.workflowInstanceDataFields.ParticipantsList.forEach(e => {
|
||||
if(e.IsRequired) {
|
||||
this.taskParticipants.push(e);
|
||||
} else {
|
||||
this.taskParticipantsCc.push(e);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
close() {
|
||||
console.log('CLOSE');
|
||||
|
||||
this.closeComponent.emit();
|
||||
/* this.setIntervenient.emit([]);
|
||||
this.setIntervenientCC.emit([]);
|
||||
this.clearContact.emit(); */
|
||||
|
||||
//this.deleteTemporaryData();
|
||||
}
|
||||
|
||||
save() {
|
||||
// set dates to eventProcess object
|
||||
this.getDatepickerData()
|
||||
|
||||
this.taskParticipantsCc.forEach(e=>{
|
||||
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: ''
|
||||
}
|
||||
|
||||
console.log(event);
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
/* async openAttendees() {
|
||||
|
||||
if(window.innerWidth <= 1024) {
|
||||
const modal = await this.modalController.create({
|
||||
component: AttendeesPageModal,
|
||||
componentProps: {
|
||||
adding: this.adding,
|
||||
taskParticipants: this.taskParticipants,
|
||||
taskParticipantsCc: this.taskParticipantsCc
|
||||
},
|
||||
cssClass: 'attendee modal modal-desktop',
|
||||
backdropDismiss: false
|
||||
});
|
||||
|
||||
await modal.present();
|
||||
|
||||
modal.onDidDismiss().then((data) => {
|
||||
|
||||
if(data){
|
||||
data = data['data'];
|
||||
|
||||
const newAttendees: EventPerson[] = data['taskParticipants'];
|
||||
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
|
||||
|
||||
this.setIntervenient(newAttendees);
|
||||
this.setIntervenientCC(newAttendeesCC);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.showAttendees = true
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
dynamicSetIntervenient({taskParticipants, taskParticipantsCc}){
|
||||
this.taskParticipants = taskParticipants;
|
||||
this.taskParticipantsCc = taskParticipantsCc;
|
||||
} */
|
||||
|
||||
|
||||
async addParticipants() {
|
||||
|
||||
//this.saveTemporaryData();
|
||||
|
||||
this.openAttendeesComponent.emit({
|
||||
type: "intervenient"
|
||||
});
|
||||
|
||||
this.clearContact.emit();
|
||||
}
|
||||
|
||||
|
||||
async addParticipantsCC() {
|
||||
|
||||
//this.saveTemporaryData();
|
||||
|
||||
this.openAttendeesComponent.emit({
|
||||
type: "CC"
|
||||
});
|
||||
|
||||
this.clearContact.emit();
|
||||
}
|
||||
|
||||
saveTemporaryData() {
|
||||
|
||||
this.getDatepickerData()
|
||||
|
||||
window['temp.path:/home/agenda/edit-event-to-approve.page.ts'] = {
|
||||
postEvent: this.postEvent,
|
||||
segment: this.segment
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async getAttachments() {
|
||||
|
||||
let result: any = await this.attachmentsService.getAttachmentsById(this.InstanceId).toPromise();
|
||||
|
||||
result.forEach((e)=>{
|
||||
e.action = false
|
||||
})
|
||||
|
||||
this.loadedAttachments = result
|
||||
|
||||
console.log('this.loadedAttachments', this.loadedAttachments, result)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user