Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] chore: remove deprecated property #3995

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
* type: 'info',
* message: string,
* }[],
* visibleElements?: LibresignVisibleElement[],
* }
* @psalm-type LibresignFile = array{
* account: array{
Expand Down
70 changes: 47 additions & 23 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,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']]);
Expand Down Expand Up @@ -520,29 +533,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(),
Expand Down Expand Up @@ -599,6 +593,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(),
Expand Down
6 changes: 6 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,12 @@
}
}
}
},
"visibleElements": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VisibleElement"
}
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,12 @@
}
}
}
},
"visibleElements": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VisibleElement"
}
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions src/Components/PdfEditor/PdfEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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)" />
</template>
Expand Down Expand Up @@ -76,8 +74,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) {
Expand Down
8 changes: 0 additions & 8 deletions src/Components/PdfEditor/Signature.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ export default {
type: Number,
default: 1,
},
canvasWidth: {
type: Number,
default: 1,
},
canvasHeight: {
type: Number,
default: 1,
},
fixSize: {
type: Boolean,
default: false,
Expand Down
5 changes: 1 addition & 4 deletions src/Components/Request/VisibleElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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)
Expand All @@ -222,7 +222,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
Expand All @@ -233,8 +232,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)
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ export type components = {
type: "info";
message: string;
}[];
visibleElements?: components["schemas"]["VisibleElement"][];
};
VisibleElement: {
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ export type components = {
type: "info";
message: string;
}[];
visibleElements?: components["schemas"]["VisibleElement"][];
};
VisibleElement: {
/** Format: int64 */
Expand Down
Loading