|
|
@@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
import { Observable, lastValueFrom, map, startWith } from 'rxjs';
|
|
|
import { CatalogFailure, ResponseDataCatalogFailure, ResponseDataGetCatalogFailure } from 'src/app/interfaces/failure-analysis/catalog-failure.interface';
|
|
|
+import { EquipmentByFailure, ResponseDataGetEquipmentByFailure } from 'src/app/interfaces/failure-analysis/statistical-analysis';
|
|
|
import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
import { FailureListService } from 'src/app/services/failure-analysis/failure-list.service';
|
|
|
import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
@@ -22,7 +23,7 @@ export class AnalysisFilterEquationFailuresComponent implements OnInit {
|
|
|
public formGroup: FormGroup;
|
|
|
|
|
|
public arrFailure: Array<CatalogFailure>;
|
|
|
- public arrEquipment: Array<string>;
|
|
|
+ public arrEquipment: Array<EquipmentByFailure>;
|
|
|
|
|
|
public isLoadingFailures: boolean;
|
|
|
public isLoadingEquipment: boolean;
|
|
|
@@ -90,6 +91,14 @@ export class AnalysisFilterEquationFailuresComponent implements OnInit {
|
|
|
this.getCatalogFailureByClassification(clasificacion);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ this.formGroup.controls['NOMBRE_FALLA'].valueChanges.subscribe((failure) => {
|
|
|
+ if ( failure.includes('(') && failure.includes(')') ) {
|
|
|
+
|
|
|
+ let idFailure: string = failure.split('(')[1].split(')')[0];
|
|
|
+ this.getEquipmentByFailure(idFailure);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private createFormGroup() {
|
|
|
@@ -115,8 +124,12 @@ export class AnalysisFilterEquationFailuresComponent implements OnInit {
|
|
|
(responseData: ResponseDataGetCatalogFailure) => {
|
|
|
if (!responseData.error) {
|
|
|
this.arrFailure = responseData.response;
|
|
|
- this.failureStr = responseData.response.map((catalogFailure: CatalogFailure) => `${catalogFailure.NOMBRE_FALLA} (${catalogFailure.ID_FALLA})`);
|
|
|
- this.formGroup.controls['NOMBRE_FALLA'].enable();
|
|
|
+ if (this.arrFailure.length > 0) {
|
|
|
+ this.failureStr = responseData.response.map((catalogFailure: CatalogFailure) => `${catalogFailure.NOMBRE_FALLA} (${catalogFailure.ID_FALLA})`);
|
|
|
+ this.formGroup.controls['NOMBRE_FALLA'].enable();
|
|
|
+ } else {
|
|
|
+ this.resourcesService.openSnackBar(`No existen fallas registradas en la clasificación #${classification}.`);
|
|
|
+ }
|
|
|
} else {
|
|
|
this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
}
|
|
|
@@ -126,6 +139,30 @@ export class AnalysisFilterEquationFailuresComponent implements OnInit {
|
|
|
this.isLoadingForm = false;
|
|
|
}
|
|
|
|
|
|
+ private async getEquipmentByFailure(failure: string) {
|
|
|
+ this.isLoadingForm = true;
|
|
|
+ this.isLoadingEquipment = true;
|
|
|
+ this.formGroup.controls['EQUIPAMIENTO'].disable();
|
|
|
+ const encFailure: string = await this._encService.encrypt(failure);
|
|
|
+ await lastValueFrom(this._failureListService.getEquipmentByFailure(encFailure)).then(
|
|
|
+ (responseData: ResponseDataGetEquipmentByFailure) => {
|
|
|
+ if (!responseData.error) {
|
|
|
+ this.arrEquipment = responseData.response;
|
|
|
+ if (this.arrEquipment.length > 0) {
|
|
|
+ this.equipmentStr = responseData.response.map((equipmentByFailure: EquipmentByFailure) => equipmentByFailure.CODIGO_EQUIPAMIENTO);
|
|
|
+ this.formGroup.controls['EQUIPAMIENTO'].enable();
|
|
|
+ } else {
|
|
|
+ this.resourcesService.openSnackBar(`No existen equipamientos registrados en la falla ${failure}.`);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
+ }
|
|
|
+ }, (httpErrorResponse: HttpErrorResponse) => this.resourcesService.checkErrors(httpErrorResponse)
|
|
|
+ );
|
|
|
+ this.isLoadingEquipment = false;
|
|
|
+ this.isLoadingForm = false;
|
|
|
+ }
|
|
|
+
|
|
|
public validateValues() {
|
|
|
let strClassification = this.formGroup.controls['CLASIFICACION'].value;
|
|
|
if (strClassification === null || strClassification === undefined || this.clasificateStr.includes(strClassification)) {
|