aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/files_views/shares.ts
blob: 7aec0dbeafb700d31d8ce58bacebe6d5bbd30a6e (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import { translate as t } from '@nextcloud/l10n'
import { View, getNavigation } from '@nextcloud/files'
import { ShareType } from '@nextcloud/sharing'
import AccountClockSvg from '@mdi/svg/svg/account-clock.svg?raw'
import AccountGroupSvg from '@mdi/svg/svg/account-group.svg?raw'
import AccountPlusSvg from '@mdi/svg/svg/account-plus.svg?raw'
import AccountSvg from '@mdi/svg/svg/account.svg?raw'
import DeleteSvg from '@mdi/svg/svg/delete.svg?raw'
import FileUploadSvg from '@mdi/svg/svg/file-upload.svg?raw'
import LinkSvg from '@mdi/svg/svg/link.svg?raw'

import { getContents, isFileRequest } from '../services/SharingService'

export const sharesViewId = 'shareoverview'
export const sharedWithYouViewId = 'sharingin'
export const sharedWithOthersViewId = 'sharingout'
export const sharingByLinksViewId = 'sharinglinks'
export const deletedSharesViewId = 'deletedshares'
export const pendingSharesViewId = 'pendingshares'
export const fileRequestViewId = 'filerequest'

export default () => {
	const Navigation = getNavigation()
	Navigation.register(new View({
		id: sharesViewId,
		name: t('files_sharing', 'Shares'),
		caption: t('files_sharing', 'Overview of shared files.'),

		emptyTitle: t('files_sharing', 'No shares'),
		emptyCaption: t('files_sharing', 'Files and folders you shared or have been shared with you will show up here'),

		icon: AccountPlusSvg,
		order: 20,

		columns: [],

		getContents: () => getContents(),
	}))

	Navigation.register(new View({
		id: sharedWithYouViewId,
		name: t('files_sharing', 'Shared with you'),
		caption: t('files_sharing', 'List of files that are shared with you.'),

		emptyTitle: t('files_sharing', 'Nothing shared with you yet'),
		emptyCaption: t('files_sharing', 'Files and folders others shared with you will show up here'),

		icon: AccountSvg,
		order: 1,
		parent: sharesViewId,

		columns: [],

		getContents: () => getContents(true, false, false, false),
	}))

	Navigation.register(new View({
		id: sharedWithOthersViewId,
		name: t('files_sharing', 'Shared with others'),
		caption: t('files_sharing', 'List of files that you shared with others.'),

		emptyTitle: t('files_sharing', 'Nothing shared yet'),
		emptyCaption: t('files_sharing', 'Files and folders you shared will show up here'),

		icon: AccountGroupSvg,
		order: 2,
		parent: sharesViewId,

		columns: [],

		getContents: () => getContents(false, true, false, false),
	}))

	Navigation.register(new View({
		id: sharingByLinksViewId,
		name: t('files_sharing', 'Shared by link'),
		caption: t('files_sharing', 'List of files that are shared by link.'),

		emptyTitle: t('files_sharing', 'No shared links'),
		emptyCaption: t('files_sharing', 'Files and folders you shared by link will show up here'),

		icon: LinkSvg,
		order: 3,
		parent: sharesViewId,

		columns: [],

		getContents: () => getContents(false, true, false, false, [ShareType.Link]),
	}))

	Navigation.register(new View({
		id: fileRequestViewId,
		name: t('files_sharing', 'File requests'),
		caption: t('files_sharing', 'List of file requests.'),

		emptyTitle: t('files_sharing', 'No file requests'),
		emptyCaption: t('files_sharing', 'File requests you have created will show up here'),

		icon: FileUploadSvg,
		order: 4,
		parent: sharesViewId,

		columns: [],

		getContents: () => getContents(false, true, false, false, [ShareType.Link, ShareType.Email])
			.then(({ folder, contents }) => {
				return {
					folder,
					contents: contents.filter((node) => isFileRequest(node.attributes?.['share-attributes'] || [])),
				}
			}),
	}))

	Navigation.register(new View({
		id: deletedSharesViewId,
		name: t('files_sharing', 'Deleted shares'),
		caption: t('files_sharing', 'List of shares you left.'),

		emptyTitle: t('files_sharing', 'No deleted shares'),
		emptyCaption: t('files_sharing', 'Shares you have left will show up here'),

		icon: DeleteSvg,
		order: 5,
		parent: sharesViewId,

		columns: [],

		getContents: () => getContents(false, false, false, true),
	}))

	Navigation.register(new View({
		id: pendingSharesViewId,
		name: t('files_sharing', 'Pending shares'),
		caption: t('files_sharing', 'List of unapproved shares.'),

		emptyTitle: t('files_sharing', 'No pending shares'),
		emptyCaption: t('files_sharing', 'Shares you have received but not approved will show up here'),

		icon: AccountClockSvg,
		order: 6,
		parent: sharesViewId,

		columns: [],

		getContents: () => getContents(false, false, true, false),
	}))
}