2222 </div >
2323</template >
2424
25- <script >
26- import { t } from ' @nextcloud/l10n '
25+ <script setup lang="ts" >
26+ import { computed , ref } from ' vue '
2727
2828import { mdiFile } from ' @mdi/js'
2929
@@ -33,91 +33,69 @@ import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
3333import { useFilesStore } from ' ../../store/files.js'
3434import { useSidebarStore } from ' ../../store/sidebar.js'
3535
36- export default {
36+ defineOptions ( {
3737 name: ' File' ,
38- components: {
39- NcIconSvgWrapper,
40- },
41- setup () {
42- const filesStore = useFilesStore ()
43- const sidebarStore = useSidebarStore ()
44- return {
45- filesStore,
46- sidebarStore,
47- mdiFile,
48- }
49- },
50- data () {
51- return {
52- backgroundFailed: false ,
53- gridMode: true ,
54- cropPreviews: true ,
55- }
56- },
57- computed: {
58- currentFileId () {
59- return this .filesStore .selectedFileId
60- },
61- currentFile () {
62- return this .filesStore .files [this .currentFileId ]
63- },
64- previewUrl () {
65- if (this .backgroundFailed === true ) {
66- return null
67- }
68-
69- if (! this .currentFile ) {
70- return null
71- }
72-
73- let previewUrl = ' '
74- if (this .currentFile .nodeId ) {
75- previewUrl = generateOcsUrl (' /apps/libresign/api/v1/file/thumbnail/{nodeId}' , {
76- nodeId: this .currentFile .nodeId ,
77- })
78- } else if (this .currentFile .id ) {
79- previewUrl = generateOcsUrl (' /apps/libresign/api/v1/file/thumbnail/file_id/{fileId}' , {
80- fileId: this .currentFile .id ,
81- })
82- } else {
83- previewUrl = window .location .origin + generateUrl (' /core/preview?fileId={fileid}' , {
84- fileid: this .currentFile .id ,
85- })
86- }
87-
88- const url = new URL (previewUrl)
89-
90- // Request tiny previews
91- url .searchParams .set (' x' , this .gridMode ? ' 128' : ' 32' )
92- url .searchParams .set (' y' , this .gridMode ? ' 128' : ' 32' )
93- url .searchParams .set (' mimeFallback' , ' true' )
94-
95- // Handle cropping
96- url .searchParams .set (' a' , this .cropPreviews === true ? ' 0' : ' 1' )
97- return url .toString ()
98- },
99- },
100- methods: {
101- t,
102- openSidebar () {
103- this .filesStore .selectFile (this .currentFileId )
104- this .sidebarStore .activeRequestSignatureTab ()
105- },
106- statusToClass (status ) {
107- switch (Number (status)) {
108- case 0 :
109- return ' no-signers'
110- case 1 :
111- case 2 :
112- return ' pending'
113- case 3 :
114- return ' signed'
115- default :
116- return ' '
117- }
118- },
119- },
38+ })
39+
40+ const filesStore = useFilesStore ()
41+ const sidebarStore = useSidebarStore ()
42+
43+ const backgroundFailed = ref (false )
44+ const gridMode = true
45+ const cropPreviews = true
46+
47+ const currentFileId = computed (() => filesStore .selectedFileId )
48+ const currentFile = computed (() => filesStore .files [currentFileId .value ])
49+ const previewUrl = computed (() => {
50+ if (backgroundFailed .value === true || ! currentFile .value ) {
51+ return null
52+ }
53+
54+ let filePreviewUrl = ' '
55+ if (currentFile .value .nodeId ) {
56+ filePreviewUrl = generateOcsUrl (' /apps/libresign/api/v1/file/thumbnail/{nodeId}' , {
57+ nodeId: currentFile .value .nodeId ,
58+ })
59+ } else if (currentFile .value .id ) {
60+ filePreviewUrl = generateOcsUrl (' /apps/libresign/api/v1/file/thumbnail/file_id/{fileId}' , {
61+ fileId: currentFile .value .id ,
62+ })
63+ } else {
64+ filePreviewUrl = window .location .origin + generateUrl (' /core/preview?fileId={fileid}' , {
65+ fileid: currentFile .value .id ,
66+ })
67+ }
68+
69+ const url = new URL (filePreviewUrl )
70+ url .searchParams .set (' x' , gridMode ? ' 128' : ' 32' )
71+ url .searchParams .set (' y' , gridMode ? ' 128' : ' 32' )
72+ url .searchParams .set (' mimeFallback' , ' true' )
73+ url .searchParams .set (' a' , cropPreviews === true ? ' 0' : ' 1' )
74+ return url .toString ()
75+ })
76+
77+ function openSidebar() {
78+ filesStore .selectFile (currentFileId .value )
79+ sidebarStore .activeRequestSignatureTab ()
80+ }
81+
82+ function statusToClass(status : number | string ) {
83+ switch (Number (status )) {
84+ case 0 :
85+ return ' no-signers'
86+ case 1 :
87+ case 2 :
88+ return ' pending'
89+ case 3 :
90+ return ' signed'
91+ default :
92+ return ' '
93+ }
12094}
95+
96+ defineExpose ({
97+ statusToClass ,
98+ })
12199 </script >
122100
123101<style lang="scss" scoped>
0 commit comments