|
|
@@ -6,7 +6,9 @@ import { lastValueFrom } from 'rxjs';
|
|
|
import { AlertComponent } from 'src/app/components/resources/dialogs/alert/alert.component';
|
|
|
import { ResponseDataWorkteam, DialogModule, Workteam } from 'src/app/interfaces/personal-managment/workteam.interface';
|
|
|
import { ResponseData } from 'src/app/interfaces/response-data';
|
|
|
+import { SpecialtiesListItem, SpecialtiesListResponse } from 'src/app/interfaces/specialties.interface';
|
|
|
import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
+import { InterventionService } from 'src/app/services/personal-management/intervention.service';
|
|
|
import { WorkTeamService } from 'src/app/services/personal-management/work-team.service';
|
|
|
import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
|
|
|
@@ -16,44 +18,147 @@ import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
styleUrls: ['./work-team-form.component.css']
|
|
|
})
|
|
|
export class WorkTeamFormComponent implements OnInit {
|
|
|
+ action: string;
|
|
|
+ title: string;
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
+ specialties: SpecialtiesListItem[];
|
|
|
+ workTeam: any | null;
|
|
|
|
|
|
-
|
|
|
- public isLoading: boolean;
|
|
|
public formGroup: FormGroup;
|
|
|
public idWorkteam: string;
|
|
|
public enable: string;
|
|
|
public members: any[];
|
|
|
|
|
|
constructor(
|
|
|
+ @Inject(MAT_DIALOG_DATA) private _dialogData: DialogModule,
|
|
|
private _resourcesService: ResourcesService,
|
|
|
private _dialog: MatDialog,
|
|
|
private _workteamService: WorkTeamService,
|
|
|
- private dialogRef: MatDialogRef<WorkTeamFormComponent>,
|
|
|
+ private _dialogRef: MatDialogRef<WorkTeamFormComponent>,
|
|
|
private _encService: EncService,
|
|
|
- @Inject(MAT_DIALOG_DATA) public dialogData: DialogModule
|
|
|
+ private _interventionService: InterventionService,
|
|
|
) {
|
|
|
- this.isLoading = false;
|
|
|
+ this.action = "";
|
|
|
+ this.title = "";
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+ this.specialties = [];
|
|
|
+ this.workTeam = null;
|
|
|
+
|
|
|
this.idWorkteam = "";
|
|
|
this.enable = "";
|
|
|
this.members = [];
|
|
|
this.formGroup = this.createFormGroup();
|
|
|
}
|
|
|
|
|
|
- async ngOnInit() {
|
|
|
- this.isLoading = true;
|
|
|
+ ngOnInit() {
|
|
|
+ this.action = this._dialogData.action;
|
|
|
+ if(this.action == 'REG'){
|
|
|
+ this.title = "Registrar equipo de trabajo";
|
|
|
+ this.getSpecialties();
|
|
|
+ }else{
|
|
|
+ this.title = this.action == 'UPD' ? "Modificación equipo de trabajo" : "Detalles equipo de trabajo";
|
|
|
+ this.init();
|
|
|
+ }
|
|
|
+
|
|
|
+ /*this.isLoading = true;
|
|
|
if (this.dialogData.action != "REG") {
|
|
|
this.idWorkteam = this.dialogData.dataElement.WORKTEAM_ID;
|
|
|
await this._getData();
|
|
|
await this._getMembers();
|
|
|
}
|
|
|
this.enable = this.dialogData.action == "DET" ? "0" : "1";
|
|
|
- this.isLoading = false;
|
|
|
+ this.isLoading = false;*/
|
|
|
+ }
|
|
|
+
|
|
|
+ async init(){
|
|
|
+ try{
|
|
|
+ this.workTeam = this._dialogData.dataElement;
|
|
|
+ this.idWorkteam = this.workTeam.WORKTEAM_ID;
|
|
|
+ this.formGroup.controls['name'].setValue(this.workTeam.NAME);
|
|
|
+
|
|
|
+ if(this.action == 'DET'){
|
|
|
+ this._getMembers();
|
|
|
+ }else{
|
|
|
+ this.getSpecialties();
|
|
|
+ }
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else{
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async getSpecialties(){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let specialties: SpecialtiesListResponse = await lastValueFrom(this._interventionService.getSpecialties(idUser, 1));
|
|
|
+
|
|
|
+ this.hasError = specialties.error;
|
|
|
+ this.errorStr = specialties.msg;
|
|
|
+
|
|
|
+ if(!this.hasError){
|
|
|
+ let selectedSpecialties: string[] = [];
|
|
|
+ if(this.workTeam != null){
|
|
|
+ for(const specialtyCode of this.workTeam.SPECIALTY_ARR){
|
|
|
+ let codeDec = await this._encService.decrypt(specialtyCode);
|
|
|
+ let codeArr = codeDec.split(' - ');
|
|
|
+ selectedSpecialties.push(codeArr[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let specialtiesArr: SpecialtiesListItem[] = [];
|
|
|
+ for(const specialty of specialties.response){
|
|
|
+ let codeDec = await this._encService.decrypt(specialty.CODIGO_ESPECIALIDAD);
|
|
|
+ specialty.NOMBRE_ESPECIALIDAD = `${codeDec} - ${specialty.NOMBRE_ESPECIALIDAD}`;
|
|
|
+
|
|
|
+ if(specialty.ESTADO == 'Activo'){
|
|
|
+ specialtiesArr.push(specialty);
|
|
|
+ if(selectedSpecialties.includes(codeDec)){
|
|
|
+ let specialtiesVal = this.formGroup.controls['speciality'].value;
|
|
|
+ specialtiesVal.push(specialty.CODIGO_ESPECIALIDAD);
|
|
|
+
|
|
|
+ this.formGroup.controls['speciality'].setValue(specialtiesVal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.specialties = specialtiesArr;
|
|
|
+ if(this.action == 'UPD' || this.action == 'REG'){
|
|
|
+ this.formGroup.controls['name'].enable();
|
|
|
+ this.formGroup.controls['speciality'].enable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.isLoading = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else{
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private createFormGroup() {
|
|
|
return new FormGroup({
|
|
|
- name: new FormControl('', Validators.required),
|
|
|
- speciality: new FormControl('', Validators.required),
|
|
|
+ name: new FormControl({value: '', disabled: true}, [Validators.required, Validators.maxLength(75)]),
|
|
|
+ speciality: new FormControl({value: [], disabled: true}, Validators.required),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -92,8 +197,8 @@ export class WorkTeamFormComponent implements OnInit {
|
|
|
await lastValueFrom(this._workteamService.storeWorkteam( WORKTEAM )).then(
|
|
|
(responseData: ResponseData) => {
|
|
|
if (!responseData.error) {
|
|
|
- this._resourcesService.openSnackBar("Creación Exitosa!");
|
|
|
- this.dialogRef.close(true);
|
|
|
+ this._resourcesService.openSnackBar("¡Creación Exitosa!");
|
|
|
+ this._dialogRef.close(true);
|
|
|
} else {
|
|
|
this._resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
}
|
|
|
@@ -108,7 +213,7 @@ export class WorkTeamFormComponent implements OnInit {
|
|
|
(responseData: ResponseData) => {
|
|
|
if (!responseData.error) {
|
|
|
this._resourcesService.openSnackBar("Actualización Exitosa!");
|
|
|
- this.dialogRef.close(true);
|
|
|
+ this._dialogRef.close(true);
|
|
|
} else {
|
|
|
this._resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
}
|
|
|
@@ -117,43 +222,56 @@ export class WorkTeamFormComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
private async workteamObject(idWorkteamEnc: string | undefined): Promise<Workteam> {
|
|
|
+ let formValue = this.formGroup.getRawValue();
|
|
|
+
|
|
|
return {
|
|
|
WORKTEAM_ID: idWorkteamEnc,
|
|
|
- NAME: this.formGroup.controls['name'].value == null ? null : this.formGroup.controls['name'].value.trim(),
|
|
|
- SPECIALITY: this.formGroup.controls['speciality'].value == null ? null : this.formGroup.controls['speciality'].value.trim(),
|
|
|
+ NAME: formValue.name,
|
|
|
+ SPECIALITY: JSON.stringify(formValue.speciality),
|
|
|
id_user: localStorage.getItem('idusuario')!,
|
|
|
linea: 1,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async _getData() {
|
|
|
- let idWorkteamEnc = await this._encService.encrypt(`${this.idWorkteam}`);
|
|
|
- const USER = this._resourcesService.getUser();
|
|
|
- const LINE: number = this._resourcesService.getLineNumber();
|
|
|
- await lastValueFrom(this._workteamService.getWorkteamById( idWorkteamEnc, USER, LINE )).then(
|
|
|
- (responseData: ResponseDataWorkteam) => {
|
|
|
- if (!responseData.error) {
|
|
|
- this.formGroup.controls['name'].setValue(responseData.response.NAME);
|
|
|
- this.formGroup.controls['speciality'].setValue(responseData.response.SPECIALITY);
|
|
|
- } else {
|
|
|
- this._resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
- }
|
|
|
- }, (httpErrorResponse: HttpErrorResponse) => this._resourcesService.checkErrors(httpErrorResponse)
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
private async _getMembers(){
|
|
|
- let idWorkteamEnc = await this._encService.encrypt(`${this.idWorkteam}`);
|
|
|
- const USER = this._resourcesService.getUser();
|
|
|
- const LINE: number = this._resourcesService.getLineNumber();
|
|
|
- await lastValueFrom(this._workteamService.getMembersOfWorkteamById( idWorkteamEnc, USER, LINE )).then(
|
|
|
- (responseData: any) => {
|
|
|
- if (!responseData.error) {
|
|
|
- this.members = responseData.response;
|
|
|
- } else {
|
|
|
- this._resourcesService.openSnackBar(`${responseData.msg}`);
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let idWorkteamEnc = await this._encService.encrypt(this.idWorkteam);
|
|
|
+ let members = await lastValueFrom(this._workteamService.getMembersOfWorkteamById(
|
|
|
+ idWorkteamEnc,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ this.hasError = members.error;
|
|
|
+ this.errorStr = members.msg;
|
|
|
+
|
|
|
+ if(this.hasError){
|
|
|
+ this.isLoading = false;
|
|
|
+ }else{
|
|
|
+ let membersArr: any[] = [];
|
|
|
+ for(const member of members.response){
|
|
|
+ let idEmp = await this._encService.decrypt(member.IDEMPLEADO);
|
|
|
+ let idUsr = await this._encService.decrypt(member.IDUSUARIO);
|
|
|
+
|
|
|
+ member.NAME = `${member.NAME} (${idEmp}) (${idUsr})`,
|
|
|
+ membersArr.push(member);
|
|
|
}
|
|
|
- }, (httpErrorResponse: HttpErrorResponse) => this._resourcesService.checkErrors(httpErrorResponse)
|
|
|
- );
|
|
|
+
|
|
|
+ this.members = membersArr;
|
|
|
+ this.getSpecialties();
|
|
|
+ }
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado.';
|
|
|
+ }else{
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|