|
|
@@ -1,8 +1,10 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
+import { ProfileExportPermissionsListItem, ProfileExportPermissionsListResponse } from 'src/app/interfaces/control-panel.interface';
|
|
|
import { PermissionsInterface } from 'src/app/interfaces/permissions.interface';
|
|
|
import { ProfileInterface } from 'src/app/interfaces/profile.interface';
|
|
|
+import { ControlPanelService } from 'src/app/services/control-panel.service';
|
|
|
import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
import { UsersProfilesService } from 'src/app/services/users-profiles.service';
|
|
|
@@ -17,23 +19,28 @@ export class DataElectionConfigComponent implements OnInit {
|
|
|
isLoading: boolean;
|
|
|
hasError: boolean;
|
|
|
errorStr: string;
|
|
|
+ idProfile: string;
|
|
|
|
|
|
permissions: PermissionsInterface[];
|
|
|
exportPermissions: Map<string, boolean>;
|
|
|
+ profileExportPermissions: ProfileExportPermissionsListItem[];
|
|
|
|
|
|
constructor(
|
|
|
private _activatedRoute: ActivatedRoute,
|
|
|
private _resourcesService: ResourcesService,
|
|
|
private _usersProfilesService: UsersProfilesService,
|
|
|
private _encService: EncService,
|
|
|
+ private _controlPanelService: ControlPanelService,
|
|
|
) {
|
|
|
this.screenSize = window.innerWidth;
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = '';
|
|
|
+ this.idProfile = '';
|
|
|
|
|
|
this.permissions = [];
|
|
|
this.exportPermissions = new Map();
|
|
|
+ this.profileExportPermissions = [];
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
@@ -43,11 +50,50 @@ export class DataElectionConfigComponent implements OnInit {
|
|
|
this._resourcesService.openSnackBar('No se envió información.');
|
|
|
this.goBack(1);
|
|
|
}else{
|
|
|
- this.getProfile(idProfile);
|
|
|
+ this.idProfile = idProfile;
|
|
|
+ this.getProfileExportPermissions(idProfile);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async getProfileExportPermissions(idProfile: string){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let profilePermissions: ProfileExportPermissionsListResponse = await lastValueFrom(this._controlPanelService.getProfileExportPermissions(
|
|
|
+ idProfile,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ this.hasError = profilePermissions.error;
|
|
|
+ this.errorStr = profilePermissions.msg;
|
|
|
+
|
|
|
+ if(this.hasError){
|
|
|
+ this.isLoading = false;
|
|
|
+ }else{
|
|
|
+ let profilePermissionsArr: ProfileExportPermissionsListItem[] = [];
|
|
|
+ for(const permission of profilePermissions.response){
|
|
|
+ permission.id = await this._encService.decrypt(permission.id);
|
|
|
+ profilePermissionsArr.push(permission);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.profileExportPermissions = profilePermissionsArr;
|
|
|
+ this.getProfile(idProfile);
|
|
|
+ }
|
|
|
+ }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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
goBack(steps: number){
|
|
|
window.history.go(steps * -1);
|
|
|
}
|
|
|
@@ -76,8 +122,14 @@ export class DataElectionConfigComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
if(permission.access > 0){
|
|
|
+ let exportAccess = false;
|
|
|
+ let accessFilt = this.profileExportPermissions.filter(item => item.id == permission.id);
|
|
|
+ if(accessFilt.length > 0){
|
|
|
+ exportAccess = accessFilt[0].value;
|
|
|
+ }
|
|
|
+
|
|
|
permissionsArr.push(permission);
|
|
|
- this.exportPermissions.set(permission.id, false);
|
|
|
+ this.exportPermissions.set(permission.id, exportAccess);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -99,7 +151,7 @@ export class DataElectionConfigComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async processChildren(children: PermissionsInterface[]): Promise<PermissionsInterface[]>{
|
|
|
+ private async processChildren(children: PermissionsInterface[]): Promise<PermissionsInterface[]>{
|
|
|
let childrenFn: PermissionsInterface[] = [];
|
|
|
for(const permission of children){
|
|
|
permission.id = await this._encService.decrypt(permission.id);
|
|
|
@@ -111,10 +163,66 @@ export class DataElectionConfigComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
if(permission.access > 0){
|
|
|
+ let exportAccess = false;
|
|
|
+ let accessFilt = this.profileExportPermissions.filter(item => item.id == permission.id);
|
|
|
+ if(accessFilt.length > 0){
|
|
|
+ exportAccess = accessFilt[0].value;
|
|
|
+ }
|
|
|
+
|
|
|
childrenFn.push(permission);
|
|
|
+ this.exportPermissions.set(permission.id, exportAccess);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return childrenFn;
|
|
|
}
|
|
|
+
|
|
|
+ permissionsChange(event: any, id: string, children: PermissionsInterface[] | undefined){
|
|
|
+ this.exportPermissions.set(id, event.checked);
|
|
|
+ if(children != undefined){
|
|
|
+ this.changeChildrenCheckStatus(children, event.checked);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private changeChildrenCheckStatus(children: PermissionsInterface[], status: boolean){
|
|
|
+ for(const child of children){
|
|
|
+ this.exportPermissions.set(child.id, status);
|
|
|
+ if(child.children != undefined && child.children.length > 0){
|
|
|
+ this.changeChildrenCheckStatus(child.children, status);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async saveExportPermissions(){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let profileExportPermissionsObj: any = {};
|
|
|
+
|
|
|
+ for(const [key, value] of this.exportPermissions){
|
|
|
+ profileExportPermissionsObj[key.trim()] = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ let profileExportPermissionsStr = JSON.stringify(profileExportPermissionsObj);
|
|
|
+ let profileExportPermissionsEnc = await this._encService.encrypt(profileExportPermissionsStr);
|
|
|
+ let formData = new FormData();
|
|
|
+
|
|
|
+ formData.append('id_user', idUser);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('permissions', profileExportPermissionsEnc);
|
|
|
+ formData.append('id_profile', this.idProfile);
|
|
|
+
|
|
|
+ await lastValueFrom(this._controlPanelService.saveProfileExportPermissions(formData));
|
|
|
+
|
|
|
+ this._resourcesService.openSnackBar('Los permisos se actualizaron correctamente.');
|
|
|
+ this.goBack(1);
|
|
|
+ }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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|