preventive-maintenance.component.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { MatSnackBar } from '@angular/material/snack-bar';
  2. import { MatDialog } from '@angular/material/dialog';
  3. import { lastValueFrom } from 'rxjs';
  4. import { Component, OnInit } from '@angular/core';
  5. import { EncService } from 'src/app/services/enc/enc.service';
  6. import { Submodules, SubmodulesResponse } from 'src/app/interfaces/submodules.interface';
  7. import { ModulesService } from 'src/app/services/modules.service';
  8. import { SubmoduleFunctionsResponse } from 'src/app/interfaces/submodule-functions.interface';
  9. import { SubmoduleFunctionsComponent } from '../template/menu-item/submodule-functions/submodule-functions.component';
  10. import { Router } from '@angular/router';
  11. @Component({
  12. selector: 'app-preventive-maintenance',
  13. templateUrl: './preventive-maintenance.component.html',
  14. styleUrls: ['./preventive-maintenance.component.css']
  15. })
  16. export class PreventiveMaintenanceComponent implements OnInit {
  17. isLoading: boolean;
  18. hasError: boolean;
  19. errorStr: string;
  20. submodules: Submodules[];
  21. constructor(
  22. private _encService: EncService,
  23. private _modulesService: ModulesService,
  24. private _dialog: MatDialog,
  25. private _router: Router,
  26. private _snackBar: MatSnackBar,
  27. ) {
  28. this.isLoading = true;
  29. this.hasError = false;
  30. this.errorStr = "";
  31. this.submodules = [];
  32. }
  33. ngOnInit(): void {
  34. this.getSubmodules();
  35. }
  36. async getSubmodules(){
  37. try{
  38. let moduleEnc = await this._encService.encrypt('S002V01M10GMPR');
  39. let modShort = await lastValueFrom(this._encService.shortEncrypt(moduleEnc));
  40. let idEnc = localStorage.getItem('idusuario');
  41. let idShort = await lastValueFrom(this._encService.shortEncrypt(idEnc!));
  42. let submodules: SubmodulesResponse = await lastValueFrom(this._modulesService.getSubmodules(
  43. modShort.response.encrypted,
  44. idShort.response.encrypted,
  45. 1
  46. ));
  47. this.isLoading = false;
  48. this.hasError = submodules.error;
  49. this.errorStr = submodules.msg;
  50. if(!this.hasError){
  51. this.submodules = submodules.response;
  52. }
  53. }catch(error: any){
  54. if(error.error == undefined){
  55. this.errorStr = "Ocurrió un error inesperado.";
  56. }else if(error.error.msg == undefined){
  57. this.errorStr = "Ocurrió un error inesperado.";
  58. }else{
  59. this.errorStr = error.error.msg;
  60. }
  61. this.hasError = true;
  62. this.isLoading = false;
  63. }
  64. }
  65. openMenu(submodule: Submodules){
  66. let dialogRef = this._dialog.open(SubmoduleFunctionsComponent, {
  67. width: '560px',
  68. data: {
  69. module: 'S002V01M10GMPR',
  70. submodule: submodule.IDSUBMODULO,
  71. },
  72. });
  73. dialogRef.afterClosed().subscribe(res => {
  74. if(res != null && res != undefined && res != ""){
  75. let idFunc = res.IDFUNCION.replace("S002V01F", "");
  76. idFunc = idFunc.substring(2);
  77. let idSub = submodule.IDSUBMODULO.replace("S002V01S", "");
  78. idSub = idSub.substring(2);
  79. this._router.navigate([`sam/GMPR/${idSub}/${idFunc}`]);
  80. }
  81. });
  82. }
  83. openSnackBar(msg: string){
  84. this._snackBar.open(msg, undefined, {
  85. duration: 2500,
  86. })
  87. }
  88. }