import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { ModalController, NavParams } from '@ionic/angular'; import { Despacho } from 'src/app/models/despacho.model'; import { EventPerson } from 'src/app/models/eventperson.model'; import { Participant } from 'src/app/models/participant.model'; import { Folder } from 'src/app/models/folder.model'; import { AuthService } from 'src/app/services/auth.service'; import { ProcessesService } from 'src/app/services/processes.service'; import { environment } from 'src/environments/environment'; import { AttachmentsService } from 'src/app/services/attachments.service'; import { AlertService } from 'src/app/services/alert.service'; import { AddParticipantsModalPage } from 'src/app/pages/gabinete-digital/expediente/add-participants-modal/add-participants-modal.page'; import { AddParticipantsCcModalPage } from 'src/app/pages/gabinete-digital/expediente/add-participants-cc-modal/add-participants-cc-modal.page'; import { DiscartExpedientModalPage } from 'src/app/pages/gabinete-digital/discart-expedient-modal/discart-expedient-modal.page'; import { ExpedienteDetailPage } from 'src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page'; import { SearchDocument } from 'src/app/models/search-document'; import { SearchPage } from 'src/app/pages/search/search.page'; import { BadRequestComponent } from 'src/app/shared/popover/bad-request/bad-request.component'; import { SuccessMessageComponent } from 'src/app/shared/popover/success-message/success-message.component'; @Component({ selector: 'app-create-process', templateUrl: './create-process.page.html', styleUrls: ['./create-process.page.scss'], }) export class CreateProcessPage implements OnInit { modalTitle: string[] = [ 'Efectuar Despacho', 'Solicitar Parecer', 'Solicitar Deferimento' ]; taskType:string; task: any; taskParticipants: any = []; taskParticipantsCc: any = []; taskDate: Date; taskDescription: string; user: string; loadedAttachments:any; subjectTypes:any; selectedTypes: string[]=[]; postData: Despacho; dispatchFolder: Folder; participants: Participant[]; contacts= []; // trigger hide and show for attendee component showAttendees= false; adding: "intervenient" | "CC" = "intervenient"; profile: string; emptyTextDescription = "Sem intervenientes selecionados"; showEmptyContainer = true; documents:SearchDocument[] = []; constructor( private modalController: ModalController, private router:Router, private processes:ProcessesService, private attachmentsService: AttachmentsService, private navParams: NavParams, private alertController: AlertService, private authService: AuthService) { this.user = environment.defaultuser +'@'+ environment.domain; this.task = this.navParams.get('task'); console.log('task', this.task) this.taskType = this.navParams.get('taskAction'); this.postData = new Despacho(); this.participants = this.participants = new Array(); this.dispatchFolder = { Nad: 30, Subject: '', Message: '', SourceSecFsId: this.task.workflowInstanceDataFields.FsId, //361 SourceType: 'DOC', //FOLDER SourceId: this.task.workflowInstanceDataFields.DocId, //FolderId DeadlineType: '', SubjectTypes: ['99999844'], NumberPDPP: this.task.workflowInstanceDataFields.DispatchNumber, }; this.postData.DispatchFolder = this.dispatchFolder; this.postData.UsersSelected = this.participants; /* By Default TypeDeadline should be 'Normal' */ this.postData.Priority = '99999861'; /* Initialize 'Subject' with the title of the expedient */ this.postData.DispatchFolder.Subject = this.task.workflowInstanceDataFields.Subject; this.profile = this.navParams.get('profile'); } async setAdding(type: "intervenient" | "CC"){ this.adding = type; } ngOnInit() { this.taskDate = new Date(this.task.taskStartDate); this.getSubjectType(); } close(){ //this.router.navigate(['/home/gabinete-digital/expediente']); this.modalController.dismiss(null); } getSubjectType() { this.processes.GetSubjectType().subscribe(res=>{ console.log(res); this.subjectTypes = res; }); } cancelTask() { this.modalController.dismiss(null); } async saveTask(){ if(this.postData.Priority=='99999861'){ this.dispatchFolder.DeadlineType = 'Normal'; } else if(this.postData.Priority=='99999862'){ this.dispatchFolder.DeadlineType = 'Urgente'; } else if(this.postData.Priority=='99999863'){ this.dispatchFolder.DeadlineType = 'Muito Urgente'; } else if(this.postData.Priority=='99999864'){ this.dispatchFolder.DeadlineType = 'Urgentíssimo'; } let attendees = this.taskParticipants.concat(this.taskParticipantsCc); attendees = attendees.map(function(val) { return { UserEmail: val.EmailAddress, UserType: val.IsRequired?"I": "CC" }; }); const DocumentToSave = this.documents.map((e) => { return { ApplicationId: e.ApplicationType, SourceId: e.Id } }); this.dispatchFolder.SubjectTypes = this.selectedTypes; if(this.taskParticipants.length > 0) { switch (this.taskType) { case '0': this.postData = { DistributionType: "Paralelo", CountryCode: 'AO', Priority: this.postData.Priority, UserEmail: this.user, UsersSelected: attendees, DispatchFolder: this.dispatchFolder, } console.log('this.postData', this.postData, this.taskType); try { await this.processes.postDespatcho(this.postData).toPromise() this.successMessage() } catch (error) { this.badRequest() } break; case '1': this.postData = { DistributionType: "Paralelo", CountryCode: 'AO', Priority: this.postData.Priority, UserEmail: this.user, UsersSelected: attendees, DispatchFolder: this.dispatchFolder, } console.log(this.postData); await this.processes.postParecer(this.postData).toPromise() try { await this.processes.postParecer(this.postData).toPromise() this.successMessage() } catch (error) { this.badRequest() } break; case '2': this.postData = { DistributionType: "Paralelo", CountryCode: 'AO', Priority: this.postData.Priority, UserEmail: this.user, UsersSelected: attendees, DispatchFolder: this.dispatchFolder, } console.log(this.postData); try { await this.processes.postDeferimento(this.postData).toPromise() this.successMessage() } catch (error) { this.badRequest() } break; } this.executado(); this.modalController.dismiss(); } else { this.alertController.presentAlert("Lista de intervenientes vazia. Por favor, adicione 1 ou mais intervenientes."); } } executado(){ let body = { "serialNumber": this.task.serialNumber, "action": "Conhecimento", "ActionTypeId": 104, "dataFields": { "ReviewUserComment": '', }, "AttachmentList" :null, } this.processes.CompleteTask(body); } async addParticipants() { /* console.log('HERES'); */ this.adding = "intervenient"; this.contacts = this.taskParticipants; if(window.innerWidth <=800){ this.showAttendees=false; const modal = await this.modalController.create({ component: AddParticipantsModalPage, componentProps: { eventPersons: this.participants }, cssClass: 'add-participants-modal', backdropDismiss: false }); await modal.present(); modal.onDidDismiss().then((res) => { this.taskParticipants = res.data; let newattendees: EventPerson[] = res['data']; if(newattendees!= null){ newattendees.forEach(newattendee => { let att = { 'UserEmail': newattendee.EmailAddress, 'UserType': 'I', }; if(this.participants == null){ this.participants = new Array(); } this.participants.push(att); }); } this.postData.UsersSelected = this.participants; console.log(this.postData); }); } else { this.showAttendees=true } } async addParticipantsCc() { this.adding = "CC"; this.contacts = this.taskParticipantsCc; if(window.innerWidth <=800){ this.showAttendees=false; const modal = await this.modalController.create({ component: AddParticipantsCcModalPage, componentProps: { eventPersons: this.participants }, cssClass: 'add-participants-cc-modal', backdropDismiss: false }); await modal.present(); modal.onDidDismiss().then((res) => { this.taskParticipantsCc = res.data; let newattendees: EventPerson[] = res['data']; if(newattendees!= null){ newattendees.forEach(newattendee => { let att = { 'UserEmail': newattendee.EmailAddress, 'UserType': 'CC', }; if(this.participants == null){ this.participants = new Array(); } this.participants.push(att); }); } this.postData.UsersSelected = this.participants; console.log(this.postData); }); } else { this.showAttendees=true } } async distartExpedientModal() { const modal = await this.modalController.create({ component: DiscartExpedientModalPage, componentProps: { serialNumber: this.task.serialNumber, folderId: this.task.workflowInstanceDataFields.FolderID, action: 'complete', }, cssClass: 'discart-expedient-modal', backdropDismiss: false }); await modal.present(); modal.onDidDismiss().then(res=>{ if(res['data']=='close'){ console.log('Expedient Discard closed'); this.modalController.dismiss(res['data']) } }); } async setContact(data:EventPerson[]) { if(this.adding == "intervenient"){ this.taskParticipants = data; } else if (this.adding == "CC") { this.taskParticipantsCc = data; } } async setIntervenient(data) { this.taskParticipants = data; } async setIntervenientCC(data) { this.taskParticipantsCc = data; } async closeComponent() { this.showAttendees = false; } async viewExpedientDetail() { console.log(this.profile); let classs; if( window.innerWidth <= 800){ classs = 'modal modal-desktop' } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ component: ExpedienteDetailPage, componentProps:{ serialNumber: this.task.serialNumber, profile: this.profile, }, cssClass: classs, backdropDismiss: false }); await modal.present(); modal.onDidDismiss().then((res)=>{ /* console.log('!refresh list'); */ }); } removeAttachment(index: number){ this.documents = this.documents.filter( (e, i) => index != i); } 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((res)=>{ if(res){ const data = res.data; this.documents.push(data.selected); } }); } async successMessage(message?: string) { const modal = await this.modalController.create({ component: SuccessMessageComponent, componentProps: { message: message || 'Processo efetuado' , }, cssClass: 'modal modal-desktop' }); modal.present() setTimeout(()=>{ modal.dismiss() },3000) } async badRequest(message?: string) { const modal = await this.modalController.create({ component: BadRequestComponent, componentProps: { message: message || 'Processo não efetuado' , }, cssClass: 'modal modal-desktop' }); modal.present() setTimeout(()=>{ modal.dismiss() },3000) } }