| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900 |
- import { HttpErrorResponse } from '@angular/common/http';
- import {
- Component,
- ViewChild,
- OnInit,
- AfterViewInit,
- ElementRef,
- Inject,
- } from '@angular/core';
- import { MatDialog } from '@angular/material/dialog';
- import { MatPaginator } from '@angular/material/paginator';
- import { MatSort } from '@angular/material/sort';
- import { MatTableDataSource } from '@angular/material/table';
- import { Router } from '@angular/router';
- import { AlertComponent } from 'src/app/components/resources/dialogs/alert/alert.component';
- import { AlertData } from 'src/app/interfaces/alert.interface';
- import { EncService } from 'src/app/services/enc/enc.service';
- import { ResourcesService } from 'src/app/services/resources/resources.service';
- import { lastValueFrom } from 'rxjs';
- import WebViewer from '@pdftron/webviewer';
- import { WebviewerComponent } from './webviewer/webviewer.component';
- import { DocumentManagementService } from 'src/app/services/document-management/document-management.service';
- import { MatSnackBar } from '@angular/material/snack-bar';
- import { GdelService } from 'src/app/services/document-management/gdel.service';
- import { docClassification, modules, supportedFiles } from 'src/environments/environment.prod';
- import { DateRangePickerComponent } from './date-range-picker/date-range-picker.component';
- import { FormControl } from '@angular/forms';
- import { FindedFile, FindedFilesResponse } from 'src/app/interfaces/finded-files.interface';
- import { UploadDialogComponent } from './upload-dialog/upload-dialog.component';
- 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';
- interface FoundedFiles{
- CODIGO: string;
- VERSION: string;
- NOMBRE: string;
- TAMANIO: string;
- USRREG: string;
- ACCESO: UsersAccess[];
- }
- export interface UsersAccess{
- userLabel: string;
- userName: string;
- userColor: string;
- isTrigger: boolean;
- }
- @Component({
- selector: 'app-gdel',
- templateUrl: './gdel.component.html',
- styleUrls: ['./gdel.component.css'],
- })
- export class GDELComponent implements OnInit {
- public btnSmall: boolean;
- isLoading: boolean;
- hasError: boolean;
- errorStr: string;
- category: string;
- modulesArr = modules;
- clasificationsArr = docClassification;
- supportedFilesArr = supportedFiles;
- startDate: Date | null;
- endDate: Date | null;
- @ViewChild('dateRange') dateRange?: ElementRef;
- @ViewChild(MatPaginator) paginator!: MatPaginator;
- @ViewChild(MatSort) sort!: MatSort;
- moduleControl: FormControl;
- clasificationControl: FormControl;
- fileNameControl: FormControl;
- fileTypeControl: FormControl;
- datesRangeControl: FormControl;
- files: FindedFile[];
- dataSource: MatTableDataSource<FoundedFiles>;
- displayedColumns = ['CODIGO', 'VERSION', 'NOMBRE', 'TAMANIO', 'USRREG', 'ACCESO', 'ACCIONES'];
- avatarColors = {
- A: 244, B: 67, C: 54, D: 233, E: 30, F: 99, G: 156, H: 39, I: 176,
- J: 103, K: 58, L: 58, M: 183, N: 63, Ñ: 81, O: 181, P: 33, Q: 150,
- R: 243, S: 3, T: 169, U: 244, V: 76, W: 175, X: 80, Y: 255, Z: 193
- };
- /*@ViewChild('viewer') viewRef: any;
- public displayedColumns: Array<string>;
- public dataSource: MatTableDataSource<any>;
- @ViewChild('download') a?: ElementRef;
- public isLoading: boolean;
- public isLoadingForm: boolean;
- public active: number = 0;
- public ulOptSmall: boolean;
- public txtBuscador: string;
- public clickedIndex: any = 0;
- public downloadLink: String;
- public options = [
- {
- id: 1,
- items: 'Mis documentos',
- icon: 'local_library',
- },
- {
- id: 2,
- items: 'Compartidos conmigo',
- icon: 'group_add',
- },
- {
- id: 3,
- items: 'Papelera',
- icon: 'delete',
- },
- ];
- public documents: Array<any> = [];*/
- constructor(
- @Inject(DOCUMENT) private _document: Document,
- private _encService: EncService,
- private _resourcesServices: ResourcesService,
- private _dialog: MatDialog,
- private _router: Router,
- private _gdelService: GdelService,
- private _snackBar: MatSnackBar,
- ) {
- this.btnSmall = false;
- this.isLoading = true;
- this.hasError = true;
- this.errorStr = '';
- this.category = 'my-files';
- this.startDate = null;
- this.endDate = null;
- this.moduleControl = new FormControl('');
- this.clasificationControl = new FormControl('');
- this.fileNameControl = new FormControl('');
- this.fileTypeControl = new FormControl('');
- this.datesRangeControl = new FormControl('');
- this.dataSource = new MatTableDataSource();
- this.files = [];
- /*this.displayedColumns = [
- 'ID',
- 'NAME',
- 'EXT',
- 'SIZE',
- 'VERSION',
- 'FRMOD',
- 'USMOD',
- 'ACTIONS',
- ];
- this.dataSource = new MatTableDataSource();
- this.isLoading = false;
- this.isLoadingForm = false;
- this.ulOptSmall = false;
- this.txtBuscador = '';
- this.downloadLink = '';*/
- }
- ngOnInit(): void {
- this.moduleControl.valueChanges.subscribe(mod => {
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- });
- this.clasificationControl.valueChanges.subscribe(cla => {
- let mod = this.moduleControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- });
- this.fileNameControl.valueChanges.subscribe(dna => {
- let mod = this.moduleControl.value;
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- });
- this.fileTypeControl.valueChanges.subscribe(ext => {
- let mod = this.moduleControl.value;
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- });
- this.getFiles(
- this.moduleControl.value,
- this.clasificationControl.value,
- this.startDate,
- this.endDate,
- this.fileNameControl.value,
- this.fileTypeControl.value
- );
- /*this.onResize();
- this.dataSource.data = [
- {
- ID: '01-ADSI-CA-230120-000001=01',
- NAME: 'Test',
- EXT: '.doc',
- SIZE: '20MB',
- VERSION: '1',
- FRMOD: '22/02/13',
- USMOD: 'CAVA07',
- },
- {
- ID: '01-ADSI-CA-230100-000002=02',
- NAME: 'Test2',
- EXT: '.pdf',
- SIZE: '10MB',
- VERSION: '2',
- FRMOD: '22/02/12',
- USMOD: 'CAVA07',
- },
- ];
- this.getDocuments();*/
- }
- public onResize(): void {
- this.btnSmall = window.innerWidth <= 1573;
- }
- updateCategory(category: string){
- let mod = this.moduleControl.value;
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- this.category = category;
- }
- openDateRangePicker(){
- let dialogRef = this._dialog.open(DateRangePickerComponent, {
- disableClose: true,
- width: '480px',
- data: {
- startDate: this.startDate,
- endDate: this.endDate
- }
- });
- dialogRef.afterClosed().subscribe(res => {
- if(res != null && res != undefined && res != ''){
- let resObj = JSON.parse(res);
- let dateRange = "";
- if(resObj.startDate != null || resObj.endDate != null){
- if(resObj.startDate != null){
- let startDateTimeArr = resObj.startDate.split('T');
- let startDateArr = startDateTimeArr[0].split('-').reverse();
- let startDateStr = startDateArr.join('/');
-
- this.startDate = new Date(resObj.startDate);
- dateRange += `desde ${startDateStr}, `;
- }
-
- if(resObj.endDate != null){
- let endDateTimeArr = resObj.endDate.split('T');
- let endDateArr = endDateTimeArr[0].split('-').reverse();
- let endDateStr = endDateArr.join('/');
-
- this.endDate = new Date(resObj.endDate);
- dateRange += `hasta ${endDateStr}, `;
- }
-
- let fl = dateRange[0].toUpperCase();
- let dateRangeArr = dateRange.split("");
-
- dateRangeArr[0] = fl;
- dateRange = dateRangeArr.join("");
- dateRange = dateRange.substring(0, dateRange.length - 2);
- this.dateRange!.nativeElement.value = dateRange;
- this.getFiles(
- this.moduleControl.value,
- this.clasificationControl.value,
- this.startDate,
- this.endDate,
- this.fileNameControl.value,
- this.fileTypeControl.value,
- );
- }
- }
- });
- }
- async getFiles(module: string | undefined, clas: string | undefined, startDate: Date | null, endDate: Date | null, name: string | undefined, type: string | undefined){
- try{
- this.isLoading = true;
- this.hasError = false;
- this.errorStr = "";
- let mod = module == undefined || module == '' ? '-' : module;
- let cla = clas == undefined || clas == '' ? '-' : clas;
- let sda = startDate == null ? '-' : this.formatSearchDate(startDate);
- let eda = endDate == null ? '-' : this.formatSearchDate(endDate);
- let dna = name == undefined || name == '' ? '-' : name;
- let ext = type == undefined || type == '' ? '-' : JSON.stringify(type.split(','));
- let idUser = localStorage.getItem('idusuario');
- let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
- let files: FindedFilesResponse = await lastValueFrom(this._gdelService.getFiles(
- mod, cla, sda, eda, dna, ext, this.category, shortEnc.response.encrypted, 1
- ));
- this.hasError = files.error;
- this.errorStr = files.msg;
- if(!this.hasError){
- this.files = files.response;
- let filesFound: FoundedFiles[] = [];
- files.response.forEach(file => {
- let fileSize = this.formatBytes(file.TAMANIO);
- let fileAccess = this.getUsersAccess(file.ACCESO);
- let fileObj: FoundedFiles = {
- CODIGO: file.CODIGO,
- VERSION: file.VERSION,
- NOMBRE: file.NOMBRE,
- TAMANIO: fileSize,
- USRREG: file.USRREG,
- ACCESO: fileAccess,
- };
- filesFound.push(fileObj);
- });
-
- this.dataSource = new MatTableDataSource(filesFound);
- this.dataSource.paginator = this.paginator;
- this.dataSource.sort = this.sort;
- }
- 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;
- }
- }
- formatSearchDate(date: Date): string{
- let day = date.getDate() < 10 ? `0${date.getDate()}` : `${date.getDate()}`;
- let month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : `${date.getMonth() + 1}`;
- let fullYear = `${date.getFullYear()}`;
- let year = fullYear.substring(2);
-
- 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';
- const k = 1024;
- const dm = decimals < 0 ? 0 : decimals;
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- const i = Math.floor(Math.log(bytes) / Math.log(k));
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
- }
- getUsersAccess(accessStr: string): UsersAccess[]{
- let accessArr = JSON.parse(accessStr);
- let arrFn: UsersAccess[] = [];
- for(const user of accessArr){
- let userNameArr = user.split(' ');
- let userLabel = '';
- for(let i = 0; i < 2; i++){
- userLabel += userNameArr[i][0];
- }
- let userColor = "rgb(";
- for(let i = 0; i < 3; i++){
- let char: never = user.charAt(i) as never;
- let code = this.avatarColors[char];
- userColor += `${code}, `;
- }
- userColor = userColor.substring(0, userColor.length - 2);
- userColor += ")";
- let userObj: UsersAccess = {
- userLabel: userLabel,
- userName: user,
- userColor: userColor,
- isTrigger: false,
- }
- arrFn.push(userObj);
- }
- let arrFnAux: UsersAccess[] = [];
- if(arrFn.length > 4){
- for(let i = 0; i < 3; i++){
- arrFnAux.push(arrFn[i]);
- }
- let moreUsers: UsersAccess = {
- userLabel: `${arrFn.length - 3}+`,
- userName: `Ver ${arrFn.length - 3} más...`,
- userColor: 'rgba(0,0,0,0.54)',
- isTrigger: true,
- };
- arrFnAux.push(moreUsers);
- return arrFnAux;
- }
- return arrFn;
- }
- clearDatesRange(){
- this.startDate = null;
- this.endDate = null;
- this.datesRangeControl.setValue('');
- this.getFiles(
- this.moduleControl.value,
- this.clasificationControl.value,
- this.startDate,
- this.endDate,
- this.fileNameControl.value,
- this.fileTypeControl.value
- );
- }
- openUploadDialog(){
- let dialogRef = this._dialog.open(UploadDialogComponent, {
- width: '480px',
- disableClose: true,
- });
- dialogRef.afterClosed().subscribe(res => {
- if(res == true){
- let mod = this.moduleControl.value;
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- }
- });
- }
- async downloadFile(code: string, version: string, name: string){
- try{
- let idFile = `${code}=${version}=${name}`;
- this.openSnackBar(`Iniciando la descarga del archivo ${idFile}...`);
- let idFileEnc = await this._encService.encrypt(idFile);
- let idFileShort = await lastValueFrom(this._encService.shortEncrypt(idFileEnc));
- let download = this._document.getElementById(`download`) as HTMLAnchorElement;
-
- let idUser = localStorage.getItem('idusuario');
- let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
-
- let downloadToken = await lastValueFrom(this._gdelService.getDownloadToken(
- idFileShort.response.encrypted,
- shortEnc.response.encrypted,
- 1
- ));
-
- download.href = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
- download.download = idFile;
- download.click();
- }catch(error: any){
- if(error.error == undefined){
- this.openSnackBar('Ocurrió un error inesperado.');
- }else if(error.error.msg == undefined){
- this.openSnackBar('Ocurrió un error inesperado.');
- }else{
- this.openSnackBar(error.error.msg);
- }
- }
- }
- async openViewer(code: string, version: string, name: string) {
- try{
- let idFile = `${code}=${version}=${name}`;
- this.openSnackBar(`Abriendo el archivo ${idFile}...`);
-
- let idFileEnc = await this._encService.encrypt(idFile);
- let idFileShort = await lastValueFrom(this._encService.shortEncrypt(idFileEnc));
- let idUser = localStorage.getItem('idusuario');
- let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
- let publicURL = await lastValueFrom(this._gdelService.getPublicDocumentUrl(
- idFileShort.response.encrypted,
- shortEnc.response.encrypted,
- 1
- ));
- let fileData = {
- url: publicURL.response.public_uri,
- };
- this._dialog.open(WebviewerComponent, {
- data: fileData,
- width: '100%',
- });
- }catch(error: any){
- if(error.error == undefined){
- this.openSnackBar('Ocurrió un error inesperado.');
- }else if(error.error.msg == undefined){
- this.openSnackBar('Ocurrió un error inesperado.');
- }else{
- this.openSnackBar(error.error.msg);
- }
- }
- }
- openShareDialog(code: string, version: string, name: string){
- let idFile = `${code}=${version}=${name}`;
- let dialogRef = this._dialog.open(ShareFileComponent, {
- width: '720px',
- disableClose: true,
- data: {
- idFile: idFile,
- }
- })
- dialogRef.afterClosed().subscribe((res) => {
- this.updateFilePermissions(idFile, res);
- })
- }
- async updateFilePermissions(idFile: string, permissions: string){
- try{
- this.openSnackBar(`Actualizando permisos del archivo ${idFile}`);
- this.isLoading = true;
- this.hasError = false;
- this.errorStr = '';
- let idFileEnc = await this._encService.encrypt(idFile);
- let idUser = localStorage.getItem('idusuario');
- let formData = new FormData();
- formData.append('id_user', idUser!);
- formData.append('id_file', idFileEnc);
- formData.append('linea', '1');
- formData.append('permissions', permissions);
- await lastValueFrom(this._gdelService.updateFilePermissions(formData));
- this.openSnackBar(`Los permisos se actualizaron correctamente`);
-
- let mod = this.moduleControl.value;
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- }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;
- }
- }
- openAccessDialog(code: string, version: string, name: string, isTrigger: boolean, isDeleted: boolean){
- if(isTrigger){
- let file = this.files.filter(item => item.CODIGO == code && item.VERSION == version && item.NOMBRE == name)[0];
- let accessStr = file.ACCESO;
- let idFile = `${code}=${version}=${name}`;
- let dialogRef = this._dialog.open(AccessDialogComponent, {
- width: '720px',
- data: {
- idFile: idFile,
- accessStr: accessStr,
- isDeleted: isDeleted
- }
- });
- dialogRef.afterClosed().subscribe(res => {
- if(res == true){
- this.openShareDialog(code, version, name);
- }
- })
- }
- }
- confirmDelete(code: string, version: string, name: string){
- let idFile = `${code}=${version}=${name}`;
- let dialogRef = this._dialog.open(AlertComponent, {
- disableClose: true,
- width: '480px',
- data: {
- title: 'Confirmar acción',
- icon: 'warning',
- description: `¿Está seguro de querer eliminar el archivo ${idFile}?`,
- description2: 'Esta acción no se puede deshacer'
- }
- });
- dialogRef.afterClosed().subscribe(res => {
- if(res == true){
- this.deleteFile(idFile);
- }
- });
- }
- async deleteFile(idFile: string){
- try{
- let idUser = localStorage.getItem('idusuario');
- let idFileEnc = await this._encService.encrypt(idFile);
- let formData = new FormData();
- formData.append('id_user', idUser!);
- formData.append('id_file', idFileEnc);
- formData.append('linea', '1');
- await lastValueFrom(this._gdelService.deleteFile(formData));
- this.openSnackBar('El archivo se eliminó correctamente.');
-
- let mod = this.moduleControl.value;
- let cla = this.clasificationControl.value;
- let sda = this.startDate;
- let eda = this.endDate;
- let dna = this.fileNameControl.value;
- let ext = this.fileTypeControl.value;
- this.getFiles(mod, cla, sda, eda, dna, ext);
- }catch(error: any){
- if(error.error == undefined){
- this.openSnackBar('Ocurrió un error inesperado.');
- }else if(error.error.msg == undefined){
- this.openSnackBar('Ocurrió un error inesperado.');
- }else{
- this.openSnackBar(error.error.msg);
- }
- }
- }
- openAssociationDialog(code: string, version: string, name: string){
- let idFile = `${code}=${version}=${name}`;
- this._dialog.open(OrderAssociatonComponent, {
- width: '840px',
- disableClose: true,
- data: {
- idFile: idFile,
- }
- });
- }
- /*ngAfterViewInit(): void {
- this.dataSource.paginator = this.paginator;
- this.dataSource.sort = this.sort;
- }
- registerDocument() {
- this._router.navigate(['sam/GDEL/ADDO/nuevo']);
- }
- public async getShareDocuments() {
- this.dataSource.data = [];
- }
- public async getDocuments() {
- this.isLoading = true;
- let idEnc = localStorage.getItem('idusuario')!;
- let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idEnc));
- let documents: any = await lastValueFrom(
- this._gdelService.getDocumentsByUser(shortEnc.response.encrypted, 1)
- );
- if (documents.error) {
- this.openSnackBar(documents.msg);
- } else {
- for (let index = 0; index < documents.response.length; index++) {
- let codeSAM =
- documents.response[index].NUMERO_LINEA +
- '-' +
- documents.response[index].MODULO +
- '-' +
- documents.response[index].CLASIFICACION +
- '-' +
- documents.response[index].FECHA_REGISTRO +
- '-' +
- documents.response[index].SECUENCIAL +
- '=' +
- documents.response[index].VERSION +
- '=' +
- documents.response[index].NOMBRE_ARC +
- '.' +
- documents.response[index].EXTENSION;
- let encript = await this._encService.encrypt(codeSAM);
- let short = await lastValueFrom(this._encService.shortEncrypt(encript));
- documents.response[index].ID = short.response.encrypted;
- documents.response[index].TAMANIO = this.formatBytes(
- documents.response[index].TAMANIO
- );
- }
- this.dataSource.data = documents.response;
- this.isLoading = false;
- }
- }
- async modifyDocument(idDocument: number) {
- let idDocEnc = await this._encService.encrypt(`${idDocument}`);
- this._router.navigate(['sam/GDEL/ADDO/editar'], {
- queryParams: {
- idDoc: idDocEnc,
- },
- });
- }
- // Método de filtrado de datos
- public applyFilter(event: any, type: string): void {
- let filterValue: string;
- if (type == 'INP') {
- filterValue = (event.target as HTMLInputElement).value;
- } else {
- this.txtBuscador = event;
- filterValue = event;
- }
- this.dataSource.filter = filterValue.trim().toLowerCase();
- if (this.dataSource.paginator) {
- this.dataSource.paginator.firstPage();
- }
- }
- public openViewer(url: string) {
- let dialogRef: any;
- let fileData = {
- url: url,
- };
- dialogRef = this.dialog.open(WebviewerComponent, {
- data: fileData,
- width: '100%',
- });
- dialogRef.afterClosed().subscribe((result: any) => {
- if (result) {
- console.log(result);
- }
- this.isLoadingForm = false;
- });
- }
- // Método para dar formato a las fechas y horas
- public formatDate(dateRegister: string, dateUpdate: string | null): string {
- let date: string = dateUpdate === null ? dateRegister : dateUpdate;
- let arrDateTime: Array<string> = date.split(' ');
- let arrDate: Array<string> = arrDateTime[0].split('-');
- return `${arrDate[2]}-${arrDate[1]}-${arrDate[0]} ${arrDateTime[1]}`;
- }
- public async alert(type: string, dataElement: any = null) {
- this.isLoadingForm = true;
- let dataDialog: AlertData = {} as AlertData;
- if (type === 'CANCEL') {
- dataDialog = {
- icon: 'warning',
- title: 'Cancelar Solicitud',
- description:
- '¿Está seguro de cancelar la línea de solicitud de compra?',
- };
- }
- // Se ejecuta la alerta
- const dialogRef = this._dialog.open(AlertComponent, {
- data: dataDialog,
- disableClose: true,
- width: '350px',
- });
- // Se obtiene la respuesta obtenida por la alerta
- dialogRef.afterClosed().subscribe((result) => {
- if (result && type === 'CANCEL') {
- console.log(result);
- }
- });
- this.isLoadingForm = false;
- }
- // Funcion para descargar archivos
- async downloadFile(idFile: any) {
- try {
- let idEnc = localStorage.getItem('idusuario');
- let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idEnc!));
- let downloadToken = await lastValueFrom(
- this._gdelService.getDownloadToken(
- idFile,
- shortEnc.response.encrypted,
- 1
- )
- );
- //this.downloadL ink = "http://git.ittec.mx/sam/public/api/download-file///1";
- //this.downloadLink = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
- this.downloadLink = `http://192.168.1.2:8000/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
- console.log(this.downloadLink );
- this.a?.nativeElement.click();
- } catch (error: any) {
- let msg = '';
- if (error.error == undefined) {
- msg = 'Ocurrió un error inesperado.';
- } else if (error.error.msg == undefined) {
- msg = 'Ocurrió un error inesperado.';
- } else {
- msg = error.error.msg;
- }
- this.openSnackBar(msg);
- }
- }
- public goBack(steps: number) {
- window.history.go(steps * -1);
- }
- openSnackBar(msg: string) {
- this._snackBar.open(msg, undefined, {
- duration: 2500,
- });
- }
- selectTab(index: number) {
- this.active = index;
- switch (index) {
- case 0:
- this.getDocuments();
- break;
- case 1:
- this.getShareDocuments();
- break;
- case 2:
- break;
- default:
- break;
- }
- }
- refreshDocuments() {
- switch (this.active) {
- case 0:
- this.getDocuments();
- break;
- case 1:
- this.getShareDocuments();
- break;
- case 2:
- break;
- default:
- break;
- }
- }*/
- }
|