|
|
@@ -1,10 +1,12 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
-import { FilterRequest, GetTaskByWorkflow, GetWorkflows, ProcessWorkflow, RequestSearch, ResponseDataFilterRequest, ResponseDataGetTaskByWorkflow, ResponseDataGetWorkflows, ResponseDataProcessWorkflow } from '../../../../interfaces/process-managementv/workflow-management.interface';
|
|
|
-import { lastValueFrom, map, Observable, startWith } from 'rxjs';
|
|
|
+import { FilterRequest, RequestSearch, ResponseDataFilterRequest } from '../../../../interfaces/process-managementv/workflow-management.interface';
|
|
|
+import { UserResponse, UsersResponse } from '../../../../interfaces/users.interface';
|
|
|
+import { lastValueFrom } from 'rxjs';
|
|
|
import { ResourcesService } from '../../../../services/resources.service';
|
|
|
import { InternationalizationService } from '../../../../services/internationalization/internationalization.service';
|
|
|
import { ProcessManagementService } from '../../../../services/process-management/process-management.service';
|
|
|
+import { UsersProfilesService } from '../../../../services/users-profiles.service';
|
|
|
import { MatDialogRef } from '@angular/material/dialog';
|
|
|
import { EncService } from '../../../../services/enc.service';
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
|
@@ -18,264 +20,80 @@ import { HttpErrorResponse } from '@angular/common/http';
|
|
|
export class SearchRequestComponent implements OnInit {
|
|
|
public formGroup: FormGroup;
|
|
|
public isLoading: boolean;
|
|
|
-
|
|
|
- private arrWorkflow: GetWorkflows[];
|
|
|
- public arrWorkflowStr: string[];
|
|
|
- public filteredOptionsWorkflow!: Observable<string[]>;
|
|
|
-
|
|
|
- private arrTask: GetTaskByWorkflow[];
|
|
|
- public arrTaskStr: string[];
|
|
|
- public filteredOptionsTask!: Observable<string[]>;
|
|
|
- public isLoadingTask: boolean;
|
|
|
-
|
|
|
- public arrProcessWorkflow: ProcessWorkflow[];
|
|
|
- public arrProcessWorkflowStr: string[];
|
|
|
- public filteredOptionsProcessWorkflow!: Observable<string[]>;
|
|
|
+ public arrUsers: UserResponse[];
|
|
|
+ public estadosSolicitud = ['Pendiente', 'Aprobada', 'Rechazada', 'Validada por timeout'];
|
|
|
|
|
|
constructor(
|
|
|
public resourcesService: ResourcesService,
|
|
|
public interService: InternationalizationService,
|
|
|
private _processManagementService: ProcessManagementService,
|
|
|
+ private _usersProfilesService: UsersProfilesService,
|
|
|
private _dialogReg: MatDialogRef<false | FilterRequest[]>,
|
|
|
private _encService: EncService,
|
|
|
) {
|
|
|
this.formGroup = this._createFormGroup();
|
|
|
this.isLoading = false;
|
|
|
- this.arrWorkflow = [];
|
|
|
- this.arrWorkflowStr = [];
|
|
|
-
|
|
|
- this.arrTask = [];
|
|
|
- this.arrTaskStr = [];
|
|
|
- this.isLoadingTask = false;
|
|
|
-
|
|
|
- this.arrProcessWorkflow = [];
|
|
|
- this.arrProcessWorkflowStr = [];
|
|
|
+ this.arrUsers = [];
|
|
|
}
|
|
|
|
|
|
private _createFormGroup(): FormGroup {
|
|
|
return new FormGroup({
|
|
|
- NOMBRE_WORKFLOW: new FormControl( null ),
|
|
|
- NUMERO_EJECUCION_WORKFLOW: new FormControl( null, Validators.min(1) ),
|
|
|
- ESTADO_EJECUCION_WORKFLOW: new FormControl( null ),
|
|
|
- NOMBRE_TAREA: new FormControl( { value: null, disabled: true } ),
|
|
|
- NUMERO_EJECUCION_TAREA: new FormControl( null, Validators.min(1) ),
|
|
|
- ESTADO_EJECUCION_TAREA: new FormControl( null ),
|
|
|
- NOMBRE_PROCESO: new FormControl( null ),
|
|
|
+ USUARIO_VALIDADOR: new FormControl(null),
|
|
|
+ ESTADO: new FormControl(null),
|
|
|
FECHA_INICIO: new FormControl<Date | null>(null),
|
|
|
- FECHA_FINAL: new FormControl<Date | null>(null),
|
|
|
+ FECHA_FIN: new FormControl<Date | null>(null),
|
|
|
+ FECHA_VALIDACION: new FormControl<Date | null>(null),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
async ngOnInit() {
|
|
|
this.isLoading = true;
|
|
|
- await this._getWorkflowsActives();
|
|
|
- await this._getProcessWorkflow();
|
|
|
+ await this._getUsers();
|
|
|
this.isLoading = false;
|
|
|
-
|
|
|
-
|
|
|
- this.filteredOptionsWorkflow = this.formGroup.controls['NOMBRE_WORKFLOW'].valueChanges.pipe(
|
|
|
- startWith(''),
|
|
|
- map(value => {
|
|
|
- value = value === null || value === undefined ? '' : value;
|
|
|
- const filterValue = value.toLowerCase();
|
|
|
- return this.arrWorkflowStr.filter(option => option.toLowerCase().includes(filterValue));
|
|
|
- })
|
|
|
- );
|
|
|
-
|
|
|
- this.filteredOptionsTask = this.formGroup.controls['NOMBRE_TAREA'].valueChanges.pipe(
|
|
|
- startWith(''),
|
|
|
- map(value => {
|
|
|
- value = value === null || value === undefined ? '' : value;
|
|
|
- const filterValue = value.toLowerCase();
|
|
|
- return this.arrTaskStr.filter(option => option.toLowerCase().includes(filterValue));
|
|
|
- })
|
|
|
- );
|
|
|
-
|
|
|
- this.filteredOptionsProcessWorkflow = this.formGroup.controls['NOMBRE_PROCESO'].valueChanges.pipe(
|
|
|
- startWith(''),
|
|
|
- map(value => {
|
|
|
- value = value === null || value === undefined ? '' : value;
|
|
|
- const filterValue = value.toLowerCase();
|
|
|
- return this.arrProcessWorkflowStr.filter(option => option.toLowerCase().includes(filterValue));
|
|
|
- })
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- private async _getWorkflowsActives() {
|
|
|
- const user: string = this.resourcesService.getUser();
|
|
|
- const line: number = this.resourcesService.getLineNumber();
|
|
|
- await lastValueFrom(this._processManagementService.getWorkflowsActives(user, line)).then(
|
|
|
- (responseData: ResponseDataGetWorkflows) => {
|
|
|
- if (!responseData.error) {
|
|
|
- this.arrWorkflow = responseData.response;
|
|
|
- this.arrWorkflowStr = responseData.response.map((workflow: GetWorkflows) => `${workflow.NOMBRE_WORKFLOW} (${workflow.ID_WORKFLOW})`);
|
|
|
- } else {
|
|
|
- this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
- }
|
|
|
- }, async (httpErrorResponse: HttpErrorResponse) => {
|
|
|
- let response = this.resourcesService.checkErrors(httpErrorResponse)
|
|
|
- if (response !== null && response.reload) {
|
|
|
- await this._getWorkflowsActives();
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
}
|
|
|
|
|
|
- private async _getProcessWorkflow() {
|
|
|
+ private async _getUsers() {
|
|
|
const user: string = this.resourcesService.getUser();
|
|
|
const line: number = this.resourcesService.getLineNumber();
|
|
|
- await lastValueFrom(this._processManagementService.getProcessWorkflow(user, line)).then(
|
|
|
- (responseData: ResponseDataProcessWorkflow) => {
|
|
|
+ await lastValueFrom(this._usersProfilesService.getUsers(user, line)).then(
|
|
|
+ async (responseData: UsersResponse) => {
|
|
|
if (!responseData.error) {
|
|
|
- this.arrProcessWorkflow = responseData.response;
|
|
|
- this.arrProcessWorkflowStr = responseData.response.map((processWorkflow: ProcessWorkflow) => `${processWorkflow.NOMBRE_PROCESO} (${processWorkflow.ID_PROCESO})`);
|
|
|
- } else {
|
|
|
- this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
- }
|
|
|
- }, async (httpErrorResponse: HttpErrorResponse) => {
|
|
|
- let response = this.resourcesService.checkErrors(httpErrorResponse)
|
|
|
- if (response !== null && response.reload) {
|
|
|
- await this._getProcessWorkflow();
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- public async getTaskByWorkflow(workflow: string) {
|
|
|
- this.isLoadingTask = true;
|
|
|
- if (!workflow.includes('(') || !workflow.includes(')')) {
|
|
|
- this.resourcesService.openSnackBar(`Ocurrió un error al obtener el identificador del flujo de trabajo.`);
|
|
|
- this._dialogReg.close(false);
|
|
|
- return;
|
|
|
- }
|
|
|
- const idWorkflow = workflow.split('(')[1].split(')')[0];
|
|
|
- const validate: boolean = this.arrWorkflow.every((getWorkflows: GetWorkflows) => getWorkflows.ID_WORKFLOW.toString() == idWorkflow);
|
|
|
- if (!validate) {
|
|
|
- this.resourcesService.openSnackBar(`No se pudo encontrar el flujo de trabajo seleccionado.`);
|
|
|
- this._dialogReg.close(false);
|
|
|
- return;
|
|
|
- }
|
|
|
- const encWorkflow: string = await this._encService.encrypt(idWorkflow.toString());
|
|
|
- const user: string = this.resourcesService.getUser();
|
|
|
- const line: number = this.resourcesService.getLineNumber();
|
|
|
- await lastValueFrom(this._processManagementService.getTaskByWorkflow(encWorkflow, user, line)).then(
|
|
|
- (responseData: ResponseDataGetTaskByWorkflow) => {
|
|
|
- if (!responseData.error) {
|
|
|
- this.arrTask = responseData.response;
|
|
|
- this.arrTaskStr = responseData.response.map((task: GetTaskByWorkflow) => `${task.NOMBRE_TAREA} (${task.ID_TAREA})`);
|
|
|
- if (this.arrTaskStr.length > 0) {
|
|
|
- this.formGroup.controls['NOMBRE_TAREA'].enable();
|
|
|
- } else {
|
|
|
- this.formGroup.controls['NOMBRE_TAREA'].disable();
|
|
|
+ for (let index = 0; index < responseData.response.length; index++) {
|
|
|
+ let element = responseData.response[index];
|
|
|
+ element.IDUSUARIO = await this._encService.decrypt(element.IDUSUARIO);
|
|
|
+ responseData.response[index] = element;
|
|
|
}
|
|
|
+ this.arrUsers = responseData.response;
|
|
|
} else {
|
|
|
this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
- this.formGroup.controls['NOMBRE_TAREA'].disable();
|
|
|
}
|
|
|
}, async (httpErrorResponse: HttpErrorResponse) => {
|
|
|
let response = this.resourcesService.checkErrors(httpErrorResponse)
|
|
|
if (response !== null && response.reload) {
|
|
|
- await this.getTaskByWorkflow(workflow);
|
|
|
- } else {
|
|
|
- this.formGroup.controls['NOMBRE_TAREA'].disable();
|
|
|
+ await this._getUsers();
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
- this.isLoadingTask = false;
|
|
|
}
|
|
|
|
|
|
public async search() {
|
|
|
- this.isLoading = true;
|
|
|
-
|
|
|
- let nombreWorkflow = this.formGroup.controls['NOMBRE_WORKFLOW'].value;
|
|
|
- if (nombreWorkflow !== null && nombreWorkflow !== undefined && nombreWorkflow !== '') {
|
|
|
- nombreWorkflow = nombreWorkflow.toString().trim();
|
|
|
- if ( !nombreWorkflow.includes('(') || !nombreWorkflow.includes(')') ) {
|
|
|
- this.resourcesService.openSnackBar(`Debe elegir una opción de la lista desplegable en el campo del nombre del workflow`);
|
|
|
- return;
|
|
|
- }
|
|
|
- nombreWorkflow = nombreWorkflow.split('(')[1].split(')')[0];
|
|
|
- } else {
|
|
|
- nombreWorkflow = null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- let numeroEjecucionWorkflow = this.formGroup.controls['NUMERO_EJECUCION_WORKFLOW'].value;
|
|
|
- if (numeroEjecucionWorkflow !== null && numeroEjecucionWorkflow !== undefined && numeroEjecucionWorkflow !== '') {
|
|
|
- numeroEjecucionWorkflow = parseInt(numeroEjecucionWorkflow);
|
|
|
- if ( numeroEjecucionWorkflow <= 0 ) {
|
|
|
- this.resourcesService.openSnackBar(`Ocurrió un error con el formato del número de ejecución del flujo de trabajo.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (numeroEjecucionWorkflow % 1 !== 0) {
|
|
|
- this.resourcesService.openSnackBar(`El número de ejecución del flujo de trabajo debe ser un número entero.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- numeroEjecucionWorkflow = null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- let estadoEjecucionWorkflow = this.formGroup.controls['ESTADO_EJECUCION_WORKFLOW'].value;
|
|
|
- if (estadoEjecucionWorkflow !== null && estadoEjecucionWorkflow !== undefined && estadoEjecucionWorkflow !== '') {
|
|
|
- estadoEjecucionWorkflow = estadoEjecucionWorkflow.toString().trim();
|
|
|
+ let usuarioValidador = this.formGroup.controls['USUARIO_VALIDADOR'].value;
|
|
|
+ if (usuarioValidador !== null && usuarioValidador !== undefined && usuarioValidador !== '') {
|
|
|
+ usuarioValidador = usuarioValidador.toString().trim();
|
|
|
} else {
|
|
|
- estadoEjecucionWorkflow = null;
|
|
|
+ usuarioValidador = null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- let nombreTarea = this.formGroup.controls['NOMBRE_TAREA'].value;
|
|
|
- if (nombreTarea !== null && nombreTarea !== undefined && nombreTarea !== '') {
|
|
|
- nombreTarea = nombreTarea.toString().trim();
|
|
|
- if ( !nombreTarea.includes('(') || !nombreTarea.includes(')') ) {
|
|
|
- this.resourcesService.openSnackBar(`Debe elegir una opción de la lista desplegable en el campo del nombre de la tarea.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- nombreTarea = nombreTarea.split('(')[1].split(')')[0];
|
|
|
+ let estado = this.formGroup.controls['ESTADO'].value;
|
|
|
+ if (estado !== null && estado !== undefined && estado !== '') {
|
|
|
+ estado = estado.toString().trim();
|
|
|
} else {
|
|
|
- nombreTarea = null;
|
|
|
+ estado = null;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- let numeroEjecucionTarea = this.formGroup.controls['NUMERO_EJECUCION_TAREA'].value;
|
|
|
- if (numeroEjecucionTarea !== null && numeroEjecucionTarea !== undefined && numeroEjecucionTarea !== '') {
|
|
|
- numeroEjecucionTarea = parseInt(numeroEjecucionTarea);
|
|
|
- if ( numeroEjecucionTarea <= 0 ) {
|
|
|
- this.resourcesService.openSnackBar(`Ocurrió un error con el formato del número de ejecución de la tarea.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (numeroEjecucionTarea % 1 !== 0) {
|
|
|
- this.resourcesService.openSnackBar(`El número de ejecución de la tarea debe ser un número entero.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- numeroEjecucionTarea = null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- let estadoEjecucionTarea = this.formGroup.controls['ESTADO_EJECUCION_TAREA'].value;
|
|
|
- if (estadoEjecucionTarea !== null && estadoEjecucionTarea !== undefined && estadoEjecucionTarea !== '') {
|
|
|
- estadoEjecucionTarea = estadoEjecucionTarea.toString().trim();
|
|
|
- } else {
|
|
|
- estadoEjecucionTarea = null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- let nombreProceso = this.formGroup.controls['NOMBRE_PROCESO'].value;
|
|
|
- if (nombreProceso !== null && nombreProceso !== undefined && nombreProceso !== '') {
|
|
|
- nombreProceso = nombreProceso.toString().trim();
|
|
|
- if ( !nombreProceso.includes('(') || !nombreProceso.includes(')') ) {
|
|
|
- this.resourcesService.openSnackBar(`Debe elegir una opción de la lista desplegable en el campo del nombre del proceso.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- nombreProceso = nombreProceso.split('(')[1].split(')')[0];
|
|
|
- } else {
|
|
|
- nombreProceso = null;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
let fechaInicio = this.formGroup.controls['FECHA_INICIO'].value;
|
|
|
- let fechaFinal = this.formGroup.controls['FECHA_FINAL'].value;
|
|
|
+ let fechaFin = this.formGroup.controls['FECHA_FIN'].value;
|
|
|
+ let fechaValidacion = this.formGroup.controls['FECHA_VALIDACION'].value;
|
|
|
|
|
|
if (fechaInicio !== null && fechaInicio !== undefined && fechaInicio !== '') {
|
|
|
fechaInicio = new Date(fechaInicio);
|
|
|
@@ -284,32 +102,26 @@ export class SearchRequestComponent implements OnInit {
|
|
|
fechaInicio = null;
|
|
|
}
|
|
|
|
|
|
- if (fechaFinal !== null && fechaFinal !== undefined && fechaFinal !== '') {
|
|
|
- fechaFinal = new Date(fechaFinal);
|
|
|
- fechaFinal = this.resourcesService.getDateFormatCalendar(fechaFinal);
|
|
|
+ if (fechaFin !== null && fechaFin !== undefined && fechaFin !== '') {
|
|
|
+ fechaFin = new Date(fechaFin);
|
|
|
+ fechaFin = this.resourcesService.getDateFormatCalendar(fechaFin);
|
|
|
} else {
|
|
|
- fechaFinal = null;
|
|
|
+ fechaFin = null;
|
|
|
}
|
|
|
|
|
|
- if (fechaInicio !== null && fechaFinal === null) {
|
|
|
- this.resourcesService.openSnackBar(`Ocurrió un error al obtener el rango de fechas.`);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (fechaInicio === null && fechaFinal !== null) {
|
|
|
- this.resourcesService.openSnackBar(`Ocurrió un error al obtener el rango de fechas.`);
|
|
|
- return;
|
|
|
+ if (fechaValidacion !== null && fechaValidacion !== undefined && fechaValidacion !== '') {
|
|
|
+ fechaValidacion = new Date(fechaValidacion);
|
|
|
+ fechaValidacion = this.resourcesService.getDateFormatCalendar(fechaValidacion);
|
|
|
+ } else {
|
|
|
+ fechaValidacion = null;
|
|
|
}
|
|
|
|
|
|
const REQUEST_SEARCH: RequestSearch = {
|
|
|
- 'WORKFLOW': nombreWorkflow,
|
|
|
- 'EJECUCION_WORKFLOW': numeroEjecucionWorkflow,
|
|
|
- 'ESTADO_WORKFLOW': estadoEjecucionWorkflow,
|
|
|
- 'TAREA': nombreTarea,
|
|
|
- 'EJECUCION_TAREA': numeroEjecucionTarea,
|
|
|
- 'ESTADO_TAREA': estadoEjecucionTarea,
|
|
|
- 'PROCESO': nombreProceso,
|
|
|
+ 'USUARIO_VALIDADOR': usuarioValidador,
|
|
|
+ 'ESTADO': estado,
|
|
|
'FECHA_INICIO': fechaInicio,
|
|
|
- 'FECHA_FINAL': fechaFinal,
|
|
|
+ 'FECHA_FIN': fechaFin,
|
|
|
+ 'FECHA_VALIDACION': fechaValidacion,
|
|
|
'USUARIO': this.resourcesService.getUser(),
|
|
|
'NUMERO_LINEA': this.resourcesService.getLineNumber(),
|
|
|
}
|
|
|
@@ -317,13 +129,17 @@ export class SearchRequestComponent implements OnInit {
|
|
|
await lastValueFrom(this._processManagementService.searchRequestWorkflow(REQUEST_SEARCH)).then(
|
|
|
(responseData: ResponseDataFilterRequest) => {
|
|
|
if (!responseData.error) {
|
|
|
+ console.log('Response from search solicitudes:', responseData.response);
|
|
|
this._dialogReg.close(responseData.response);
|
|
|
} else {
|
|
|
this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
}
|
|
|
- }, (httpErrorResponse: HttpErrorResponse) => this.resourcesService.checkErrors(httpErrorResponse)
|
|
|
+ }, async (httpErrorResponse: HttpErrorResponse) => {
|
|
|
+ let response = this.resourcesService.checkErrors(httpErrorResponse)
|
|
|
+ if (response !== null && response.reload) {
|
|
|
+ await this.search();
|
|
|
+ }
|
|
|
+ }
|
|
|
);
|
|
|
-
|
|
|
- this.isLoading = false;
|
|
|
}
|
|
|
}
|