|
|
@@ -27,6 +27,12 @@ import { DOCUMENT } from '@angular/common';
|
|
|
import { ShareFileComponent } from './share-file/share-file.component';
|
|
|
import { AccessDialogComponent } from './access-dialog/access-dialog.component';
|
|
|
import { OrderAssociatonComponent } from './order-associaton/order-associaton.component';
|
|
|
+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';
|
|
|
+import { FunctionsService } from 'src/app/services/functions.service';
|
|
|
|
|
|
export interface FoundedFiles{
|
|
|
CODIGO: string;
|
|
|
@@ -85,13 +91,24 @@ export class GDELComponent implements OnInit {
|
|
|
isFromModule: boolean;
|
|
|
module: string;
|
|
|
|
|
|
+ documentsManagementEnabled: boolean;
|
|
|
+ documentsViewerEnabled: boolean;
|
|
|
+ documentsEditorEnabled: boolean;
|
|
|
+ shareDocumentsEnabled: boolean;
|
|
|
+ registerDocumentsEnabled: boolean;
|
|
|
+ versionsHistoryEnabled: boolean;
|
|
|
+
|
|
|
constructor(
|
|
|
@Inject(DOCUMENT) private _document: Document,
|
|
|
private _encService: EncService,
|
|
|
private _dialog: MatDialog,
|
|
|
private _gdelService: GdelService,
|
|
|
- private _snackBar: MatSnackBar,
|
|
|
private _activatedRoute: ActivatedRoute,
|
|
|
+ private _resourcesService: ResourcesService,
|
|
|
+ private _socketService: SocketService,
|
|
|
+ private _usersProfilesService: UsersProfilesService,
|
|
|
+ private _router: Router,
|
|
|
+ private _functionsService: FunctionsService,
|
|
|
) {
|
|
|
this.btnSmall = false;
|
|
|
this.isLoading = true;
|
|
|
@@ -112,9 +129,91 @@ export class GDELComponent implements OnInit {
|
|
|
|
|
|
this.isFromModule = false;
|
|
|
this.module = '';
|
|
|
+
|
|
|
+ this.documentsManagementEnabled = true;
|
|
|
+ this.documentsViewerEnabled = true;
|
|
|
+ this.documentsEditorEnabled = true;
|
|
|
+ this.shareDocumentsEnabled = true;
|
|
|
+ this.registerDocumentsEnabled = true;
|
|
|
+ this.versionsHistoryEnabled = true;
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
+ this.initPermissions();
|
|
|
+ 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 == 'S002V01M04GDEL');
|
|
|
+ if(modPerm.length > 0){
|
|
|
+ let funPerm = modPerm[0].children.filter(item => item.id == 'S002V01F01ADDO');
|
|
|
+ if(funPerm.length > 0){
|
|
|
+ let documentsManagementEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P01GEDO');
|
|
|
+ if(documentsManagementEnabled.length > 0){
|
|
|
+ this.documentsManagementEnabled = documentsManagementEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let documentsViewerEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P02VIDO');
|
|
|
+ if(documentsViewerEnabled.length > 0){
|
|
|
+ this.documentsViewerEnabled = documentsViewerEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let documentsEditorEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P03EDDO');
|
|
|
+ if(documentsEditorEnabled.length > 0){
|
|
|
+ this.documentsEditorEnabled = documentsEditorEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let shareDocumentsEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P04CODO');
|
|
|
+ if(shareDocumentsEnabled.length > 0){
|
|
|
+ this.shareDocumentsEnabled = shareDocumentsEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let registerDocumentsEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P05REDO');
|
|
|
+ if(registerDocumentsEnabled.length > 0){
|
|
|
+ this.registerDocumentsEnabled = registerDocumentsEnabled[0].access > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let versionsHistoryEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P06HIVE');
|
|
|
+ if(versionsHistoryEnabled.length > 0){
|
|
|
+ this.versionsHistoryEnabled = versionsHistoryEnabled[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}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
this.moduleControl.valueChanges.subscribe(mod => {
|
|
|
let cla = this.clasificationControl.value;
|
|
|
let sda = this.startDate;
|
|
|
@@ -246,6 +345,28 @@ export class GDELComponent implements OnInit {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async initPermissions(){
|
|
|
+ try{
|
|
|
+ let permissionsEnc = localStorage.getItem('permisos');
|
|
|
+ let permissionsDec = await this._encService.decrypt(permissionsEnc!);
|
|
|
+ let permissionsArr: Permissions = JSON.parse(permissionsDec);
|
|
|
+
|
|
|
+ let modPerm = permissionsArr.permissions.filter(item => item.id == 'S002V01M04GDEL')[0];
|
|
|
+ let funPerm = modPerm.children.filter(item => item.id == 'S002V01F01ADDO')[0];
|
|
|
+
|
|
|
+ this.documentsManagementEnabled = funPerm.children.filter(item => item.id == 'S002V01P01GEDO')[0].access > 0;
|
|
|
+ this.documentsViewerEnabled = funPerm.children.filter(item => item.id == 'S002V01P02VIDO')[0].access > 0;
|
|
|
+ this.documentsEditorEnabled = funPerm.children.filter(item => item.id == 'S002V01P03EDDO')[0].access > 0;
|
|
|
+ this.shareDocumentsEnabled = funPerm.children.filter(item => item.id == 'S002V01P04CODO')[0].access > 0;
|
|
|
+ this.registerDocumentsEnabled = funPerm.children.filter(item => item.id == 'S002V01P05REDO')[0].access > 0;
|
|
|
+ this.versionsHistoryEnabled = funPerm.children.filter(item => item.id == 'S002V01P06HIVE')[0].access > 0;
|
|
|
+ console.log(this.documentsManagementEnabled);
|
|
|
+ }catch(error: any){
|
|
|
+ this._resourcesService.openSnackBar('Hubo un error al obtener los permisos del módulo.');
|
|
|
+ this.documentsManagementEnabled = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async getFiles(module: string | undefined, clas: string | undefined, startDate: Date | null, endDate: Date | null, name: string | undefined, type: string | undefined){
|
|
|
try{
|
|
|
this.isLoading = true;
|
|
|
@@ -314,12 +435,6 @@ export class GDELComponent implements OnInit {
|
|
|
return `${year}${month}${day}`;
|
|
|
}
|
|
|
|
|
|
- openSnackBar(msg: string){
|
|
|
- this._snackBar.open(msg, undefined, {
|
|
|
- duration: 2500,
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
formatBytes(bytes: number, decimals = 2) {
|
|
|
if (bytes === 0) return '0 Bytes';
|
|
|
|
|
|
@@ -401,7 +516,7 @@ export class GDELComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
openUploadDialog(){
|
|
|
- if(!this.isFromModule){
|
|
|
+ if(!this.isFromModule && this.registerDocumentsEnabled){
|
|
|
let dialogRef = this._dialog.open(UploadDialogComponent, {
|
|
|
width: '480px',
|
|
|
disableClose: true,
|
|
|
@@ -425,7 +540,7 @@ export class GDELComponent implements OnInit {
|
|
|
async downloadFile(code: string, version: string, name: string){
|
|
|
try{
|
|
|
let idFile = `${code}=${version}=${name}`;
|
|
|
- this.openSnackBar(`Iniciando la descarga del archivo ${idFile}...`);
|
|
|
+ this._resourcesService.openSnackBar(`Iniciando la descarga del archivo ${idFile}...`);
|
|
|
|
|
|
let idFileEnc = await this._encService.encrypt(idFile);
|
|
|
let download = this._document.getElementById(`download`) as HTMLAnchorElement;
|
|
|
@@ -442,11 +557,11 @@ export class GDELComponent implements OnInit {
|
|
|
download.click();
|
|
|
}catch(error: any){
|
|
|
if(error.error == undefined){
|
|
|
- this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else if(error.error.msg == undefined){
|
|
|
- this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else{
|
|
|
- this.openSnackBar(error.error.msg);
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -454,7 +569,7 @@ export class GDELComponent implements OnInit {
|
|
|
async openViewer(code: string, version: string, name: string) {
|
|
|
try{
|
|
|
let idFile = `${code}=${version}=${name}`;
|
|
|
- this.openSnackBar(`Abriendo el archivo ${idFile}...`);
|
|
|
+ this._resourcesService.openSnackBar(`Abriendo el archivo ${idFile}...`);
|
|
|
|
|
|
let idFileEnc = await this._encService.encrypt(idFile);
|
|
|
let idUser = localStorage.getItem('idusuario')!;
|
|
|
@@ -475,11 +590,11 @@ export class GDELComponent implements OnInit {
|
|
|
});
|
|
|
}catch(error: any){
|
|
|
if(error.error == undefined){
|
|
|
- this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else if(error.error.msg == undefined){
|
|
|
- this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else{
|
|
|
- this.openSnackBar(error.error.msg);
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -501,7 +616,7 @@ export class GDELComponent implements OnInit {
|
|
|
|
|
|
async updateFilePermissions(idFile: string, permissions: string){
|
|
|
try{
|
|
|
- this.openSnackBar(`Actualizando permisos del archivo ${idFile}`);
|
|
|
+ this._resourcesService.openSnackBar(`Actualizando permisos del archivo ${idFile}`);
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = '';
|
|
|
@@ -516,7 +631,7 @@ export class GDELComponent implements OnInit {
|
|
|
formData.append('permissions', permissions);
|
|
|
|
|
|
await lastValueFrom(this._gdelService.updateFilePermissions(formData));
|
|
|
- this.openSnackBar(`Los permisos se actualizaron correctamente`);
|
|
|
+ this._resourcesService.openSnackBar(`Los permisos se actualizaron correctamente`);
|
|
|
|
|
|
let mod = this.moduleControl.value;
|
|
|
let cla = this.clasificationControl.value;
|
|
|
@@ -594,7 +709,7 @@ export class GDELComponent implements OnInit {
|
|
|
formData.append('linea', '1');
|
|
|
|
|
|
await lastValueFrom(this._gdelService.deleteFile(formData));
|
|
|
- this.openSnackBar('El archivo se eliminó correctamente.');
|
|
|
+ this._resourcesService.openSnackBar('El archivo se eliminó correctamente.');
|
|
|
|
|
|
let mod = this.moduleControl.value;
|
|
|
let cla = this.clasificationControl.value;
|
|
|
@@ -606,11 +721,11 @@ export class GDELComponent implements OnInit {
|
|
|
this.getFiles(mod, cla, sda, eda, dna, ext);
|
|
|
}catch(error: any){
|
|
|
if(error.error == undefined){
|
|
|
- this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else if(error.error.msg == undefined){
|
|
|
- this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
}else{
|
|
|
- this.openSnackBar(error.error.msg);
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
}
|
|
|
}
|
|
|
}
|