Skip to content
Snippets Groups Projects
document.component.ts 23 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alex ORLUC's avatar
    Alex ORLUC committed
    import { Component, OnInit, ViewChild, ElementRef, Input, Inject } from '@angular/core';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    import { SignaturesContentService } from '../service/signatures.service';
    import { DomSanitizer } from '@angular/platform-browser';
    import * as $ from 'jquery';
    import { SignaturePad } from 'angular2-signaturepad/signature-pad';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    import {
        MatDialogRef,
        MatDialog,
        MAT_DIALOG_DATA,
        MatBottomSheet,
        MatBottomSheetRef,
        MatBottomSheetConfig,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        MatSidenav
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    } from '@angular/material';
    import { SignaturesComponent } from '../signatures/signatures.component';
    
    import { ActivatedRoute, Router } from '@angular/router';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    import { HttpClient } from '@angular/common/http';
    
    import { NotificationService } from '../service/notification.service';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    import { trigger, transition, style, animate } from '@angular/animations';
    
    Florian Azizian's avatar
    Florian Azizian committed
    import { CookieService } from 'ngx-cookie-service';
    
    import { PDFDocumentProxy } from 'ng2-pdf-viewer';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    @Component({
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        selector: 'app-document',
        templateUrl: 'document.component.html',
    
        styleUrls: ['document.component.scss'],
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        animations: [
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            trigger(
                'enterApp',
                [
                    transition(
                        ':leave', [
                            style({ transform: 'translateY(0)' }),
                            animate('500ms', style({ transform: 'translateY(-100%)' })),
                        ]
                    )]
            ),
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            trigger(
                'slideDown',
                [
                    transition(
                        ':enter', [
                            style({ transform: 'translateY(-100%)', opacity: 0 }),
                            animate('500ms', style({ transform: 'translateY(0)', 'opacity': 1 }))
                        ]
                    ),
                    transition(
                        ':leave', [
                            style({ transform: 'translateY(0)', 'opacity': 1 }),
                            animate('500ms', style({ transform: 'translateY(-100%)', 'opacity': 0 })),
                        ]
                    )]
            ),
            trigger(
                'slideUp',
                [
                    transition(
                        ':enter', [
                            style({ transform: 'translateY(100%)', opacity: 0 }),
                            animate('500ms', style({ transform: 'translateY(0)', 'opacity': 1 }))
                        ]
                    ),
                    transition(
                        ':leave', [
                            style({ transform: 'translateY(0)', 'opacity': 1 }),
                            animate('500ms', style({ transform: 'translateY(100%)', 'opacity': 0 })),
                        ]
                    )]
            )
        ],
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    })
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    export class DocumentComponent implements OnInit {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        enterApp = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        loadingPage = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        pageNum = 1;
        signaturesContent: any = [];
        pageRendering = false;
        pageNumPending: null;
        scale = 1;
        totalPages: number;
        draggable: boolean;
        loadingDoc = true;
    
        renderingDoc = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        signaturePadPosX = 0;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        currentDoc = 0;
        docList: any = [];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        actionsList: any = [];
        currentAction = 0;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        lockSignaturePad = false;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        annotationPadOptions = {
            throttle: 0,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            minWidth: 1,
            maxWidth: 2.5,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            backgroundColor: 'rgba(255, 255, 255, 0)',
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            canvasWidth: 768,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            canvasHeight: 270
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        };
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        freezeSidenavClose = false;
    
        penColors = [{ id: 'black' }, { id: '#1a75ff' }, { id: '#FF0000' }];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        @Input() mainDocument: any = {};
    
        @ViewChild('pdfpage') elPdfContainer: ElementRef;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        @ViewChild('snav') snav: MatSidenav;
    
        @ViewChild('snavRight') snavRight: MatSidenav;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        @ViewChild('canvas') canvas: ElementRef;
        @ViewChild('canvasWrapper') canvasWrapper: ElementRef;
        @ViewChild(SignaturePad) signaturePad: SignaturePad;
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        public context: CanvasRenderingContext2D;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        constructor(private router: Router, private route: ActivatedRoute, public http: HttpClient,
    
            public signaturesService: SignaturesContentService,
            public notificationService: NotificationService,
    
    Florian Azizian's avatar
    Florian Azizian committed
            private sanitization: DomSanitizer, public dialog: MatDialog, private bottomSheet: MatBottomSheet, 
            private cookieService: CookieService) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.draggable = false;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        ngOnInit(): void {
    
    Florian Azizian's avatar
    Florian Azizian committed
            const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            setTimeout(() => {
                this.enterApp = false;
            }, 500);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.route.params.subscribe(params => {
                if (typeof params['id'] !== 'undefined') {
    
                    this.renderingDoc = true;
                    this.loadingDoc = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    this.http.get('../rest/documents/' + params['id'])
                        .subscribe((data: any) => {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.initDoc();
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.mainDocument = data.document;
    
                            this.signaturesService.mainDocumentId = this.mainDocument.id;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.actionsList = data.document.actionsAllowed;
    
                            if (this.signaturesService.signaturesList.length === 0) {
    
    Florian Azizian's avatar
    Florian Azizian committed
                                this.http.get('../rest/users/' + cookieInfo.id + '/signatures')
    
                                .subscribe((dataSign: any) => {
                                    this.signaturesService.signaturesList = dataSign.signatures;
                                    this.signaturesService.loadingSign = false;
                                });
                            }
    
                            this.docList.push({ 'id': this.mainDocument.id, 'encodedDocument': this.mainDocument.encodedDocument, 'subject': this.mainDocument.subject });
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.mainDocument.attachments.forEach((attach: any, index: any) => {
    
                                this.docList.push({ 'id': attach.id, 'encodedDocument': '', 'title': '' });
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            });
    
                            this.loadingDoc = false;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.pdfRender(this.docList[this.currentDoc]);
    
                            setTimeout(() => {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                this.loadingPage = false;
    
                                this.renderingDoc = false;
                            }, 500);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.loadNextDoc();
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        }, (err: any) => {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            this.notificationService.handleErrors(err);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        });
                } else {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    this.snav.open();
                    this.freezeSidenavClose = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        initDoc() {
            this.docList = [];
            this.signaturesService.signaturesContent = [];
            this.signaturesService.notesContent = [];
            this.signaturesService.currentAction = 0;
            this.signaturesService.currentPage = 1;
            this.pageNum = 1;
            this.signaturesContent.currentDoc = 1;
            this.currentDoc = 0;
        }
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        pdfRender(document: any) {
    
            const binary_string = window.atob(document.encodedDocument);
            const len = binary_string.length;
            const bytes = new Uint8Array(len);
            for (let i = 0; i < len; i++) {
                bytes[i] = binary_string.charCodeAt(i);
            }
            this.pdfDataArr = bytes.buffer;
    
        pdfRendered(pdf: PDFDocumentProxy) {
            this.totalPages = pdf.numPages;
    
            this.signaturesService.totalPage = this.totalPages;
        }
    
    
            this.signaturesService.workingAreaWidth = e.target.clientWidth;
            this.signaturesService.workingAreaHeight = e.target.clientHeight;
    
            this.canvasWrapper.nativeElement.style.width = this.signaturesService.workingAreaWidth + 'px';
            this.canvasWrapper.nativeElement.style.height = this.signaturesService.workingAreaHeight + 'px';
    
            this.annotationPadOptions.canvasWidth = this.signaturesService.workingAreaWidth;
            this.annotationPadOptions.canvasHeight = this.signaturesService.workingAreaHeight;
    
            const ratio =  Math.max(window.devicePixelRatio || 1, 1);
            this.annotationPadOptions.canvasHeight = this.annotationPadOptions.canvasHeight * ratio;
            this.annotationPadOptions.canvasWidth = this.annotationPadOptions.canvasWidth * ratio;
    
            if (this.signaturePad !== undefined) {
                this.signaturePad.set('canvasWidth', this.annotationPadOptions.canvasWidth);
                this.signaturePad.set('canvasHeight', this.annotationPadOptions.canvasHeight);
            }
    
            this.signaturesService.signWidth = this.signaturesService.workingAreaWidth / 4.5;
    
            this.renderingDoc = false;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        prevPage() {
            this.pageNum--;
            if (this.pageNum === 0) {
                this.pageNum = 1;
            } else {
            }
    
            if (this.currentDoc === 0) {
                this.signaturesService.currentPage = this.pageNum;
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        nextPage() {
            if (this.pageNum >= this.totalPages) {
                this.pageNum = this.totalPages;
            } else {
                this.pageNum++;
            }
    
            // only for main document
            if (this.currentDoc === 0) {
                this.signaturesService.currentPage = this.pageNum;
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        nextDoc() {
    
            this.renderingDoc = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.isTaggable = false;
            this.pageNum = 1;
            this.currentDoc++;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.pdfRender(this.docList[this.currentDoc]);
            this.loadNextDoc();
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        prevDoc() {
    
            this.renderingDoc = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.pageNum = 1;
            this.currentDoc--;
            if (this.currentDoc === 0) {
                this.signaturesService.currentPage = 1;
                this.signaturesService.isTaggable = true;
            }
            this.pdfRender(this.docList[this.currentDoc]);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        addAnnotation() {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (!this.signaturesService.lockNote && this.currentDoc === 0) {
                this.signaturesService.annotationMode = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                this.signaturePadPosX = 0;
                this.signaturePadPosY = 0;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                this.signaturesService.lockNote = true;
            }
        }
    
    
        moveSign(event: any, i: number) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.signaturesContent[this.signaturesService.currentPage][i].positionX = event.x;
            this.signaturesService.signaturesContent[this.signaturesService.currentPage][i].positionY = event.y;
        }
    
    
        moveNote(event: any, i: number) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.notesContent[this.signaturesService.currentPage][i].positionX = event.x;
            this.signaturesService.notesContent[this.signaturesService.currentPage][i].positionY = event.y;
        }
    
        movePad(event: any) {
            this.signaturePadPosX = event.x;
            this.signaturePadPosY = event.y;
            $('.page-viewer, .canvas-wrapper, .mat-sidenav-content').css({ 'overflow': 'auto' });
        }
    
        deleteSignature(index: number) {
            this.signaturesService.signaturesContent[this.signaturesService.currentPage].splice(index, 1);
        }
    
        deleteNote(index: number) {
            this.signaturesService.notesContent[this.signaturesService.currentPage].splice(index, 1);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        validateAnnotation() {
            if (!this.signaturesService.notesContent[this.signaturesService.currentPage]) {
                this.signaturesService.notesContent[this.signaturesService.currentPage] = [];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.notesContent[this.signaturesService.currentPage].push(
                {
    
                    'fullPath': this.signaturePad.toDataURL('image/svg+xml'),
    
                    'positionX': (this.signaturePadPosX * 100) / this.annotationPadOptions.canvasWidth,
                    'positionY': (this.signaturePadPosY * 100) / this.annotationPadOptions.canvasHeight,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    'height': this.annotationPadOptions.canvasHeight,
    
                    'width': 768,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                }
            );
            this.signaturePad.clear();
    
            if (this.scale > 1) {
                this.renderingDoc = true;
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.scale = 1;
            this.signaturesService.annotationMode = false;
            this.signaturesService.lockNote = false;
    
            this.notificationService.success('Annotation ajoutée');
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
        cancelAnnotation() {
            this.signaturePad.clear();
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.annotationMode = false;
            this.signaturesService.lockNote = false;
        }
    
        freezDoc() {
            $('.page-viewer, .canvas-wrapper, .mat-sidenav-content').css({ 'overflow': 'hidden' });
        }
    
        onColorChange(entry: any) {
            this.signaturePad.set('penColor', entry.id);
        }
    
        onDotChange(entry: any) {
            this.signaturePad.set('minWidth', parseFloat(entry));
            this.signaturePad.set('maxWidth', parseFloat(entry) + 2);
        }
    
        openDialog(): void {
            const dialogRef = this.dialog.open(WarnModalComponent, {
                width: '350px',
                data: {}
            });
    
            dialogRef.afterClosed().subscribe(result => {
                if (result === 'sucess') {
                    const config: MatBottomSheetConfig = {
                        disableClose: true,
                        direction: 'ltr'
                    };
                    this.bottomSheet.open(RejectInfoBottomSheetComponent, config);
                } else if (result === 'annotation') {
                    this.signaturesService.annotationMode = true;
                    this.signaturesService.lockNote = true;
                }
            });
        }
    
    
        confirmDialog(mode: any): void {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            const dialogRef = this.dialog.open(ConfirmModalComponent, {
                width: '350px',
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                data: { msg: 'Êtes-vous sûr  ?' }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            });
    
            dialogRef.afterClosed().subscribe(result => {
                if (result) {
                    const config: MatBottomSheetConfig = {
                        disableClose: true,
                        direction: 'ltr'
                    };
                    this.bottomSheet.open(SuccessInfoValidBottomSheetComponent, config);
                }
            });
        }
    
        openDrawer(): void {
    
            if (this.currentDoc > 0) {
                this.currentDoc = 0;
                this.pageNum = 1;
                this.pdfRender(this.docList[this.currentDoc]);
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.showSign = true;
            const config: MatBottomSheetConfig = {
                disableClose: false,
                direction: 'ltr'
            };
            this.bottomSheet.open(SignaturesComponent, config);
        }
    
        removeTags() {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturesService.currentAction = 0;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            const dialogRef = this.dialog.open(ConfirmModalComponent, {
                width: '350px',
                data: { msg: 'Effacer toutes les annotations et signatures ?' }
            });
    
            dialogRef.afterClosed().subscribe(result => {
                if (result) {
                    this.signaturesService.signaturesContent = [];
                    this.signaturesService.notesContent = [];
    
                    this.notificationService.success('Annotations / signatures supprimées du document');
    
        undoTag() {
            if (this.signaturesService.notesContent[this.pageNum]) {
                this.signaturesService.notesContent[this.pageNum].pop();
            }
        }
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        loadNextDoc () {
    
            if (this.docList[this.currentDoc + 1] && this.docList[this.currentDoc + 1].id && this.docList[this.currentDoc + 1].encodedDocument === '') {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                this.http.get('../rest/attachments/' + this.docList[this.currentDoc + 1].id)
                    .subscribe((dataPj: any) => {
                        this.docList[this.currentDoc + 1] = dataPj.attachment;
    
                    }, (err: any) => {
                        this.notificationService.handleErrors(err);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        launchEvent(action: any) {
            this.signaturesService.currentAction = action.id;
            this[action.event]();
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        test() {
            if (this.lockSignaturePad) {
                this.lockSignaturePad = false;
                this.signaturePad.on();
            } else {
                this.lockSignaturePad = true;
                this.signaturePad.off();
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
        zoomPlus() {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.renderingDoc = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.lockSignaturePad = true;
            this.scale = 2;
        }
    
        zoomMinus() {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.renderingDoc = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.signaturePad.clear();
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.lockSignaturePad = true;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.scale = 1;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        }
    
        undo() {
            const data = this.signaturePad.toData();
            if (data) {
                data.pop(); // remove the last dot or line
                this.signaturePad.fromData(data);
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    }
    
    @Component({
        templateUrl: '../modal/warn-modal.component.html',
    
        styleUrls: ['../modal/warn-modal.component.scss']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    })
    export class WarnModalComponent {
    
        constructor(@Inject(MAT_DIALOG_DATA) public data: any, public http: HttpClient, public dialogRef: MatDialogRef<WarnModalComponent>, public signaturesService: SignaturesContentService, public notificationService: NotificationService) { }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
        confirmDoc () {
            const signatures: any[] = [];
            if (this.signaturesService.currentAction > 0) {
                for (let index = 1; index <= this.signaturesService.totalPage; index++) {
                    if (this.signaturesService.signaturesContent[index]) {
                        this.signaturesService.signaturesContent[index].forEach((signature: any) => {
                            signatures.push(
                                {
    
    Damien's avatar
    Damien committed
                                    'encodedImage'  : signature.encodedSignature,
                                    'width'         : (this.signaturesService.signWidth * 100) / signature.pdfAreaX,
                                    'positionX'     : (signature.positionX * 100) / signature.pdfAreaX,
                                    'positionY'     : (signature.positionY * 100) / signature.pdfAreaY,
                                    'type'          : 'PNG',
                                    'page'          : index
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                }
                            );
                        });
                    }
                    if (this.signaturesService.notesContent[index]) {
                        this.signaturesService.notesContent[index].forEach((note: any) => {
                            signatures.push(
                                {
    
    Damien's avatar
    Damien committed
                                    'encodedImage'  : note.fullPath,
                                    'width'         : note.width,
                                    'positionX'     : note.positionX,
                                    'positionY'     : note.positionY,
                                    'type'          : 'SVG',
                                    'page'          : index
    
    Damien's avatar
    Damien committed
                this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, {'signatures': signatures})
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    .subscribe(() => {
                        this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1);
                        this.signaturesService.documentsListCount--;
                        this.dialogRef.close('sucess');
                    }, (err: any) => {
    
                        this.notificationService.handleErrors(err);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    });
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            } else {
                this.dialogRef.close('sucess');
            }
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    }
    
    @Component({
        templateUrl: '../modal/confirm-modal.component.html',
    
        styleUrls: ['../modal/confirm-modal.component.scss']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    })
    export class ConfirmModalComponent {
    
        constructor(@Inject(MAT_DIALOG_DATA) public data: any, public http: HttpClient, public dialogRef: MatDialogRef<ConfirmModalComponent>, public signaturesService: SignaturesContentService, public notificationService: NotificationService) { }
    
    
        confirmDoc () {
            const signatures: any[] = [];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (this.signaturesService.currentAction > 0) {
    
                for (let index = 1; index <= this.signaturesService.totalPage; index++) {
                    if (this.signaturesService.signaturesContent[index]) {
                        this.signaturesService.signaturesContent[index].forEach((signature: any) => {
                            signatures.push(
                                {
    
    Damien's avatar
    Damien committed
                                    'encodedImage'  : signature.encodedSignature,
                                    'width'         : (this.signaturesService.signWidth * 100) / signature.pdfAreaX,
                                    'positionX'     : (signature.positionX * 100) / signature.pdfAreaX,
                                    'positionY'     : (signature.positionY * 100) / signature.pdfAreaY,
                                    'type'          : 'PNG',
                                    'page'          : index,
    
                                }
                            );
                        });
                    }
                    if (this.signaturesService.notesContent[index]) {
                        this.signaturesService.notesContent[index].forEach((note: any) => {
                            signatures.push(
                                {
    
    Damien's avatar
    Damien committed
                                    'encodedImage'  : note.fullPath,
                                    'width'         : note.width,
                                    'positionX'     : note.positionX,
                                    'positionY'     : note.positionY,
                                    'type'          : 'SVG',
                                    'page'          : index,
    
    Damien's avatar
    Damien committed
                this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, {'signatures': signatures})
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    .subscribe(() => {
                        this.dialogRef.close('sucess');
                        this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1);
                        this.signaturesService.documentsListCount--;
                    }, (err: any) => {
    
                        this.notificationService.handleErrors(err);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    });
    
            } else {
                this.dialogRef.close('sucess');
            }
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    }
    
    @Component({
        templateUrl: '../modal/success-info-valid.html',
    
        styleUrls: ['../modal/success-info-valid.scss']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    })
    
    export class SuccessInfoValidBottomSheetComponent implements OnInit {
    
        date: Date = new Date();
    
        constructor(private router: Router, public signaturesService: SignaturesContentService, private bottomSheetRef: MatBottomSheetRef<SuccessInfoValidBottomSheetComponent>) { }
         ngOnInit(): void {
            setTimeout(() => {
                if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList]) {
    
                    this.router.navigate(['/documents/' + this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].id]);
    
                } else {
                    this.router.navigate(['/documents']);
    
                }
                this.bottomSheetRef.dismiss();
            }, 2000);
         }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    }
    
    @Component({
        templateUrl: '../modal/reject-info.html',
    
        styleUrls: ['../modal/reject-info.scss']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    })
    
    export class RejectInfoBottomSheetComponent implements OnInit {
    
        date: Date = new Date();
    
        constructor(private router: Router, public signaturesService: SignaturesContentService, private bottomSheetRef: MatBottomSheetRef<RejectInfoBottomSheetComponent>) { }
        ngOnInit(): void {
            setTimeout(() => {
                if (this.signaturesService.documentsList[this.signaturesService.indexDocumentsList]) {
    
                    this.router.navigate(['/documents/' + this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].id]);
    
                } else {
                    this.router.navigate(['/documents']);
    
                }
                this.bottomSheetRef.dismiss();
            }, 2000);
         }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    }