Skip to content

Commit

Permalink
feat: implement sign tab
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed Apr 2, 2024
1 parent 8483ae4 commit 0a9aa6b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 14 deletions.
17 changes: 16 additions & 1 deletion src/Components/RightSidebar/RightSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
:subtitle="subTitle"
:active="fileName"
@close="closeSidebar">
<NcAppSidebarTab v-if="showListSigners"
<NcAppSidebarTab v-if="showSign()"
id="sign-tab"
name="">
<SignTab />
</NcAppSidebarTab>
<NcAppSidebarTab v-if="showListSigners()"
id="request-signature-list-signers"
:name="fileName">
<RequestSignatureTab />
Expand All @@ -16,6 +21,7 @@
import NcAppSidebar from '@nextcloud/vue/dist/Components/NcAppSidebar.js'
import NcAppSidebarTab from '@nextcloud/vue/dist/Components/NcAppSidebarTab.js'
import RequestSignatureTab from '../RightSidebar/RequestSignatureTab.vue'
import SignTab from '../RightSidebar/SignTab.vue'
import { useFilesStore } from '../../store/files.js'
import { useSignStore } from '../../store/sign.js'
Expand All @@ -25,6 +31,7 @@ export default {
NcAppSidebar,
NcAppSidebarTab,
RequestSignatureTab,
SignTab,
},
setup() {
const filesStore = useFilesStore()
Expand All @@ -48,9 +55,17 @@ export default {
methods: {
showListSigners() {
return !!this.filesStore.getFile()?.name
&& !this.showSign()
},
showSign() {
return this.signStore.document.uuid.length > 0
},
handleUpdateActive() {
console.log('handleUpdateActive')

Check warning on line 64 in src/Components/RightSidebar/RightSidebar.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
},
closeSidebar() {
this.filesStore.selectFile()
this.signStore.reset()
this.$emit('close')
},
},
Expand Down
92 changes: 92 additions & 0 deletions src/Components/RightSidebar/SignTab.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>
<div class="sign-pdf-sidebar">
<header>
<img class="pdf-icon" :src="PDFIcon">
<h1>
{{ signStore.document.name }}
<br>
<Chip>
{{ signStore.document.statusText }}
</Chip>
</h1>
</header>

<main>
<div v-if="loading" class="sidebar-loading">
<p>
{{ t('libresign', 'Loading …') }}
</p>
</div>
<div v-if="!signEnabled">
{{ t('libresign', 'Document not available for signature.') }}
</div>
<Sign v-else-if="!loading"
v-bind="{ docType }"
@signed="onSigned" />
</main>
</div>
</template>

<script>
import PDFIcon from '../../../img/application-pdf.png'
import { SIGN_STATUS } from '../../domains/sign/enum.js'
import Chip from '../../Components/Chip.vue'
import Sign from '../../views/SignPDF/_partials/Sign.vue'
import { useSignStore } from '../../store/sign.js'
export default {
name: 'SignTab',
components: {
Chip,
Sign,
},
setup() {
const signStore = useSignStore()
return { signStore }
},
data() {
return {
loading: true,
PDFIcon,
}
},
computed: {
docType() {
return this.$route.name === 'AccountFileApprove'
? 'document-validate'
: 'default'
},
},
methods: {
signEnabled() {
return SIGN_STATUS.ABLE_TO_SIGN === this.signStore.document.status
|| SIGN_STATUS.PARTIAL_SIGNED === this.signStore.document.status
},
updateSigners(data) {
this.signStore.document.signers.forEach(signer => {
if (this.signStore.document.visibleElements) {
this.signStore.document.visibleElements.forEach(element => {
if (element.signRequestId === signer.signRequestId) {
const object = structuredClone(signer)
object.readOnly = true
element.coordinates.ury = Math.round(data.measurement[element.coordinates.page].height)
- element.coordinates.ury
object.element = element
this.$refs.pdfEditor.addSigner(object)
}
})
}
})
this.loading = false
},
onSigned(data) {
this.$router.push({
name: 'DefaultPageSuccess',
params: {
uuid: data.file.uuid,
},
})
},
},
}
</script>
5 changes: 5 additions & 0 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { set } from 'vue'
import Moment from '@nextcloud/moment'
import { useSignStore } from './sign.js'

export const useFilesStore = defineStore('files', {
state: () => {
Expand All @@ -42,6 +43,10 @@ export const useFilesStore = defineStore('files', {
},
selectFile(nodeId) {
this.selectedNodeId = nodeId ?? 0
if (this.selectedNodeId === 0) {
const signStore = useSignStore()
signStore.reset()
}
},
getFile() {
return this.files[this.selectedNodeId] ?? {}
Expand Down
31 changes: 18 additions & 13 deletions src/store/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
import { defineStore } from 'pinia'
import { loadState } from '@nextcloud/initial-state'

const defaultState = {
errors: [],
document: {
name: '',
description: '',
status: '',
statusText: '',
url: '',
uuid: '',
signers: [],
visibleElements: [],
},
}

export const useSignStore = defineStore('sign', {
state: () => ({
errors: [],
document: {
name: '',
description: '',
status: '',
statusText: '',
url: '',
uuid: '',
signers: [],
visibleElements: [],
},
}),
state: () => ({ ...defaultState }),

actions: {
initFromState() {
Expand All @@ -52,5 +54,8 @@ export const useSignStore = defineStore('sign', {
visibleElements: loadState('libresign', 'visibleElements', []),
}
},
reset() {
Object.assign(this, defaultState);

Check failure on line 58 in src/store/sign.js

View workflow job for this annotation

GitHub Actions / NPM lint

Extra semicolon
}

Check warning on line 59 in src/store/sign.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing trailing comma
},
})

0 comments on commit 0a9aa6b

Please sign in to comment.