|
|
@@ -11,6 +11,11 @@ import { FunctionsService } from 'src/app/services/functions.service';
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
import { Router } from '@angular/router';
|
|
|
+import { Permissions } from 'src/app/interfaces/permissions.interface';
|
|
|
+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';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-families-management',
|
|
|
@@ -31,6 +36,9 @@ export class FamiliesManagementComponent implements OnInit {
|
|
|
@ViewChild(MatPaginator) paginator?: MatPaginator;
|
|
|
@ViewChild(MatSort) sort?: MatSort;
|
|
|
|
|
|
+ familyConsultEnabled: boolean;
|
|
|
+ familyRegisterEnabled: boolean;
|
|
|
+
|
|
|
constructor(
|
|
|
private _dialog: MatDialog,
|
|
|
private _encService: EncService,
|
|
|
@@ -38,6 +46,8 @@ export class FamiliesManagementComponent implements OnInit {
|
|
|
private _equipmentManagementService: EquipmentManagementService,
|
|
|
private _functionsService: FunctionsService,
|
|
|
private _router: Router,
|
|
|
+ private _socketService: SocketService,
|
|
|
+ private _usersProfilesService: UsersProfilesService,
|
|
|
) {
|
|
|
this.btnSmall = window.innerWidth <= 1405;
|
|
|
this.txtBuscador = '';
|
|
|
@@ -45,10 +55,67 @@ export class FamiliesManagementComponent implements OnInit {
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = "";
|
|
|
+
|
|
|
+ this.familyConsultEnabled = true;
|
|
|
+ this.familyRegisterEnabled = true;
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
this.getData();
|
|
|
+
|
|
|
+ this._socketService.refreshPermissions().subscribe(async (profUpdEnc) => {
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let usrInfo: UserConsultResponse = await lastValueFrom(this._usersProfilesService.getUser(idUser, idUser, 1));
|
|
|
+
|
|
|
+ if(usrInfo.error){
|
|
|
+ this._resourcesService.openSnackBar('ERR_NPE000: Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ let idProfDec = await this._encService.decrypt(usrInfo.response.PERFIL);
|
|
|
+ let currentProfile = await this._encService.decrypt(localStorage.getItem('perfil')!);
|
|
|
+
|
|
|
+ if(idProfDec != currentProfile){
|
|
|
+ this._router.navigate(['/sam/home']);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let profileUpdated = await this._encService.decrypt(`${profUpdEnc}`);
|
|
|
+ if(profileUpdated == currentProfile){
|
|
|
+ let profile = localStorage.getItem('perfil')!;
|
|
|
+ let profInfo: ProfileInterface = await lastValueFrom(this._usersProfilesService.getProfile(
|
|
|
+ profile,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ let permArr = await this._functionsService.processPermissions(profInfo.response.PERMISOS.permissions);
|
|
|
+ let modPerm = permArr.filter(item => item.id == 'S002V01M07GEEQ');
|
|
|
+ if(modPerm.length > 0){
|
|
|
+ let funPerm = modPerm[0].children.filter(item => item.id == 'S002V01F02DFSU');
|
|
|
+ if(funPerm.length > 0){
|
|
|
+ let familyConsultEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P01COFA');
|
|
|
+ if(familyConsultEnabled.length > 0){
|
|
|
+ this.familyConsultEnabled = familyConsultEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let familyRegisterEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P02REFA');
|
|
|
+ if(familyRegisterEnabled.length > 0){
|
|
|
+ this.familyRegisterEnabled = familyRegisterEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar('ERR_PAD001: Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar('ERR_PAD002: Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(`ERR_PAD003: ${error.error.msg}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
public onResize():void {
|
|
|
@@ -120,6 +187,33 @@ export class FamiliesManagementComponent implements OnInit {
|
|
|
this.dataSource = new MatTableDataSource(familiesArr);
|
|
|
this.dataSource.paginator = this.paginator!;
|
|
|
this.dataSource.sort = this.sort!;
|
|
|
+
|
|
|
+ let permissionsEnc = localStorage.getItem('permisos');
|
|
|
+ let permissionsDec = '';
|
|
|
+ if(permissionsEnc == '' || permissionsEnc == undefined || permissionsEnc == null){
|
|
|
+ permissionsDec = '[]';
|
|
|
+ }else{
|
|
|
+ permissionsDec = await this._encService.decrypt(permissionsEnc!);
|
|
|
+ }
|
|
|
+
|
|
|
+ let permissionsArr: Permissions = JSON.parse(permissionsDec);
|
|
|
+ if(permissionsArr.permissions != undefined){
|
|
|
+ let modPerm = permissionsArr.permissions.filter(item => item.id == 'S002V01M07GEEQ');
|
|
|
+ if(modPerm.length > 0){
|
|
|
+ let funPerm = modPerm[0].children.filter(item => item.id == 'S002V01F02DFSU');
|
|
|
+ if(funPerm.length > 0){
|
|
|
+ let familyConsultEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P01COFA');
|
|
|
+ if(familyConsultEnabled.length > 0){
|
|
|
+ this.familyConsultEnabled = familyConsultEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let familyRegisterEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P02REFA');
|
|
|
+ if(familyRegisterEnabled.length > 0){
|
|
|
+ this.familyRegisterEnabled = familyRegisterEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
this.isLoading = false;
|