|
|
@@ -31,6 +31,7 @@ import { SocketService } from 'src/app/services/socket.service';
|
|
|
import { UserConsultResponse } from 'src/app/interfaces/user.interface';
|
|
|
import { UsersProfilesService } from 'src/app/services/users-profiles.service';
|
|
|
import { ProfileInterface } from 'src/app/interfaces/profile.interface';
|
|
|
+import { GroupPendingComponent } from './group-pending/group-pending.component';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-equipment-management',
|
|
|
@@ -42,6 +43,8 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
hasError: boolean;
|
|
|
errorStr: string;
|
|
|
params: any;
|
|
|
+ totalPending: number;
|
|
|
+ loadingPending: boolean;
|
|
|
|
|
|
pendingEquipments: PendingEquipmentsListItem[];
|
|
|
families: FamiliesListItem[];
|
|
|
@@ -90,6 +93,8 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
this.hasError = false;
|
|
|
this.errorStr = "";
|
|
|
this.params = null;
|
|
|
+ this.totalPending = 0;
|
|
|
+ this.loadingPending = false;
|
|
|
|
|
|
this.pendingEquipments = [];
|
|
|
this.families = [];
|
|
|
@@ -498,6 +503,21 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
}, 150);
|
|
|
}
|
|
|
|
|
|
+ addPendingEquipmentsScrollListener(){
|
|
|
+ setTimeout(() => {
|
|
|
+ let equipmentList = this._document.getElementById('pending-equipments-list')!;
|
|
|
+ equipmentList.addEventListener('scroll', (event: any) => {
|
|
|
+ let delta = equipmentList.scrollHeight - equipmentList.scrollTop;
|
|
|
+ if(delta < 400 && !this.loadingPending){
|
|
|
+ let offset = this.pendingEquipments.length;
|
|
|
+ if(offset < this.totalPending){
|
|
|
+ this.consultPendingEquipments(offset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
async openGraphicArborescence(){
|
|
|
let arborescenceStr = JSON.stringify(this.graphicArborescence);
|
|
|
let arborescenceEnc = await this._encService.encrypt(arborescenceStr);
|
|
|
@@ -583,18 +603,56 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- async getPendingEquipments(){
|
|
|
+ async getTotalPendingEquipments(){
|
|
|
try{
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+ this.totalPending = 0;
|
|
|
+ this.pendingEquipments = [];
|
|
|
+
|
|
|
let idUser = localStorage.getItem('idusuario')!;
|
|
|
- let pendingEquipments: PendingEquipmentsListResponse = await lastValueFrom(this._equipmentManagementService.equipmentConsultPending(idUser, 1));
|
|
|
+ let pendingTotal = await lastValueFrom(this._equipmentManagementService.equipmentConsultPendingTotal(idUser, 1));
|
|
|
|
|
|
- this.hasError = pendingEquipments.error;
|
|
|
- this.errorStr = pendingEquipments.msg;
|
|
|
+ this.hasError = pendingTotal.error;
|
|
|
+ this.errorStr = pendingTotal.msg;
|
|
|
|
|
|
if(!this.hasError){
|
|
|
- let equipments: PendingEquipmentsListItem[] = [];
|
|
|
+ this.totalPending = pendingTotal.response.TOTAL;
|
|
|
+ this.consultPendingEquipments(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.isLoading = false;
|
|
|
+ this.scrollArborescence();
|
|
|
+ this.addPendingEquipmentsScrollListener();
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado (3).';
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.errorStr = 'Ocurrió un error inesperado (4).';
|
|
|
+ }else{
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
+ }
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async consultPendingEquipments(offset: number){
|
|
|
+ try{
|
|
|
+ this.loadingPending = true;
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let pendingEquipments: PendingEquipmentsListResponse = await lastValueFrom(this._equipmentManagementService.equipmentConsultPending(
|
|
|
+ offset,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ if(pendingEquipments.error){
|
|
|
+ this._resourcesService.openSnackBar(pendingEquipments.msg);
|
|
|
+ }else{
|
|
|
for(const equipment of pendingEquipments.response){
|
|
|
-
|
|
|
equipment.CODIGO = await this._encService.decrypt(equipment.CODIGO);
|
|
|
equipment.TIPO_EQUIPAMIENTO = await this._encService.decrypt(equipment.TIPO_EQUIPAMIENTO);
|
|
|
equipment.MODELO_EQUIPAMIENTO = await this._encService.decrypt(equipment.MODELO_EQUIPAMIENTO);
|
|
|
@@ -607,24 +665,21 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
equipment.GALERIA_IMAGENES = gallery;
|
|
|
- equipments.push(equipment);
|
|
|
+ this.pendingEquipments.push(equipment);
|
|
|
}
|
|
|
-
|
|
|
- this.pendingEquipments = equipments;
|
|
|
}
|
|
|
|
|
|
- this.isLoading = false;
|
|
|
- this.scrollArborescence();
|
|
|
+ this.loadingPending = false;
|
|
|
}catch(error: any){
|
|
|
if(error.error == undefined){
|
|
|
- this.errorStr = 'Ocurrió un error inesperado (3).';
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else if(error.error.msg == undefined){
|
|
|
- this.errorStr = 'Ocurrió un error inesperado (4).';
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else{
|
|
|
- this.errorStr = error.error.msg;
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
}
|
|
|
- this.hasError = true;
|
|
|
- this.isLoading = false;
|
|
|
+
|
|
|
+ this.loadingPending = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -658,7 +713,7 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
|
|
|
this.families = familiesArr;
|
|
|
if(searchPending){
|
|
|
- this.getPendingEquipments();
|
|
|
+ this.getTotalPendingEquipments();
|
|
|
}
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
@@ -706,7 +761,7 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
|
|
|
this.subfamilies = subfamiliesArr;
|
|
|
if(searchPending){
|
|
|
- this.getPendingEquipments();
|
|
|
+ this.getTotalPendingEquipments();
|
|
|
}
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
@@ -759,7 +814,7 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
|
|
|
this.equipmentsBySubfamily = equipments;
|
|
|
if(searchPending){
|
|
|
- this.getPendingEquipments();
|
|
|
+ this.getTotalPendingEquipments();
|
|
|
}
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
@@ -958,7 +1013,7 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
this.parentEquipmentDetails = equipment.response;
|
|
|
- this.getPendingEquipments();
|
|
|
+ this.getTotalPendingEquipments();
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
console.log(error);
|
|
|
@@ -976,7 +1031,7 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
|
|
|
shouldRefresh(event: any){
|
|
|
if(event == 'refresh'){
|
|
|
- this.getPendingEquipments();
|
|
|
+ this.getTotalPendingEquipments();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1139,4 +1194,48 @@ export class EquipmentManagementComponent implements OnInit {
|
|
|
navigateToArborescenceCalendar(){
|
|
|
this._router.navigate(['sam/GEEQ/ADEQ/VAFD']);
|
|
|
}
|
|
|
+
|
|
|
+ openPendingGroups(action: string){
|
|
|
+ let dialogRef = this._dialog.open(GroupPendingComponent, {
|
|
|
+ disableClose: true,
|
|
|
+ width: '480px',
|
|
|
+ data: {
|
|
|
+ action: action,
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ dialogRef.afterClosed().subscribe(res => {
|
|
|
+ if(res != null && res != undefined && res != ''){
|
|
|
+ this.changeGroupStatus(res, action);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private async changeGroupStatus(groupCode: string, action: string){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let formData = new FormData();
|
|
|
+ let newStatus = action == 'decline' ? 'Rechazado' : 'Aprobado';
|
|
|
+ let codeDec = await this._encService.decrypt(groupCode);
|
|
|
+
|
|
|
+ formData.append('id_user', idUser);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('code', groupCode);
|
|
|
+ formData.append('status', newStatus);
|
|
|
+ formData.append('comments', 'test aaaaaaaaaaaaaaa');
|
|
|
+
|
|
|
+ await lastValueFrom(this._equipmentManagementService.equipmentPreCodificationGroupStatusUpdate(formData));
|
|
|
+
|
|
|
+ this._resourcesService.openSnackBar(`El grupo de equipos ${codeDec} fue ${newStatus} correctamente.`);
|
|
|
+ this.getTotalPendingEquipments();
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|