From 6cc631111ce9bf0b0545c1680814071c3df3eb7d Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 21 Oct 2025 09:38:47 +0200 Subject: [PATCH] refactor(annotation): simplify field mapping and return structured objects Refactored the mapSignature function to: - Return cleaner structured objects for formFields, frames, and signatures - Include `type` and `value` properties in returned objects - Remove direct mutation of field and annotation objects - Improve readability and maintainability of data mapping logic --- .../wwwroot/js/annotation.js | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/EnvelopeGenerator.Web/wwwroot/js/annotation.js b/EnvelopeGenerator.Web/wwwroot/js/annotation.js index 097840f6..5f3199d8 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/annotation.js +++ b/EnvelopeGenerator.Web/wwwroot/js/annotation.js @@ -320,34 +320,44 @@ function mapSignature(iJSON) { return { formFields: iJSON.formFieldValues.filter(field => !field.name.includes("label")).map((field) => { const nameParts = field.name.split('#'); - field.elementId = Number(nameParts[2]); - field.name = nameParts[3]; - return field; + return { + elementId: Number(nameParts[2]), + name: nameParts[3], + value: field.value, + type: field.type + }; }), frames: iJSON.annotations.filter(annot => annot.description === 'FRAME').map((annot) => { const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature"))); const idPartsOfPre = preElement.id.split('#'); - annot.elementId = Number(idPartsOfPre[2]); - annot.name = 'frame'; - annot.value = fixBase64(iJSON.attachments[annot.imageAttachmentId]?.binary); - return annot; + return { + elementId: Number(idPartsOfPre[2]), + name: 'frame', + value: fixBase64(iJSON.attachments[annot.imageAttachmentId]?.binary), + type: annot.type + }; }), signatures: iJSON.annotations.filter(annot => annot.isSignature).map(annot => { const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature"))); const idPartsOfPre = preElement.id.split('#'); - annot.elementId = Number(idPartsOfPre[2]); + + let value; if (annot.imageAttachmentId) - annot.value = iJSON.attachments[annot.imageAttachmentId]?.binary; + value = iJSON.attachments[annot.imageAttachmentId]?.binary; else if (annot.lines && annot.strokeColor) - annot.value = JSON.stringify({ + value = JSON.stringify({ lines: annot.lines, strokeColor: annot.strokeColor }); else throw new Error("Signature mapping failed: The data structure from the third-party library is incompatible or missing required fields."); - annot.name = 'signature'; - return annot; + return { + elementId: Number(idPartsOfPre[2]), + name: 'signature', + value, + type: annot.type + }; }) }; } \ No newline at end of file