Files
doneit-web/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts
T
Peter Maquiran 74a2fe8058 fix update
2023-04-20 13:36:59 +01:00

333 lines
9.2 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ModalController, PopoverController } from '@ionic/angular';
import { ProcessesService } from 'src/app/services/processes.service';
import { momentG } from 'src/plugin/momentG';
import { ActivatedRoute } from '@angular/router';
import { DeplomaOptionsPage } from 'src/app/shared/popover/deploma-options/deploma-options.page';
import { ToastService } from 'src/app/services/toast.service';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service'
import { RouteService } from 'src/app/services/route.service';
import {HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { AddNotePage } from 'src/app/modals/add-note/add-note.page';
import { DespachoService } from 'src/app/Rules/despacho.service'
import { AttachmentList } from 'src/app/models/Excludetask';
import { CreateProcessPage } from 'src/app/modals/create-process/create-process.page';
import { DiscartExpedientModalPage } from '../../discart-expedient-modal/discart-expedient-modal.page';
import { TaskService } from 'src/app/services/task.service'
@Component({
selector: 'app-diploma-assinar',
templateUrl: './diploma-assinar.page.html',
styleUrls: ['./diploma-assinar.page.scss'],
})
export class DiplomaAssinarPage 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;
caller:string;
constructor(
private processes: ProcessesService,
public popoverController: PopoverController,
private modalController: ModalController,
private activatedRoute: ActivatedRoute,
private toastService: ToastService,
private RouteService: RouteService,
public ThemeService: ThemeService,
private httpErroHandle: HttpErrorHandle,
private despachoService: DespachoService,
public TaskService: TaskService
) {
this.activatedRoute.paramMap.subscribe(params => {
if(params["params"].SerialNumber) {
this.serialnumber = params["params"].SerialNumber;
}
if(params["params"].caller) {
this.caller = params["params"].caller;
}
});
}
ngOnInit() {
this.profile = "mdgpr";
this.LoadTaskDetail(this.serialnumber);
}
goBack() {
this.RouteService.goBack();
}
async openOptions(taskAction?: any) {
const popover = await this.popoverController.create({
component: DeplomaOptionsPage,
cssClass: 'exp-options',
componentProps: {
serialNumber: this.task.SerialNumber,
task: this.task,
showEnviarPendentes: false,
fulltask: this.fulltask
},
translucent: true
});
return await popover.present();
}
async LoadTaskDetail(serial: string) {
this.processes.GetTask(serial).subscribe(res => {
this.TaskService.loadDiplomas();
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.TaskMessage || res.workflowInstanceDataFields.Note,
"FolderId": res.workflowInstanceDataFields.FolderID,
"FsId": '361',
"DocId": res.workflowInstanceDataFields.DispatchDocId,
"WorkflowName": res.workflowDisplayName,
"DeadlineType": res.workflowInstanceDataFields.DeadlineType,
"activityInstanceName": res.activityInstanceName,
"Deadline": res.deadline,
"TaskStartDate": res.taskStartDate
}
this.fulltask = 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';
});
});
this.getDocumentDetails(this.task.FolderId, '361');
}, (error)=>{
try {
this.httpErroHandle.httpStatusHandle(error)
this.goBack()
} catch (e) {
window.history.back();
} finally {
this.httpErroHandle.httpStatusHandle(error)
}
});
}
async viewDocument(DocId:string, Document) {
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: Document.Assunto,
url: '',
title_link: '',
},
Document,
applicationId: Document.ApplicationId,
docId: Document.DocId || Document.SourceId,
folderId: this.task.FolderId,
task: this.fulltask
},
cssClass: 'modal modal-desktop'
});
await modal.present();
}
getDocumentDetails(forlderId:string, applicationId:string) {
this.processes.GetDocumentDetails(forlderId,applicationId).subscribe(res=>{
this.attachments = res.Documents;
})
}
async Assinar(){
let body = {
"serialNumber": this.serialnumber,
"action": "Assinado",
"ActionTypeId": 99999842,
"dataFields": {
"ReviewUserComment": '',
},
"AttachmentList": {},
}
const loader = this.toastService.loading()
try {
await this.processes.CompleteTask(body).toPromise()
this.httpErroHandle.httpsSucessMessagge('Assinado')
this.goBack();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async openAddNoteModal(actionName: string) {
let classs;
if (window.innerWidth <= 800) {
classs = 'modal modal-desktop'
} else {
classs = 'add-note-modal-no-height'
}
const modal = await this.modalController.create({
component: AddNotePage,
componentProps: {
showAttachmentBtn: true,
actionName: actionName
},
cssClass: classs,
backdropDismiss: true
});
await modal.present();
modal.onDidDismiss().then(async (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 == 'Executado') {
/* await this.executado(res.data.note, docs);
this.goBack(); */
}
else if (actionName == 'Arquivo') {
await this.arquivar(res.data.note, docs);
this.goBack();
}
else if (actionName == 'Reexecução') {
/* await this.reexecute(res.data.note, docs);
this.goBack(); */
} else if(actionName == 'Gerar Diploma') {
/* await this.generateDiploma(res.data.note, docs);
this.goBack(); */
}
}
});
}
async arquivar(note: string, documents: AttachmentList) {
const loader = this.toastService.loading()
try {
await this.despachoService.arquivar(note, documents, this.serialnumber).toPromise()
this.httpErroHandle.httpsSucessMessagge('Arquivar')
this.close();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async openExpedientActionsModal(taskAction: any, task: any) {
let classs;
if (window.innerWidth <= 800) {
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: CreateProcessPage,
componentProps: {
taskAction: taskAction,
task: task,
profile: this.profile,
fulltask: this.fulltask
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then(async (res) => {
if (res['data'] == 'openDiscart') {
await this.distartExpedientModal();
}
this.goBack();
});
}
async distartExpedientModal() {
const modal = await this.modalController.create({
component: DiscartExpedientModalPage,
componentProps: {
serialNumber: this.fulltask.serialNumber,
folderId: this.fulltask.workflowInstanceDataFields.FolderID,
action: 'complete',
},
cssClass: 'discart-expedient-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(res => {
if (res['data'] == 'close') {
this.close();
/*
this.close();
this.openMenu(); */
}
});
}
toDateString(e) {
return new Date(e).toDateString()
}
close() {
this.modalController.dismiss();
}
}