Files
doneit-web/src/app/modals/create-process/create-process.page.ts
T

642 lines
19 KiB
TypeScript
Raw Normal View History

2021-04-29 13:58:52 +01:00
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
2021-06-08 15:59:06 +01:00
import { AnimationController, ModalController, NavParams } from '@ionic/angular';
2021-04-29 13:58:52 +01:00
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';
2021-05-07 14:22:54 +01:00
import { SearchDocument } from 'src/app/models/search-document';
import { SearchPage } from 'src/app/pages/search/search.page';
2021-06-08 15:59:06 +01:00
import { BadRequestPage } from 'src/app/shared/popover/bad-request/bad-request.page';
import { SuccessMessagePage } from 'src/app/shared/popover/success-message/success-message.page';
2021-05-28 16:37:57 +01:00
import { User } from 'src/app/models/user.model';
2021-06-15 11:39:59 +01:00
import { AttendeesPage } from 'src/app/pages/events/attendees/attendees.page';
2021-06-14 13:48:02 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-04-29 13:58:52 +01:00
@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;
2021-05-07 15:27:31 +01:00
selectedTypes: string[]=[];
2021-04-29 13:58:52 +01:00
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;
2021-05-07 14:22:54 +01:00
documents:SearchDocument[] = [];
2021-05-28 16:37:57 +01:00
loggeduser: User;
2021-05-07 14:22:54 +01:00
2021-04-29 13:58:52 +01:00
constructor(
private modalController: ModalController,
private router:Router,
private processes:ProcessesService,
private attachmentsService: AttachmentsService,
private navParams: NavParams,
private alertController: AlertService,
2021-05-28 16:37:57 +01:00
private authService: AuthService,
private userAuth: AuthService,
2021-06-08 15:59:06 +01:00
private animationController: AnimationController,
2021-06-14 13:48:02 +01:00
private toastService: ToastService,
2021-05-28 16:37:57 +01:00
) {
this.loggeduser = userAuth.ValidatedUser;
2021-04-29 13:58:52 +01:00
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();
2021-06-14 14:04:00 +01:00
//Initialize SubjectTypes Array with the value "Indefinido"
this.selectedTypes = ['99999850'];
2021-04-29 13:58:52 +01:00
this.dispatchFolder = {
Nad: 30,
Subject: '',
Message: '',
2021-05-28 16:37:57 +01:00
SourceSecFsId: this.task.workflowInstanceDataFields.SourceSecFsID, //361
SourceType: 'DOC', //FOLDER
2021-05-28 16:37:57 +01:00
SourceId: this.task.workflowInstanceDataFields.SourceID, //FolderId
2021-04-29 13:58:52 +01:00
DeadlineType: '',
2021-06-14 14:04:00 +01:00
SubjectTypes: this.selectedTypes,
2021-05-26 13:57:51 +01:00
NumberPDPP: this.task.workflowInstanceDataFields.DispatchNumber,
2021-04-29 13:58:52 +01:00
};
2021-06-14 14:04:00 +01:00
2021-04-29 13:58:52 +01:00
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() {
2021-06-14 13:48:02 +01:00
console.log(this.postData.DispatchFolder.SubjectTypes);
2021-04-29 13:58:52 +01:00
this.taskDate = new Date(this.task.taskStartDate);
this.getSubjectType();
2021-06-14 13:48:02 +01:00
if(this.selectedTypes.length > 1){
console.log('Yes');
}
}
onSelectedTypesChanged(ev:any){
console.log(ev);
if(ev.length > 1){
console.log(ev.filter(data => data != '99999850'));
this.selectedTypes = ev.filter(data => data != '99999850');
}
if(ev.length == 0){
this.selectedTypes = ["99999850"];
}
2021-04-29 13:58:52 +01:00
}
close(){
2021-05-28 09:29:18 +01:00
//this.router.navigate(['/home/gabinete-digital/expediente']);
2021-04-29 13:58:52 +01:00
this.modalController.dismiss(null);
}
getSubjectType() {
this.processes.GetSubjectType().subscribe(res=>{
console.log(res);
this.subjectTypes = res;
});
}
cancelTask() {
this.modalController.dismiss(null);
}
2021-05-25 13:38:46 +01:00
async saveTask(){
2021-04-29 13:58:52 +01:00
2021-06-09 14:45:36 +01:00
if(this.postData.Priority=='99999861') {
2021-04-29 13:58:52 +01:00
this.dispatchFolder.DeadlineType = 'Normal';
}
2021-06-09 14:45:36 +01:00
else if(this.postData.Priority=='99999862') {
2021-04-29 13:58:52 +01:00
this.dispatchFolder.DeadlineType = 'Urgente';
}
2021-06-09 14:45:36 +01:00
else if(this.postData.Priority=='99999863') {
2021-04-29 13:58:52 +01:00
this.dispatchFolder.DeadlineType = 'Muito Urgente';
}
2021-06-09 14:45:36 +01:00
else if(this.postData.Priority=='99999864') {
2021-04-29 13:58:52 +01:00
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"
};
2021-05-07 15:27:31 +01:00
});
2021-04-29 13:58:52 +01:00
2021-05-07 14:22:54 +01:00
const DocumentToSave = this.documents.map((e) => {
return {
ApplicationId: e.ApplicationType,
SourceId: e.Id
}
});
2021-05-07 15:27:31 +01:00
this.dispatchFolder.SubjectTypes = this.selectedTypes;
2021-05-28 16:37:57 +01:00
switch (this.loggeduser.Profile) {
case 'MDGPR':
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 {
2021-06-15 11:55:36 +01:00
//await this.processes.postDespatcho(this.postData).toPromise();
2021-06-14 14:28:10 +01:00
this.FinalizarDespacho();
2021-06-14 14:04:00 +01:00
this.toastService.badRequest('Despacho criado');
2021-05-28 16:37:57 +01:00
} catch (error) {
2021-06-14 13:48:02 +01:00
this.toastService.badRequest('Processo não efectuado');
2021-05-28 16:37:57 +01:00
}
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);
try {
2021-06-14 13:48:02 +01:00
await this.processes.postParecer(this.postData).toPromise();
2021-06-14 14:28:10 +01:00
this.FinalizarParecer();
2021-06-14 13:48:02 +01:00
this.toastService.successMessage('Pedido de Parecer criado');
}
catch (error) {
this.toastService.badRequest('Processo não efectuado');
2021-05-28 16:37:57 +01:00
}
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 {
2021-06-14 13:48:02 +01:00
await this.processes.postDeferimento(this.postData).toPromise();
2021-06-14 14:43:57 +01:00
this.executado();
2021-06-14 13:48:02 +01:00
this.toastService.successMessage('Pedido de Deferimento criado');
}
catch (error) {
this.toastService.badRequest('Processo não efectuado');
2021-05-28 16:37:57 +01:00
}
break;
}
this.modalController.dismiss();
}
else {
2021-06-14 13:48:02 +01:00
this.toastService.badRequest('Lista de intervenientes vazia. Por favor, adicione 1 ou mais intervenientes.');
2021-05-28 16:37:57 +01:00
}
2021-05-25 13:38:46 +01:00
2021-05-28 16:37:57 +01:00
break;
case 'PR':
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 {
2021-06-14 13:48:02 +01:00
await this.processes.postDespatcho(this.postData).toPromise();
this.executado();
this.toastService.successMessage('Despacho criado');
2021-05-28 16:37:57 +01:00
} catch (error) {
2021-06-14 13:48:02 +01:00
this.toastService.badRequest('Processo não efectuado');
2021-05-28 16:37:57 +01:00
}
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);
try {
2021-06-14 13:48:02 +01:00
await this.processes.postParecer(this.postData).toPromise();
this.executado();
this.toastService.successMessage('Pedido de Parecer criado');
}
catch (error) {
this.toastService.badRequest('Processo não efectuado');
2021-05-28 16:37:57 +01:00
}
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 {
2021-06-14 13:48:02 +01:00
await this.processes.postDeferimento(this.postData).toPromise();
this.executado();
this.toastService.successMessage('Pedido de Deferimento criado');
}
catch (error) {
this.toastService.badRequest('Processo não efectuado');
2021-05-28 16:37:57 +01:00
}
break;
2021-05-25 13:38:46 +01:00
}
2021-05-28 16:37:57 +01:00
this.modalController.dismiss();
break;
}
2021-05-25 13:38:46 +01:00
2021-04-29 13:58:52 +01:00
}
2021-06-14 13:48:02 +01:00
2021-06-09 10:49:37 +01:00
async executado() {
2021-04-30 21:19:57 +01:00
let body = {
"serialNumber": this.task.serialNumber,
"action": "Conhecimento",
2021-05-06 13:37:22 +01:00
"ActionTypeId": 104,
2021-04-30 21:19:57 +01:00
"dataFields": {
2021-05-21 10:05:59 +01:00
"ReviewUserComment": '',
2021-05-17 09:44:24 +01:00
},
"AttachmentList" :null,
2021-06-14 14:28:10 +01:00
}
await this.processes.CompleteTask(body).toPromise();
}
async FinalizarDespacho() {
let body = {
"serialNumber": this.task.serialNumber,
"action": "Despacho",
"ActionTypeId": 94,
"dataFields": {
"ReviewUserComment": '',
},
"AttachmentList" :null,
}
await this.processes.CompleteTask(body).toPromise();
}
2021-05-17 09:44:24 +01:00
2021-06-14 14:28:10 +01:00
async FinalizarParecer() {
let body = {
"serialNumber": this.task.serialNumber,
"action": "Parecer",
"ActionTypeId": 92,
"dataFields": {
"ReviewUserComment": '',
},
"AttachmentList" :null,
2021-06-14 13:48:02 +01:00
}
await this.processes.CompleteTask(body).toPromise();
2021-04-30 21:19:57 +01:00
}
2021-04-29 13:58:52 +01:00
async addParticipants() {
this.adding = "intervenient";
this.contacts = this.taskParticipants;
2021-06-15 11:39:59 +01:00
if(window.innerWidth <=800) {
2021-04-29 13:58:52 +01:00
this.showAttendees=false;
const modal = await this.modalController.create({
2021-06-15 11:39:59 +01:00
component: AttendeesPage,
componentProps: {
adding: this.adding,
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
2021-04-29 13:58:52 +01:00
},
2021-06-15 11:39:59 +01:00
cssClass: 'attendee',
2021-04-29 13:58:52 +01:00
backdropDismiss: false
});
2021-06-15 11:39:59 +01:00
2021-04-29 13:58:52 +01:00
await modal.present();
2021-06-15 11:39:59 +01:00
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);
2021-04-29 13:58:52 +01:00
}
});
2021-06-15 11:39:59 +01:00
2021-04-29 13:58:52 +01:00
} 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({
2021-06-15 11:39:59 +01:00
component: AttendeesPage,
componentProps: {
adding: this.adding,
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
2021-04-29 13:58:52 +01:00
},
2021-06-15 11:39:59 +01:00
cssClass: 'attendee',
2021-04-29 13:58:52 +01:00
backdropDismiss: false
});
2021-06-15 11:39:59 +01:00
2021-04-29 13:58:52 +01:00
await modal.present();
2021-06-15 11:39:59 +01:00
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);
2021-04-29 13:58:52 +01:00
}
});
2021-06-15 11:39:59 +01:00
2021-04-29 13:58:52 +01:00
} 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){
2021-05-07 16:57:53 +01:00
classs = 'modal modal-desktop'
2021-04-29 13:58:52 +01:00
} 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'); */
});
}
2021-05-07 14:22:54 +01:00
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);
}
});
}
2021-04-29 13:58:52 +01:00
2021-05-25 13:38:46 +01:00
2021-06-09 16:38:41 +01:00
async successMessage(message?: any, callback?) {
2021-05-25 13:38:46 +01:00
2021-06-08 15:59:06 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-05-25 13:38:46 +01:00
const modal = await this.modalController.create({
2021-06-08 15:59:06 +01:00
enterAnimation,
leaveAnimation,
component: SuccessMessagePage,
2021-05-25 13:38:46 +01:00
componentProps: {
message: message || 'Processo efetuado' ,
},
2021-06-08 15:59:06 +01:00
cssClass: 'notification-modal'
2021-05-25 13:38:46 +01:00
});
modal.present()
setTimeout(()=>{
2021-06-09 16:34:14 +01:00
if (callback) {
callback()
}
2021-05-25 13:38:46 +01:00
modal.dismiss()
2021-06-09 10:49:37 +01:00
},7000)
2021-05-25 13:38:46 +01:00
}
2021-06-09 16:34:14 +01:00
async badRequest(message?: string, callback?) {
2021-06-08 15:59:06 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-05-25 13:38:46 +01:00
const modal = await this.modalController.create({
2021-06-08 15:59:06 +01:00
enterAnimation,
leaveAnimation,
component: BadRequestPage,
2021-05-25 13:38:46 +01:00
componentProps: {
2021-06-08 16:56:48 +01:00
message: message || 'Processo não efetuado' ,
2021-05-25 13:38:46 +01:00
},
2021-06-08 15:59:06 +01:00
cssClass: 'notification-modal'
2021-05-25 13:38:46 +01:00
});
modal.present()
setTimeout(()=>{
2021-06-09 16:34:14 +01:00
if (callback) {
callback()
}
2021-05-25 13:38:46 +01:00
modal.dismiss()
2021-06-09 10:49:37 +01:00
},7000)
2021-05-25 13:38:46 +01:00
}
2021-04-29 13:58:52 +01:00
}