|
|
@@ -0,0 +1,120 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { ActivatedRoute } from '@angular/router';
|
|
|
+import { lastValueFrom } from 'rxjs';
|
|
|
+import { PermissionsInterface } from 'src/app/interfaces/permissions.interface';
|
|
|
+import { ProfileInterface } from 'src/app/interfaces/profile.interface';
|
|
|
+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';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-data-election-config',
|
|
|
+ templateUrl: './data-election-config.component.html',
|
|
|
+ styleUrl: './data-election-config.component.css'
|
|
|
+})
|
|
|
+export class DataElectionConfigComponent implements OnInit {
|
|
|
+ screenSize: number;
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
+
|
|
|
+ permissions: PermissionsInterface[];
|
|
|
+ exportPermissions: Map<string, boolean>;
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private _activatedRoute: ActivatedRoute,
|
|
|
+ private _resourcesService: ResourcesService,
|
|
|
+ private _usersProfilesService: UsersProfilesService,
|
|
|
+ private _encService: EncService,
|
|
|
+ ) {
|
|
|
+ this.screenSize = window.innerWidth;
|
|
|
+ this.isLoading = true;
|
|
|
+ this.hasError = false;
|
|
|
+ this.errorStr = '';
|
|
|
+
|
|
|
+ this.permissions = [];
|
|
|
+ this.exportPermissions = new Map();
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit(): void {
|
|
|
+ this._activatedRoute.queryParams.subscribe(params => {
|
|
|
+ let idProfile = params['data'];
|
|
|
+ if(idProfile == undefined){
|
|
|
+ this._resourcesService.openSnackBar('No se envió información.');
|
|
|
+ this.goBack(1);
|
|
|
+ }else{
|
|
|
+ this.getProfile(idProfile);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ goBack(steps: number){
|
|
|
+ window.history.go(steps * -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ onResize():void{
|
|
|
+ this.screenSize = window.innerWidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getProfile(idProfile: string){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let profile: ProfileInterface = await lastValueFrom(this._usersProfilesService.getProfile(idProfile, idUser, 1));
|
|
|
+
|
|
|
+ this.hasError = profile.error;
|
|
|
+ this.errorStr = profile.msg;
|
|
|
+
|
|
|
+ if(!this.hasError){
|
|
|
+ let permissionsArr: PermissionsInterface[] = [];
|
|
|
+ for(const permission of profile.response.PERMISOS.permissions){
|
|
|
+ permission.id = await this._encService.decrypt(permission.id);
|
|
|
+
|
|
|
+ let children: PermissionsInterface[] = [];
|
|
|
+ if(permission.children.length > 0){
|
|
|
+ children = await this.processChildren(permission.children);
|
|
|
+ permission.children = children;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(permission.access > 0){
|
|
|
+ permissionsArr.push(permission);
|
|
|
+ this.exportPermissions.set(permission.id, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.permissions = permissionsArr;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async processChildren(children: PermissionsInterface[]): Promise<PermissionsInterface[]>{
|
|
|
+ let childrenFn: PermissionsInterface[] = [];
|
|
|
+ for(const permission of children){
|
|
|
+ permission.id = await this._encService.decrypt(permission.id);
|
|
|
+
|
|
|
+ let grandChildren: PermissionsInterface[] = [];
|
|
|
+ if(permission.children != undefined){
|
|
|
+ grandChildren = await this.processChildren(permission.children);
|
|
|
+ permission.children = grandChildren;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(permission.access > 0){
|
|
|
+ childrenFn.push(permission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return childrenFn;
|
|
|
+ }
|
|
|
+}
|