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

415 lines
12 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-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-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,
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: '',
2021-05-07 16:17:01 +01:00
SourceSecFsId: this.task.workflowInstanceDataFields.FsId, //361
SourceType: 'DOC', //FOLDER
2021-05-07 16:17:01 +01:00
SourceId: this.task.workflowInstanceDataFields.DocId, //FolderId
2021-04-29 13:58:52 +01:00
DeadlineType: '',
2021-05-07 15:27:31 +01:00
SubjectTypes: ['99999844'],
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);
if(!this.task.hasOwnProperty('isEvent')) {
// if not
this.getAttachments();
}
this.getSubjectType();
console.log('CHEGOU');
}
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);
}
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"
};
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-04-29 13:58:52 +01:00
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);
this.processes.postDespatcho(this.postData);
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);
this.processes.postParecer(this.postData);
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);
this.processes.postDeferimento(this.postData);
break;
}
2021-04-30 21:19:57 +01:00
this.executado();
this.modalController.dismiss();
2021-04-29 13:58:52 +01:00
}
else {
this.alertController.presentAlert("Lista de intervenientes vazia. Por favor, adicione 1 ou mais intervenientes.");
}
}
2021-04-30 21:19:57 +01:00
executado(){
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-07 16:13:59 +01:00
"ReviewUserComent": '',
2021-05-17 09:44:24 +01:00
},
"AttachmentList" :null,
2021-04-30 21:19:57 +01:00
}
2021-05-06 13:37:22 +01:00
this.processes.CompleteTask(body);
2021-04-30 21:19:57 +01:00
}
2021-04-29 13:58:52 +01:00
getAttachments() {
this.attachmentsService.getAttachmentsBySerial(this.task.serialNumber).subscribe(res=>{
this.loadedAttachments = res;
console.log(res);
});
}
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
}