Bladeren bron

integracion de funciones para validar/rechazar y visualizar las solicitudes de workflow, al modal le faltan estilos y acciones

EmilianoOrtiz 1 maand geleden
bovenliggende
commit
76866d880f

+ 2 - 1
src/app/app.module.ts

@@ -465,6 +465,7 @@ import { SignatureViewComponent } from './components/template/notification-dialo
 import { CommentsViewComponent } from './components/template/notification-dialog/comments-view/comments-view.component';
 import { AgreeOrderComponent } from './components/template/notification-dialog/agree-order/agree-order.component';
 import { SignaturePadComponent } from './components/template/notification-dialog/signature-pad/signature-pad.component';
+import { ValidateApplicationsModalComponent } from './components/template/notification-dialog/validate-applications-modal/validate-applications-modal.component';
 import { SignaturePadModule } from 'angular-signature-pad-v2';
 /*FIN Componentes SAM*/
 
@@ -841,7 +842,6 @@ import { SignaturePadModule } from 'angular-signature-pad-v2';
     WorkflowDetailsComponent,
     ChangeStatusWorkflowComponent,
     WorkflowHistoryComponent,
-
     SelectColorComponent,
     GridIconsSelectorComponent,
     TableManagementFormComponent,
@@ -863,6 +863,7 @@ import { SignaturePadModule } from 'angular-signature-pad-v2';
     CommentsViewComponent,
     AgreeOrderComponent,
     SignaturePadComponent,
+    ValidateApplicationsModalComponent,
   ],
   imports: [
     SocketIoModule.forRoot(config),

+ 216 - 93
src/app/components/template/notification-dialog/notification-dialog.component.ts

@@ -1,22 +1,33 @@
 import { Component, Inject, OnInit } from '@angular/core';
-import { NotificationAction, NotificationDetailsResponse, NotificationsListItem } from '../../../interfaces/notification.interface';
-import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
+import {
+  NotificationAction,
+  NotificationDetailsResponse,
+  NotificationsListItem,
+} from '../../../interfaces/notification.interface';
+import {
+  MAT_DIALOG_DATA,
+  MatDialog,
+  MatDialogRef,
+} from '@angular/material/dialog';
 import { EncService } from '../../../services/enc.service';
 import { NotificationsService } from '../../../services/notifications.service';
 import { ResourcesService } from '../../../services/resources.service';
 import { CorrectiveMaintenanceService } from '../../../services/corrective-maintenance.service';
+import { ProcessManagementService } from '../../../services/process-management/process-management.service';
 import { lastValueFrom } from 'rxjs';
 import { CorrectiveOrderDetailsComponent } from '../../corrective-maintenance/operations-management/corrective-order-details/corrective-order-details.component';
 import { AgreeOrderComponent } from './agree-order/agree-order.component';
 import { SignatureViewComponent } from './signature-view/signature-view.component';
 import { StaffSelectionComponent } from '../../corrective-maintenance/operations-management/staff-selection/staff-selection.component';
 import { CommentsViewComponent } from './comments-view/comments-view.component';
+import { ValidateApplicationsModalComponent } from './validate-applications-modal/validate-applications-modal.component';
+import { ResponseDataValidateApplications } from '../../../interfaces/process-managementv/workflow-management.interface';
 
 @Component({
-    selector: 'app-notification-dialog',
-    templateUrl: './notification-dialog.component.html',
-    styleUrl: './notification-dialog.component.css',
-    standalone: false
+  selector: 'app-notification-dialog',
+  templateUrl: './notification-dialog.component.html',
+  styleUrl: './notification-dialog.component.css',
+  standalone: false,
 })
 export class NotificationDialogComponent implements OnInit {
   idNotification: string;
@@ -33,7 +44,8 @@ export class NotificationDialogComponent implements OnInit {
     private _dialog: MatDialog,
     private _resourcesService: ResourcesService,
     private _correctiveMaintenanceService: CorrectiveMaintenanceService,
-    private _dialogRef: MatDialogRef<NotificationDialogComponent>,
+    private _processManagementService: ProcessManagementService,
+    private _dialogRef: MatDialogRef<NotificationDialogComponent>
   ) {
     this.idNotification = '';
     this.isLoading = true;
@@ -46,42 +58,50 @@ export class NotificationDialogComponent implements OnInit {
     this.init();
   }
 
-  async init(){
-    this.idNotification = await this._encService.decrypt(this._data.idNotification);
+  async init() {
+    this.idNotification = await this._encService.decrypt(
+      this._data.idNotification
+    );
     this.getNotification();
   }
 
-  async getNotification(){
-    try{
+  async getNotification() {
+    try {
       let idUser = localStorage.getItem('idusuario')!;
-      let notification: NotificationDetailsResponse = await lastValueFrom(this._notificationsService.getNotification(
-        this._data.idNotification, 
-        'S',
-        idUser, 
-        1
-      ));
+      let notification: NotificationDetailsResponse = await lastValueFrom(
+        this._notificationsService.getNotification(
+          this._data.idNotification,
+          'S',
+          idUser,
+          1
+        )
+      );
 
       this.hasError = notification.error;
       this.errorStr = notification.msg;
 
-      if(!this.hasError){
-        let notificationActionsArr: NotificationAction[] = JSON.parse(notification.response.ACCIONES);
-        
+      if (!this.hasError) {
+        let notificationActionsArr: NotificationAction[] = JSON.parse(
+          notification.response.ACCIONES
+        );
+
         notification.response.ACCIONES_ARR = notificationActionsArr;
         if (notification.response.ID_ORDEN !== null) {
-          notification.response.ID_ORDEN = await this._encService.decrypt(notification.response.ID_ORDEN);
+          notification.response.ID_ORDEN = await this._encService.decrypt(
+            notification.response.ID_ORDEN
+          );
         }
 
         this.notification = notification.response;
       }
 
       this.isLoading = false;
-    }catch(error: any){
-      if(error.error == undefined){
+    } catch (error: any) {
+      if (error.error == undefined) {
         this.errorStr = 'Ocurrió un error inesperado.';
-      }else if(error.error.msg == undefined){
+      } else if (error.error.msg == undefined) {
         this.errorStr = 'Ocurrió un error inesperado.';
-      }else{
+      } else {
         this.errorStr = error.error.msg;
       }
 
@@ -90,82 +110,156 @@ export class NotificationDialogComponent implements OnInit {
     }
   }
 
-  executeNotificationAction(func: string, params: string){
+  executeNotificationAction(func: string, params: string) {
+    console.log(params);
+
     let paramsArr = JSON.parse(params);
-    switch(func){
-      case "openCorrectiveWorkOrderDetails":
+    switch (func) {
+      case 'openCorrectiveWorkOrderDetails':
         this.openCorrectiveWorkOrderDetails(paramsArr[0]);
-      break;
-      case "validateCorrectiveWorkOrder":
+        break;
+      case 'validateCorrectiveWorkOrder':
         this.validateCorrectiveWorkOrder(paramsArr[0]);
-      break;
-      case "openModule":
+        break;
+      case 'openModule':
         this._dialogRef.close(`go|${paramsArr[0]}`);
-      break;
-      case "attendCorrectiveWorkOrder":
+        break;
+      case 'attendCorrectiveWorkOrder':
         this.attendCorrectiveWorkOrder(paramsArr[0]);
-      break;
-      case "reviewSignatureInCorrectiveWorkOrder":
+        break;
+      case 'reviewSignatureInCorrectiveWorkOrder':
         this.reviewSignatureInCorrectiveWorkOrder(paramsArr[0], paramsArr[1]);
-      break;
-      case "reviewCommentsInCorrectiveWorkOrder":
+        break;
+      case 'reviewCommentsInCorrectiveWorkOrder':
         this.reviewCommentsInCorrectiveWorkOrder(paramsArr[0], paramsArr[1]);
-      break;
-      case "revalidateCorrectiveWorkOrder":
+        break;
+      case 'revalidateCorrectiveWorkOrder':
         this.revalidateCorrectiveWorkOrder(paramsArr[0]);
-      break;
+        break;
+      case 'getValidateApplications':
+        this.getValidateApplications(paramsArr[0], paramsArr[1]);
+        break;
+      case 'asignStateToApplication':
+        this.asignStateToApplication(
+          paramsArr[0],
+          paramsArr[1],
+          paramsArr[2],
+          paramsArr[3]
+        );
+        break;
       default:
-        this._resourcesService.openSnackBar('La función seleccionada no existe.');
-      break;
+        this._resourcesService.openSnackBar(
+          'La función seleccionada no existe.'
+        );
+        break;
     }
   }
 
   //FUNCIONES POSIBLES PARA LAS NOTIFICACIONES
-  openCorrectiveWorkOrderDetails(idOrder: string){
+  async getValidateApplications(user: string, line: number) {
+    if (!user || !line) {
+      this._resourcesService.openSnackBar('Parámetros inválidos.');
+      return;
+    }
+    try {
+      const response: ResponseDataValidateApplications = await lastValueFrom(
+        this._processManagementService.getValidateApplications(
+          await this._encService.encrypt(user),
+          line
+        )
+      );
+
+      console.log(response);
+
+      if (!response.error) {
+        this._dialog.open(ValidateApplicationsModalComponent, {
+          width: '800px',
+          data: { applications: response.response },
+        });
+      } else {
+        this._resourcesService.openSnackBar(response.msg);
+      }
+    } catch (error: any) {
+      this._resourcesService.openSnackBar(
+        error?.error?.msg || 'Ocurrió un error inesperado.'
+      );
+    }
+  }
+
+  async asignStateToApplication(
+    user: string,
+    line: number,
+    idapplication: number,
+    state: string
+  ) {
+    if (!user || !line || !idapplication || !state) {
+      this._resourcesService.openSnackBar('Parámetros inválidos.');
+      return;
+    }
+    try {
+      await lastValueFrom(
+        this._processManagementService.assignStateToApplication({
+          USUARIO: await this._encService.encrypt(user),
+          NUMERO_LINEA: line,
+          ID_APPLICATION: idapplication,
+          STATE: state,
+        })
+      );
+      this._resourcesService.openSnackBar(
+        'Estado asignado correctamente a la solicitud.'
+      );
+    } catch (error: any) {
+      this._resourcesService.openSnackBar(
+        error?.error?.msg || 'Ocurrió un error inesperado.'
+      );
+    }
+  }
+
+  openCorrectiveWorkOrderDetails(idOrder: string) {
     this._dialog.open(CorrectiveOrderDetailsComponent, {
       width: '480px',
       data: {
         idOrder: idOrder,
-      }
-    })
+      },
+    });
   }
 
-  private validateCorrectiveWorkOrder(idOrder: string){
+  private validateCorrectiveWorkOrder(idOrder: string) {
     let dialogRef = this._dialog.open(StaffSelectionComponent, {
       disableClose: true,
       width: '540px',
       maxWidth: '540px',
       data: {
         idOrder: idOrder,
-      }
+      },
     });
 
-    dialogRef.afterClosed().subscribe(res => {
-      if(res != null && res != undefined && res != ''){
+    dialogRef.afterClosed().subscribe((res) => {
+      if (res != null && res != undefined && res != '') {
         this.approveWorkOrder(idOrder, res);
       }
     });
   }
 
-  private revalidateCorrectiveWorkOrder(idOrder: string){
+  private revalidateCorrectiveWorkOrder(idOrder: string) {
     let dialogRef = this._dialog.open(StaffSelectionComponent, {
       disableClose: true,
       width: '540px',
       maxWidth: '540px',
       data: {
         idOrder: idOrder,
-      }
+      },
     });
 
-    dialogRef.afterClosed().subscribe(res => {
-      if(res != null && res != undefined && res != ''){
+    dialogRef.afterClosed().subscribe((res) => {
+      if (res != null && res != undefined && res != '') {
         this.updateApprovedWorkOrder(idOrder, res);
       }
     });
   }
 
-  private async approveWorkOrder(idOrder: string, config: string){
-    try{
+  private async approveWorkOrder(idOrder: string, config: string) {
+    try {
       let idUser = localStorage.getItem('idusuario')!;
       let formData = new FormData();
 
@@ -174,22 +268,30 @@ export class NotificationDialogComponent implements OnInit {
       formData.append('id_order', idOrder);
       formData.append('config', config);
 
-      await lastValueFrom(this._correctiveMaintenanceService.approveWorkOrder(formData));
-      this._resourcesService.openSnackBar('La orden de trabajo se aprobó correctamente.');
+      await lastValueFrom(
+        this._correctiveMaintenanceService.approveWorkOrder(formData)
+      );
+      this._resourcesService.openSnackBar(
+        'La orden de trabajo se aprobó correctamente.'
+      );
       this._dialogRef.close();
-    }catch(error: any){
-      if(error.error == undefined){
-        this._resourcesService.openSnackBar('Ocurrió un error inesperado (14).');
-      }else if(error.error.msg == undefined){
-        this._resourcesService.openSnackBar('Ocurrió un error inesperado (15).');
-      }else{
+    } catch (error: any) {
+      if (error.error == undefined) {
+        this._resourcesService.openSnackBar(
+          'Ocurrió un error inesperado (14).'
+        );
+      } else if (error.error.msg == undefined) {
+        this._resourcesService.openSnackBar(
+          'Ocurrió un error inesperado (15).'
+        );
+      } else {
         this._resourcesService.openSnackBar(error.error.msg);
       }
     }
   }
 
-  private async updateApprovedWorkOrder(idOrder: string, config: string){
-    try{
+  private async updateApprovedWorkOrder(idOrder: string, config: string) {
+    try {
       let idUser = localStorage.getItem('idusuario')!;
       let formData = new FormData();
 
@@ -198,39 +300,50 @@ export class NotificationDialogComponent implements OnInit {
       formData.append('id_order', idOrder);
       formData.append('config', config);
 
-      await lastValueFrom(this._correctiveMaintenanceService.updateApprovedWorkOrder(formData));
-      this._resourcesService.openSnackBar('La orden de trabajo se actualizó correctamente.');
+      await lastValueFrom(
+        this._correctiveMaintenanceService.updateApprovedWorkOrder(formData)
+      );
+      this._resourcesService.openSnackBar(
+        'La orden de trabajo se actualizó correctamente.'
+      );
       this._dialogRef.close();
-    }catch(error: any){
-      if(error.error == undefined){
-        this._resourcesService.openSnackBar('Ocurrió un error inesperado (14).');
-      }else if(error.error.msg == undefined){
-        this._resourcesService.openSnackBar('Ocurrió un error inesperado (15).');
-      }else{
+    } catch (error: any) {
+      if (error.error == undefined) {
+        this._resourcesService.openSnackBar(
+          'Ocurrió un error inesperado (14).'
+        );
+      } else if (error.error.msg == undefined) {
+        this._resourcesService.openSnackBar(
+          'Ocurrió un error inesperado (15).'
+        );
+      } else {
         this._resourcesService.openSnackBar(error.error.msg);
       }
     }
   }
 
-  attendCorrectiveWorkOrder(idOrder: string){
+  attendCorrectiveWorkOrder(idOrder: string) {
     let dialogRef = this._dialog.open(AgreeOrderComponent, {
       disableClose: true,
-      width: "560px",
-      maxWidth: "560px",
+      width: '560px',
+      maxWidth: '560px',
       data: {
         idOrder: idOrder,
-      }
+      },
     });
 
-    dialogRef.afterClosed().subscribe(res => {
-      if(res != null && res != undefined && res != ''){
+    dialogRef.afterClosed().subscribe((res) => {
+      if (res != null && res != undefined && res != '') {
         this.saveAttendanceCorrectiveOrder(idOrder, res);
       }
-    })
+    });
   }
 
-  private async saveAttendanceCorrectiveOrder(idOrder: string, dataEnc: string){
-    try{
+  private async saveAttendanceCorrectiveOrder(
+    idOrder: string,
+    dataEnc: string
+  ) {
+    try {
       let idUser = localStorage.getItem('idusuario')!;
       let dataDec = await this._encService.decrypt(dataEnc);
       let dataArr = JSON.parse(dataDec);
@@ -242,39 +355,49 @@ export class NotificationDialogComponent implements OnInit {
       formData.append('attendance', dataArr[0]);
       formData.append('data', dataArr[1]);
 
-      await lastValueFrom(this._correctiveMaintenanceService.setWorkOrderAttendance(formData));
-      this._resourcesService.openSnackBar('La atención a la orden de trabajo se registró correctamente.');
+      await lastValueFrom(
+        this._correctiveMaintenanceService.setWorkOrderAttendance(formData)
+      );
+      this._resourcesService.openSnackBar(
+        'La atención a la orden de trabajo se registró correctamente.'
+      );
       this._dialogRef.close();
-    }catch(error: any){
-      if(error.error == undefined){
+    } catch (error: any) {
+      if (error.error == undefined) {
         this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
-      }else if(error.error.msg == undefined){
+      } else if (error.error.msg == undefined) {
         this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
-      }else{
+      } else {
         this._resourcesService.openSnackBar(error.error.msg);
       }
     }
   }
 
-  private reviewSignatureInCorrectiveWorkOrder(idOrder: string, idUserAction: string){
+  private reviewSignatureInCorrectiveWorkOrder(
+    idOrder: string,
+    idUserAction: string
+  ) {
     this._dialog.open(SignatureViewComponent, {
       width: '420px',
       maxWidth: '420px',
       data: {
         idOrder: idOrder,
         idUserAction: idUserAction,
-      }
+      },
     });
   }
 
-  private reviewCommentsInCorrectiveWorkOrder(idOrder: string, idUserAction: string){
+  private reviewCommentsInCorrectiveWorkOrder(
+    idOrder: string,
+    idUserAction: string
+  ) {
     this._dialog.open(CommentsViewComponent, {
       width: '420px',
       maxWidth: '420px',
       data: {
         idOrder: idOrder,
         idUserAction: idUserAction,
-      }
+      },
     });
   }
 }

+ 17 - 0
src/app/components/template/notification-dialog/validate-applications-modal/validate-applications-modal.component.css

@@ -0,0 +1,17 @@
+.modal-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: 16px;
+  border-bottom: 1px solid #e0e0e0;
+}
+
+.modal-content {
+  padding: 16px;
+  max-height: 400px;
+  overflow-y: auto;
+}
+
+.applications-table {
+  width: 100%;
+}

+ 38 - 0
src/app/components/template/notification-dialog/validate-applications-modal/validate-applications-modal.component.html

@@ -0,0 +1,38 @@
+<div class="modal-header">
+  <h2>Solicitudes de Validación</h2>
+  <button mat-icon-button (click)="close()">
+    <mat-icon>close</mat-icon>
+  </button>
+</div>
+
+<div class="modal-content">
+  <table mat-table [dataSource]="applications" class="applications-table">
+    <ng-container matColumnDef="fecha">
+      <th mat-header-cell *matHeaderCellDef>Fecha Solicitud</th>
+      <td mat-cell *matCellDef="let app">{{ app.FECHA_SOLICITUD }}</td>
+    </ng-container>
+
+    <ng-container matColumnDef="estado">
+      <th mat-header-cell *matHeaderCellDef>Estado</th>
+      <td mat-cell *matCellDef="let app">{{ app.ESTADO_SOLICITUD }}</td>
+    </ng-container>
+
+    <ng-container matColumnDef="tarea">
+      <th mat-header-cell *matHeaderCellDef>Tarea</th>
+      <td mat-cell *matCellDef="let app">{{ app.NOMBRE_TAREA }}</td>
+    </ng-container>
+
+    <ng-container matColumnDef="secuencia">
+      <th mat-header-cell *matHeaderCellDef>Secuencia</th>
+      <td mat-cell *matCellDef="let app">{{ app.SECUENCIA_TAREA }}</td>
+    </ng-container>
+
+    <ng-container matColumnDef="workflow">
+      <th mat-header-cell *matHeaderCellDef>Workflow</th>
+      <td mat-cell *matCellDef="let app">{{ app.NOMBRE_WORKFLOW }}</td>
+    </ng-container>
+
+    <tr mat-header-row *matHeaderRowDef="['fecha', 'estado', 'tarea', 'secuencia', 'workflow']"></tr>
+    <tr mat-row *matRowDef="let row; columns: ['fecha', 'estado', 'tarea', 'secuencia', 'workflow']"></tr>
+  </table>
+</div>

+ 24 - 0
src/app/components/template/notification-dialog/validate-applications-modal/validate-applications-modal.component.ts

@@ -0,0 +1,24 @@
+import { Component, Inject } from '@angular/core';
+import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
+import { ValidateApplication } from '../../../../interfaces/process-managementv/workflow-management.interface';
+
+@Component({
+  selector: 'app-validate-applications-modal',
+  templateUrl: './validate-applications-modal.component.html',
+  styleUrl: './validate-applications-modal.component.css',
+  standalone: false,
+})
+export class ValidateApplicationsModalComponent {
+  applications: ValidateApplication[];
+
+  constructor(
+    @Inject(MAT_DIALOG_DATA) public data: { applications: ValidateApplication[] },
+    private dialogRef: MatDialogRef<ValidateApplicationsModalComponent>
+  ) {
+    this.applications = data.applications;
+  }
+
+  close() {
+    this.dialogRef.close();
+  }
+}

+ 21 - 0
src/app/interfaces/process-managementv/workflow-management.interface.ts

@@ -342,3 +342,24 @@ export interface ActiveWorkflow {
   ID_WORKFLOW: number;
   NOMBRE_WORKFLOW: string;
 }
+
+export interface AssignStateToApplicationRequest {
+  USUARIO: string;
+  NUMERO_LINEA: number;
+  ID_APPLICATION: number;
+  STATE: string;
+}
+
+export interface ValidateApplication {
+  FECHA_SOLICITUD: string;
+  ESTADO_SOLICITUD: string;
+  NOMBRE_TAREA: string;
+  SECUENCIA_TAREA: number;
+  NOMBRE_WORKFLOW: string;
+}
+
+export interface ResponseDataValidateApplications {
+  error: boolean;
+  msg: string;
+  response: ValidateApplication[];
+}

+ 23 - 1
src/app/services/process-management/process-management.service.ts

@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
 import { HttpRequestService } from '../http-request.service';
 import { map, Observable } from 'rxjs';
 import {
+  AssignStateToApplicationRequest,
   ChangeWorkflowStatusRequest,
   RegisterWorkflowRequest,
   RequestFormRequestWorkflow,
@@ -22,6 +23,7 @@ import {
   ResponseDataGetWorkflows,
   ResponseDataProcessWorkflow,
   ResponseDataTask,
+  ResponseDataValidateApplications,
   ResponseDataWorkflow,
 } from '../../interfaces/process-managementv/workflow-management.interface';
 import { ResponseData } from '../resources.service';
@@ -270,7 +272,10 @@ export class ProcessManagementService {
     requestFormTask: RequestFormTask
   ): Observable<ResponseData> {
     return this._httpRequestService
-      .postQuery(`${this._url}/update-task-configuration/${idTask}`, requestFormTask)
+      .postQuery(
+        `${this._url}/update-task-configuration/${idTask}`,
+        requestFormTask
+      )
       .pipe(map((data: any) => data));
   }
 
@@ -283,4 +288,21 @@ export class ProcessManagementService {
       .getQuery(`${this._url}/get-task-configuration/${idTask}/${user}/${line}`)
       .pipe(map((data: any) => data));
   }
+
+  public getValidateApplications(
+    user: string,
+    line: number
+  ): Observable<ResponseDataValidateApplications> {
+    return this._httpRequestService
+      .getQuery(`${this._url}/get-validate-applications/${user}/${line}`)
+      .pipe(map((data: any) => data));
+  }
+
+  public assignStateToApplication(
+    request: AssignStateToApplicationRequest
+  ): Observable<ResponseData> {
+    return this._httpRequestService
+      .postQuery(`${this._url}/asign-state-to-application`, request)
+      .pipe(map((data: any) => data));
+  }
 }