diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 6677c1468f..2b0756e76e 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -153,6 +153,7 @@ * type: 'info', * message: string, * }[], + * visibleElements?: LibresignVisibleElement[], * } * @psalm-type LibresignFile = array{ * account: array{ diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 7c20b31c2e..ba1bc45977 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -370,6 +370,19 @@ private function getFile(): array { 'displayName' => $this->userManager->get($this->file->getUserId())->getDisplayName(), ]; $return['file'] = $this->urlGenerator->linkToRoute('libresign.page.getPdf', ['uuid' => $this->file->getUuid()]); + if ($this->showVisibleElements) { + $signers = $this->signRequestMapper->getByMultipleFileId([$this->file->getId()]); + $return['visibleElements'] = []; + foreach ($this->signRequestMapper->getVisibleElementsFromSigners($signers) as $visibleElements) { + $return['visibleElements'] = array_merge( + $this->formatVisibleElementsToArray( + $visibleElements, + $this->file->getMetadata() + ), + $return['visibleElements'] + ); + } + } foreach ($this->getSigners() as $signer) { if ($signer['me']) { $return['url'] = $this->urlGenerator->linkToRoute('libresign.page.getPdfFile', ['uuid' => $signer['sign_uuid']]); @@ -504,29 +517,10 @@ private function associateAllAndFormat(IUser $user, array $files, array $signers } return $carry; }, false), - 'visibleElements' => array_map(function (FileElement $visibleElement) use ($file) { - $element = [ - 'elementId' => $visibleElement->getId(), - 'signRequestId' => $visibleElement->getSignRequestId(), - 'type' => $visibleElement->getType(), - 'coordinates' => [ - 'page' => $visibleElement->getPage(), - 'urx' => $visibleElement->getUrx(), - 'ury' => $visibleElement->getUry(), - 'llx' => $visibleElement->getLlx(), - 'lly' => $visibleElement->getLly() - ] - ]; - $metadata = json_decode($file['metadata'], true); - $dimension = $metadata['d'][$element['coordinates']['page'] - 1]; - - $element['coordinates']['left'] = $element['coordinates']['llx']; - $element['coordinates']['height'] = abs($element['coordinates']['ury'] - $element['coordinates']['lly']); - $element['coordinates']['top'] = $dimension['h'] - $element['coordinates']['ury']; - $element['coordinates']['width'] = $element['coordinates']['urx'] - $element['coordinates']['llx']; - - return $element; - }, $visibleElements[$signer->getId()] ?? []), + 'visibleElements' => $this->formatVisibleElementsToArray( + $visibleElements[$signer->getId()] ?? [], + json_decode($file['metadata'], true) + ), 'identifyMethods' => array_map(function (IdentifyMethod $identifyMethod) use ($signer): array { return [ 'method' => $identifyMethod->getIdentifierKey(), @@ -583,6 +577,36 @@ private function associateAllAndFormat(IUser $user, array $files, array $signers return $files; } + /** + * @param FileElement[] $visibleElements + * @param array + * @return array + */ + private function formatVisibleElementsToArray(array $visibleElements, array $metadata): array { + return array_map(function (FileElement $visibleElement) use ($metadata) { + $element = [ + 'elementId' => $visibleElement->getId(), + 'signRequestId' => $visibleElement->getSignRequestId(), + 'type' => $visibleElement->getType(), + 'coordinates' => [ + 'page' => $visibleElement->getPage(), + 'urx' => $visibleElement->getUrx(), + 'ury' => $visibleElement->getUry(), + 'llx' => $visibleElement->getLlx(), + 'lly' => $visibleElement->getLly() + ] + ]; + $dimension = $metadata['d'][$element['coordinates']['page'] - 1]; + + $element['coordinates']['left'] = $element['coordinates']['llx']; + $element['coordinates']['height'] = abs($element['coordinates']['ury'] - $element['coordinates']['lly']); + $element['coordinates']['top'] = $dimension['h'] - $element['coordinates']['ury']; + $element['coordinates']['width'] = $element['coordinates']['urx'] - $element['coordinates']['llx']; + + return $element; + }, $visibleElements); + } + public function getMyLibresignFile(int $nodeId): File { return $this->signRequestMapper->getMyLibresignFile( userId: $this->me->getUID(), diff --git a/openapi-full.json b/openapi-full.json index 8badd571ae..8479e0bb33 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -794,6 +794,12 @@ } } } + }, + "visibleElements": { + "type": "array", + "items": { + "$ref": "#/components/schemas/VisibleElement" + } } } }, diff --git a/openapi.json b/openapi.json index 0f582fc3b0..5e52209878 100644 --- a/openapi.json +++ b/openapi.json @@ -698,6 +698,12 @@ } } } + }, + "visibleElements": { + "type": "array", + "items": { + "$ref": "#/components/schemas/VisibleElement" + } } } }, diff --git a/package-lock.json b/package-lock.json index f157ea152b..33d5dcb99a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "agpl", "dependencies": { "@fontsource/dancing-script": "^5.1.0", - "@libresign/vue-pdf-editor": "^1.4.4", + "@libresign/vue-pdf-editor": "^1.4.5", "@marionebl/option": "^1.0.8", "@mdi/js": "^7.4.47", "@mdi/svg": "^7.4.47", @@ -2635,9 +2635,9 @@ "peer": true }, "node_modules/@libresign/vue-pdf-editor": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/@libresign/vue-pdf-editor/-/vue-pdf-editor-1.4.4.tgz", - "integrity": "sha512-UpyqrLy11guAgJ3swndbjzJtLRqcqNt3SpTdet5b6JDPZtActkWwcZ5vbhYgic3oJXAGu4AKr+F0RQrBoEXcTA==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/@libresign/vue-pdf-editor/-/vue-pdf-editor-1.4.5.tgz", + "integrity": "sha512-ntt3JWlXSXuaQzH7wzdLlgD13fKEReTaQbEMw0WkFyNFzCHfQs2PmMHrz4vLyX1qGFcu4k7gHcJmnbForJ6eog==", "license": "MIT", "dependencies": { "@cantoo/pdf-lib": "^2.2.3", diff --git a/package.json b/package.json index 5b261b9c13..4adc585bba 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "dependencies": { "@fontsource/dancing-script": "^5.1.0", - "@libresign/vue-pdf-editor": "^1.4.4", + "@libresign/vue-pdf-editor": "^1.4.5", "@marionebl/option": "^1.0.8", "@mdi/js": "^7.4.47", "@mdi/svg": "^7.4.47", diff --git a/src/Components/PdfEditor/PdfEditor.vue b/src/Components/PdfEditor/PdfEditor.vue index f8f6ce19aa..8d29ad8461 100644 --- a/src/Components/PdfEditor/PdfEditor.vue +++ b/src/Components/PdfEditor/PdfEditor.vue @@ -30,8 +30,6 @@ :origin-width="object.originWidth" :origin-height="object.originHeight" :page-scale="pagesScale" - :canvas-width="object.canvasWidth" - :canvas-height="object.canvasHeight" @onUpdate="$refs.vuePdfEditor.updateObject(object.id, $event)" @onDelete="onDeleteSigner(object)" /> @@ -80,8 +78,6 @@ export default { originHeight: signer.element.coordinates.height, x: signer.element.coordinates.llx, y: signer.element.coordinates.ury, - canvasWidth: signer.element.coordinates.canvasWidth, - canvasHeight: signer.element.coordinates.canvasHeight, } this.$refs.vuePdfEditor.allObjects = this.$refs.vuePdfEditor.allObjects.map((objects, pIndex) => { if (pIndex === signer.element.coordinates.page - 1) { diff --git a/src/Components/PdfEditor/Signature.vue b/src/Components/PdfEditor/Signature.vue index e59155c7de..157352b3c9 100644 --- a/src/Components/PdfEditor/Signature.vue +++ b/src/Components/PdfEditor/Signature.vue @@ -93,14 +93,6 @@ export default { type: Number, default: 1, }, - canvasWidth: { - type: Number, - default: 1, - }, - canvasHeight: { - type: Number, - default: 1, - }, fixSize: { type: Boolean, default: false, diff --git a/src/Components/Request/VisibleElements.vue b/src/Components/Request/VisibleElements.vue index 249c0638c5..272873696e 100644 --- a/src/Components/Request/VisibleElements.vue +++ b/src/Components/Request/VisibleElements.vue @@ -199,7 +199,7 @@ export default { updateSigners(data) { this.document.signers.forEach(signer => { if (this.document.visibleElements) { - this.document.visibleElements.forEach(element => { + Object.values(this.document.visibleElements).forEach(element => { if (element.signRequestId === signer.signRequestId) { const object = structuredClone(signer) element.coordinates.ury = Math.round(data.measurement[element.coordinates.page].height) @@ -226,7 +226,6 @@ export default { this.stopAddSigner() }, addSignerToPosition(event, page) { - const measurement = this.$refs.pdfEditor.$refs.vuePdfEditor.$refs['page' + page][0].getCanvasMeasurement() const rect = event.target.getBoundingClientRect() const x = event.clientX - rect.left const y = event.clientY - rect.top @@ -237,8 +236,6 @@ export default { ury: y - SignatureImageDimensions.height / 2, height: SignatureImageDimensions.height, width: SignatureImageDimensions.width, - canvasWidth: measurement.canvasWidth, - canvasHeight: measurement.canvasHeight, }, } this.$refs.pdfEditor.addSigner(this.signerSelected) diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index febe0d49d5..bec8581075 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -1262,6 +1262,7 @@ export type components = { type: "info"; message: string; }[]; + visibleElements?: components["schemas"]["VisibleElement"][]; }; VisibleElement: { /** Format: int64 */ diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 0822e40042..04c7b08487 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -1116,6 +1116,7 @@ export type components = { type: "info"; message: string; }[]; + visibleElements?: components["schemas"]["VisibleElement"][]; }; VisibleElement: { /** Format: int64 */