-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathshowStatusInlineAction.js
More file actions
57 lines (49 loc) · 1.83 KB
/
showStatusInlineAction.js
File metadata and controls
57 lines (49 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { FileAction, registerFileAction, getSidebar } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { t } from '@nextcloud/l10n'
import { SIGN_STATUS } from '../domains/sign/enum.js'
import { fileStatus } from '../helpers/fileStatus.js'
const action = new FileAction({
id: 'show-status-inline',
displayName: () => '',
title: ({ nodes }) => {
const node = nodes?.[0]
if (!node) return ''
const signedNodeId = node.attributes['libresign-signed-node-id']
if (!signedNodeId || node.fileid === signedNodeId) {
const status = fileStatus.find(status => status.id === node.attributes['libresign-signature-status'])
return status?.label ?? ''
}
return t('libresign', 'original file')
},
exec: async ({ nodes }) => {
const node = nodes[0]
sidebar.open(node, 'libresign')
sidebar.setActiveTab('libresign')
return null
},
iconSvgInline: ({ nodes }) => {
const node = nodes?.[0]
if (!node) return ''
const signedNodeId = node.attributes['libresign-signed-node-id']
if (!signedNodeId || node.fileid === signedNodeId) {
const status = fileStatus.find(status => status.id === node.attributes['libresign-signature-status'])
return status?.icon ?? ''
}
const ableToSignStatus = fileStatus.find(status => status.id === SIGN_STATUS.ABLE_TO_SIGN)
return ableToSignStatus?.icon ?? ''
},
inline: () => true,
enabled: ({ nodes }) => {
const certificateOk = loadState('libresign', 'certificate_ok')
const allPdf = nodes?.length > 0 && nodes.every(node => node.mime === 'application/pdf')
const allHaveStatus = nodes?.every(node => node.attributes['libresign-signature-status'])
return certificateOk && allPdf && allHaveStatus
},
order: -1,
})
registerFileAction(action)