Files
doneit-web/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts
T
tiago.kayaya 86c2a2c3ce save
2021-06-28 15:45:49 +01:00

286 lines
8.0 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { AnimationController, ModalController, PopoverController } from '@ionic/angular';
import { AddNotePage } from 'src/app/modals/add-note/add-note.page';
import { ProcessesService } from 'src/app/services/processes.service';
import { OptsExpedientePage } from 'src/app/shared/popover/opts-expediente/opts-expediente.page';
import { momentG } from 'src/plugin/momentG';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { BookMeetingModalPage } from '../../expediente/book-meeting-modal/book-meeting-modal.page';
import { BadRequestPage } from 'src/app/shared/popover/bad-request/bad-request.page';
import { SuccessMessagePage } from 'src/app/shared/popover/success-message/success-message.page';
import { DeplomaOptionsPage } from 'src/app/shared/popover/deploma-options/deploma-options.page';
import { ToastService } from 'src/app/services/toast.service';
@Component({
selector: 'app-diploma',
templateUrl: './diploma.page.html',
styleUrls: ['./diploma.page.scss'],
})
export class DiplomaPage implements OnInit {
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
serialnumber: string;
profile: string;
task: any
fulltask: any
intervenientes: any;
cc: any = [];
attachments:any;
customDate: any
constructor(
private processes: ProcessesService,
public popoverController: PopoverController,
private modalController: ModalController,
private iab: InAppBrowser,
private activatedRoute: ActivatedRoute,
private router: Router,
private animationController: AnimationController,
private toastService: ToastService,
) {
this.activatedRoute.queryParams.subscribe(params => {
if(params["serialNumber"]) {
this.serialnumber = params["serialNumber"];
console.log(params["serialNumber"]);
}
});
}
ngOnInit() {
this.profile = "mdgpr";
this.LoadTaskDetail(this.serialnumber);
}
goBack() {
if (window.innerWidth < 801) {
this.router.navigate(['/home/gabinete-digital/diplomas']);
} else {
let navigationExtras: NavigationExtras = {
queryParams: {
"diplomas": true,
}
}
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
}
async openOptions(taskAction?: any) {
const popover = await this.popoverController.create({
component: DeplomaOptionsPage,
cssClass: 'exp-options',
componentProps: {
task: this.task,
fulltask: this.fulltask,
taskAction:taskAction,
showEnviarPendentes: false
},
translucent: true
});
return await popover.present();
}
async LoadTaskDetail(serial: string) {
this.processes.GetTask(serial).subscribe(res => {
this.task = {
"SerialNumber": res.serialNumber,
"Folio": res.workflowInstanceDataFields.Subject,
"Senders": res.originator.email,
"CreateDate": momentG(new Date(res.taskStartDate),'yyyy-MM-dd HH:mm:ss'),
"DocumentURL": res.workflowInstanceDataFields.ViewerRequest,
"Remetente": res.workflowInstanceDataFields.Sender,
"Note": res.workflowInstanceDataFields.Note,
"FolderId": res.workflowInstanceDataFields.FolderID,
"FsId": '361',
"DocId": res.workflowInstanceDataFields.DispatchDocId,
"WorkflowName": res.workflowDisplayName,
"DeadlineType": res.workflowInstanceDataFields.DeadlineType,
"activityInstanceName": res.activityInstanceName,
}
this.fulltask = res;
console.log(this.task);
console.log('GetTask', res);
let thedate = new Date(this.task.CreateDate);
this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]);
this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users=>{
this.intervenientes = users.filter(user=>{
return user.Type == 'I';
});
this.cc = users.filter(user=>{
return user.Type == 'CC';
});
console.log(users);
});
this.getDocumentDetails(this.task.FolderId, '361');
});
}
viewDocument(docId:string){
this.processes.GetDocumentUrl(docId, '361').subscribe(res=>{
console.log(res);
const url: string = res.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
const browser = this.iab.create(url,"_blank");
browser.show();
});
}
getDocumentDetails(forlderId:string, applicationId:string) {
this.processes.GetDocumentDetails(forlderId,applicationId).subscribe(res=>{
this.attachments = res.Documents;
console.log(res['Documents']);
console.log(this.attachments);
})
}
async askSignature(note:string, documents:any){
let body = {
"serialNumber": this.serialnumber,
"action": "Aprovar",
"ActionTypeId": 99999840,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
try {
await this.processes.CompleteTask(body).toPromise()
this.toastService.successMessage(false, ()=>{
this.close();
})
} catch (error) {
this.toastService.badRequest()
}
}
async askToChange(note:string, documents:any){
let body = {
"serialNumber": this.serialnumber,
"action": "Retificar",
"ActionTypeId": 99999841,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
try {
await this.processes.CompleteTask(body).toPromise()
this.toastService.successMessage()
} catch (error) {
this.toastService.badRequest()
}
}
async finish(note:string, documents:any){
let body = {
"serialNumber": this.serialnumber,
"action": "Concluir",
"ActionTypeId": 95,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
try {
await this.processes.CompleteTask(body).toPromise();
this.toastService.successMessage('Processo concluído')
} catch (error) {
this.toastService.badRequest()
}
}
async openAddNoteModal(actionName:string) {
let classs;
if( window.innerWidth <= 800){
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop'
}
const modal = await this.modalController.create({
component: AddNotePage,
componentProps:{
},
cssClass: classs,
backdropDismiss: true
});
await modal.present();
modal.onDidDismiss().then(res => {
if(res.data){
const DocumentToSave = res.data.documents.map((e) => {
return {
ApplicationId: e.ApplicationType,
SourceId: e.Id,
}
});
let docs = {
ProcessInstanceID: "",
Attachments: DocumentToSave,
}
if(actionName == 'Solicitar assinatura'){
this.askSignature(res.data.note, docs);
this.goBack();
}
else if(actionName == 'Solicitar alteração'){
this.askToChange(res.data.note, docs);
this.goBack();
}
else if(actionName == 'Concluir diploma'){
this.finish(res.data.note, docs);
this.goBack();
}
}
});
}
async openBookMeetingModal(task: any) {
let classs;
if( window.innerWidth <= 800){
classs = 'book-meeting-modal modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: BookMeetingModalPage,
componentProps: {
task: this.task,
},
cssClass: classs,
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
close(){
this.modalController.dismiss();
}
}