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

540 lines
16 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';
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';
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-05-25 13:38:46 +01:00
import { BadRequestComponent } from 'src/app/shared/popover/bad-request/bad-request.component';
import { SuccessMessageComponent } from 'src/app/shared/popover/success-message/success-message.component';
2021-05-28 16:37:57 +01:00
import { User } from 'src/app/models/user.model';
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,
) {
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();
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-05-07 15:27:31 +01:00
SubjectTypes: ['99999844'],
2021-05-26 13:57:51 +01:00
NumberPDPP: this.task.workflowInstanceDataFields.DispatchNumber,
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() {
this.taskDate = new Date(this.task.taskStartDate);
this.getSubjectType();
}
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
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"
};
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 {
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.");
}
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 {
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;
2021-05-25 13:38:46 +01:00
}
2021-05-28 16:37:57 +01:00
this.executado();
this.modalController.dismiss();
break;
}
2021-05-25 13:38:46 +01:00
2021-05-28 16:37:57 +01:00
2021-04-29 13:58:52 +01:00
}
2021-05-28 15:45:41 +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-04-30 21:19:57 +01:00
}
2021-05-28 15:45:41 +01:00
try {
await this.processes.CompleteTask(body).toPromise()
this.successMessage()
} catch (error) {
this.badRequest()
}
2021-04-30 21:19:57 +01:00
}
2021-04-29 13:58:52 +01:00
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){
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
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)
}
2021-04-29 13:58:52 +01:00
}