Skip to content

Commit 3003bba

Browse files
authored
Merge pull request #6284 from LibreSign/backport/6283/stable31
[stable31] fix: load envelope child files in signature positions modal
2 parents 3ad9f7b + 77f28fc commit 3003bba

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

src/Components/Request/VisibleElements.vue

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
</NcButton>
5555
</div>
5656
<div class="image-page">
57-
<PdfEditor ref="pdfEditor"
57+
<PdfEditor v-if="!filesStore.loading && pdfFiles.length > 0"
58+
ref="pdfEditor"
5859
width="100%"
5960
height="100%"
6061
:files="pdfFiles"
@@ -69,9 +70,9 @@
6970
import axios from '@nextcloud/axios'
7071
import { getCapabilities } from '@nextcloud/capabilities'
7172
import { showSuccess, showError } from '@nextcloud/dialogs'
72-
import { subscribe, unsubscribe, emit } from '@nextcloud/event-bus'
73+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
7374
import { loadState } from '@nextcloud/initial-state'
74-
import { generateOcsUrl } from '@nextcloud/router'
75+
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
7576
7677
import NcButton from '@nextcloud/vue/components/NcButton'
7778
import NcDialog from '@nextcloud/vue/components/NcDialog'
@@ -108,7 +109,7 @@ export default {
108109
signerSelected: null,
109110
width: getCapabilities().libresign.config['sign-elements']['full-signature-width'],
110111
height: getCapabilities().libresign.config['sign-elements']['full-signature-height'],
111-
filePagesMap: {},
112+
filePagesMap: {},
112113
elementsLoaded: false,
113114
loadedPdfsCount: 0,
114115
}
@@ -130,14 +131,10 @@ export default {
130131
return this.filesStore.getFile()
131132
},
132133
pdfFiles() {
133-
return this.document.files.map(f => f.file)
134+
return (this.document.files || []).map(f => f.file)
134135
},
135136
pdfFileNames() {
136-
return this.document.files.map(f => {
137-
const metadata = f.metadata
138-
const ext = metadata?.extension || 'pdf'
139-
return `${f.name}.${ext}`
140-
})
137+
return (this.document.files || []).map(f => `${f.name}.${f.metadata?.extension || 'pdf'}`)
141138
},
142139
documentNameWithExtension() {
143140
const doc = this.document
@@ -200,14 +197,56 @@ export default {
200197
}
201198
this.modal = true
202199
this.filesStore.loading = true
200+
201+
if (this.document.nodeType === 'envelope' && this.document.files.length === 0) {
202+
await this.fetchEnvelopeFiles()
203+
} else if (this.document.nodeType !== 'envelope') {
204+
if (!this.document.files || this.document.files.length === 0) {
205+
const fileUrl = this.document.file || generateUrl('/apps/libresign/p/pdf/{uuid}', { uuid: this.document.uuid })
206+
this.document.files = [{
207+
id: this.document.id,
208+
nodeId: this.document.nodeId,
209+
uuid: this.document.uuid,
210+
name: this.document.name,
211+
file: fileUrl,
212+
metadata: this.document.metadata,
213+
signers: this.document.signers,
214+
visibleElements: this.document.visibleElements || [],
215+
}]
216+
} else {
217+
this.document.files = this.document.files.map(f => {
218+
if (!f.file) {
219+
const fileUrl = this.document.file || generateUrl('/apps/libresign/p/pdf/{uuid}', { uuid: f.uuid || this.document.uuid })
220+
return { ...f, file: fileUrl }
221+
}
222+
return f
223+
})
224+
}
225+
}
226+
203227
this.buildFilePagesMap()
204228
this.filesStore.loading = false
205229
},
230+
async fetchEnvelopeFiles() {
231+
const response = await axios.get(generateOcsUrl('/apps/libresign/api/v1/file/list'), {
232+
params: {
233+
parentFileId: this.document.id,
234+
force_fetch: true,
235+
},
236+
})
237+
const childFiles = response?.data?.ocs?.data?.data || []
238+
this.document.files = Array.isArray(childFiles) ? childFiles : []
239+
},
206240
buildFilePagesMap() {
207241
this.filePagesMap = {}
208242
243+
const filesToProcess = this.document.files || []
244+
if (!Array.isArray(filesToProcess)) {
245+
return
246+
}
247+
209248
let currentPage = 1
210-
this.document.files.forEach((file, index) => {
249+
filesToProcess.forEach((file, index) => {
211250
const metadata = file.metadata
212251
const pageCount = metadata?.p || 0
213252
for (let i = 0; i < pageCount; i++) {
@@ -228,21 +267,22 @@ export default {
228267
this.loadedPdfsCount = 0
229268
},
230269
getPageHeightForFile(fileId, page) {
231-
const fileInfo = this.document.files.find(f => f.id === fileId)
270+
const filesToSearch = this.document.files || []
271+
const fileInfo = filesToSearch.find(f => f.id === fileId)
232272
const metadata = fileInfo?.metadata
233273
return metadata?.d?.[page - 1]?.h
234274
},
235275
updateSigners(data) {
236276
this.loadedPdfsCount++
237277
238-
const expectedPdfsCount = this.document.files.length
278+
const filesToProcess = this.document.files || []
279+
const expectedPdfsCount = filesToProcess.length
239280
if (this.elementsLoaded || this.loadedPdfsCount < expectedPdfsCount) {
240281
return
241282
}
242283
243-
// Coletar visibleElements de múltiplas fontes no array unificado `files`
244284
let visibleElementsToAdd = []
245-
this.document.files.forEach((f, fileIndex) => {
285+
filesToProcess.forEach((f, fileIndex) => {
246286
const elements = Array.isArray(f.visibleElements) ? f.visibleElements : []
247287
elements.forEach(element => {
248288
visibleElementsToAdd.push({
@@ -253,12 +293,11 @@ export default {
253293
})
254294
})
255295
256-
// Adicionar signers com seus elementos usando correspondência por identifyMethods
257296
visibleElementsToAdd.forEach(element => {
258297
let envelopeSignerMatch = null
259298
let childSigner = null
260299
if (element.fileId) {
261-
const fileInfo = this.document.files.find(f => f.id === element.fileId)
300+
const fileInfo = filesToProcess.find(f => f.id === element.fileId)
262301
if (fileInfo) {
263302
childSigner = (fileInfo.signers || []).find(s => s.signRequestId === element.signRequestId)
264303
}
@@ -286,7 +325,6 @@ export default {
286325
return
287326
}
288327
289-
// fallback: add without documentIndex
290328
object.element = element
291329
this.$refs.pdfEditor.addSigner(object)
292330
})
@@ -413,7 +451,6 @@ export default {
413451
objects.forEach(object => {
414452
if (!object.signer) return
415453
416-
// Map per-file page index to global using filePagesMap
417454
let globalPageNumber = object.pageNumber
418455
for (const [page, info] of Object.entries(this.filePagesMap)) {
419456
if (info.fileIndex === docIndex) {
@@ -422,7 +459,6 @@ export default {
422459
}
423460
}
424461
425-
// Coordinates normalized for PDF editor
426462
const pageInfo = this.filePagesMap[globalPageNumber]
427463
const pageHeight = this.getPageHeightForFile(pageInfo.id, object.pageNumber)
428464
if (!pageHeight) {
@@ -448,12 +484,10 @@ export default {
448484
coordinates,
449485
}
450486
451-
// Target file and per-file page number
452487
const targetFileId = pageInfo.id
453488
element.fileId = targetFileId
454489
element.coordinates.page = globalPageNumber - pageInfo.startPage + 1
455490
456-
// Resolve child signer SR for the specific file via identifyMethods
457491
const fileInfo = this.document.files.find(f => f.id === targetFileId)
458492
if (!fileInfo || !Array.isArray(fileInfo.signers)) {
459493
return

0 commit comments

Comments
 (0)