Files
doneit-web/src/app/pages/gabinete-digital/gabinete-digital.page.ts
T
Peter Maquiran 1b389b186e save
2021-05-25 15:46:50 +01:00

537 lines
15 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ProcessesService } from 'src/app/services/processes.service';
import { AlertService } from 'src/app/services/alert.service';
import { ModalController } from '@ionic/angular';
import { EventListPage } from './event-list/event-list.page';
import { ExpedientePage } from './expediente/expediente.page';
import { ActivatedRoute, NavigationEnd, NavigationExtras, Router } from '@angular/router';
import { DespachosPage } from './despachos/despachos.page';
import { PedidosPage } from './pedidos/pedidos.page';
import { PendentesPage } from './pendentes/pendentes.page';
import { AuthService } from 'src/app/services/auth.service';
import { User } from 'src/app/models/user.model';
import { DespachosPrPage } from 'src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page'
import { DiplomasPage } from 'src/app/shared/gabinete-digital/diplomas/diplomas.page';
import { SignedDiplomaComponent } from 'src/app/shared/gabinete-digital/signed-diploma/signed-diploma.component';
@Component({
selector: 'app-gabinete-digital',
templateUrl: './gabinete-digital.page.html',
styleUrls: ['./gabinete-digital.page.scss'],
})
export class GabineteDigitalPage implements OnInit {
segment:string;
showLoader: boolean;
public profile:string;
count_exp_dailywork=0;
count_exp_pr =0
count_desp_dailywork=0;
count_desp_pending=0;
count_par_dailywork=0;
count_par_pending=0;
count_def_dailywork=0;
count_def_pending=0;
count_exp_pp : string;
count_exp_pd : string;
count_dip_apr : string;
count_dip_Signed =0
count_dip_pv=0;
count_de_pr = 0;
count_ev_pr=0;
count_ev_md=0;
count_total_pending = 0;
count_desp_pr_active = 0;
selectedElement = "";
desktopComponent: any = {
showEventList: false,
showExpediente : false
}
showEventsToApprove = false;
showEmptyContainer = false;
showExpedients = false;
showExpedientesPr = false;
showPedidos = false;
showDespachos = false;
showDespachosPr = false;
showPendentes = false;
showDiplomas = false;
showExpedientDetail = false;
showSignedDiploma = false
emptyTextDescription = 'Sem opção selecionada';
serialNumber:string;
loggeduser: User;
constructor(
private processesbackend:ProcessesService,
private modalController: ModalController,
private alertService: AlertService,
private activatedRoute: ActivatedRoute,
private router: Router,
authService: AuthService
) {
this.loggeduser = authService.ValidatedUser;
window.onresize = (event) => {
// if not mobile remove all component
if( window.innerWidth <= 800){
this.modalController.dismiss();
}
};
this.activatedRoute.queryParams.subscribe(params => {
switch (params)
{
case params["eventos"]:
this.openEventsToApprovePage("MDGPR");
this.selectedElement='approval'
break;
case params["expedientes"]:
this.openExpedientListPage();
this.selectedElement='Correspondence';
break;
case params["pendentes"]:
this.openPendentesPage('');
this.selectedElement='Pending'
break;
case params["despachos"]:
this.openDespachosPage('');
this.selectedElement='Dispatches';
break;
case params["pedidos"]:
this.openPedidosPage('parecer');
this.selectedElement='RequestsForOpinion';
break;
case params["expedientespr"]:
this.openEventsToApprovePage("MDGPR");
this.selectedElement='Expediente Presidente'
break;
case params["despachospr"]:
this.openDespachosPrPage('');
this.selectedElement='DispatchesPr'
break;
case params["diplomas"]:
this.openDiplomasPage('');
this.selectedElement='DiplomasPorAssinar'
break;
}
});
/* if (window.innerWidth >= 800 && this.loggeduser.Profile == 'MDGPR') {
this.openEventsToApprovePage('MDGPR');
this.selectedElement='approval'
} */
}
closeAllDesktopComponent(){
this.desktopComponent = {
showEventList: false,
showExpediente: false
}
}
ngOnInit() {
switch(this.loggeduser.Profile){
case 'MDGPR':
this.showExpedients = true;
break;
case 'PR':
this.showExpedientesPr = true;
break;
}
this.router.events.forEach((event) => {
if(event instanceof NavigationEnd && event.url == this.router.url) {
this.LoadCounts();
}
});
}
closeAllDesktopComponents() {
this.showEmptyContainer = false;
this.showEventsToApprove = false;
this.showExpedients = false;
this.showPedidos = false;
this.showDespachos = false;
this.showDespachosPr = false;
this.showPendentes = false;
this.showDiplomas = false;
this.showExpedientesPr = false;
this.showExpedientDetail = false;
this.showSignedDiploma = false
}
async LoadCounts() {
this.showLoader = true;
let expedientes = await this.processesbackend.GetTasksList("Expediente", false).toPromise();
switch(this.loggeduser.Profile){
case 'MDGPR':
this.count_exp_dailywork = Object.keys(expedientes.filter(data => data.workflowInstanceDataFields.Status == "Active")).length;
break;
case 'PR':
this.count_exp_pr = Object.keys(expedientes.filter(data => data.workflowInstanceDataFields.Status == "Active")).length;
break;
}
let despachos = await this.processesbackend.GetTasksList("Despacho", false).toPromise();
this.count_desp_dailywork = Object.keys(despachos).length;
let pareceres = await this.processesbackend.GetTasksList("Pedido de Parecer", false).toPromise();
this.count_par_dailywork = Object.keys(pareceres).length;
let deferimentos = await this.processesbackend.GetTasksList("Pedido de Deferimento", false).toPromise();
this.count_def_dailywork = Object.keys(deferimentos).length;
let pendentes = despachos.concat(pareceres, deferimentos, expedientes).reverse().filter(data => data.workflowInstanceDataFields.Status == "Pending");
this.count_total_pending = Object.keys(pendentes).length;
let despachospr = await this.processesbackend.GetTasksList("Despacho do Presidente da República", false).toPromise();
let despachosPr = despachospr.filter(data => data.activityInstanceName == "Tarefa de Despacho");
this.count_de_pr = Object.keys(despachosPr).length;
let diplomasValidar = despachospr.filter(data => data.activityInstanceName == "Revisar Diploma");
this.count_dip_pv = Object.keys(diplomasValidar).length;
this.processesbackend.GetTasksList("Expediente", false).subscribe(result => {
let res = result.reverse().filter(data => data.workflowInstanceDataFields.Status == "Active");
this.count_exp_pr = Object.keys(res).length
});
this.processesbackend.GetTasksList("Expediente", false).subscribe(result => {
let res = result.reverse().filter(data => data.workflowInstanceDataFields.Status == "Signed");
this.count_dip_Signed = Object.keys(res).length
});
this.processesbackend.GetToApprovedEvents('PR','true').subscribe(res=>{
this.count_ev_pr = res;
});
this.processesbackend.GetToApprovedEvents('MDGPR','true').subscribe(res=>{
this.count_ev_md = res;
});
this.showLoader = false;
this.count_exp_pp = "-";
this.count_exp_pd = "-";
this.count_dip_apr = "-";
}
doRefresh() {
this.closeAllDesktopComponents();
switch(this.loggeduser.Profile){
case 'MDGPR':
this.selectedElement='Correspondence';
this.showExpedients = true;
break;
case 'PR':
this.selectedElement='ExpedientesPr';
this.showExpedientesPr = true;
break;
}
this.LoadCounts();
setTimeout(() => {
//event.target.complete();
}, 2000);
}
notImplemented(){
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
}
selectedElementF(element:string) {
if (window.innerWidth >= 800) {
return element == this.selectedElement
}
return false;
}
openEventsToApprovePage(profile:any) {
console.log(profile);
this.closeAllDesktopComponents();
let navigationExtras: NavigationExtras = { queryParams: {"eventos": true,}};
if( window.innerWidth <= 800) {
//this.openEventsToApproveList(profile);
this.router.navigate(['/home/gabinete-digital/event-list']);
}
else {
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showEventsToApprove = true;
}
}
async openEventsToApproveList(profile:any) {
this.closeAllDesktopComponent();
//if( window.innerWidth <= 1024){
const modal = await this.modalController.create({
component: EventListPage,
componentProps:{
profile: profile,
},
cssClass: 'modal modal-desktop',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
//} else {
//this.desktopComponent.showEventList = true;
//}
}
openExpedientListPage() {
this.closeAllDesktopComponents();
switch(this.loggeduser.Profile){
case 'MDGPR':
if( window.innerWidth <= 800) {
//this.openExpedientList();
this.router.navigate(['/home/gabinete-digital/expediente']);
}
else {
this.selectedElement='Correspondence'
let navigationExtras: NavigationExtras = { queryParams: {"expedientes": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showExpedients = true;
}
break;
case 'PR':
if( window.innerWidth <= 800) {
//this.openExpedientList();
this.router.navigate(['/home/gabinete-digital/expedientes-pr']);
}
else {
this.selectedElement='ExpedientesPr'
let navigationExtras: NavigationExtras = { queryParams: {"expedientes": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showExpedientesPr = true;
}
break;
}
}
openExpedientPage(data){
console.log(data);
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
//this.openExpedientList();
}
else{
this.serialNumber = data;
this.showExpedientDetail = true;
}
}
openPedidosPage(segment:string){
this.closeAllDesktopComponents();
if( window.innerWidth <= 800) {
this.openPedidoList();
}
else{
this.segment = segment;
let navigationExtras: NavigationExtras = { queryParams: {"pedidos": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showPedidos = true;
}
}
openDespachosPage(segment:string){
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
this.openDespachoList();
}
else{
let navigationExtras: NavigationExtras = {queryParams: {"despachos": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showDespachos = true;
}
}
openDespachosPrPage(segment:string) {
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
this.openDespachoListPr();
}
else{
let navigationExtras: NavigationExtras = {queryParams: {"despachospr": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showDespachosPr = true;
}
}
openPendentesPage(segment:string){
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
this.openPendenteList();
}
else{
let navigationExtras: NavigationExtras = { queryParams: {"pendentes": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showPendentes = true;
}
}
openExpedientesPrPage(segment:string){
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
this.openDespachoList();
}
else{
let navigationExtras: NavigationExtras = {queryParams: {"expedientespr": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showExpedientesPr = true;
}
}
openDiplomasPage(segment:string) {
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
this.openDeploma();
}
else{
this.segment = segment;
let navigationExtras: NavigationExtras = { queryParams: {"diplomas": true,}};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
this.showDiplomas = true;
}
}
openSignedDiploma(segment:string) {
this.closeAllDesktopComponents();
if( window.innerWidth <= 800){
this.openDeploma();
}
else{
this.segment = segment;
this.showSignedDiploma = true;
}
}
async openSignedDiplom(){
const modal = await this.modalController.create({
component: SignedDiplomaComponent,
componentProps:{
profile: this.profile,
},
cssClass: 'modal modal-desktop',
//backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
async openDeploma() {
const modal = await this.modalController.create({
component: DiplomasPage,
componentProps:{
profile: this.profile,
},
cssClass: 'modal modal-desktop',
//backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
async openExpedientList(){
this.closeAllDesktopComponent();
//if( window.innerWidth <= 1024){
const modal = await this.modalController.create({
component: ExpedientePage,
componentProps: {
profile: this.profile,
},
cssClass: 'modal modal-desktop',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
//} else {
console.log('show desktop modal')
//this.desktopComponent.showExpediente = true;
//}
}
async openPendenteList(){
this.closeAllDesktopComponent();
const modal = await this.modalController.create({
component: PendentesPage,
componentProps:{
profile: this.profile,
},
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss();
console.log('show desktop modal')
}
async openDespachoList(){
this.closeAllDesktopComponent();
const modal = await this.modalController.create({
component: DespachosPage,
componentProps:{
profile: this.profile,
serialNumber: this.serialNumber
},
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss();
console.log('show desktop modal')
}
async openDespachoListPr(){
this.closeAllDesktopComponent();
const modal = await this.modalController.create({
component: DespachosPrPage,
componentProps:{
profile: this.profile,
},
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss();
console.log('show desktop modal')
}
async openPedidoList(){
this.closeAllDesktopComponent();
const modal = await this.modalController.create({
component: PedidosPage,
componentProps:{
profile: this.profile,
},
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss();
console.log('show desktop modal')
}
}