|
|
@@ -8,6 +8,7 @@ import {
|
|
|
import {
|
|
|
DetailsFormWorkflow,
|
|
|
RequestFormWorkflow,
|
|
|
+ RegisterWorkflowRequest,
|
|
|
ResponseDataWorkflow,
|
|
|
} from '../../../../interfaces/process-managementv/workflow-management.interface';
|
|
|
import {
|
|
|
@@ -32,6 +33,7 @@ export class FormWorkflowComponent implements OnInit {
|
|
|
public formGroup: FormGroup;
|
|
|
public isLoading: boolean;
|
|
|
public idWorkflow!: string;
|
|
|
+ public isEditMode: boolean;
|
|
|
|
|
|
constructor(
|
|
|
@Inject(MAT_DIALOG_DATA) public detailsFormWorkflow: DetailsFormWorkflow,
|
|
|
@@ -42,21 +44,32 @@ export class FormWorkflowComponent implements OnInit {
|
|
|
private _encService: EncService,
|
|
|
private _processManagementService: ProcessManagementService
|
|
|
) {
|
|
|
- this.titleForm = this.interService.get('modificacion_flujo_trabajo');
|
|
|
+ this.isEditMode = this.detailsFormWorkflow.type === 'UPD';
|
|
|
+ this.titleForm = this.isEditMode
|
|
|
+ ? this.interService.get('modificacion_flujo_trabajo')
|
|
|
+ : this.interService.get('registro_flujo_trabajo');
|
|
|
this.isLoading = false;
|
|
|
this.formGroup = this._createFormGroup();
|
|
|
}
|
|
|
|
|
|
private _createFormGroup() {
|
|
|
- return new FormGroup({
|
|
|
+ const formControls: any = {
|
|
|
NOMBRE_WORKFLOW: new FormControl(null, Validators.required),
|
|
|
DESCRIPCION: new FormControl(null, Validators.required),
|
|
|
- COMENTARIO_CAMBIO: new FormControl(null, Validators.required),
|
|
|
- });
|
|
|
+ };
|
|
|
+
|
|
|
+ if (this.isEditMode) {
|
|
|
+ formControls.COMENTARIO_CAMBIO = new FormControl(
|
|
|
+ null,
|
|
|
+ Validators.required
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return new FormGroup(formControls);
|
|
|
}
|
|
|
|
|
|
async ngOnInit() {
|
|
|
- if (this.detailsFormWorkflow.idWorkflow !== undefined) {
|
|
|
+ if (this.isEditMode && this.detailsFormWorkflow.idWorkflow !== undefined) {
|
|
|
this.idWorkflow = this.detailsFormWorkflow.idWorkflow.toString();
|
|
|
await this.getWorkflowById();
|
|
|
}
|
|
|
@@ -107,24 +120,28 @@ export class FormWorkflowComponent implements OnInit {
|
|
|
this.isLoading = false;
|
|
|
}
|
|
|
|
|
|
- public save() {
|
|
|
- this._dialog
|
|
|
- .open(AlertComponent, {
|
|
|
- disableClose: true,
|
|
|
- data: {
|
|
|
- title: this.interService.get('confirmacion'),
|
|
|
- description: this.interService.get('update_description_alert'),
|
|
|
- icon: `warning`,
|
|
|
- btnCancelar: this.interService.get('cancelar'),
|
|
|
- btnAceptar: this.interService.get('aceptar'),
|
|
|
- },
|
|
|
- })
|
|
|
- .afterClosed()
|
|
|
- .subscribe(async (result) => {
|
|
|
- if (result) {
|
|
|
- await this._updateWorkflow();
|
|
|
- }
|
|
|
- });
|
|
|
+ public async save() {
|
|
|
+ if (this.isEditMode) {
|
|
|
+ this._dialog
|
|
|
+ .open(AlertComponent, {
|
|
|
+ disableClose: true,
|
|
|
+ data: {
|
|
|
+ title: this.interService.get('confirmacion'),
|
|
|
+ description: this.interService.get('update_description_alert'),
|
|
|
+ icon: `warning`,
|
|
|
+ btnCancelar: this.interService.get('cancelar'),
|
|
|
+ btnAceptar: this.interService.get('aceptar'),
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .afterClosed()
|
|
|
+ .subscribe(async (result) => {
|
|
|
+ if (result) {
|
|
|
+ await this._updateWorkflow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ await this._registerWorkflow();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private async _updateWorkflow() {
|
|
|
@@ -157,6 +174,42 @@ export class FormWorkflowComponent implements OnInit {
|
|
|
this.isLoading = false;
|
|
|
}
|
|
|
|
|
|
+ private async _registerWorkflow() {
|
|
|
+ this.isLoading = true;
|
|
|
+ const registerRequest: RegisterWorkflowRequest = {
|
|
|
+ NOMBRE_WORKFLOW: this.formGroup.controls['NOMBRE_WORKFLOW'].value
|
|
|
+ .toString()
|
|
|
+ .trim(),
|
|
|
+ DESCRIPCION: this.formGroup.controls['DESCRIPCION'].value
|
|
|
+ .toString()
|
|
|
+ .trim(),
|
|
|
+ USUARIO: this.resourcesService.getUser(),
|
|
|
+ NUMERO_LINEA: this.resourcesService.getLineNumber(),
|
|
|
+ };
|
|
|
+
|
|
|
+ await lastValueFrom(
|
|
|
+ this._processManagementService.registerNewWorkflow(registerRequest)
|
|
|
+ ).then(
|
|
|
+ (responseData: ResponseData) => {
|
|
|
+ if (!responseData.error) {
|
|
|
+ this.resourcesService.openSnackBar(
|
|
|
+ this.interService.get('registro_exitoso')
|
|
|
+ );
|
|
|
+ this._dialogRef.close(true);
|
|
|
+ } else {
|
|
|
+ this.resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async (httpErrorResponse: HttpErrorResponse) => {
|
|
|
+ let response = this.resourcesService.checkErrors(httpErrorResponse);
|
|
|
+ if (response !== null && response.reload) {
|
|
|
+ await this._registerWorkflow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
+
|
|
|
private _createRequestFormWorkflow(): RequestFormWorkflow {
|
|
|
let nombreWorkflow = this.formGroup.controls['NOMBRE_WORKFLOW'].value;
|
|
|
nombreWorkflow = nombreWorkflow.toString().trim();
|