|
|
@@ -10,6 +10,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { ResponseData } from 'src/app/interfaces/response-data';
|
|
|
import { PurchasePurpose } from 'src/app/interfaces/acquisition-management/purchase-purpose.interface';
|
|
|
+import { Permissions, PermissionsInterface } from 'src/app/interfaces/permissions.interface';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-acquisition-management',
|
|
|
@@ -17,39 +18,89 @@ import { PurchasePurpose } from 'src/app/interfaces/acquisition-management/purch
|
|
|
styleUrls: ['./acquisition-management.component.css']
|
|
|
})
|
|
|
export class AcquisitionManagementComponent implements OnInit {
|
|
|
+ isLoading: boolean;
|
|
|
+ hasError: boolean;
|
|
|
+ errorStr: string;
|
|
|
+ submodules: Submodules[];
|
|
|
+ submodulesAux: Submodules[];
|
|
|
|
|
|
- public arrSubmodules: Array<Submodules>;
|
|
|
- public isLoading: boolean;
|
|
|
- public hasError: boolean;
|
|
|
- public errorStr: string;
|
|
|
constructor(
|
|
|
- private _encService: EncService,
|
|
|
- public resourcesService: ResourcesService,
|
|
|
+ private _encService: EncService,
|
|
|
private _modulesService: ModulesService,
|
|
|
private _dialog: MatDialog,
|
|
|
private _router: Router,
|
|
|
) {
|
|
|
- this.arrSubmodules = [];
|
|
|
- this.isLoading = false;
|
|
|
+ this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = '';
|
|
|
+ this.submodules = [];
|
|
|
+ this.submodulesAux = [];
|
|
|
}
|
|
|
|
|
|
- async ngOnInit() {
|
|
|
- this.isLoading = true;
|
|
|
- const moduleEnc = await this._encService.encrypt('S002V01M05GEAD');
|
|
|
- const user: string = this.resourcesService.getUser();
|
|
|
- const line: number = this.resourcesService.getLineNumber();
|
|
|
- await lastValueFrom(this._modulesService.getSubmodules(moduleEnc, user, line)).then(
|
|
|
- (responseData: SubmodulesResponse) => {
|
|
|
- if (!responseData.error) {
|
|
|
- this.arrSubmodules = responseData.response;
|
|
|
- } else {
|
|
|
- this.errorStr = `${responseData.msg}`;
|
|
|
+ ngOnInit(): void {
|
|
|
+ this.getSubmodules();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getSubmodules(){
|
|
|
+ try{
|
|
|
+ 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);
|
|
|
+ let permFun: PermissionsInterface[] = [];
|
|
|
+ if(permissionsArr.permissions == undefined){
|
|
|
+ permFun = [];
|
|
|
+ }else{
|
|
|
+ permFun = permissionsArr.permissions.filter(item => item.id == 'S002V01M05GEAD');
|
|
|
+ }
|
|
|
+
|
|
|
+ let moduleEnc = await this._encService.encrypt('S002V01M05GEAD');
|
|
|
+ let idEnc = localStorage.getItem('idusuario')!;
|
|
|
+ let submodules: SubmodulesResponse = await lastValueFrom(this._modulesService.getSubmodules(
|
|
|
+ moduleEnc,
|
|
|
+ idEnc,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ this.hasError = submodules.error;
|
|
|
+ this.errorStr = submodules.msg;
|
|
|
+
|
|
|
+ if(!this.hasError){
|
|
|
+ for(const submodule of submodules.response){
|
|
|
+ let idSub = await this._encService.decrypt(submodule.IDSUBMODULO);
|
|
|
+ submodule.IDSUBMODULO = idSub;
|
|
|
+
|
|
|
+ if(permFun.length > 0){
|
|
|
+ let subm = permFun[0].children.filter(item2 => idSub == item2.id);
|
|
|
+ if(subm.length > 0){
|
|
|
+ if(subm[0].access > 0){
|
|
|
+ this.submodules.push(submodule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }, (httpErrorResponse:HttpErrorResponse) => this.errorStr = this.resourcesService.checkErrorsStr(httpErrorResponse)
|
|
|
- );
|
|
|
- this.isLoading = false;
|
|
|
+
|
|
|
+ this.submodulesAux = submodules.response;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public async openMenu(submodule: Submodules){
|