Skip to content
Snippets Groups Projects
Commit 8a8edf35 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #14565 TIME 1 fix note send doc + improve handle errors + functions refactoring

parent b46e9d2e
No related branches found
No related tags found
No related merge requests found
......@@ -467,9 +467,9 @@ export class DocumentComponent implements OnInit {
if (notesContent) {
const storageContent = JSON.parse(notesContent);
this.signaturesService.notesContent = storageContent['note'];
this.signaturesService.signaturesContent = storageContent['sign'];
this.signaturesService.datesContent = storageContent['date'];
this.signaturesService.notesContent = storageContent['note'] !== undefined ? storageContent['note'] : [];
this.signaturesService.signaturesContent = storageContent['sign'] !== undefined ? storageContent['sign'] : [];
this.signaturesService.datesContent = storageContent['date'] !== undefined ? storageContent['date'] : [];
}
this.signaturesService.currentAction = 0;
......
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { LatinisePipe } from 'ngx-pipes';
import { tap, catchError } from 'rxjs/operators';
import { SignaturesContentService } from './signatures.service';
import { NotificationService } from '../service/notification.service';
......@@ -16,67 +15,21 @@ export class ActionsService {
constructor(
public http: HttpClient,
public translate: TranslateService,
private latinisePipe: LatinisePipe,
public notificationService: NotificationService,
public signaturesService: SignaturesContentService,
private functionsService: FunctionsService
) { }
sendDocument(note: string, eSignature: any = null, signatureLength: any = null, tmpUniqueId: string = null, imgSignatures: any[] = null) {
sendDocument(note: string, eSignature: any = null, signatureLength: any = null, tmpUniqueId: string = null, imgDocElements: any[] = null) {
return new Promise(async (resolve) => {
let signatures: any[] = [];
let data: any = {};
if (this.signaturesService.currentAction > 0) {
if (imgSignatures === null) {
for (let index = 1; index <= this.signaturesService.totalPage; index++) {
if (this.signaturesService.datesContent[index]) {
this.signaturesService.datesContent[index].forEach((date: any) => {
signatures.push(
{
'encodedImage': date.content.replace('data:image/svg+xml;base64,', ''),
'width': date.width,
'positionX': date.positionX,
'positionY': date.positionY,
'type': 'SVG',
'page': index,
}
);
});
}
if (this.signaturesService.signaturesContent[index]) {
this.signaturesService.signaturesContent[index].forEach((signature: any) => {
signatures.push(
{
'encodedImage': signature.encodedSignature,
'width': signature.width,
'positionX': signature.positionX,
'positionY': signature.positionY,
'type': 'PNG',
'page': index,
}
);
});
}
if (this.signaturesService.notesContent[index]) {
this.signaturesService.notesContent[index].forEach((noteItem: any) => {
signatures.push(
{
'encodedImage': noteItem.fullPath.replace('data:image/png;base64,', ''),
'width': noteItem.width,
'positionX': noteItem.positionX,
'positionY': noteItem.positionY,
'type': 'PNG',
'page': index,
}
);
});
}
}
if (imgDocElements === null) {
data.signatures = this.getElementsFromDoc();
} else {
signatures = imgSignatures;
data.signatures = imgDocElements;
}
let data: any = {};
data.signatures = signatures;
if (eSignature !== null) {
data = {...data, ...eSignature };
......@@ -125,4 +78,54 @@ export class ActionsService {
}
});
}
getElementsFromDoc() {
const signatures: any[] = [];
for (let index = 1; index <= this.signaturesService.totalPage; index++) {
if (this.signaturesService.datesContent[index]) {
this.signaturesService.datesContent[index].forEach((date: any) => {
signatures.push(
{
'encodedImage': date.content.replace('data:image/svg+xml;base64,', ''),
'width': date.width,
'positionX': date.positionX,
'positionY': date.positionY,
'type': 'SVG',
'page': index,
}
);
});
}
if (this.signaturesService.signaturesContent[index]) {
this.signaturesService.signaturesContent[index].forEach((signature: any) => {
signatures.push(
{
'encodedImage': signature.encodedSignature,
'width': signature.width,
'positionX': signature.positionX,
'positionY': signature.positionY,
'type': 'PNG',
'page': index,
}
);
});
}
if (this.signaturesService.notesContent[index]) {
this.signaturesService.notesContent[index].forEach((noteItem: any) => {
signatures.push(
{
'encodedImage': noteItem.fullPath.replace('data:image/png;base64,', ''),
'width': noteItem.width,
'positionX': noteItem.positionX,
'positionY': noteItem.positionY,
'type': 'PNG',
'page': index,
}
);
});
}
}
return signatures;
}
}
<ion-content>
<peculiar-fortify-certificates style="height: 100%;width: 100%;" language="fr" [filters]="filters"
(continue)="continueSignature($event)" (cancel)="cancelSign()" hide-footer></peculiar-fortify-certificates>
(continue)="certificateChosen($event)" (cancel)="cancelSign()" hide-footer></peculiar-fortify-certificates>
</ion-content>
......@@ -54,61 +54,15 @@ export class SignatureMethodModalComponent implements OnInit {
) { }
ngOnInit(): void {
this.getSignatures();
this.signatures = this.actionsService.getElementsFromDoc();
const signatureModeData = this.authService.signatureRoles.filter((mode: any) => mode.id === this.signatureMode)[0];
if (!this.functionsService.empty(signatureModeData.issuer)) {
this.filters.issuerDNMatch = new RegExp(signatureModeData.issuer, 'i');
}
}
getSignatures() {
for (let index = 1; index <= this.signaturesService.totalPage; index++) {
if (this.signaturesService.datesContent[index]) {
this.signaturesService.datesContent[index].forEach((date: any) => {
this.signatures.push(
{
'encodedImage': date.content.replace('data:image/svg+xml;base64,', ''),
'width': date.width,
'positionX': date.positionX,
'positionY': date.positionY,
'type': 'SVG',
'page': index,
}
);
});
}
if (this.signaturesService.signaturesContent[index]) {
this.signaturesService.signaturesContent[index].forEach((signature: any) => {
this.signatures.push(
{
'encodedImage': signature.encodedSignature,
'width': signature.width,
'positionX': signature.positionX,
'positionY': signature.positionY,
'type': 'PNG',
'page': index,
}
);
});
}
if (this.signaturesService.notesContent[index]) {
this.signaturesService.notesContent[index].forEach((noteItem: any) => {
this.signatures.push(
{
'encodedImage': noteItem.fullPath.replace('data:image/png;base64,', ''),
'width': noteItem.width,
'positionX': noteItem.positionX,
'positionY': noteItem.positionY,
'type': 'PNG',
'page': index,
}
);
});
}
}
}
async continueSignature(certData: any) {
async certificateChosen(certData: any) {
this.loadingController.create({
message: this.translate.instant('lang.processing'),
spinner: 'dots'
......@@ -138,6 +92,38 @@ export class SignatureMethodModalComponent implements OnInit {
});
}
async sendAndSign() {
let allSignaturesComplete: boolean = false;
let res: any = {};
while (!allSignaturesComplete) {
let signDocComplete: any = false;
while (signDocComplete === false) {
res = await this.fusionStampAndGenerateSignature(res.tmpUniqueId);
if (res === null) {
return false;
} else if (res !== false) {
signDocComplete = await this.signDocument(res.hashDocument, res.signatureContentLength, res.signatureFieldName, res.tmpUniqueId);
console.log('signDocComplete', signDocComplete);
if (signDocComplete === true) {
this.signatures.shift();
allSignaturesComplete = this.signatures.length === 0;
} else {
return false;
}
} else {
return false;
}
}
}
return allSignaturesComplete;
}
async fusionStampAndGenerateSignature(tmpUniqueId: string = null) {
let res: any = {};
res = await this.actionsService.sendDocument(null, this.certificate, this.signatureLength, tmpUniqueId, this.signatures);
return res;
}
signDocument(hashDocument: any, eSignatureLength: any, signatureFieldName: any, tmpUniqueId: string) {
return new Promise(async (resolve) => {
const alg = {
......@@ -156,6 +142,10 @@ export class SignatureMethodModalComponent implements OnInit {
return of(false);
}
const note = {
note: this.note
};
const objEsign = {
signatures : this.signatures,
certificate: this.certPem,
......@@ -164,7 +154,10 @@ export class SignatureMethodModalComponent implements OnInit {
signatureFieldName: signatureFieldName,
tmpUniqueId: tmpUniqueId,
};
this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, objEsign)
const objToSend = {...note, ...objEsign };
this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, objToSend)
.pipe(
tap(() => {
resolve(true);
......@@ -175,7 +168,7 @@ export class SignatureMethodModalComponent implements OnInit {
resolve(false);
} else {
this.notificationService.handleErrors(err);
resolve(null);
resolve('error');
}
return of(false);
})
......@@ -184,27 +177,6 @@ export class SignatureMethodModalComponent implements OnInit {
});
}
async sendAndSign() {
let allSignaturesComplete: boolean = false;
let res: any = {};
while (!allSignaturesComplete) {
let signDocComplete: any = false;
while (signDocComplete === false) {
res = await this.actionsService.sendDocument(this.note, this.certificate, this.signatureLength, res.tmpUniqueId, this.signatures);
if (res === null) {
return false;
} else if (res !== false) {
signDocComplete = await this.signDocument(res.hashDocument, res.signatureContentLength, res.signatureFieldName, res.tmpUniqueId);
if (signDocComplete) {
this.signatures.shift();
allSignaturesComplete = this.signatures.length === 0;
}
}
}
}
return allSignaturesComplete;
}
cancelSign() {
this.modalController.dismiss(false);
}
......
......@@ -16,7 +16,6 @@ export class SignatureMethodService {
) { }
async checkAuthenticationAndLaunchAction(userWorkflow: any, note: any = null) {
console.log(userWorkflow);
if (['rgs_2stars', 'rgs_2stars_timestamped', 'inca_card', 'inca_card_eidas'].indexOf(userWorkflow.signatureMode) > -1) {
const res = await this.openRgsAuth(note, userWorkflow.signatureMode);
return res;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment