@open-commune/web 0.2.14 → 0.2.16

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.
Files changed (69) hide show
  1. package/app.config.ts +7 -0
  2. package/components/audience/audience-bar-list.vue +29 -0
  3. package/components/audience/audience-panel.vue +230 -0
  4. package/components/data/lists/data-table.vue +203 -0
  5. package/components/data/lists/row-actions.vue +41 -0
  6. package/components/elements/badges/status-badge.vue +23 -0
  7. package/components/elements/media/media-image.vue +26 -0
  8. package/components/forms/fields/input-files-media.vue +87 -0
  9. package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
  10. package/components/forms/{inputs → fields}/input-search.vue +8 -2
  11. package/components/forms/fields/input-text-area.vue +86 -0
  12. package/components/forms/fields/input-text.vue +47 -0
  13. package/components/forms/fields/select-enum.vue +69 -0
  14. package/components/forms/handlers/handler-collections.vue +100 -170
  15. package/components/forms/handlers/handler-list.vue +187 -0
  16. package/components/forms/handlers/handler-members.vue +171 -0
  17. package/components/forms/handlers/handler-password-reset.vue +45 -0
  18. package/components/forms/handlers/handler-roles.vue +28 -166
  19. package/components/forms/handlers/handler-sessions.vue +77 -0
  20. package/components/forms/handlers/handler-tokens.vue +54 -69
  21. package/components/forms/layouts/form-default.vue +99 -0
  22. package/components/forms/layouts/form.vue +4 -0
  23. package/components/forms/layouts/forms-layout.vue +236 -0
  24. package/components/forms/layouts/forms-section.vue +186 -0
  25. package/components/forms/layouts/layout.vue +4 -0
  26. package/components/forms/layouts/modal.vue +4 -0
  27. package/components/forms/layouts/section.vue +4 -0
  28. package/components/layout/shell/shell-account-menu.vue +10 -2
  29. package/composables/core/domains/use-api-tokens.ts +80 -0
  30. package/composables/core/domains/use-audience.ts +26 -0
  31. package/composables/core/domains/use-auth.ts +56 -2
  32. package/composables/core/domains/use-definitions.ts +18 -5
  33. package/composables/core/domains/use-entries.ts +125 -3
  34. package/composables/core/domains/use-media.ts +24 -1
  35. package/composables/core/domains/use-members.ts +68 -0
  36. package/composables/core/domains/use-organization.ts +53 -0
  37. package/composables/use-models.js +1 -7
  38. package/constants/errors.ts +29 -0
  39. package/constants/forms/account.ts +62 -0
  40. package/constants/forms/collections.ts +39 -0
  41. package/constants/forms/members.ts +40 -0
  42. package/constants/forms/organization.ts +188 -0
  43. package/constants/forms/tokens.ts +15 -0
  44. package/constants/roles.ts +57 -0
  45. package/constants/settings.ts +26 -0
  46. package/constants/statuses.ts +8 -5
  47. package/nuxt.config.ts +4 -1
  48. package/package.json +4 -3
  49. package/pages/[collection]/[record]/index.vue +7 -0
  50. package/pages/[collection]/index.vue +117 -97
  51. package/pages/account.vue +40 -0
  52. package/pages/overview.vue +106 -2
  53. package/pages/settings.vue +26 -181
  54. package/plugins/01.validation.client.ts +23 -0
  55. package/store/layout/workspace.js +4 -28
  56. package/utils/colors.ts +26 -0
  57. package/utils/errors.ts +13 -0
  58. package/utils/forms.ts +67 -0
  59. package/utils/list-columns.ts +90 -0
  60. package/utils/settings.ts +38 -0
  61. package/utils/statuses.ts +4 -0
  62. package/models/role.js +0 -66
  63. package/models/token.js +0 -56
  64. package/models/user.js +0 -97
  65. package/pages/management/index.vue +0 -15
  66. package/pages/management/members.vue +0 -176
  67. package/pages/management/organizations.vue +0 -192
  68. package/pages/management/roles.vue +0 -183
  69. /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
@@ -4,7 +4,7 @@
4
4
  and the box stayed at 48px instead of 36. -->
5
5
  <div
6
6
  class="transition-[width] duration-200"
7
- :class="expanded ? 'w-64' : 'w-9'"
7
+ :class="expanded ? openClass : 'w-9'"
8
8
  @mouseenter="hovered = true"
9
9
  @mouseleave="hovered = false"
10
10
  >
@@ -28,12 +28,18 @@
28
28
  </template>
29
29
 
30
30
  <script setup>
31
+ // The collapsible search: a magnifier that opens on hover or focus, and stays
32
+ // open while it holds text. The collection list and the settings rail share it.
31
33
  import { refDebounced } from '@vueuse/core'
32
34
 
33
35
  // Prepare props
34
36
  const $props = defineProps({
35
37
  modelValue: { type: String, default: '' },
36
38
  placeholder: { type: String, default: 'Rechercher' },
39
+ /** Width once open: the collection list's fixed width, or the rail's own. */
40
+ openClass: { type: String, default: 'w-64' },
41
+ /** A request per keystroke is too many; a filter in the page wants none. */
42
+ debounce: { type: Number, default: 350 },
37
43
  })
38
44
 
39
45
  // Prepare emitters
@@ -45,7 +51,7 @@ const hovered = ref(false)
45
51
  const focused = ref(false)
46
52
 
47
53
  // A keystroke must not fire a request.
48
- const debounced = refDebounced(term, 350)
54
+ const debounced = refDebounced(term, $props.debounce)
49
55
 
50
56
  // Prepare computed
51
57
  const expanded = computed(() => hovered.value || focused.value || Boolean(term.value))
@@ -0,0 +1,86 @@
1
+ <template>
2
+ <!-- No field of its own: `form-default` puts the label and the name around
3
+ it, and the textarea reads them from there. -->
4
+ <UTextarea
5
+ v-model="text"
6
+ :placeholder="placeHolder"
7
+ :disabled="readOnly"
8
+ :rows="format === 'json' ? 8 : 3"
9
+ class="w-full"
10
+ :ui="format === 'json' ? { base: 'font-mono text-xs' } : {}"
11
+ />
12
+ </template>
13
+
14
+ <script setup>
15
+ // Prepare props
16
+ const $props = defineProps({
17
+ placeHolder: {
18
+ type: String,
19
+ default: ''
20
+ },
21
+ /**
22
+ * `json`: the value is an object or an array, shown as indented JSON and
23
+ * given back parsed. Half-typed JSON is not an error, it is a moment: nothing
24
+ * is given back until the text reads again.
25
+ */
26
+ format: {
27
+ type: String,
28
+ default: 'text'
29
+ },
30
+ readOnly: {
31
+ type: Boolean,
32
+ default: false
33
+ }
34
+ })
35
+
36
+ // Prepare reactive
37
+ const model = defineModel({ type: [String, Object, Array], default: '' })
38
+ const text = ref('')
39
+
40
+ // Prepare methods
41
+ const _blank = value => value === undefined || value === null || value === ''
42
+
43
+ function _sameJson(written, value) {
44
+ try {
45
+ return JSON.stringify(JSON.parse(written)) === JSON.stringify(value)
46
+ } catch {
47
+ return false
48
+ }
49
+ }
50
+
51
+ // Prepare watchers
52
+ watch(
53
+ model,
54
+ (value) => {
55
+ if ($props.format !== 'json') {
56
+ text.value = value ?? ''
57
+ return
58
+ }
59
+ // Typing must not be rewritten under the cursor: the text is replaced only
60
+ // when the value it describes changed.
61
+ // Nothing yet is an empty box, not the text of an empty value.
62
+ if (_blank(value)) {
63
+ if (text.value.trim()) text.value = ''
64
+ } else if (!_sameJson(text.value, value)) {
65
+ text.value = JSON.stringify(value, null, 2)
66
+ }
67
+ },
68
+ { immediate: true }
69
+ )
70
+ watch(text, (written) => {
71
+ if ($props.format !== 'json') {
72
+ model.value = written
73
+ return
74
+ }
75
+ if (!written.trim()) {
76
+ if (!_blank(model.value)) model.value = undefined
77
+ return
78
+ }
79
+ try {
80
+ const parsed = JSON.parse(written)
81
+ if (!_sameJson(written, model.value)) model.value = parsed
82
+ } catch {
83
+ // Nothing given back: the form keeps the last value that read.
84
+ }
85
+ })
86
+ </script>
@@ -0,0 +1,47 @@
1
+ <template>
2
+ <!-- No field of its own: `form-default` puts the label and the name around
3
+ it, and the input reads them from there. -->
4
+ <UInput
5
+ v-model="model"
6
+ :autocomplete="autoComplete"
7
+ :placeholder="placeHolder"
8
+ :icon="icon || undefined"
9
+ :type="type"
10
+ :required="required"
11
+ :disabled="readOnly"
12
+ class="w-full"
13
+ />
14
+ </template>
15
+
16
+ <script setup>
17
+ // Prepare props
18
+ defineProps({
19
+ autoComplete: {
20
+ type: String,
21
+ default: 'given-name'
22
+ },
23
+ type: {
24
+ type: String,
25
+ default: 'text'
26
+ },
27
+ icon: {
28
+ type: String,
29
+ default: ''
30
+ },
31
+ placeHolder: {
32
+ type: String,
33
+ default: ''
34
+ },
35
+ readOnly: {
36
+ type: Boolean,
37
+ default: false
38
+ },
39
+ required: {
40
+ type: Boolean,
41
+ default: false
42
+ }
43
+ })
44
+
45
+ // Prepare reactive
46
+ const model = defineModel({ type: String, default: '' })
47
+ </script>
@@ -0,0 +1,69 @@
1
+ <template>
2
+ <!-- No field of its own: `form-default` puts the label and the name around
3
+ it. -->
4
+ <USelectMenu
5
+ v-model="model"
6
+ :items="options"
7
+ :multiple="enableMultiple"
8
+ :disabled="readOnly"
9
+ :placeholder="placeHolder"
10
+ value-key="value"
11
+ class="w-full"
12
+ />
13
+ </template>
14
+
15
+ <script setup>
16
+ // Prepare props
17
+ const $props = defineProps({
18
+ filter: {
19
+ type: Function,
20
+ default: () => () => true
21
+ },
22
+ items: {
23
+ type: Array,
24
+ default: () => []
25
+ },
26
+ itemKey: {
27
+ type: String,
28
+ default: 'name'
29
+ },
30
+ itemValue: {
31
+ type: String,
32
+ default: '_id'
33
+ },
34
+ enableMultiple: {
35
+ type: Boolean,
36
+ default: false
37
+ },
38
+ object: {
39
+ type: Boolean,
40
+ default: true
41
+ },
42
+ placeHolder: {
43
+ type: String,
44
+ default: 'Sélectionnez'
45
+ },
46
+ readOnly: {
47
+ type: Boolean,
48
+ default: false
49
+ }
50
+ })
51
+
52
+ // Prepare reactive
53
+ // A choice is not always a string: APIDAE-fed fields carry numeric ids.
54
+ const model = defineModel({ type: [String, Number, Array], default: undefined })
55
+
56
+ // Prepare computed
57
+ /**
58
+ * The choices in the ONE shape the menu reads: a label to show, a value to
59
+ * emit. `object: false` describes a list of plain scalars, where the choice IS
60
+ * the value.
61
+ */
62
+ const options = computed(() =>
63
+ $props.items
64
+ .filter($props.filter)
65
+ .map(item => ($props.object
66
+ ? { label: item?.[$props.itemKey], value: item?.[$props.itemValue] }
67
+ : { label: item, value: item }))
68
+ )
69
+ </script>
@@ -1,189 +1,119 @@
1
1
  <template>
2
- <div class="relative block w-full">
3
- <!-- <div class="bg-gray-200 text-gray-500 text-sm rounded-md w-full p-4">
4
- /!\ Navigation should be based on organization.collections array only<br>
5
- Collections that does not belong to organization can't be updated or deleted only enabled / disabled<br>
6
- Let user duplicate an existing collection for this organization only
7
- </div> -->
8
- <button-secondary class="my-1" label="Ajouter une collection" @click="_openModalForm('add')" />
9
- <list-table
10
- :headers="TABLE_HEADERS"
11
- :items="collections"
12
- :actions="['update', 'remove']"
13
- @update="_openModalForm('update', $event)"
14
- @remove="_handleCollection('remove', $event)"
15
- @usage="_updateCollectionUsage($event)"
16
- />
17
- </div>
2
+ <handler-list
3
+ v-model:open="isModalOpen"
4
+ :rows="rows"
5
+ :loading="isLoading"
6
+ empty="Aucune collection."
7
+ action-label="Ajouter une collection"
8
+ :form="COLLECTION_FORM"
9
+ :schema="action === 'add' ? definitionCreateDto : definitionUpdateDto"
10
+ :record="editing"
11
+ :title="modalTitle"
12
+ description="Entrez un nom pour votre collection afin de l'identifier facilement."
13
+ :submit-label="submitLabel"
14
+ @add="_openModalForm('add')"
15
+ @submit="_handleCollection(action, $event)"
16
+ >
17
+ <template #row="{ row }">
18
+ <button
19
+ type="button"
20
+ class="flex min-w-0 flex-1 cursor-pointer flex-wrap items-baseline gap-x-2 text-left"
21
+ @click="_openModalForm('update', row.source)"
22
+ >
23
+ <span class="truncate text-sm font-medium text-highlighted">{{ row.name }}</span>
24
+ <span class="truncate text-[13px] text-dimmed">{{ row.measure }}</span>
25
+ </button>
26
+ <UButton
27
+ icon="i-lucide-trash-2"
28
+ color="neutral"
29
+ variant="ghost"
30
+ size="sm"
31
+ class="shrink-0 text-dimmed opacity-0 transition hover:text-error group-hover:opacity-100 focus-visible:opacity-100"
32
+ :aria-label="`Supprimer ${row.name}`"
33
+ @click="_handleCollection('remove', row.source)"
34
+ />
35
+ </template>
36
+ </handler-list>
18
37
  </template>
19
38
 
20
39
  <script setup>
21
- import listTable from '~/components/data/lists/data-lists-table'
22
- import buttonSecondary from '~/components/elements/buttons/secondary'
23
- import { useModalStore } from '~/store/layout/modal'
24
- import { useWorkspaceStore } from '~/store/layout/workspace'
40
+ import { refusalOf } from '~/utils/errors'
41
+ import { definitionCreateDto, definitionUpdateDto } from '@open-commune/core/dtos'
42
+ import handlerList from '~/components/forms/handlers/handler-list.vue'
43
+ import { COLLECTION_FORM } from '~/constants/forms/collections'
25
44
 
26
- const { Organization, Collection } = useModels()
27
- const { open } = useModalStore()
28
- const $workspaceStore = useWorkspaceStore()
45
+ // Prepare composables
46
+ const $definitions = useDefinitions()
47
+ const { mutateAsync: createDefinition } = $definitions.create()
48
+ const { mutateAsync: updateDefinition } = $definitions.update()
49
+ const { mutateAsync: removeDefinition } = $definitions.remove()
50
+ const $entries = useEntries()
29
51
 
30
- // prepare constants
31
- const TABLE_HEADERS = [
32
- {
33
- title: 'Utilisation',
34
- property: 'usage',
35
- component: 'data-toggle'
36
- },
37
- {
38
- title: 'Nom',
39
- property: 'name',
40
- component: 'data-text'
41
- },
42
- {
43
- title: 'Organisation',
44
- property: 'organization',
45
- component: 'data-badge'
46
- },
47
- {
48
- title: 'Dernière modification',
49
- nestedValue: false,
50
- alignRight: true,
51
- component: 'data-last-update',
52
- componentOptions: {
53
- inline: true
54
- }
55
- },
56
- {
57
- title: '',
58
- component: 'actions'
59
- }
60
- ]
52
+ // Prepare reactive
53
+ /**
54
+ * How many entries each collection holds — counted on the server, once per
55
+ * collection. A collection whose count has not landed says nothing rather than
56
+ * zero, which would be a lie for the second it lasts.
57
+ */
58
+ const counts = ref({})
59
+ const isModalOpen = ref(false)
60
+ /** Which gesture the open modal is serving, and on which collection. */
61
+ const action = ref('add')
62
+ const editing = ref({})
61
63
 
62
- // Prepare dynamic data
63
- const availableCollections = ref([])
64
+ // Fetch data
65
+ const { data: collections, isLoading } = $definitions.list()
64
66
 
65
67
  // Prepare computed
66
- const organizationId = computed(() => $workspaceStore.workspaceId)
67
- const organizationPath = computed(() => $workspaceStore.workspacePath)
68
- const organizationCollections = computed(() => $workspaceStore.workspaceCollections)
69
- const collections = computed(() => {
70
- const collectionRecords = Collection.repo.all()
71
- return collectionRecords.map(({ _id, ...rest }) => ({ _id, usage: organizationCollections.value.includes(_id), ...rest }))
72
- })
68
+ const rows = computed(() => (collections.value ?? []).map((collection) => {
69
+ const total = counts.value[collection.id]
70
+ const fields = collection.fields?.length ?? 0
71
+ return {
72
+ key: collection.id,
73
+ name: collection.name,
74
+ measure: [
75
+ total === undefined ? null : _plural(total, 'entrée'),
76
+ _plural(fields, 'champ'),
77
+ ].filter(Boolean).join(' · '),
78
+ source: collection,
79
+ }
80
+ }))
81
+
82
+ const modalTitle = computed(() => `${action.value === 'add' ? 'Créer' : 'Modifier'} une collection`)
83
+ const submitLabel = computed(() => (action.value === 'add' ? 'Créer' : 'Modifier'))
73
84
 
74
85
  // Prepare methods
75
- const _updateCollectionUsage = async ({ _id, usage }) => {
76
- if (usage && !organizationCollections.value.includes(_id)) {
77
- await Organization.update(organizationId.value, { collections: [...organizationCollections.value, _id] })
78
- }
79
- if (!usage && organizationCollections.value.includes(_id)) {
80
- await Organization.update(organizationId.value, { collections: [...organizationCollections.value.filter(check => check !== _id)] })
81
- }
82
- }
86
+ const _plural = (count, word) => `${count} ${word}${count > 1 ? 's' : ''}`
83
87
 
84
- const _handleCollection = async (action, data = {}) => {
85
- const { _id } = data
86
- switch (action) {
87
- case 'add':
88
- await Collection.create(data)
89
- break
90
- case 'update':
91
- await Collection.update(_id, data)
92
- break
93
- case 'remove':
94
- await Collection.remove(_id)
95
- break
96
- default:
97
- throw new Error('E_UNHANDLED')
88
+ // `gesture`, not `action`: the ref above holds the one the modal is serving.
89
+ const _handleCollection = async (gesture, data = {}) => {
90
+ try {
91
+ if (gesture === 'add') await createDefinition(data)
92
+ else if (gesture === 'update') await updateDefinition({ id: data.id, data })
93
+ else if (gesture === 'remove') await removeDefinition(data.id)
94
+ } catch (error) {
95
+ // A refusal is said, in the words of the core's error when it sent one:
96
+ // a slug already taken used to fail without a word.
97
+ useToast().add({
98
+ color: 'error',
99
+ title: "La collection n'a pas pu être enregistrée",
100
+ description: refusalOf(error, 'Le serveur a refusé la modification. Réessayez dans un instant.'),
101
+ })
98
102
  }
99
103
  }
100
104
 
101
- const _openModalForm = (action, record) => {
102
- console.log(action, record)
103
- open({
104
- onSubmit: async (data) => _handleCollection(action, data),
105
- details: {
106
- title: `${action === 'add'? 'Créer' : 'Modifier'} une collection`,
107
- subTitle: 'Entrez un nom pour votre collection afin de l\'identifier facilement.',
108
- acceptButton: `${action === 'add' ? 'Créer' : 'Modifier'}`,
109
- closeButton: 'Annuler'
110
- },
111
- attributes: [
112
- {
113
- property: 'name',
114
- componentOptions: {
115
- label: 'Titre de la collection',
116
- name: 'name'
117
- },
118
- component: 'input-text'
119
- },
120
- {
121
- property: 'slug',
122
- componentOptions: {
123
- label: 'Slug de la collection',
124
- name: 'slug'
125
- },
126
- component: 'input-text'
127
- },
128
- {
129
- property: 'description',
130
- componentOptions: {
131
- label: 'Description de la collection',
132
- name: 'description'
133
- },
134
- component: 'input-text-area'
135
- },
136
- {
137
- property: 'attributes',
138
- componentOptions: {
139
- label: 'Attribut(s) de la collection',
140
- name: 'attributes'
141
- },
142
- component: 'input-json'
143
- },
144
- {
145
- property: 'editor',
146
- componentOptions: {
147
- label: 'Editeur de la collection',
148
- name: 'editor'
149
- },
150
- component: 'input-json'
151
- },
152
- {
153
- property: 'headings',
154
- componentOptions: {
155
- label: 'Titres de la collection',
156
- name: 'headings'
157
- },
158
- component: 'input-json'
159
- },
160
- {
161
- property: 'display',
162
- componentOptions: {
163
- label: 'Affichage de la collection',
164
- name: 'display'
165
- },
166
- component: 'input-json'
167
- }
168
- ],
169
- record
170
- })
105
+ const _openModalForm = (nextAction, record = {}) => {
106
+ action.value = nextAction
107
+ editing.value = record
108
+ isModalOpen.value = true
171
109
  }
172
110
 
173
- // Prepare lifecyle hooks
174
- onMounted(async () => {
175
- if (!collections.value.length) {
176
- await Collection.list()
177
- }
178
- if (!availableCollections.value.length) {
179
- const parents = organizationPath.value.split('/')
180
- if (parents.length) {
181
- parents.pop()
182
- const results = await Promise.all(
183
- parents.map(parent => Collection.list(undefined, parent))
184
- )
185
- availableCollections.value = results.flat()
186
- }
111
+ // Prepare watchers
112
+ watch(collections, async (list) => {
113
+ for (const { id } of list ?? []) {
114
+ if (counts.value[id] !== undefined) continue
115
+ const total = await $entries.count(id).catch(() => null)
116
+ if (total !== null) counts.value = { ...counts.value, [id]: total }
187
117
  }
188
- })
118
+ }, { immediate: true })
189
119
  </script>