diff --git a/src/Components/RightSidebar/AppFilesTab.vue b/src/Components/RightSidebar/AppFilesTab.vue index c32f90c3c8..04719a1149 100644 --- a/src/Components/RightSidebar/AppFilesTab.vue +++ b/src/Components/RightSidebar/AppFilesTab.vue @@ -30,14 +30,73 @@ export default { }, data() { return { - file: {}, - signers: [], - requested_by: {}, - requestDate: '', + sidebarTitleObserver: null, } }, methods: { + checkAndLoadPendingEnvelope() { + const pendingEnvelope = window.OCA?.Libresign?.pendingEnvelope + if (pendingEnvelope?.id) { + this.filesStore.addFile(pendingEnvelope) + this.filesStore.selectFile(pendingEnvelope.id) + delete window.OCA.Libresign.pendingEnvelope + + this.$nextTick(() => { + this.updateSidebarTitle(pendingEnvelope.name) + }) + + return true + } + return false + }, + + updateSidebarTitle(envelopeName) { + if (!envelopeName) return + + this.disconnectTitleObserver() + + const titleElement = document.querySelector('.app-sidebar-header__mainname') + + if (titleElement) { + titleElement.textContent = envelopeName + titleElement.setAttribute('title', envelopeName) + + this.sidebarTitleObserver = new MutationObserver(() => { + if (titleElement.textContent !== envelopeName) { + titleElement.textContent = envelopeName + titleElement.setAttribute('title', envelopeName) + } + }) + + this.sidebarTitleObserver.observe(titleElement, { + childList: true, + characterData: true, + subtree: true + }) + + setTimeout(() => this.disconnectTitleObserver(), 5000) + } + }, + + disconnectTitleObserver() { + if (this.sidebarTitleObserver) { + console.log('Disconnecting sidebar title observer') + this.sidebarTitleObserver.disconnect() + this.sidebarTitleObserver = null + } + }, + async update(fileInfo) { + if (this.checkAndLoadPendingEnvelope()) { + return + } + + this.disconnectTitleObserver() + + if (this.filesStore.selectedId === fileInfo.id) { + return + } + this.filesStore.addFile({ nodeId: fileInfo.id, name: fileInfo.name, @@ -46,6 +105,14 @@ export default { signers: [], }) this.filesStore.selectFile(fileInfo.id) + + this.$nextTick(() => { + const titleElement = document.querySelector('.app-sidebar-header__mainname') + if (titleElement) { + titleElement.textContent = fileInfo.name + titleElement.setAttribute('title', fileInfo.name) + } + }) }, }, } diff --git a/src/actions/openInLibreSignAction.js b/src/actions/openInLibreSignAction.js index 5579c1248c..c891f2a27d 100644 --- a/src/actions/openInLibreSignAction.js +++ b/src/actions/openInLibreSignAction.js @@ -79,9 +79,16 @@ export const action = new FileAction({ return new Array(nodes.length).fill(null) } + const rawDir = nodes[0].dirname ?? nodes[0].path.substring(0, nodes[0].path.lastIndexOf('/')) + const normalizedDir = (rawDir && rawDir !== '/') ? rawDir.replace(/\/+$/, '') : '' + const envelopePath = normalizedDir ? `${normalizedDir}/${envelopeName}` : `/${envelopeName}` + return axios.post(generateOcsUrl('/apps/libresign/api/v1/file'), { files: nodes.map(node => ({ fileId: node.fileid })), name: envelopeName, + settings: { + path: envelopePath, + }, }).then((response) => { const envelopeData = response.data?.ocs?.data