-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathExternalStorageTableRow.vue
More file actions
182 lines (161 loc) · 5.03 KB
/
Copy pathExternalStorageTableRow.vue
File metadata and controls
182 lines (161 loc) · 5.03 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<script setup lang="ts">
import type { IBackend, IStorage } from '../types.ts'
import { mdiAccountGroupOutline, mdiInformationOutline, mdiPencilOutline, mdiTrashCanOutline } from '@mdi/js'
import { loadState } from '@nextcloud/initial-state'
import { t } from '@nextcloud/l10n'
import { NcChip, NcLoadingIcon, NcUserBubble, spawnDialog } from '@nextcloud/vue'
import { computed, ref } from 'vue'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
import AddExternalStorageDialog from './AddExternalStorageDialog/AddExternalStorageDialog.vue'
import { useUsers } from '../composables/useEntities.ts'
import { useStorages } from '../store/storages.ts'
import { StorageStatus, StorageStatusIcons, StorageStatusMessage } from '../types.ts'
const props = defineProps<{
storage: IStorage
isAdmin: boolean
}>()
const store = useStorages()
const backends = loadState<IBackend[]>('files_external', 'backends')
const backendName = computed(() => backends.find((b) => b.identifier === props.storage.backend)!.name)
const authMechanisms = loadState<IBackend[]>('files_external', 'authMechanisms')
const authMechanismName = computed(() => authMechanisms.find((a) => a.identifier === props.storage.authMechanism)!.name)
const checkingStatus = ref(false)
const status = computed(() => {
if (checkingStatus.value) {
return {
icon: 'loading',
label: t('files_external', 'Checking …'),
}
}
const status = props.storage.status ?? StorageStatus.Indeterminate
const label = props.storage.statusMessage || StorageStatusMessage[status]
const icon = StorageStatusIcons[status]
const isWarning = status === StorageStatus.NetworkError || status === StorageStatus.Timeout
const isError = !isWarning && status !== StorageStatus.Success && status !== StorageStatus.Indeterminate
return { icon, label, isWarning, isError }
})
const users = useUsers(() => props.storage.applicableUsers || [])
/**
* Handle deletion of the external storage mount point
*/
async function onDelete() {
await store.deleteStorage(props.storage)
}
/**
* Handle editing of the external storage mount point
*/
async function onEdit() {
const storage = await spawnDialog(AddExternalStorageDialog, {
storage: props.storage,
})
if (!storage) {
return
}
await store.updateStorage(storage as IStorage)
}
/**
* Reload the status of the external storage mount point
*/
async function reloadStatus() {
checkingStatus.value = true
try {
await store.reloadStorage(props.storage)
} finally {
checkingStatus.value = false
}
}
</script>
<template>
<tr :class="$style.storageTableRow">
<td>
<span class="hidden-visually">{{ status.label }}</span>
<NcButton
:aria-label="t('files_external', 'Recheck status')"
:title="status.label"
variant="tertiary-no-background"
@click="reloadStatus">
<template #icon>
<NcLoadingIcon v-if="status.icon === 'loading'" />
<NcIconSvgWrapper
v-else
:class="{
[$style.storageTableRow__status_error]: status.isError,
[$style.storageTableRow__status_warning]: status.isWarning,
}"
:path="status.icon" />
</template>
</NcButton>
</td>
<td>{{ storage.mountPoint }}</td>
<td>{{ backendName }}</td>
<td>{{ authMechanismName }}</td>
<td v-if="isAdmin">
<div :class="$style.storageTableRow__cellApplicable">
<NcChip
v-for="group of storage.applicableGroups"
:key="group"
:iconPath="mdiAccountGroupOutline"
noClose
:text="group" />
<NcUserBubble
v-for="user of users"
:key="user.user"
:displayName="user.displayName"
:size="24"
:user="user.user" />
</div>
</td>
<td>
<div v-if="isAdmin || storage.type === 'personal'" :class="$style.storageTableRow__cellActions">
<NcButton
:aria-label="t('files_external', 'Edit')"
:title="t('files_external', 'Edit')"
@click="onEdit">
<template #icon>
<NcIconSvgWrapper :path="mdiPencilOutline" />
</template>
</NcButton>
<NcButton
:aria-label="t('files_external', 'Delete')"
:title="t('files_external', 'Delete')"
variant="error"
@click="onDelete">
<template #icon>
<NcIconSvgWrapper :path="mdiTrashCanOutline" />
</template>
</NcButton>
</div>
<NcIconSvgWrapper
v-else
inline
:path="mdiInformationOutline"
:name="t('files_external', 'System provided storage')"
:title="t('files_external', 'System provided storage')" />
</td>
</tr>
</template>
<style module>
.storageTableRow__cellActions {
display: flex;
gap: var(--default-grid-baseline);
}
.storageTableRow__cellApplicable {
display: flex;
flex-wrap: wrap;
gap: var(--default-grid-baseline);
align-items: center;
max-height: calc(48px + 2 * var(--default-grid-baseline));
overflow: scroll;
}
.storageTableRow__status_warning {
color: var(--color-element-warning);
}
.storageTableRow__status_error {
color: var(--color-element-error);
}
</style>