Skip to content

Commit 0f2880d

Browse files
AntDavidLimavitormattos
authored andcommitted
feat(files-app-integration): change action icon and tooltip text based on the file attributes
1 parent ce3ab98 commit 0f2880d

File tree

2 files changed

+20
-46
lines changed

2 files changed

+20
-46
lines changed

lib/Service/FileService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ public function getStatus(): int {
254254
return $this->file->getStatus();
255255
}
256256

257-
public function getSignedNodeId(): int {
257+
public function getSignedNodeId(): ?int {
258+
$status = $this->file->getStatus();
259+
260+
if (!in_array($status, [File::STATUS_PARTIAL_SIGNED, File::STATUS_SIGNED])) {
261+
return null;
262+
}
258263
return $this->file->getSignedNodeId();
259264
}
260265

src/actions/showStatusInlineAction.js

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,45 @@
22
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import axios from '@nextcloud/axios'
65
import { FileAction, registerFileAction } from '@nextcloud/files'
76
import { loadState } from '@nextcloud/initial-state'
87
import { t } from '@nextcloud/l10n'
9-
import { generateOcsUrl } from '@nextcloud/router'
108

119
import { SIGN_STATUS } from '../domains/sign/enum.js'
1210
import { fileStatus } from '../helpers/fileStatus.js'
1311

14-
let nodeIds = []
15-
const nodeStatusById = new Map()
16-
1712
const action = new FileAction({
1813
id: 'show-status-inline',
1914
displayName: () => '',
2015
title: (nodes) => {
21-
const nodeId = nodes[0].fileid
22-
23-
if (nodeStatusById.has(nodeId)) {
24-
const node = nodeStatusById.get(nodeId)
16+
const node = nodes[0]
2517

26-
if ([SIGN_STATUS.PARTIAL_SIGNED, SIGN_STATUS.SIGNED].includes(node.status)) {
27-
return node.original
28-
? t('libresign', 'original file')
29-
: fileStatus.find(status => status.id === node.status).label
30-
}
31-
}
18+
const signedNodeId = node.attributes['signed-node-id'];
3219

33-
nodeIds.push(nodeId)
34-
35-
return ''
20+
return !signedNodeId || node.fileid === signedNodeId
21+
? fileStatus.find(status => status.id === node.attributes['signature-status']).label
22+
: t('libresign', 'original file')
3623
},
3724
exec: async () => null,
3825
iconSvgInline: (nodes) => {
39-
const nodeId = nodes[0].fileid
40-
41-
if (nodeStatusById.has(nodeId)) {
42-
const node = nodeStatusById.get(nodeId)
26+
const node = nodes[0]
4327

44-
if ([SIGN_STATUS.PARTIAL_SIGNED, SIGN_STATUS.SIGNED].includes(node.status)) {
45-
return node.original
46-
? fileStatus.find(status => status.id === SIGN_STATUS.ABLE_TO_SIGN).icon
47-
: fileStatus.find(status => status.id === node.status).icon
48-
}
49-
}
28+
const signedNodeId = node.attributes['signed-node-id'];
5029

51-
return ''
30+
return !signedNodeId || node.fileid === signedNodeId
31+
? fileStatus.find(status => status.id === node.attributes['signature-status']).icon
32+
: fileStatus.find(status => status.id === SIGN_STATUS.ABLE_TO_SIGN).icon
5233
},
5334
inline: () => true,
5435
enabled: (nodes) => {
5536
return loadState('libresign', 'certificate_ok')
56-
&& nodes.length > 0 && nodes
37+
&& nodes.length > 0
38+
&& nodes
5739
.map(node => node.mime)
5840
.every(mime => mime === 'application/pdf')
41+
&& nodes.every(node => node.attributes['signature-status'])
5942
},
6043
order: -1,
6144
})
6245

63-
axios.get(generateOcsUrl('/apps/libresign/api/v1/file/list'), {
64-
params: {
65-
nodeIds,
66-
},
67-
}).then(({ data }) => {
68-
data.ocs.data.data.forEach(node => {
69-
nodeStatusById.set(node.nodeId, { status: node.status, original: true })
70-
71-
if (node.signedNodeId) {
72-
nodeStatusById.set(node.signedNodeId, { status: node.status, original: false })
73-
}
74-
})
75-
76-
registerFileAction(action)
77-
}).finally(() => { nodeIds = [] })
46+
registerFileAction(action)

0 commit comments

Comments
 (0)