gdel.component.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. import {
  2. Component,
  3. ViewChild,
  4. OnInit,
  5. ElementRef,
  6. Inject,
  7. } from '@angular/core';
  8. import { MatDialog } from '@angular/material/dialog';
  9. import { MatPaginator } from '@angular/material/paginator';
  10. import { MatSort } from '@angular/material/sort';
  11. import { MatTableDataSource } from '@angular/material/table';
  12. import { ActivatedRoute, Router } from '@angular/router';
  13. import { AlertComponent } from 'src/app/components/resources/dialogs/alert/alert.component';
  14. import { EncService } from 'src/app/services/enc/enc.service';
  15. import { ResourcesService } from 'src/app/services/resources/resources.service';
  16. import { lastValueFrom } from 'rxjs';
  17. import { WebviewerComponent } from './webviewer/webviewer.component';
  18. import { MatSnackBar } from '@angular/material/snack-bar';
  19. import { GdelService } from 'src/app/services/document-management/gdel.service';
  20. import { docClassification, modules, supportedFiles } from 'src/environments/environment.prod';
  21. import { DateRangePickerComponent } from './date-range-picker/date-range-picker.component';
  22. import { FormControl } from '@angular/forms';
  23. import { FindedFile, FindedFilesResponse } from 'src/app/interfaces/finded-files.interface';
  24. import { UploadDialogComponent } from './upload-dialog/upload-dialog.component';
  25. import { DOCUMENT } from '@angular/common';
  26. import { ShareFileComponent } from './share-file/share-file.component';
  27. import { AccessDialogComponent } from './access-dialog/access-dialog.component';
  28. import { OrderAssociatonComponent } from './order-associaton/order-associaton.component';
  29. import { Permissions } from 'src/app/interfaces/permissions.interface';
  30. import { SocketService } from 'src/app/services/socket.service';
  31. import { UserConsultResponse } from 'src/app/interfaces/user.interface';
  32. import { UsersProfilesService } from 'src/app/services/users-profiles.service';
  33. import { ProfileInterface } from 'src/app/interfaces/profile.interface';
  34. import { FunctionsService } from 'src/app/services/functions.service';
  35. export interface FoundedFiles{
  36. CODIGO: string;
  37. VERSION: string;
  38. NOMBRE: string;
  39. TAMANIO: string;
  40. USRREG: string;
  41. ACCESO: UsersAccess[];
  42. }
  43. export interface UsersAccess{
  44. userLabel: string;
  45. userName: string;
  46. userColor: string;
  47. isTrigger: boolean;
  48. }
  49. @Component({
  50. selector: 'app-gdel',
  51. templateUrl: './gdel.component.html',
  52. styleUrls: ['./gdel.component.css'],
  53. })
  54. export class GDELComponent implements OnInit {
  55. public btnSmall: boolean;
  56. isLoading: boolean;
  57. hasError: boolean;
  58. errorStr: string;
  59. category: string;
  60. modulesArr = modules;
  61. clasificationsArr = docClassification;
  62. supportedFilesArr = supportedFiles;
  63. startDate: Date | null;
  64. endDate: Date | null;
  65. @ViewChild('dateRange') dateRange?: ElementRef;
  66. @ViewChild(MatPaginator) paginator!: MatPaginator;
  67. @ViewChild(MatSort) sort!: MatSort;
  68. moduleControl: FormControl;
  69. clasificationControl: FormControl;
  70. fileNameControl: FormControl;
  71. fileTypeControl: FormControl;
  72. datesRangeControl: FormControl;
  73. files: FindedFile[];
  74. dataSource: MatTableDataSource<FoundedFiles>;
  75. displayedColumns = ['CODIGO', 'VERSION', 'NOMBRE', 'TAMANIO', 'USRREG', 'ACCESO', 'ACCIONES'];
  76. avatarColors = {
  77. A: 244, B: 67, C: 54, D: 233, E: 30, F: 99, G: 156, H: 39, I: 176,
  78. J: 103, K: 58, L: 58, M: 183, N: 63, Ñ: 81, O: 181, P: 33, Q: 150,
  79. R: 243, S: 3, T: 169, U: 244, V: 76, W: 175, X: 80, Y: 255, Z: 193
  80. };
  81. isFromModule: boolean;
  82. module: string;
  83. documentsManagementEnabled: boolean;
  84. documentsViewerEnabled: boolean;
  85. documentsEditorEnabled: boolean;
  86. shareDocumentsEnabled: boolean;
  87. registerDocumentsEnabled: boolean;
  88. versionsHistoryEnabled: boolean;
  89. constructor(
  90. @Inject(DOCUMENT) private _document: Document,
  91. private _encService: EncService,
  92. private _dialog: MatDialog,
  93. private _gdelService: GdelService,
  94. private _activatedRoute: ActivatedRoute,
  95. private _resourcesService: ResourcesService,
  96. private _socketService: SocketService,
  97. private _usersProfilesService: UsersProfilesService,
  98. private _router: Router,
  99. private _functionsService: FunctionsService,
  100. ) {
  101. this.btnSmall = false;
  102. this.isLoading = true;
  103. this.hasError = true;
  104. this.errorStr = '';
  105. this.category = 'my-files';
  106. this.startDate = null;
  107. this.endDate = null;
  108. this.moduleControl = new FormControl('');
  109. this.clasificationControl = new FormControl('');
  110. this.fileNameControl = new FormControl('');
  111. this.fileTypeControl = new FormControl('');
  112. this.datesRangeControl = new FormControl('');
  113. this.dataSource = new MatTableDataSource();
  114. this.files = [];
  115. this.isFromModule = false;
  116. this.module = '';
  117. this.documentsManagementEnabled = true;
  118. this.documentsViewerEnabled = true;
  119. this.documentsEditorEnabled = true;
  120. this.shareDocumentsEnabled = true;
  121. this.registerDocumentsEnabled = true;
  122. this.versionsHistoryEnabled = true;
  123. }
  124. ngOnInit(): void {
  125. this.initPermissions();
  126. this._socketService.refreshPermissions().subscribe(async (profUpdEnc) => {
  127. try{
  128. let idUser = localStorage.getItem('idusuario')!;
  129. let usrInfo: UserConsultResponse = await lastValueFrom(this._usersProfilesService.getUser(idUser, idUser, 1));
  130. if(usrInfo.error){
  131. this._resourcesService.openSnackBar('ERR_NPE000: Ocurrió un error inesperado.');
  132. }else{
  133. let idProfDec = await this._encService.decrypt(usrInfo.response.PERFIL);
  134. let currentProfile = await this._encService.decrypt(localStorage.getItem('perfil')!);
  135. if(idProfDec != currentProfile){
  136. this._router.navigate(['/sam/home']);
  137. return;
  138. }
  139. let profileUpdated = await this._encService.decrypt(`${profUpdEnc}`);
  140. if(profileUpdated == currentProfile){
  141. let profile = localStorage.getItem('perfil')!;
  142. let profInfo: ProfileInterface = await lastValueFrom(this._usersProfilesService.getProfile(
  143. profile,
  144. idUser,
  145. 1
  146. ));
  147. let permArr = await this._functionsService.processPermissions(profInfo.response.PERMISOS.permissions);
  148. let modPerm = permArr.filter(item => item.id == 'S002V01M04GDEL');
  149. if(modPerm.length > 0){
  150. let funPerm = modPerm[0].children.filter(item => item.id == 'S002V01F01ADDO');
  151. if(funPerm.length > 0){
  152. let documentsManagementEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P01GEDO');
  153. if(documentsManagementEnabled.length > 0){
  154. this.documentsManagementEnabled = documentsManagementEnabled[0].access > 0;
  155. }
  156. let documentsViewerEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P02VIDO');
  157. if(documentsViewerEnabled.length > 0){
  158. this.documentsViewerEnabled = documentsViewerEnabled[0].access > 0;
  159. }
  160. let documentsEditorEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P03EDDO');
  161. if(documentsEditorEnabled.length > 0){
  162. this.documentsEditorEnabled = documentsEditorEnabled[0].access > 0;
  163. }
  164. let shareDocumentsEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P04CODO');
  165. if(shareDocumentsEnabled.length > 0){
  166. this.shareDocumentsEnabled = shareDocumentsEnabled[0].access > 0;
  167. }
  168. let registerDocumentsEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P05REDO');
  169. if(registerDocumentsEnabled.length > 0){
  170. this.registerDocumentsEnabled = registerDocumentsEnabled[0].access > 0;
  171. }
  172. let versionsHistoryEnabled = funPerm[0].children.filter(item => item.id == 'S002V01P06HIVE');
  173. if(versionsHistoryEnabled.length > 0){
  174. this.versionsHistoryEnabled = versionsHistoryEnabled[0].access > 0;
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }catch(error: any){
  181. if(error.error == undefined){
  182. this._resourcesService.openSnackBar('ERR_PAD001: Ocurrió un error inesperado.');
  183. }else if(error.error.msg == undefined){
  184. this._resourcesService.openSnackBar('ERR_PAD002: Ocurrió un error inesperado.');
  185. }else{
  186. this._resourcesService.openSnackBar(`ERR_PAD003: ${error.error.msg}`);
  187. }
  188. }
  189. });
  190. this.moduleControl.valueChanges.subscribe(mod => {
  191. let cla = this.clasificationControl.value;
  192. let sda = this.startDate;
  193. let eda = this.endDate;
  194. let dna = this.fileNameControl.value;
  195. let ext = this.fileTypeControl.value;
  196. this.getFiles(mod, cla, sda, eda, dna, ext);
  197. });
  198. this.clasificationControl.valueChanges.subscribe(cla => {
  199. let mod = this.moduleControl.value;
  200. let sda = this.startDate;
  201. let eda = this.endDate;
  202. let dna = this.fileNameControl.value;
  203. let ext = this.fileTypeControl.value;
  204. this.getFiles(mod, cla, sda, eda, dna, ext);
  205. });
  206. this.fileNameControl.valueChanges.subscribe(dna => {
  207. let mod = this.moduleControl.value;
  208. let cla = this.clasificationControl.value;
  209. let sda = this.startDate;
  210. let eda = this.endDate;
  211. let ext = this.fileTypeControl.value;
  212. this.getFiles(mod, cla, sda, eda, dna, ext);
  213. });
  214. this.fileTypeControl.valueChanges.subscribe(ext => {
  215. let mod = this.moduleControl.value;
  216. let cla = this.clasificationControl.value;
  217. let sda = this.startDate;
  218. let eda = this.endDate;
  219. let dna = this.fileNameControl.value;
  220. this.getFiles(mod, cla, sda, eda, dna, ext);
  221. });
  222. this._activatedRoute.queryParams.subscribe(params => {
  223. let module = params['module'];
  224. if(module != undefined && module != null && module != ''){
  225. this.isFromModule = true;
  226. this.module = module;
  227. this.moduleControl.disable();
  228. this.moduleControl.setValue(module);
  229. }
  230. this.getFiles(
  231. this.moduleControl.value,
  232. this.clasificationControl.value,
  233. this.startDate,
  234. this.endDate,
  235. this.fileNameControl.value,
  236. this.fileTypeControl.value
  237. );
  238. });
  239. }
  240. public onResize(): void {
  241. this.btnSmall = window.innerWidth <= 1573;
  242. }
  243. updateCategory(category: string){
  244. let mod = this.moduleControl.value;
  245. let cla = this.clasificationControl.value;
  246. let sda = this.startDate;
  247. let eda = this.endDate;
  248. let dna = this.fileNameControl.value;
  249. let ext = this.fileTypeControl.value;
  250. this.category = category;
  251. this.getFiles(mod, cla, sda, eda, dna, ext);
  252. }
  253. openDateRangePicker(){
  254. let dialogRef = this._dialog.open(DateRangePickerComponent, {
  255. disableClose: true,
  256. width: '480px',
  257. data: {
  258. startDate: this.startDate,
  259. endDate: this.endDate
  260. }
  261. });
  262. dialogRef.afterClosed().subscribe(res => {
  263. if(res != null && res != undefined && res != ''){
  264. let resObj = JSON.parse(res);
  265. let dateRange = "";
  266. if(resObj.startDate != null || resObj.endDate != null){
  267. if(resObj.startDate != null){
  268. let startDateTimeArr = resObj.startDate.split('T');
  269. let startDateArr = startDateTimeArr[0].split('-').reverse();
  270. let startDateStr = startDateArr.join('/');
  271. this.startDate = new Date(resObj.startDate);
  272. dateRange += `desde ${startDateStr}, `;
  273. }
  274. if(resObj.endDate != null){
  275. let endDateTimeArr = resObj.endDate.split('T');
  276. let endDateArr = endDateTimeArr[0].split('-').reverse();
  277. let endDateStr = endDateArr.join('/');
  278. this.endDate = new Date(resObj.endDate);
  279. dateRange += `hasta ${endDateStr}, `;
  280. }
  281. let fl = dateRange[0].toUpperCase();
  282. let dateRangeArr = dateRange.split("");
  283. dateRangeArr[0] = fl;
  284. dateRange = dateRangeArr.join("");
  285. dateRange = dateRange.substring(0, dateRange.length - 2);
  286. this.dateRange!.nativeElement.value = dateRange;
  287. this.getFiles(
  288. this.moduleControl.value,
  289. this.clasificationControl.value,
  290. this.startDate,
  291. this.endDate,
  292. this.fileNameControl.value,
  293. this.fileTypeControl.value,
  294. );
  295. }
  296. }
  297. });
  298. }
  299. async initPermissions(){
  300. try{
  301. let permissionsEnc = localStorage.getItem('permisos');
  302. let permissionsDec = await this._encService.decrypt(permissionsEnc!);
  303. let permissionsArr: Permissions = JSON.parse(permissionsDec);
  304. let modPerm = permissionsArr.permissions.filter(item => item.id == 'S002V01M04GDEL')[0];
  305. let funPerm = modPerm.children.filter(item => item.id == 'S002V01F01ADDO')[0];
  306. this.documentsManagementEnabled = funPerm.children.filter(item => item.id == 'S002V01P01GEDO')[0].access > 0;
  307. this.documentsViewerEnabled = funPerm.children.filter(item => item.id == 'S002V01P02VIDO')[0].access > 0;
  308. this.documentsEditorEnabled = funPerm.children.filter(item => item.id == 'S002V01P03EDDO')[0].access > 0;
  309. this.shareDocumentsEnabled = funPerm.children.filter(item => item.id == 'S002V01P04CODO')[0].access > 0;
  310. this.registerDocumentsEnabled = funPerm.children.filter(item => item.id == 'S002V01P05REDO')[0].access > 0;
  311. this.versionsHistoryEnabled = funPerm.children.filter(item => item.id == 'S002V01P06HIVE')[0].access > 0;
  312. console.log(this.documentsManagementEnabled);
  313. }catch(error: any){
  314. this._resourcesService.openSnackBar('Hubo un error al obtener los permisos del módulo.');
  315. this.documentsManagementEnabled = false;
  316. }
  317. }
  318. async getFiles(module: string | undefined, clas: string | undefined, startDate: Date | null, endDate: Date | null, name: string | undefined, type: string | undefined){
  319. try{
  320. this.isLoading = true;
  321. this.hasError = false;
  322. this.errorStr = "";
  323. let mod = module == undefined || module == '' ? '-' : module;
  324. let cla = clas == undefined || clas == '' ? '-' : clas;
  325. let sda = startDate == null ? '-' : this.formatSearchDate(startDate);
  326. let eda = endDate == null ? '-' : this.formatSearchDate(endDate);
  327. let dna = name == undefined || name == '' ? '-' : name;
  328. let ext = type == undefined || type == '' ? '-' : JSON.stringify(type.split(','));
  329. let idUser = localStorage.getItem('idusuario')!;
  330. let files: FindedFilesResponse = await lastValueFrom(this._gdelService.getFiles(
  331. mod, cla, sda, eda, dna, ext, this.category, idUser, 1
  332. ));
  333. this.hasError = files.error;
  334. this.errorStr = files.msg;
  335. if(!this.hasError){
  336. this.files = files.response;
  337. let filesFound: FoundedFiles[] = [];
  338. files.response.forEach(file => {
  339. let fileSize = this.formatBytes(file.TAMANIO as number);
  340. let fileAccess = this.getUsersAccess(file.ACCESO);
  341. let fileObj: FoundedFiles = {
  342. CODIGO: file.CODIGO,
  343. VERSION: file.VERSION,
  344. NOMBRE: file.NOMBRE,
  345. TAMANIO: fileSize,
  346. USRREG: file.USRREG,
  347. ACCESO: fileAccess,
  348. };
  349. filesFound.push(fileObj);
  350. });
  351. this.dataSource = new MatTableDataSource(filesFound);
  352. this.dataSource.paginator = this.paginator;
  353. this.dataSource.sort = this.sort;
  354. }
  355. this.isLoading = false;
  356. }catch(error: any){
  357. if(error.error == undefined){
  358. this.errorStr = 'Ocurrió un error inesperado.';
  359. }else if(error.error.msg == undefined){
  360. this.errorStr = 'Ocurrió un error inesperado.';
  361. }else{
  362. this.errorStr = error.error.msg;
  363. }
  364. this.hasError = true;
  365. this.isLoading = false;
  366. }
  367. }
  368. formatSearchDate(date: Date): string{
  369. let day = date.getDate() < 10 ? `0${date.getDate()}` : `${date.getDate()}`;
  370. let month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : `${date.getMonth() + 1}`;
  371. let fullYear = `${date.getFullYear()}`;
  372. let year = fullYear.substring(2);
  373. return `${year}${month}${day}`;
  374. }
  375. formatBytes(bytes: number, decimals = 2) {
  376. if (bytes === 0) return '0 Bytes';
  377. const k = 1024;
  378. const dm = decimals < 0 ? 0 : decimals;
  379. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  380. const i = Math.floor(Math.log(bytes) / Math.log(k));
  381. return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
  382. }
  383. getUsersAccess(accessStr: string): UsersAccess[]{
  384. let accessArr = JSON.parse(accessStr);
  385. let arrFn: UsersAccess[] = [];
  386. for(const user of accessArr){
  387. let userNameArr = user.split(' ');
  388. let userLabel = '';
  389. for(let i = 0; i < 2; i++){
  390. userLabel += userNameArr[i][0];
  391. }
  392. let userColor = "rgb(";
  393. for(let i = 0; i < 3; i++){
  394. let char: never = user.charAt(i) as never;
  395. let code = this.avatarColors[char];
  396. userColor += `${code}, `;
  397. }
  398. userColor = userColor.substring(0, userColor.length - 2);
  399. userColor += ")";
  400. let userObj: UsersAccess = {
  401. userLabel: userLabel,
  402. userName: user,
  403. userColor: userColor,
  404. isTrigger: false,
  405. }
  406. arrFn.push(userObj);
  407. }
  408. let arrFnAux: UsersAccess[] = [];
  409. if(arrFn.length > 4){
  410. for(let i = 0; i < 3; i++){
  411. arrFnAux.push(arrFn[i]);
  412. }
  413. let moreUsers: UsersAccess = {
  414. userLabel: `${arrFn.length - 3}+`,
  415. userName: `Ver ${arrFn.length - 3} más...`,
  416. userColor: 'rgba(0,0,0,0.54)',
  417. isTrigger: true,
  418. };
  419. arrFnAux.push(moreUsers);
  420. return arrFnAux;
  421. }
  422. return arrFn;
  423. }
  424. clearDatesRange(){
  425. this.startDate = null;
  426. this.endDate = null;
  427. this.datesRangeControl.setValue('');
  428. this.getFiles(
  429. this.moduleControl.value,
  430. this.clasificationControl.value,
  431. this.startDate,
  432. this.endDate,
  433. this.fileNameControl.value,
  434. this.fileTypeControl.value
  435. );
  436. }
  437. openUploadDialog(){
  438. if(!this.isFromModule && this.registerDocumentsEnabled){
  439. let dialogRef = this._dialog.open(UploadDialogComponent, {
  440. width: '480px',
  441. disableClose: true,
  442. });
  443. dialogRef.afterClosed().subscribe(res => {
  444. if(res == true){
  445. let mod = this.moduleControl.value;
  446. let cla = this.clasificationControl.value;
  447. let sda = this.startDate;
  448. let eda = this.endDate;
  449. let dna = this.fileNameControl.value;
  450. let ext = this.fileTypeControl.value;
  451. this.getFiles(mod, cla, sda, eda, dna, ext);
  452. }
  453. });
  454. }
  455. }
  456. async downloadFile(code: string, version: string, name: string){
  457. try{
  458. let idFile = `${code}=${version}=${name}`;
  459. this._resourcesService.openSnackBar(`Iniciando la descarga del archivo ${idFile}...`);
  460. let idFileEnc = await this._encService.encrypt(idFile);
  461. let download = this._document.getElementById(`download`) as HTMLAnchorElement;
  462. let idUser = localStorage.getItem('idusuario')!;
  463. let downloadToken = await lastValueFrom(this._gdelService.getDownloadToken(
  464. idFileEnc,
  465. idUser,
  466. 1
  467. ));
  468. download.href = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${idUser}/1`;
  469. download.download = idFile;
  470. download.click();
  471. }catch(error: any){
  472. if(error.error == undefined){
  473. this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
  474. }else if(error.error.msg == undefined){
  475. this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
  476. }else{
  477. this._resourcesService.openSnackBar(error.error.msg);
  478. }
  479. }
  480. }
  481. async openViewer(code: string, version: string, name: string) {
  482. try{
  483. let idFile = `${code}=${version}=${name}`;
  484. this._resourcesService.openSnackBar(`Abriendo el archivo ${idFile}...`);
  485. let idFileEnc = await this._encService.encrypt(idFile);
  486. let idUser = localStorage.getItem('idusuario')!;
  487. let publicURL = await lastValueFrom(this._gdelService.getPublicDocumentUrl(
  488. idFileEnc,
  489. idUser,
  490. 1
  491. ));
  492. let fileData = {
  493. url: publicURL.response.public_uri,
  494. };
  495. this._dialog.open(WebviewerComponent, {
  496. data: fileData,
  497. width: '100%',
  498. });
  499. }catch(error: any){
  500. if(error.error == undefined){
  501. this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
  502. }else if(error.error.msg == undefined){
  503. this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
  504. }else{
  505. this._resourcesService.openSnackBar(error.error.msg);
  506. }
  507. }
  508. }
  509. openShareDialog(code: string, version: string, name: string){
  510. let idFile = `${code}=${version}=${name}`;
  511. let dialogRef = this._dialog.open(ShareFileComponent, {
  512. width: '720px',
  513. disableClose: true,
  514. data: {
  515. idFile: idFile,
  516. }
  517. })
  518. dialogRef.afterClosed().subscribe((res) => {
  519. this.updateFilePermissions(idFile, res);
  520. })
  521. }
  522. async updateFilePermissions(idFile: string, permissions: string){
  523. try{
  524. this._resourcesService.openSnackBar(`Actualizando permisos del archivo ${idFile}`);
  525. this.isLoading = true;
  526. this.hasError = false;
  527. this.errorStr = '';
  528. let idFileEnc = await this._encService.encrypt(idFile);
  529. let idUser = localStorage.getItem('idusuario');
  530. let formData = new FormData();
  531. formData.append('id_user', idUser!);
  532. formData.append('id_file', idFileEnc);
  533. formData.append('linea', '1');
  534. formData.append('permissions', permissions);
  535. await lastValueFrom(this._gdelService.updateFilePermissions(formData));
  536. this._resourcesService.openSnackBar(`Los permisos se actualizaron correctamente`);
  537. let mod = this.moduleControl.value;
  538. let cla = this.clasificationControl.value;
  539. let sda = this.startDate;
  540. let eda = this.endDate;
  541. let dna = this.fileNameControl.value;
  542. let ext = this.fileTypeControl.value;
  543. this.getFiles(mod, cla, sda, eda, dna, ext);
  544. }catch(error: any){
  545. if(error.error == undefined){
  546. this.errorStr = 'Ocurrió un error inesperado.';
  547. }else if(error.error.msg == undefined){
  548. this.errorStr = 'Ocurrió un error inesperado.';
  549. }else{
  550. this.errorStr = error.error.msg;
  551. }
  552. this.hasError = true;
  553. this.isLoading = false;
  554. }
  555. }
  556. openAccessDialog(code: string, version: string, name: string, isTrigger: boolean, isDeleted: boolean){
  557. if(isTrigger){
  558. let file = this.files.filter(item => item.CODIGO == code && item.VERSION == version && item.NOMBRE == name)[0];
  559. let accessStr = file.ACCESO;
  560. let idFile = `${code}=${version}=${name}`;
  561. let dialogRef = this._dialog.open(AccessDialogComponent, {
  562. width: '720px',
  563. data: {
  564. idFile: idFile,
  565. accessStr: accessStr,
  566. isDeleted: isDeleted
  567. }
  568. });
  569. dialogRef.afterClosed().subscribe(res => {
  570. if(res == true){
  571. this.openShareDialog(code, version, name);
  572. }
  573. })
  574. }
  575. }
  576. confirmDelete(code: string, version: string, name: string){
  577. let idFile = `${code}=${version}=${name}`;
  578. let dialogRef = this._dialog.open(AlertComponent, {
  579. disableClose: true,
  580. width: '480px',
  581. data: {
  582. title: 'Confirmar acción',
  583. icon: 'warning',
  584. description: `¿Está seguro de querer eliminar el archivo ${idFile}?`,
  585. description2: 'Esta acción no se puede deshacer'
  586. }
  587. });
  588. dialogRef.afterClosed().subscribe(res => {
  589. if(res == true){
  590. this.deleteFile(idFile);
  591. }
  592. });
  593. }
  594. async deleteFile(idFile: string){
  595. try{
  596. let idUser = localStorage.getItem('idusuario');
  597. let idFileEnc = await this._encService.encrypt(idFile);
  598. let formData = new FormData();
  599. formData.append('id_user', idUser!);
  600. formData.append('id_file', idFileEnc);
  601. formData.append('linea', '1');
  602. await lastValueFrom(this._gdelService.deleteFile(formData));
  603. this._resourcesService.openSnackBar('El archivo se eliminó correctamente.');
  604. let mod = this.moduleControl.value;
  605. let cla = this.clasificationControl.value;
  606. let sda = this.startDate;
  607. let eda = this.endDate;
  608. let dna = this.fileNameControl.value;
  609. let ext = this.fileTypeControl.value;
  610. this.getFiles(mod, cla, sda, eda, dna, ext);
  611. }catch(error: any){
  612. if(error.error == undefined){
  613. this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
  614. }else if(error.error.msg == undefined){
  615. this._resourcesService.openSnackBar('Ocurrió un error inesperado.');
  616. }else{
  617. this._resourcesService.openSnackBar(error.error.msg);
  618. }
  619. }
  620. }
  621. openAssociationDialog(code: string, version: string, name: string){
  622. let idFile = `${code}=${version}=${name}`;
  623. this._dialog.open(OrderAssociatonComponent, {
  624. width: '840px',
  625. disableClose: true,
  626. data: {
  627. idFile: idFile,
  628. }
  629. });
  630. }
  631. goBack(steps: number){
  632. window.history.go(steps * -1);
  633. }
  634. }