@open-commune/web 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.config.ts +7 -0
- package/components/data/lists/data-table.vue +203 -0
- package/components/data/lists/row-actions.vue +41 -0
- package/components/elements/badges/status-badge.vue +23 -0
- package/components/elements/media/media-image.vue +26 -0
- package/components/forms/fields/input-files-media.vue +87 -0
- package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
- package/components/forms/{inputs → fields}/input-search.vue +8 -2
- package/components/forms/fields/input-text-area.vue +86 -0
- package/components/forms/fields/input-text.vue +47 -0
- package/components/forms/fields/select-enum.vue +69 -0
- package/components/forms/handlers/handler-collections.vue +100 -170
- package/components/forms/handlers/handler-list.vue +187 -0
- package/components/forms/handlers/handler-members.vue +171 -0
- package/components/forms/handlers/handler-password-reset.vue +45 -0
- package/components/forms/handlers/handler-roles.vue +28 -166
- package/components/forms/handlers/handler-sessions.vue +77 -0
- package/components/forms/handlers/handler-tokens.vue +54 -69
- package/components/forms/layouts/form-default.vue +99 -0
- package/components/forms/layouts/form.vue +4 -0
- package/components/forms/layouts/forms-layout.vue +236 -0
- package/components/forms/layouts/forms-section.vue +186 -0
- package/components/forms/layouts/layout.vue +4 -0
- package/components/forms/layouts/modal.vue +4 -0
- package/components/forms/layouts/section.vue +4 -0
- package/components/layout/shell/shell-account-menu.vue +10 -2
- package/composables/core/domains/use-api-tokens.ts +80 -0
- package/composables/core/domains/use-auth.ts +56 -2
- package/composables/core/domains/use-definitions.ts +18 -5
- package/composables/core/domains/use-entries.ts +113 -3
- package/composables/core/domains/use-media.ts +24 -1
- package/composables/core/domains/use-members.ts +68 -0
- package/composables/core/domains/use-organization.ts +53 -0
- package/composables/use-models.js +1 -7
- package/constants/errors.ts +28 -0
- package/constants/forms/account.ts +62 -0
- package/constants/forms/collections.ts +39 -0
- package/constants/forms/members.ts +40 -0
- package/constants/forms/organization.ts +188 -0
- package/constants/forms/tokens.ts +15 -0
- package/constants/roles.ts +57 -0
- package/constants/settings.ts +26 -0
- package/constants/statuses.ts +8 -5
- package/package.json +3 -3
- package/pages/[collection]/index.vue +92 -79
- package/pages/account.vue +40 -0
- package/pages/settings.vue +26 -181
- package/plugins/01.validation.client.ts +23 -0
- package/store/layout/workspace.js +4 -28
- package/utils/colors.ts +26 -0
- package/utils/errors.ts +13 -0
- package/utils/forms.ts +67 -0
- package/utils/list-columns.ts +90 -0
- package/utils/settings.ts +38 -0
- package/utils/statuses.ts +4 -0
- package/models/role.js +0 -66
- package/models/token.js +0 -56
- package/models/user.js +0 -97
- package/pages/management/index.vue +0 -15
- package/pages/management/members.vue +0 -176
- package/pages/management/organizations.vue +0 -192
- package/pages/management/roles.vue +0 -183
- /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative block w-full">
|
|
3
|
+
<UButton
|
|
4
|
+
color="neutral"
|
|
5
|
+
variant="outline"
|
|
6
|
+
class="bg-elevated"
|
|
7
|
+
:label="sent ? 'Email envoyé' : 'Recevoir un lien de réinitialisation'"
|
|
8
|
+
:disabled="sent"
|
|
9
|
+
:loading="isLoading"
|
|
10
|
+
@click="_request"
|
|
11
|
+
/>
|
|
12
|
+
</div>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup>
|
|
16
|
+
/**
|
|
17
|
+
* Changing one's password goes through the reset email, not a form. Two
|
|
18
|
+
* reasons: no new server procedure to write, and the link PROVES access to
|
|
19
|
+
* the mailbox — which a current-password field does not, on a session
|
|
20
|
+
* left open on an unattended machine.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// Prepare composables
|
|
24
|
+
const $auth = useAuth()
|
|
25
|
+
const $session = useSession()
|
|
26
|
+
|
|
27
|
+
// Prepare reactive
|
|
28
|
+
const sent = ref(false)
|
|
29
|
+
|
|
30
|
+
// Prepare computed
|
|
31
|
+
const isLoading = computed(() => $auth.isRequestingPasswordReset.value)
|
|
32
|
+
|
|
33
|
+
// Prepare methods
|
|
34
|
+
const _request = async () => {
|
|
35
|
+
const address = $session.user.value?.email
|
|
36
|
+
if (!address) return
|
|
37
|
+
|
|
38
|
+
// `requestPasswordReset` now carries its own catch, its pending state and
|
|
39
|
+
// both toasts, and answers rather than throwing. `sent` stays here: locking
|
|
40
|
+
// the button is this screen's business, not the request's.
|
|
41
|
+
if (await $auth.requestPasswordReset(address)) {
|
|
42
|
+
sent.value = true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
@@ -1,176 +1,38 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="
|
|
3
|
-
<
|
|
4
|
-
v-
|
|
5
|
-
|
|
6
|
-
class="
|
|
2
|
+
<div class="grid gap-4 sm:grid-cols-2">
|
|
3
|
+
<div
|
|
4
|
+
v-for="role in ROLES"
|
|
5
|
+
:key="role.id"
|
|
6
|
+
class="rounded-xl bg-elevated p-7 shadow-card dark:shadow-none dark:ring dark:ring-[var(--ui-border)] plain:bg-default plain:ring plain:ring-default"
|
|
7
7
|
>
|
|
8
|
-
{{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/>
|
|
28
|
-
<select-enum
|
|
29
|
-
:items="collections"
|
|
30
|
-
:value="currentCollections"
|
|
31
|
-
:read-only="!currentOrganization || !currentRole"
|
|
32
|
-
place-holder="Collection(s)"
|
|
33
|
-
class="w-full"
|
|
34
|
-
enable-multiple
|
|
35
|
-
@change="currentCollections = $event"
|
|
36
|
-
/>
|
|
37
|
-
</div>
|
|
38
|
-
<button-secondary class="col-span-1" label="Ajouter un rôle" @click="_addRole" />
|
|
39
|
-
<!-- @click="_openModalForm('add')" -->
|
|
8
|
+
<h3 class="text-base font-semibold text-highlighted">{{ role.name }}</h3>
|
|
9
|
+
<p class="mt-0.5 text-sm text-muted">{{ role.description }}</p>
|
|
10
|
+
|
|
11
|
+
<ul class="mt-5 space-y-2.5">
|
|
12
|
+
<li
|
|
13
|
+
v-for="capability in CAPABILITIES"
|
|
14
|
+
:key="capability.label"
|
|
15
|
+
class="flex items-start gap-2 text-sm"
|
|
16
|
+
>
|
|
17
|
+
<UIcon
|
|
18
|
+
:name="_can(role, capability) ? 'i-lucide-check' : 'i-lucide-x'"
|
|
19
|
+
class="mt-0.5 size-4 shrink-0"
|
|
20
|
+
:class="_can(role, capability) ? 'text-success' : 'text-dimmed'"
|
|
21
|
+
/>
|
|
22
|
+
<span :class="_can(role, capability) ? 'text-default' : 'text-dimmed'">
|
|
23
|
+
{{ capability.label }}
|
|
24
|
+
</span>
|
|
25
|
+
</li>
|
|
26
|
+
</ul>
|
|
40
27
|
</div>
|
|
41
|
-
<list-table
|
|
42
|
-
:headers="TABLE_HEADERS"
|
|
43
|
-
:items="selection"
|
|
44
|
-
:actions="['remove']"
|
|
45
|
-
class="bg-gray-100 p-2"
|
|
46
|
-
@remove="_removeRole"
|
|
47
|
-
/>
|
|
48
|
-
<!-- @update="_openModalForm('update', $event)"
|
|
49
|
-
@remove="_handle('remove', $event)" -->
|
|
50
28
|
</div>
|
|
51
29
|
</template>
|
|
52
30
|
|
|
53
31
|
<script setup>
|
|
54
|
-
import {
|
|
55
|
-
import listTable from '~/components/data/lists/data-lists-table'
|
|
56
|
-
import selectEnum from '~/components/forms/selects/select-enum'
|
|
57
|
-
import buttonSecondary from '~/components/elements/buttons/secondary'
|
|
58
|
-
|
|
59
|
-
// Prepare composable
|
|
60
|
-
const { Organization, Role, Collection } = useModels()
|
|
61
|
-
|
|
62
|
-
// Prepare constants
|
|
63
|
-
const TABLE_HEADERS = [
|
|
64
|
-
{
|
|
65
|
-
title: 'Organisation',
|
|
66
|
-
nestedValue: false,
|
|
67
|
-
component: 'data-summary',
|
|
68
|
-
componentOptions: {
|
|
69
|
-
titleKey: 'organization',
|
|
70
|
-
descriptionKey: 'role',
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
property: 'collections',
|
|
75
|
-
component: 'data-text'
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
component: 'data-spacer',
|
|
79
|
-
grow: true
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
title: '',
|
|
83
|
-
component: 'actions',
|
|
84
|
-
componentOptions: {
|
|
85
|
-
options: [
|
|
86
|
-
{ label: 'Supprimer', action: 'remove' }
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
// Prepare props
|
|
93
|
-
const $props = defineProps({
|
|
94
|
-
label: {
|
|
95
|
-
type: String,
|
|
96
|
-
default: ''
|
|
97
|
-
},
|
|
98
|
-
value: {
|
|
99
|
-
type: Array,
|
|
100
|
-
default: () => []
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
// Prepare $emitters
|
|
105
|
-
const $emitters = defineEmits(['keyup.enter', 'change'])
|
|
106
|
-
|
|
107
|
-
// Prepare data
|
|
108
|
-
const selection = ref([])
|
|
109
|
-
const currentOrganization = ref(null)
|
|
110
|
-
const currentRole = ref(null)
|
|
111
|
-
const currentCollections = ref([])
|
|
112
|
-
|
|
113
|
-
// Prepare computed
|
|
114
|
-
const organizations = computed(() => Organization.repo.all())
|
|
115
|
-
const roles = computed(() => Role.repo.all())
|
|
116
|
-
const collections = computedAsync(
|
|
117
|
-
async () => {
|
|
118
|
-
if (currentOrganization.value) {
|
|
119
|
-
const collections = await Collection.list(undefined, currentOrganization.value)
|
|
120
|
-
console.log(collections)
|
|
121
|
-
return [{ _id: '*', name: 'Toutes les collections (*)'}, ...collections]
|
|
122
|
-
}
|
|
123
|
-
return []
|
|
124
|
-
},
|
|
125
|
-
[],
|
|
126
|
-
)
|
|
127
|
-
|
|
32
|
+
import { CAPABILITIES, ROLES } from '~/constants/roles'
|
|
128
33
|
|
|
129
34
|
// Prepare methods
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
role: currentRole.value,
|
|
134
|
-
collections: currentCollections.value
|
|
135
|
-
})
|
|
136
|
-
currentOrganization.value = null
|
|
137
|
-
currentRole.value = null
|
|
138
|
-
currentCollections.value = []
|
|
139
|
-
}
|
|
140
|
-
const _removeRole = (val) => {
|
|
141
|
-
const indexToRemove = selection.value.findIndex(
|
|
142
|
-
({ organization, collections, role }) =>organization === val.organization
|
|
143
|
-
&& role === val.role
|
|
144
|
-
&& val.collections.every((_id) => collections.includes(_id))
|
|
145
|
-
)
|
|
146
|
-
if (indexToRemove >= 0) {
|
|
147
|
-
selection.value.splice(indexToRemove, 1)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// prepare watchers
|
|
152
|
-
watch(
|
|
153
|
-
() => $props.value,
|
|
154
|
-
(newValue) => {
|
|
155
|
-
if (newValue) {
|
|
156
|
-
selection.value = newValue
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
{ immediate: true }
|
|
160
|
-
)
|
|
161
|
-
watch(
|
|
162
|
-
selection,
|
|
163
|
-
(newValue) => $emitters('change', newValue),
|
|
164
|
-
{ immediate: true }
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
// Prepare lifecycle hook
|
|
168
|
-
onMounted(async () => {
|
|
169
|
-
if (!roles.value.length) {
|
|
170
|
-
await Role.list()
|
|
171
|
-
}
|
|
172
|
-
if (!organizations.value.length) {
|
|
173
|
-
await Organization.list()
|
|
174
|
-
}
|
|
175
|
-
})
|
|
35
|
+
// `manage:all` is CASL's joker: it opens everything without being listed.
|
|
36
|
+
const _can = (role, { ability }) =>
|
|
37
|
+
role.permissions.includes('manage:all') || role.permissions.includes(ability)
|
|
176
38
|
</script>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<handler-list :rows="rows" :loading="isLoading" empty="Aucune session ouverte.">
|
|
3
|
+
<template #row="{ row }">
|
|
4
|
+
<span class="min-w-0 flex-1 truncate text-sm font-medium text-highlighted">{{ row.device }}</span>
|
|
5
|
+
<span class="shrink-0 text-[13px] text-dimmed">{{ row.opened }}</span>
|
|
6
|
+
<UButton
|
|
7
|
+
v-if="!row.current"
|
|
8
|
+
icon="i-lucide-trash-2"
|
|
9
|
+
color="neutral"
|
|
10
|
+
variant="ghost"
|
|
11
|
+
size="sm"
|
|
12
|
+
class="shrink-0 text-dimmed opacity-0 transition hover:text-error group-hover:opacity-100 focus-visible:opacity-100"
|
|
13
|
+
:aria-label="`Fermer la session ${row.device}`"
|
|
14
|
+
@click="revoke(row.id)"
|
|
15
|
+
/>
|
|
16
|
+
<span v-else class="w-8 shrink-0" />
|
|
17
|
+
</template>
|
|
18
|
+
</handler-list>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup>
|
|
22
|
+
import handlerList from '~/components/forms/handlers/handler-list.vue'
|
|
23
|
+
import { DateTime } from 'luxon'
|
|
24
|
+
|
|
25
|
+
// Prepare constants
|
|
26
|
+
/**
|
|
27
|
+
* How many sessions the table shows.
|
|
28
|
+
*
|
|
29
|
+
* A session lives thirty days: someone signing in daily from two devices
|
|
30
|
+
* piles up sixty, and the screen becomes a wall where the intruder one is
|
|
31
|
+
* looking for is invisible. Ten are shown, and the rest are counted.
|
|
32
|
+
*/
|
|
33
|
+
const VISIBLE = 10
|
|
34
|
+
|
|
35
|
+
// Prepare composables
|
|
36
|
+
const $auth = useAuth()
|
|
37
|
+
|
|
38
|
+
// Fetch data
|
|
39
|
+
// The query hands back the list AND the gesture that closes one of them: the
|
|
40
|
+
// close button calls `revoke` directly, the list refreshes through its key.
|
|
41
|
+
const { data: sessions, isLoading, revoke } = $auth.sessions()
|
|
42
|
+
|
|
43
|
+
// Prepare computed
|
|
44
|
+
/** Most recent first, the current session ahead of them all. */
|
|
45
|
+
const sorted = computed(() =>
|
|
46
|
+
[...(sessions.value ?? [])].sort((a, b) => (
|
|
47
|
+
// Current session first: it is the one to recognize before the others.
|
|
48
|
+
Number(b.current) - Number(a.current) || b.createdAt.localeCompare(a.createdAt)
|
|
49
|
+
))
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const rows = computed(() => sorted.value.slice(0, VISIBLE).map(session => ({
|
|
53
|
+
key: session.id,
|
|
54
|
+
// The id the close button hands back — `key` belongs to the list that renders
|
|
55
|
+
// the row, and reusing it as data would tie one to the other.
|
|
56
|
+
id: session.id,
|
|
57
|
+
current: session.current,
|
|
58
|
+
device: [
|
|
59
|
+
_device(session.ua),
|
|
60
|
+
session.ip,
|
|
61
|
+
session.current ? 'session courante' : null
|
|
62
|
+
].filter(Boolean).join(' · '),
|
|
63
|
+
opened: DateTime.fromISO(session.createdAt).setLocale('fr').toRelative(),
|
|
64
|
+
})))
|
|
65
|
+
|
|
66
|
+
// Prepare methods
|
|
67
|
+
/**
|
|
68
|
+
* A full user-agent is unreadable in a table. Only what helps someone
|
|
69
|
+
* recognize their own device is kept: the browser and the system.
|
|
70
|
+
*/
|
|
71
|
+
const _device = (ua) => {
|
|
72
|
+
if (!ua) return 'Appareil inconnu'
|
|
73
|
+
const browser = /Firefox\/|Edg\/|Chrome\/|Safari\//.exec(ua)?.[0]?.replace('/', '') ?? 'Navigateur'
|
|
74
|
+
const system = /Mac OS X|Windows|Android|iPhone|iPad|Linux/.exec(ua)?.[0] ?? ''
|
|
75
|
+
return system ? `${browser} sur ${system}` : browser
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
@@ -1,79 +1,64 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
<handler-list
|
|
3
|
+
v-model:open="isModalOpen"
|
|
4
|
+
:rows="rows"
|
|
5
|
+
:loading="isLoading"
|
|
6
|
+
empty="Aucun token."
|
|
7
|
+
action-label="Ajouter un token"
|
|
8
|
+
:form="TOKEN_FORM"
|
|
9
|
+
:schema="apiTokenCreateDto"
|
|
10
|
+
title="Créer un token"
|
|
11
|
+
description="Entrez un nom pour votre token afin de l'identifier facilement."
|
|
12
|
+
submit-label="Créer"
|
|
13
|
+
@add="_openModalForm"
|
|
14
|
+
@submit="_createToken"
|
|
15
|
+
>
|
|
16
|
+
<template #row="{ row }">
|
|
17
|
+
<span class="min-w-0 flex-1 truncate text-sm font-medium text-highlighted">{{ row.name }}</span>
|
|
18
|
+
<span class="shrink-0 text-[13px] text-dimmed">{{ row.lastUsedAt }}</span>
|
|
19
|
+
<UButton
|
|
20
|
+
icon="i-lucide-trash-2"
|
|
21
|
+
color="neutral"
|
|
22
|
+
variant="ghost"
|
|
23
|
+
size="sm"
|
|
24
|
+
class="shrink-0 text-dimmed opacity-0 transition hover:text-error group-hover:opacity-100 focus-visible:opacity-100"
|
|
25
|
+
:aria-label="`Révoquer ${row.name}`"
|
|
26
|
+
@click="_removeToken(row.source)"
|
|
27
|
+
/>
|
|
28
|
+
</template>
|
|
29
|
+
</handler-list>
|
|
11
30
|
</template>
|
|
12
31
|
|
|
13
32
|
<script setup>
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
33
|
+
import { apiTokenCreateDto } from '@open-commune/core/dtos'
|
|
34
|
+
import handlerList from '~/components/forms/handlers/handler-list.vue'
|
|
35
|
+
import { DateTime } from 'luxon'
|
|
36
|
+
import { TOKEN_FORM } from '~/constants/forms/tokens'
|
|
17
37
|
|
|
18
|
-
|
|
19
|
-
const
|
|
38
|
+
// Prepare composables
|
|
39
|
+
const $apiTokens = useApiTokens()
|
|
40
|
+
const { mutateAsync: createToken } = $apiTokens.create()
|
|
41
|
+
const { mutate: revokeToken } = $apiTokens.revoke()
|
|
20
42
|
|
|
21
|
-
// Prepare
|
|
22
|
-
const
|
|
23
|
-
{
|
|
24
|
-
title: 'Nom',
|
|
25
|
-
property: 'name',
|
|
26
|
-
component: 'data-text'
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
title: 'Token',
|
|
30
|
-
property: 'token',
|
|
31
|
-
component: 'data-text'
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
title: '',
|
|
35
|
-
component: 'actions'
|
|
36
|
-
}
|
|
37
|
-
]
|
|
43
|
+
// Prepare reactive
|
|
44
|
+
const isModalOpen = ref(false)
|
|
38
45
|
|
|
39
|
-
//
|
|
40
|
-
const tokens =
|
|
46
|
+
// Fetch data
|
|
47
|
+
const { data: tokens = [], isLoading } = $apiTokens.list()
|
|
41
48
|
|
|
42
|
-
// Prepare
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
// Prepare computed
|
|
50
|
+
const rows = computed(() => tokens.value?.map(token => ({
|
|
51
|
+
key: token.id,
|
|
52
|
+
name: token.name,
|
|
53
|
+
lastUsedAt: token.lastUsedAt
|
|
54
|
+
? DateTime.fromISO(token.lastUsedAt).setLocale('fr').toRelative()
|
|
55
|
+
: 'Jamais utilisé',
|
|
56
|
+
source: token,
|
|
57
|
+
})))
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
subTitle: 'Entrez un nom pour votre token afin de l\'identifier facilement.',
|
|
57
|
-
acceptButton: 'Créer',
|
|
58
|
-
closeButton: 'Annuler'
|
|
59
|
-
},
|
|
60
|
-
attributes: [
|
|
61
|
-
{
|
|
62
|
-
property: 'name',
|
|
63
|
-
componentOptions: {
|
|
64
|
-
placeHolder: 'ex: landing pages, mobile app, ... ',
|
|
65
|
-
name: 'name'
|
|
66
|
-
},
|
|
67
|
-
component: 'input-text'
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Prepare lifecle hooks
|
|
74
|
-
onMounted(async () => {
|
|
75
|
-
if (!tokens.value.length) {
|
|
76
|
-
await Token.list()
|
|
77
|
-
}
|
|
78
|
-
})
|
|
59
|
+
// Prepare methods
|
|
60
|
+
// The toast is the mutation's, success or failure: a refusal is said, not thrown.
|
|
61
|
+
const _createToken = ({ name }) => createToken(name).catch(() => {})
|
|
62
|
+
const _removeToken = ({ id, name }) => revokeToken({ id, name })
|
|
63
|
+
const _openModalForm = () => { isModalOpen.value = true }
|
|
79
64
|
</script>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-show="attributes.length" class="space-y-4">
|
|
3
|
+
<template v-for="({ property, control, standalone, componentOptions }, i) in controls" :key="i">
|
|
4
|
+
<!-- A standalone handler carries neither a value nor a label: it has
|
|
5
|
+
nothing to bind an error to, so it gets no field around it. -->
|
|
6
|
+
<component
|
|
7
|
+
:is="control"
|
|
8
|
+
v-if="standalone"
|
|
9
|
+
class="w-full"
|
|
10
|
+
v-bind="{ ...componentOptions, readOnly: componentOptions.readOnly || loading }"
|
|
11
|
+
/>
|
|
12
|
+
<!-- Every other control gets its field HERE, label and `name`: the
|
|
13
|
+
control draws only its input, bound to the form's state, and the
|
|
14
|
+
field shows under it what the schema refuses. -->
|
|
15
|
+
<UFormField v-else :label="componentOptions.label" :name="property">
|
|
16
|
+
<component
|
|
17
|
+
:is="control"
|
|
18
|
+
v-model="state[property]"
|
|
19
|
+
class="w-full"
|
|
20
|
+
v-bind="{ ..._withoutLabel(componentOptions), readOnly: componentOptions.readOnly || loading }"
|
|
21
|
+
/>
|
|
22
|
+
</UFormField>
|
|
23
|
+
</template>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup>
|
|
28
|
+
import handlerCollections from '~/components/forms/handlers/handler-collections'
|
|
29
|
+
import handlerMembers from '~/components/forms/handlers/handler-members'
|
|
30
|
+
import handlerPasswordReset from '~/components/forms/handlers/handler-password-reset'
|
|
31
|
+
import handlerRoles from '~/components/forms/handlers/handler-roles'
|
|
32
|
+
import handlerSessions from '~/components/forms/handlers/handler-sessions'
|
|
33
|
+
import handlerTokens from '~/components/forms/handlers/handler-tokens'
|
|
34
|
+
import inputFilesMedia from '~/components/forms/fields/input-files-media'
|
|
35
|
+
import inputText from '~/components/forms/fields/input-text'
|
|
36
|
+
import inputTextArea from '~/components/forms/fields/input-text-area'
|
|
37
|
+
import selectEnum from '~/components/forms/fields/select-enum'
|
|
38
|
+
import { isStandalone } from '~/utils/forms'
|
|
39
|
+
|
|
40
|
+
// Prepare props
|
|
41
|
+
const $props = defineProps({
|
|
42
|
+
loading: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: false
|
|
45
|
+
},
|
|
46
|
+
attributes: {
|
|
47
|
+
type: Array,
|
|
48
|
+
default: () => []
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* The state of the enclosing `UForm`, keyed by property. The controls write
|
|
52
|
+
* into it: it is the form's one copy of what is being typed.
|
|
53
|
+
*/
|
|
54
|
+
state: {
|
|
55
|
+
type: Object,
|
|
56
|
+
required: true
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Prepare constants
|
|
61
|
+
/**
|
|
62
|
+
* The controls a described form may name. The settings and the account are
|
|
63
|
+
* its only callers so far: the record's own controls join with the record page
|
|
64
|
+
* (A6), which retires the older `forms/inputs` it still renders today.
|
|
65
|
+
*/
|
|
66
|
+
const CONTROLS = {
|
|
67
|
+
'handler-collections': handlerCollections,
|
|
68
|
+
'handler-members': handlerMembers,
|
|
69
|
+
'handler-password-reset': handlerPasswordReset,
|
|
70
|
+
'handler-roles': handlerRoles,
|
|
71
|
+
'handler-sessions': handlerSessions,
|
|
72
|
+
'handler-tokens': handlerTokens,
|
|
73
|
+
'input-files-media': inputFilesMedia,
|
|
74
|
+
'input-text': inputText,
|
|
75
|
+
'input-text-area': inputTextArea,
|
|
76
|
+
'select-enum': selectEnum,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Prepare constants
|
|
80
|
+
const globals = getCurrentInstance()?.appContext.components ?? {}
|
|
81
|
+
|
|
82
|
+
// Prepare computed
|
|
83
|
+
// A control the catalogue does not know may be a layer's: a globally
|
|
84
|
+
// registered component, which owns its data like a handler. Anything else
|
|
85
|
+
// renders nothing.
|
|
86
|
+
const controls = computed(() => $props.attributes
|
|
87
|
+
.map(attribute => ({
|
|
88
|
+
...attribute,
|
|
89
|
+
componentOptions: attribute.componentOptions ?? {},
|
|
90
|
+
control: CONTROLS[attribute.component] ?? (attribute.component in globals ? attribute.component : undefined),
|
|
91
|
+
standalone: isStandalone(attribute) || !(attribute.component in CONTROLS),
|
|
92
|
+
}))
|
|
93
|
+
.filter(({ control }) => control)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
// Prepare methods
|
|
97
|
+
/** The label and the name are the field's, not the control's. */
|
|
98
|
+
const _withoutLabel = ({ label, name, ...options }) => options
|
|
99
|
+
</script>
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<!-- Former form engine: only the record page renders it now. The settings use
|
|
2
|
+
forms-layout / forms-section / form-default and the fields under
|
|
3
|
+
components/forms/fields. Deleted with forms/inputs and forms/selects when
|
|
4
|
+
the record page is ported (A6). -->
|
|
1
5
|
<template>
|
|
2
6
|
<div v-show="attributes.length" class="space-y-4">
|
|
3
7
|
<div
|