-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathAuthMechanismConfiguration.vue
More file actions
111 lines (97 loc) · 3.1 KB
/
Copy pathAuthMechanismConfiguration.vue
File metadata and controls
111 lines (97 loc) · 3.1 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
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<script setup lang="ts">
import type { IAuthMechanism } from '../../types.ts'
import { t } from '@nextcloud/l10n'
import { NcLoadingIcon } from '@nextcloud/vue'
import { computed, ref, watch, watchEffect } from 'vue'
import ConfigurationEntry from './ConfigurationEntry.vue'
import { ConfigurationFlag, ConfigurationType } from '../../types.ts'
const modelValue = defineModel<Record<string, string | boolean>>({ required: true })
const props = defineProps<{
authMechanism: IAuthMechanism
}>()
const configuration = computed(() => {
if (!props.authMechanism.configuration) {
return undefined
}
const entries = Object.entries(props.authMechanism.configuration)
.filter(([, option]) => !(option.flags & ConfigurationFlag.UserProvided))
return Object.fromEntries(entries) as typeof props.authMechanism.configuration
})
const customComponent = computed(() => window.OCA.FilesExternal.AuthMechanism!.getHandler(props.authMechanism))
const hasConfiguration = computed(() => {
if (!configuration.value) {
return false
}
for (const option of Object.values(configuration.value)) {
if ((option.flags & ConfigurationFlag.Hidden) || (option.flags & ConfigurationFlag.UserProvided)) {
continue
}
// a real config option
return true
}
return false
})
const isLoadingCustomComponent = ref(false)
watchEffect(async () => {
if (customComponent.value) {
isLoadingCustomComponent.value = true
await window.customElements.whenDefined(customComponent.value.tagName)
isLoadingCustomComponent.value = false
}
})
watch(configuration, () => {
for (const key in configuration.value) {
if (!(key in modelValue.value)) {
modelValue.value[key] = configuration.value[key]?.type === ConfigurationType.Boolean
? false
: ''
}
}
})
/**
* Update the model value when the custom component emits an update event.
*
* @param event - The custom event
*/
function onUpdateModelValue(event: CustomEvent) {
const config = [event.detail].flat()[0]
modelValue.value = { ...modelValue.value, ...config }
}
</script>
<template>
<fieldset v-if="hasConfiguration" :class="$style.authMechanismConfiguration">
<legend>
{{ t('files_external', 'Authentication') }}
</legend>
<template v-if="customComponent">
<NcLoadingIcon v-if="isLoadingCustomComponent" />
<!-- eslint-disable vue/attribute-hyphenation,vue/v-on-event-hyphenation -- for custom elements the casing is fixed! -->
<component
:is="customComponent.tagName"
v-else
:modelValue.prop="modelValue"
:authMechanism.prop="authMechanism"
@update:modelValue="onUpdateModelValue" />
</template>
<template v-else>
<ConfigurationEntry
v-for="(configOption, configKey) in configuration"
v-show="!(configOption.flags & ConfigurationFlag.Hidden)"
:key="configOption.value"
v-model="modelValue[configKey]!"
:config-key
:config-option />
</template>
</fieldset>
</template>
<style module>
.authMechanismConfiguration {
display: flex;
flex-direction: column;
gap: var(--default-grid-baseline);
}
</style>