-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathAddExternalStorageDialog.vue
More file actions
159 lines (136 loc) · 5.02 KB
/
Copy pathAddExternalStorageDialog.vue
File metadata and controls
159 lines (136 loc) · 5.02 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
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<script lang="ts">
import { loadState } from '@nextcloud/initial-state'
const { isAdmin } = loadState<{ isAdmin: boolean }>('files_external', 'settings')
const allowedBackendIds = loadState<string[]>('files_external', 'allowedBackends')
const backends = loadState<IBackend[]>('files_external', 'backends')
.filter((b) => allowedBackendIds.includes(b.identifier))
const allAuthMechanisms = loadState<IAuthMechanism[]>('files_external', 'authMechanisms')
</script>
<script setup lang="ts">
import type { IAuthMechanism, IBackend, IStorage } from '../../types.ts'
import { t } from '@nextcloud/l10n'
import { computed, ref, toRaw, watch, watchEffect } from 'vue'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcDialog from '@nextcloud/vue/components/NcDialog'
import NcSelect from '@nextcloud/vue/components/NcSelect'
import NcTextField from '@nextcloud/vue/components/NcTextField'
import ApplicableEntities from './ApplicableEntities.vue'
import AuthMechanismConfiguration from './AuthMechanismConfiguration.vue'
import BackendConfiguration from './BackendConfiguration.vue'
import MountOptions from './MountOptions.vue'
import { DEFAULT_MOUNT_OPTIONS } from '../../store/storages.ts'
import { pruneUnusedAuthMechanismOptions } from '../../utils/externalStorageUtils.ts'
const open = defineModel<boolean>('open', { default: true })
const {
storage = { backendOptions: {}, mountOptions: { ...DEFAULT_MOUNT_OPTIONS }, type: isAdmin ? 'system' : 'personal' },
} = defineProps<{
storage?: Partial<IStorage>
}>()
defineEmits<{
close: [storage?: Partial<IStorage>]
}>()
const internalStorage = ref(structuredClone(toRaw(storage)))
watchEffect(() => {
if (open.value) {
internalStorage.value = structuredClone(toRaw(storage))
}
})
const backend = computed({
get() {
return backends.find((b) => b.identifier === internalStorage.value.backend)
},
set(value?: IBackend) {
internalStorage.value.backend = value?.identifier
},
})
const authMechanisms = computed(() => allAuthMechanisms
.filter(({ scheme }) => backend.value?.authSchemes[scheme]))
const authMechanism = computed({
get() {
return authMechanisms.value.find((a) => a.identifier === internalStorage.value.authMechanism)
},
set(value?: IAuthMechanism) {
const previous = authMechanisms.value.find((a) => a.identifier === internalStorage.value.authMechanism)
if (previous && previous.identifier !== value?.identifier && internalStorage.value.backendOptions) {
pruneUnusedAuthMechanismOptions(
internalStorage.value.backendOptions,
previous.configuration,
[value?.configuration, backend.value?.configuration],
)
}
internalStorage.value.authMechanism = value?.identifier
},
})
// auto set the auth mechanism if there's only one available
watch(authMechanisms, () => {
if (authMechanisms.value.length === 1) {
internalStorage.value.authMechanism = authMechanisms.value[0]!.identifier
}
})
</script>
<template>
<NcDialog
v-model:open="open"
isForm
:contentClasses="$style.externalStorageDialog"
:name="internalStorage.id ? t('files_external', 'Edit storage') : t('files_external', 'Add storage')"
@submit="$emit('close', internalStorage)"
@update:open="$event || $emit('close')">
<NcTextField
v-model="internalStorage.mountPoint"
:label="t('files_external', 'Folder name')"
required />
<MountOptions v-model="internalStorage.mountOptions!" />
<ApplicableEntities
v-if="isAdmin"
v-model:groups="internalStorage.applicableGroups"
v-model:users="internalStorage.applicableUsers" />
<NcSelect
v-model="backend"
:options="backends"
:disabled="!!(internalStorage.id && internalStorage.backend)"
:inputLabel="t('files_external', 'External storage')"
label="name"
required />
<NcSelect
v-model="authMechanism"
:options="authMechanisms"
:disabled="!internalStorage.backend || authMechanisms.length <= 1"
:inputLabel="t('files_external', 'Authentication')"
label="name"
required />
<BackendConfiguration
v-if="backend && internalStorage.backendOptions"
v-model="internalStorage.backendOptions"
:class="$style.externalStorageDialog__configuration"
:configuration="backend.configuration" />
<AuthMechanismConfiguration
v-if="authMechanism && internalStorage.backendOptions"
v-model="internalStorage.backendOptions"
:class="$style.externalStorageDialog__configuration"
:authMechanism="authMechanism" />
<template #actions>
<NcButton v-if="storage.id" @click="$emit('close')">
{{ t('files_external', 'Cancel') }}
</NcButton>
<NcButton variant="primary" type="submit">
{{ storage.id ? t('files_external', 'Edit') : t('files_external', 'Create') }}
</NcButton>
</template>
</NcDialog>
</template>
<style module>
.externalStorageDialog {
display: flex;
flex-direction: column;
gap: var(--default-grid-baseline);
min-height: calc(14 * var(--default-clickable-area)) !important;
}
.externalStorageDialog__configuration {
margin-block: 0.5rem;
}
</style>