adminforth 1.3.55-next.0 → 1.3.55-next.2

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 (63) hide show
  1. package/dist/spa/.eslintrc.cjs +14 -0
  2. package/dist/spa/README.md +39 -0
  3. package/dist/spa/env.d.ts +1 -0
  4. package/dist/spa/index.html +23 -0
  5. package/dist/spa/package-lock.json +4659 -0
  6. package/dist/spa/package.json +52 -0
  7. package/dist/spa/postcss.config.js +6 -0
  8. package/dist/spa/public/assets/favicon.png +0 -0
  9. package/dist/spa/src/App.vue +418 -0
  10. package/dist/spa/src/assets/base.css +2 -0
  11. package/dist/spa/src/assets/logo.svg +19 -0
  12. package/dist/spa/src/components/AcceptModal.vue +45 -0
  13. package/dist/spa/src/components/Breadcrumbs.vue +41 -0
  14. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +26 -0
  15. package/dist/spa/src/components/CustomDatePicker.vue +176 -0
  16. package/dist/spa/src/components/CustomDateRangePicker.vue +218 -0
  17. package/dist/spa/src/components/CustomRangePicker.vue +156 -0
  18. package/dist/spa/src/components/Dropdown.vue +168 -0
  19. package/dist/spa/src/components/Filters.vue +222 -0
  20. package/dist/spa/src/components/HelloWorld.vue +17 -0
  21. package/dist/spa/src/components/MenuLink.vue +27 -0
  22. package/dist/spa/src/components/ResourceForm.vue +325 -0
  23. package/dist/spa/src/components/ResourceListTable.vue +466 -0
  24. package/dist/spa/src/components/SingleSkeletLoader.vue +13 -0
  25. package/dist/spa/src/components/SkeleteLoader.vue +23 -0
  26. package/dist/spa/src/components/ThreeDotsMenu.vue +43 -0
  27. package/dist/spa/src/components/Toast.vue +78 -0
  28. package/dist/spa/src/components/ValueRenderer.vue +141 -0
  29. package/dist/spa/src/components/icons/IconCalendar.vue +5 -0
  30. package/dist/spa/src/components/icons/IconCommunity.vue +7 -0
  31. package/dist/spa/src/components/icons/IconDocumentation.vue +7 -0
  32. package/dist/spa/src/components/icons/IconEcosystem.vue +7 -0
  33. package/dist/spa/src/components/icons/IconSupport.vue +7 -0
  34. package/dist/spa/src/components/icons/IconTime.vue +5 -0
  35. package/dist/spa/src/components/icons/IconTooling.vue +19 -0
  36. package/dist/spa/src/composables/useFrontendApi.ts +26 -0
  37. package/dist/spa/src/composables/useStores.ts +131 -0
  38. package/dist/spa/src/index.scss +31 -0
  39. package/dist/spa/src/main.ts +18 -0
  40. package/dist/spa/src/renderers/CompactUUID.vue +48 -0
  41. package/dist/spa/src/renderers/CountryFlag.vue +69 -0
  42. package/dist/spa/src/router/index.ts +59 -0
  43. package/dist/spa/src/spa_types/core.ts +53 -0
  44. package/dist/spa/src/stores/core.ts +148 -0
  45. package/dist/spa/src/stores/filters.ts +27 -0
  46. package/dist/spa/src/stores/modal.ts +48 -0
  47. package/dist/spa/src/stores/toast.ts +31 -0
  48. package/dist/spa/src/stores/user.ts +72 -0
  49. package/dist/spa/src/types/AdminForthConfig.ts +1762 -0
  50. package/dist/spa/src/types/FrontendAPI.ts +143 -0
  51. package/dist/spa/src/utils.ts +160 -0
  52. package/dist/spa/src/views/CreateView.vue +167 -0
  53. package/dist/spa/src/views/EditView.vue +170 -0
  54. package/dist/spa/src/views/ListView.vue +352 -0
  55. package/dist/spa/src/views/LoginView.vue +192 -0
  56. package/dist/spa/src/views/ResourceParent.vue +17 -0
  57. package/dist/spa/src/views/ShowView.vue +194 -0
  58. package/dist/spa/tailwind.config.js +17 -0
  59. package/dist/spa/tsconfig.app.json +14 -0
  60. package/dist/spa/tsconfig.json +11 -0
  61. package/dist/spa/tsconfig.node.json +19 -0
  62. package/dist/spa/vite.config.ts +56 -0
  63. package/package.json +2 -2
@@ -0,0 +1,325 @@
1
+ <template>
2
+ <div class="rounded-default">
3
+ <div
4
+ class="relative shadow-resourseFormShadow dark:shadow-darkResourseFormShadow sm:rounded-lg dark:shadow-2xl rounded-default"
5
+ >
6
+ <form autocomplete="off" @submit.prevent>
7
+ <table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400 ">
8
+ <thead class="text-xs text-gray-700 uppercase bg-lightFormHeading dark:bg-gray-700 dark:text-gray-400 block md:table-row-group">
9
+ <tr>
10
+ <th scope="col" class="px-6 py-3 hidden md:table-cell">
11
+ Field
12
+ </th>
13
+ <th scope="col" class="px-6 py-3 w-5/6 hidden md:table-cell">
14
+ Value
15
+ </th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <tr v-for="column, i in editableColumns" :key="column.name"
20
+ v-if="currentValues !== null"
21
+ class="bg-ligftForm dark:bg-gray-800 dark:border-gray-700 block md:table-row"
22
+ :class="{ 'border-b': i !== editableColumns.length - 1 }"
23
+ >
24
+ <td class="px-6 py-4 sm:pb-0 whitespace-nowrap flex items-center block md:table-cell"> <!--align-top-->
25
+ {{ column.label }}
26
+ <span :data-tooltip-target="`tooltip-show-${i}`" class="ml-1 relative inline-block">
27
+ <IconExclamationCircleSolid v-if="column.required[mode]" class="w-4 h-4"
28
+ :class="(columnError(column) && validating) ? 'text-red-500 dark:text-red-400' : 'text-gray-400 dark:text-gray-500'"
29
+ />
30
+ </span>
31
+ <div :id="`tooltip-show-${i}`"
32
+ role="tooltip"
33
+ class="ml-1 absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
34
+ Required field
35
+ <div class="tooltip-arrow" data-popper-arrow></div>
36
+ </div>
37
+ </td>
38
+ <td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap relative block md:table-cell">
39
+ <template v-if="column?.components?.[props.source]?.file">
40
+ <component
41
+ :is="getCustomComponent(column.components[props.source])"
42
+ :column="column"
43
+ :value="currentValues[column.name]"
44
+ @update:value="setCurrentValue(column.name, $event)"
45
+ :meta="column.components[props.source].meta"
46
+ :record="currentValues"
47
+ @update:inValidity="customComponentsInValidity[column.name] = $event"
48
+ @update:emptiness="customComponentsEmptiness[column.name] = $event"
49
+ />
50
+ </template>
51
+ <template v-else>
52
+ <Dropdown
53
+ single
54
+ v-if="column.foreignResource"
55
+ :options="columnOptions[column.name] || []"
56
+ :placeholder = "columnOptions[column.name]?.length ?'Select...': 'There are no options available'"
57
+ :modelValue="currentValues[column.name]"
58
+ @update:modelValue="setCurrentValue(column.name, $event)"
59
+ ></Dropdown>
60
+ <Dropdown
61
+ single
62
+ v-else-if="column.enum"
63
+ :options="column.enum"
64
+ :modelValue="currentValues[column.name]"
65
+ @update:modelValue="setCurrentValue(column.name, $event)"
66
+ />
67
+ <Dropdown
68
+ single
69
+ v-else-if="column.type === 'boolean'"
70
+ :options="[{ label: 'Yes', value: true }, { label: 'No', value: false }, { label: 'Unset', value: null }]"
71
+ :modelValue="currentValues[column.name]"
72
+ @update:modelValue="setCurrentValue(column.name, $event)"
73
+ />
74
+ <input
75
+ v-else-if="['integer'].includes(column.type)"
76
+ type="number"
77
+ step="1"
78
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-40 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
79
+ placeholder="0"
80
+ :value="currentValues[column.name]"
81
+ @input="setCurrentValue(column.name, $event.target.value)"
82
+ >
83
+ <CustomDatePicker
84
+ v-else-if="['datetime'].includes(column.type)"
85
+ :column="column"
86
+ :valueStart="currentValues[column.name]"
87
+ auto-hide
88
+ @update:valueStart="setCurrentValue(column.name, $event)"
89
+ />
90
+ <input
91
+ v-else-if="['decimal', 'float'].includes(column.type)"
92
+ type="number"
93
+ step="0.1"
94
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-40 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
95
+ placeholder="0.0"
96
+ :value="currentValues[column.name]"
97
+ @input="setCurrentValue(column.name, $event.target.value)"
98
+ />
99
+ <textarea
100
+ v-else-if="['text', 'richtext'].includes(column.type)"
101
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
102
+ placeholder="Text"
103
+ :value="currentValues[column.name]"
104
+ @input="setCurrentValue(column.name, $event.target.value)"
105
+ >
106
+ </textarea>
107
+ <textarea
108
+ v-else-if="['json'].includes(column.type)"
109
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
110
+ placeholder="Text"
111
+ :value="currentValues[column.name]"
112
+ @input="setCurrentValue(column.name, $event.target.value)"
113
+ >
114
+ </textarea>
115
+ <input
116
+ v-else
117
+ :type="!column.masked || unmasked[column.name] ? 'text' : 'password'"
118
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
119
+ placeholder="Text"
120
+ :value="currentValues[column.name]"
121
+ @input="setCurrentValue(column.name, $event.target.value)"
122
+ autocomplete="false"
123
+ data-lpignore="true"
124
+ readonly
125
+ onfocus="this.removeAttribute('readonly');"
126
+ >
127
+
128
+ <button
129
+ v-if="column.masked"
130
+ type="button"
131
+ @click="unmasked[column.name] = !unmasked[column.name]"
132
+ class="h-6 absolute inset-y-2 top-6 right-6 flex items-center pr-2 z-index-100 focus:outline-none"
133
+ >
134
+ <IconEyeSolid class="w-6 h-6 text-gray-400" v-if="!unmasked[column.name]" />
135
+ <IconEyeSlashSolid class="w-6 h-6 text-gray-400" v-else />
136
+ </button>
137
+ </template>
138
+ <div v-if="columnError(column) && validating" class="mt-1 text-xs text-red-500 dark:text-red-400">{{ columnError(column) }}</div>
139
+ <div v-if="column.editingNote && column.editingNote[mode]" class="mt-1 text-xs text-gray-400 dark:text-gray-500">{{ column.editingNote[mode] }}</div>
140
+
141
+ </td>
142
+ </tr>
143
+
144
+ </tbody>
145
+ </table>
146
+ </form>
147
+ </div>
148
+ </div>
149
+
150
+ </template>
151
+
152
+ <script setup>
153
+
154
+ import CustomDatePicker from "@/components/CustomDatePicker.vue";
155
+ import Dropdown from '@/components/Dropdown.vue';
156
+ import { applyRegexValidation, callAdminForthApi, getCustomComponent } from '@/utils';
157
+ import { IconExclamationCircleSolid, IconEyeSlashSolid, IconEyeSolid } from '@iconify-prerendered/vue-flowbite';
158
+ import { computedAsync } from '@vueuse/core';
159
+ import { initFlowbite } from 'flowbite';
160
+ import { computed, onMounted, ref, watch } from 'vue';
161
+ import { useRouter, useRoute } from 'vue-router';
162
+
163
+ const router = useRouter();
164
+ const route = useRoute();
165
+ const props = defineProps({
166
+ resource: Object,
167
+ record: Object,
168
+ validating: Boolean,
169
+ source: String,
170
+ });
171
+
172
+ const unmasked = ref({});
173
+
174
+ const mode = computed(() => route.name === 'resource-create' ? 'create' : 'edit');
175
+
176
+ const emit = defineEmits(['update:record', 'update:isValid']);
177
+
178
+ const currentValues = ref(null);
179
+
180
+ const customComponentsInValidity = ref({});
181
+ const customComponentsEmptiness = ref({});
182
+
183
+
184
+ const columnError = (column) => {
185
+ const val = computed(() => {
186
+ if (!currentValues.value) {
187
+ return null;
188
+ }
189
+ if (customComponentsInValidity.value[column.name]) {
190
+ return customComponentsInValidity.value[column.name];
191
+ }
192
+
193
+ if (
194
+ column.required[mode.value] &&
195
+ (currentValues.value[column.name] === undefined || currentValues.value[column.name] === null || currentValues.value[column.name] === '') &&
196
+ // if component is custum it might tell other criteria for emptiness by emitting 'update:emptiness'
197
+ // components which do not emit 'update:emptiness' will have undefined value in customComponentsEmptiness
198
+ (customComponentsEmptiness.value[column.name] !== false)
199
+
200
+ ) {
201
+ return 'This field is required';
202
+ }
203
+ if (column.type === 'json' && currentValues.value[column.name]) {
204
+ try {
205
+ JSON.parse(currentValues.value[column.name]);
206
+ } catch (e) {
207
+ return 'Invalid JSON';
208
+ }
209
+ }
210
+ if ( column.type === 'string' || column.type === 'text' ) {
211
+ if ( column.maxLength && currentValues.value[column.name]?.length > column.maxLength ) {
212
+ return `This field must be shorter than ${column.maxLength} characters`;
213
+ }
214
+
215
+ if ( column.minLength && currentValues.value[column.name]?.length < column.minLength ) {
216
+ // if column.required[mode.value] is false, then we check if the field is empty
217
+ let needToCheckEmpty = column.required[mode.value] || currentValues.value[column.name]?.length > 0;
218
+ if (!needToCheckEmpty) {
219
+ return null;
220
+ }
221
+ return `This field must be longer than ${column.minLength} characters`;
222
+ }
223
+ }
224
+ if ( ['integer', 'decimal', 'float'].includes(column.type) ) {
225
+ if ( column.minValue !== undefined
226
+ && currentValues.value[column.name] !== null
227
+ && currentValues.value[column.name] < column.minValue
228
+ ) {
229
+ return `This field must be greater than ${column.minValue}`;
230
+ }
231
+ if ( column.maxValue !== undefined && currentValues.value[column.name] > column.maxValue ) {
232
+ return `This field must be less than ${column.maxValue}`;
233
+ }
234
+ }
235
+ if (currentValues.value[column.name] && column.validation) {
236
+ const error = applyRegexValidation(currentValues.value[column.name], column.validation);
237
+ if (error) {
238
+ return error;
239
+ }
240
+ }
241
+
242
+ return null;
243
+ });
244
+ return val.value;
245
+ };
246
+
247
+
248
+ const setCurrentValue = (key, value) => {
249
+ const col = props.resource.columns.find((column) => column.name === key);
250
+ if (['integer', 'float'].includes(col.type) && (value || value === 0)) {
251
+ currentValues.value[key] = +value;
252
+ } else {
253
+ currentValues.value[key] = value;
254
+ }
255
+ if (['text', 'richtext', 'string'].includes(col.type) && col.enforceLowerCase) {
256
+ currentValues.value[key] = currentValues.value[key].toLowerCase();
257
+ }
258
+
259
+ currentValues.value = { ...currentValues.value };
260
+
261
+ //json fields should transform to object
262
+ const up = {...currentValues.value};
263
+ props.resource.columns.forEach((column) => {
264
+ if (column.type === 'json' && up[column.name]) {
265
+ try {
266
+ up[column.name] = JSON.parse(up[column.name]);
267
+ } catch (e) {
268
+ // do nothing
269
+ }
270
+ }
271
+ });
272
+ emit('update:record', up);
273
+ };
274
+
275
+ onMounted(() => {
276
+
277
+ currentValues.value = Object.assign({}, props.record);
278
+ // json values should transform to string
279
+ props.resource.columns.forEach((column) => {
280
+ if (column.type === 'json' && currentValues.value[column.name]) {
281
+ currentValues.value[column.name] = JSON.stringify(currentValues.value[column.name], null, 2);
282
+ }
283
+ });
284
+ console.log('currentValues', currentValues.value);
285
+
286
+ initFlowbite();
287
+ emit('update:isValid', isValid.value);
288
+ });
289
+
290
+ const columnOptions = computedAsync(async () => {
291
+ return (await Promise.all(
292
+ Object.values(props.resource.columns).map(async (column) => {
293
+ if (column.foreignResource) {
294
+ const list = await callAdminForthApi({
295
+ method: 'POST',
296
+ path: `/get_resource_foreign_data`,
297
+ body: {
298
+ resourceId: router.currentRoute.value.params.resourceId,
299
+ column: column.name,
300
+ limit: 1000,
301
+ offset: 0,
302
+ },
303
+ });
304
+ return { [column.name]: list.items };
305
+ }
306
+ })
307
+ )).reduce((acc, val) => Object.assign(acc, val), {})
308
+
309
+ }, {});
310
+
311
+
312
+ const editableColumns = computed(() => {
313
+ const mode = props.record ? 'edit' : 'create';
314
+ return props.resource?.columns?.filter(column => column.showIn.includes(mode));
315
+ });
316
+
317
+ const isValid = computed(() => {
318
+ return editableColumns.value?.every(column => !columnError(column));
319
+ });
320
+
321
+ watch(() => isValid.value, (value) => {
322
+ emit('update:isValid', value);
323
+ });
324
+
325
+ </script>