Newer
Older
import { Component, OnInit, ViewChild, ElementRef, Input, Inject } from '@angular/core';
import { SignaturesContentService } from '../service/signatures.service';
import { DomSanitizer } from '@angular/platform-browser';
import { MatDialog, MatBottomSheet, MatBottomSheetConfig, MatSidenav } from '@angular/material';
import { SignaturesComponent } from '../signatures/signatures.component';
import { ActivatedRoute, Router } from '@angular/router';
import { NotificationService } from '../service/notification.service';
import { trigger, transition, style, animate } from '@angular/animations';
import { PDFDocumentProxy } from 'ng2-pdf-viewer';
import { CookieService } from 'ngx-cookie-service';
import { DocumentNotePadComponent } from '../documentNotePad/document-note-pad.component';
import { WarnModalComponent } from '../modal/warn-modal.component';
import { RejectInfoBottomSheetComponent } from '../modal/reject-info.component';
import { ConfirmModalComponent } from '../modal/confirm-modal.component';
import { SuccessInfoValidBottomSheetComponent } from '../modal/success-info-valid.component';
selector: 'app-document',
templateUrl: 'document.component.html',
trigger(
'enterApp',
[
transition(
':leave', [
style({ transform: 'translateY(0)' }),
animate('500ms', style({ transform: 'translateY(-100%)' })),
]
)]
),
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 })),
]
)]
)
],
pageNum = 1;
signaturesContent: any = [];
totalPages: number;
draggable: boolean;
loadingDoc = true;
signaturePadPosX = 0;
signaturePadPosY = 50;
pdfDataArr: any;
@ViewChild('snavRight') snavRight: MatSidenav;
@ViewChild('canvas') canvas: ElementRef;
@ViewChild('canvasWrapper') canvasWrapper: ElementRef;
@ViewChild('appDocumentNotePad') appDocumentNotePad: DocumentNotePadComponent;
constructor(private router: Router, private route: ActivatedRoute, public http: HttpClient,
public signaturesService: SignaturesContentService,
public notificationService: NotificationService,
private cookieService: CookieService,
private sanitization: DomSanitizer, public dialog: MatDialog, private bottomSheet: MatBottomSheet) {
if (!this.cookieService.check('maarchParapheurAuth')) {
this.router.navigate(['/login']);
}
setTimeout(() => {
this.enterApp = false;
}, 500);
this.route.params.subscribe(params => {
if (typeof params['id'] !== 'undefined') {
this.http.get('../rest/documents/' + params['id'])
.subscribe((data: any) => {
this.signaturesService.mainDocumentId = this.mainDocument.id;
if (this.signaturesService.signaturesList.length === 0) {
this.http.get('../rest/users/' + this.signaturesService.userLogged.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 });
this.mainDocument.attachments.forEach((attach: any, index: any) => {
this.docList.push({ 'id': attach.id, 'encodedDocument': '', 'title': '' });
this.snav.open();
this.freezeSidenavClose = true;
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;
}
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;
}
pageRendered(e: any) {
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.signaturesService.signWidth = this.signaturesService.workingAreaWidth / 4.5;
prevPage() {
this.pageNum--;
if (this.pageNum === 0) {
this.pageNum = 1;
} else {
}
if (this.currentDoc === 0) {
this.signaturesService.currentPage = this.pageNum;
}
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;
}
this.signaturesService.isTaggable = false;
this.pageNum = 1;
this.currentDoc++;
this.pdfRender(this.docList[this.currentDoc]);
this.loadNextDoc();
this.pageNum = 1;
this.currentDoc--;
if (this.currentDoc === 0) {
this.signaturesService.currentPage = 1;
this.signaturesService.isTaggable = true;
}
this.pdfRender(this.docList[this.currentDoc]);
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
if (!this.signaturesService.lockNote && this.currentDoc === 0) {
this.signaturesService.annotationMode = true;
this.signaturesService.lockNote = true;
}
}
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;
}
});
}
const dialogRef = this.dialog.open(ConfirmModalComponent, {
width: '350px',
});
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]);
}
this.signaturesService.showPad = false;
const config: MatBottomSheetConfig = {
disableClose: false,
direction: 'ltr'
};
this.bottomSheet.open(SignaturesComponent, config);
}
removeTags() {
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');
if (this.docList[this.currentDoc + 1] && this.docList[this.currentDoc + 1].id && this.docList[this.currentDoc + 1].encodedDocument === '') {
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);
launchEvent(action: any) {
this.signaturesService.currentAction = action.id;
this[action.event]();
}