adminforth 1.6.2-next.3 → 1.6.2-next.5
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/spa/.eslintrc.cjs +14 -0
- package/dist/spa/README.md +39 -0
- package/dist/spa/env.d.ts +1 -0
- package/dist/spa/index.html +23 -0
- package/dist/spa/package-lock.json +5062 -0
- package/dist/spa/package.json +58 -0
- package/dist/spa/postcss.config.js +6 -0
- package/dist/spa/public/assets/favicon.png +0 -0
- package/dist/spa/src/App.vue +432 -0
- package/dist/spa/src/adminforth.ts +160 -0
- package/dist/spa/src/afcl/AreaChart.vue +160 -0
- package/dist/spa/src/afcl/BarChart.vue +170 -0
- package/dist/spa/src/afcl/Button.vue +27 -0
- package/dist/spa/src/afcl/Checkbox.vue +24 -0
- package/dist/spa/src/afcl/Dropzone.vue +128 -0
- package/dist/spa/src/afcl/Input.vue +41 -0
- package/dist/spa/src/afcl/Link.vue +17 -0
- package/dist/spa/src/afcl/LinkButton.vue +25 -0
- package/dist/spa/src/afcl/PieChart.vue +175 -0
- package/dist/spa/src/afcl/ProgressBar.vue +57 -0
- package/dist/spa/src/afcl/Select.vue +246 -0
- package/dist/spa/src/afcl/Skeleton.vue +26 -0
- package/dist/spa/src/afcl/Spinner.vue +9 -0
- package/dist/spa/src/afcl/Table.vue +116 -0
- package/dist/spa/src/afcl/Tooltip.vue +43 -0
- package/dist/spa/src/afcl/VerticalTabs.vue +49 -0
- package/dist/spa/src/afcl/index.ts +20 -0
- package/dist/spa/src/assets/base.css +2 -0
- package/dist/spa/src/assets/logo.svg +19 -0
- package/dist/spa/src/components/AcceptModal.vue +44 -0
- package/dist/spa/src/components/Breadcrumbs.vue +41 -0
- package/dist/spa/src/components/BreadcrumbsWithButtons.vue +25 -0
- package/dist/spa/src/components/CustomDatePicker.vue +180 -0
- package/dist/spa/src/components/CustomDateRangePicker.vue +218 -0
- package/dist/spa/src/components/CustomRangePicker.vue +156 -0
- package/dist/spa/src/components/Filters.vue +232 -0
- package/dist/spa/src/components/GroupsTable.vue +218 -0
- package/dist/spa/src/components/HelloWorld.vue +17 -0
- package/dist/spa/src/components/MenuLink.vue +41 -0
- package/dist/spa/src/components/ResourceForm.vue +260 -0
- package/dist/spa/src/components/ResourceListTable.vue +486 -0
- package/dist/spa/src/components/ShowTable.vue +81 -0
- package/dist/spa/src/components/SingleSkeletLoader.vue +13 -0
- package/dist/spa/src/components/SkeleteLoader.vue +18 -0
- package/dist/spa/src/components/ThreeDotsMenu.vue +43 -0
- package/dist/spa/src/components/Toast.vue +78 -0
- package/dist/spa/src/components/ValueRenderer.vue +141 -0
- package/dist/spa/src/components/icons/IconCalendar.vue +5 -0
- package/dist/spa/src/components/icons/IconCommunity.vue +7 -0
- package/dist/spa/src/components/icons/IconDocumentation.vue +7 -0
- package/dist/spa/src/components/icons/IconEcosystem.vue +7 -0
- package/dist/spa/src/components/icons/IconSupport.vue +7 -0
- package/dist/spa/src/components/icons/IconTime.vue +5 -0
- package/dist/spa/src/components/icons/IconTooling.vue +19 -0
- package/dist/spa/src/composables/useFrontendApi.ts +28 -0
- package/dist/spa/src/i18n.ts +54 -0
- package/dist/spa/src/index.scss +34 -0
- package/dist/spa/src/main.ts +22 -0
- package/dist/spa/src/renderers/CompactField.vue +46 -0
- package/dist/spa/src/renderers/CompactUUID.vue +46 -0
- package/dist/spa/src/renderers/CountryFlag.vue +65 -0
- package/dist/spa/src/renderers/HumanNumber.vue +58 -0
- package/dist/spa/src/renderers/RelativeTime.vue +42 -0
- package/dist/spa/src/renderers/URL.vue +18 -0
- package/dist/spa/src/router/index.ts +70 -0
- package/dist/spa/src/spa_types/core.ts +51 -0
- package/dist/spa/src/stores/core.ts +228 -0
- package/dist/spa/src/stores/filters.ts +27 -0
- package/dist/spa/src/stores/modal.ts +48 -0
- package/dist/spa/src/stores/toast.ts +30 -0
- package/dist/spa/src/stores/user.ts +79 -0
- package/dist/spa/src/types/Adapters.ts +26 -0
- package/dist/spa/src/types/Back.ts +1344 -0
- package/dist/spa/src/types/Common.ts +940 -0
- package/dist/spa/src/types/FrontendAPI.ts +189 -0
- package/dist/spa/src/utils.ts +184 -0
- package/dist/spa/src/views/CreateView.vue +167 -0
- package/dist/spa/src/views/EditView.vue +171 -0
- package/dist/spa/src/views/ListView.vue +442 -0
- package/dist/spa/src/views/LoginView.vue +199 -0
- package/dist/spa/src/views/PageNotFound.vue +20 -0
- package/dist/spa/src/views/ResourceParent.vue +50 -0
- package/dist/spa/src/views/ShowView.vue +209 -0
- package/dist/spa/src/websocket.ts +129 -0
- package/dist/spa/tailwind.config.js +19 -0
- package/dist/spa/tsconfig.app.json +14 -0
- package/dist/spa/tsconfig.json +11 -0
- package/dist/spa/tsconfig.node.json +19 -0
- package/dist/spa/vite.config.ts +52 -0
- package/package.json +1 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="rounded-default">
|
|
3
|
+
<pre>
|
|
4
|
+
</pre>
|
|
5
|
+
<form autocomplete="off" @submit.prevent>
|
|
6
|
+
<div v-if="!groups || groups.length === 0">
|
|
7
|
+
<GroupsTable
|
|
8
|
+
:source="source"
|
|
9
|
+
:group="{groupName: '', columns: editableColumns}"
|
|
10
|
+
:currentValues="currentValues"
|
|
11
|
+
:editableColumns="editableColumns"
|
|
12
|
+
:mode="mode"
|
|
13
|
+
:unmasked="unmasked"
|
|
14
|
+
:columnOptions="columnOptions"
|
|
15
|
+
:validating="validating"
|
|
16
|
+
:columnError="columnError"
|
|
17
|
+
:setCurrentValue="setCurrentValue"
|
|
18
|
+
@update:customComponentsInValidity="(data) => customComponentsInValidity.value = { ...customComponentsInValidity.value, ...data }"
|
|
19
|
+
@update:customComponentsEmptiness="(data) => customComponentsEmptiness.value = { ...customComponentsEmptiness.value, ...data }"
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
22
|
+
<div v-else class="flex flex-col gap-4">
|
|
23
|
+
<template v-for="group in groupedColumns" :key="group.groupName">
|
|
24
|
+
<GroupsTable
|
|
25
|
+
:source="source"
|
|
26
|
+
:group="group"
|
|
27
|
+
:currentValues="currentValues"
|
|
28
|
+
:editableColumns="editableColumns"
|
|
29
|
+
:mode="mode"
|
|
30
|
+
:unmasked="unmasked"
|
|
31
|
+
:columnOptions="columnOptions"
|
|
32
|
+
:validating="validating"
|
|
33
|
+
:columnError="columnError"
|
|
34
|
+
:setCurrentValue="setCurrentValue"
|
|
35
|
+
@update:customComponentsInValidity="(data) => customComponentsInValidity.value = { ...customComponentsInValidity.value, ...data }"
|
|
36
|
+
@update:customComponentsEmptiness="(data) => customComponentsEmptiness.value = { ...customComponentsEmptiness.value, ...data }"
|
|
37
|
+
/>
|
|
38
|
+
</template>
|
|
39
|
+
<div v-if="otherColumns.length > 0">
|
|
40
|
+
<GroupsTable
|
|
41
|
+
:source="source"
|
|
42
|
+
:group="{groupName: $t('Other'), columns: otherColumns}"
|
|
43
|
+
:currentValues="currentValues"
|
|
44
|
+
:editableColumns="editableColumns"
|
|
45
|
+
:mode="mode"
|
|
46
|
+
:unmasked="unmasked"
|
|
47
|
+
:columnOptions="columnOptions"
|
|
48
|
+
:validating="validating"
|
|
49
|
+
:columnError="columnError"
|
|
50
|
+
:setCurrentValue="setCurrentValue"
|
|
51
|
+
@update:customComponentsInValidity="(data) => customComponentsInValidity.value = { ...customComponentsInValidity.value, ...data }"
|
|
52
|
+
@update:customComponentsEmptiness="(data) => customComponentsEmptiness.value = { ...customComponentsEmptiness.value, ...data }"
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</form>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<script setup>
|
|
62
|
+
|
|
63
|
+
import { applyRegexValidation, callAdminForthApi} from '@/utils';
|
|
64
|
+
import { computedAsync } from '@vueuse/core';
|
|
65
|
+
import { computed, onMounted, ref, watch } from 'vue';
|
|
66
|
+
import { useRouter, useRoute } from 'vue-router';
|
|
67
|
+
import { useCoreStore } from "@/stores/core";
|
|
68
|
+
import GroupsTable from '@/components/GroupsTable.vue';
|
|
69
|
+
import { useI18n } from 'vue-i18n';
|
|
70
|
+
|
|
71
|
+
const { t } = useI18n();
|
|
72
|
+
|
|
73
|
+
const coreStore = useCoreStore();
|
|
74
|
+
const router = useRouter();
|
|
75
|
+
const route = useRoute();
|
|
76
|
+
const props = defineProps({
|
|
77
|
+
resource: Object,
|
|
78
|
+
record: Object,
|
|
79
|
+
validating: Boolean,
|
|
80
|
+
source: String,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const unmasked = ref({});
|
|
84
|
+
|
|
85
|
+
const mode = computed(() => route.name === 'resource-create' ? 'create' : 'edit');
|
|
86
|
+
|
|
87
|
+
const emit = defineEmits(['update:record', 'update:isValid']);
|
|
88
|
+
|
|
89
|
+
const currentValues = ref(null);
|
|
90
|
+
const customComponentsInValidity = ref({});
|
|
91
|
+
const customComponentsEmptiness = ref({});
|
|
92
|
+
|
|
93
|
+
const columnError = (column) => {
|
|
94
|
+
const val = computed(() => {
|
|
95
|
+
if (!currentValues.value) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (customComponentsInValidity.value[column.name]) {
|
|
99
|
+
return customComponentsInValidity.value[column.name];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
column.required[mode.value] &&
|
|
104
|
+
(currentValues.value[column.name] === undefined || currentValues.value[column.name] === null || currentValues.value[column.name] === '') &&
|
|
105
|
+
// if component is custum it might tell other criteria for emptiness by emitting 'update:emptiness'
|
|
106
|
+
// components which do not emit 'update:emptiness' will have undefined value in customComponentsEmptiness
|
|
107
|
+
(customComponentsEmptiness.value[column.name] !== false)
|
|
108
|
+
|
|
109
|
+
) {
|
|
110
|
+
return t('This field is required');
|
|
111
|
+
}
|
|
112
|
+
if (column.type === 'json' && currentValues.value[column.name]) {
|
|
113
|
+
try {
|
|
114
|
+
JSON.parse(currentValues.value[column.name]);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return t('Invalid JSON');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if ( column.type === 'string' || column.type === 'text' ) {
|
|
120
|
+
if ( column.maxLength && currentValues.value[column.name]?.length > column.maxLength ) {
|
|
121
|
+
return t('This field must be shorter than {maxLength} characters', { maxLength: column.maxLength });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if ( column.minLength && currentValues.value[column.name]?.length < column.minLength ) {
|
|
125
|
+
// if column.required[mode.value] is false, then we check if the field is empty
|
|
126
|
+
let needToCheckEmpty = column.required[mode.value] || currentValues.value[column.name]?.length > 0;
|
|
127
|
+
if (!needToCheckEmpty) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return t('This field must be longer than {minLength} characters', { minLength: column.minLength });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if ( ['integer', 'decimal', 'float'].includes(column.type) ) {
|
|
134
|
+
if ( column.minValue !== undefined
|
|
135
|
+
&& currentValues.value[column.name] !== null
|
|
136
|
+
&& currentValues.value[column.name] < column.minValue
|
|
137
|
+
) {
|
|
138
|
+
return t('This field must be greater than {minValue}', { minValue: column.minValue });
|
|
139
|
+
}
|
|
140
|
+
if ( column.maxValue !== undefined && currentValues.value[column.name] > column.maxValue ) {
|
|
141
|
+
return t('This field must be less than {maxValue}', { maxValue: column.maxValue });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (currentValues.value[column.name] && column.validation) {
|
|
145
|
+
const error = applyRegexValidation(currentValues.value[column.name], column.validation);
|
|
146
|
+
if (error) {
|
|
147
|
+
return error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return null;
|
|
152
|
+
});
|
|
153
|
+
return val.value;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
const setCurrentValue = (key, value) => {
|
|
158
|
+
const col = props.resource.columns.find((column) => column.name === key);
|
|
159
|
+
if (['integer', 'float'].includes(col.type) && (value || value === 0)) {
|
|
160
|
+
currentValues.value[key] = +value;
|
|
161
|
+
} else {
|
|
162
|
+
currentValues.value[key] = value;
|
|
163
|
+
}
|
|
164
|
+
if (['text', 'richtext', 'string'].includes(col.type) && col.enforceLowerCase) {
|
|
165
|
+
currentValues.value[key] = currentValues.value[key].toLowerCase();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
currentValues.value = { ...currentValues.value };
|
|
169
|
+
|
|
170
|
+
//json fields should transform to object
|
|
171
|
+
const up = {...currentValues.value};
|
|
172
|
+
props.resource.columns.forEach((column) => {
|
|
173
|
+
if (column.type === 'json' && up[column.name]) {
|
|
174
|
+
try {
|
|
175
|
+
up[column.name] = JSON.parse(up[column.name]);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
// do nothing
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
emit('update:record', up);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
onMounted(() => {
|
|
185
|
+
currentValues.value = Object.assign({}, props.record);
|
|
186
|
+
// json values should transform to string
|
|
187
|
+
props.resource.columns.forEach((column) => {
|
|
188
|
+
if (column.type === 'json' && currentValues.value[column.name]) {
|
|
189
|
+
currentValues.value[column.name] = JSON.stringify(currentValues.value[column.name], null, 2);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
emit('update:isValid', isValid.value);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const columnOptions = computedAsync(async () => {
|
|
196
|
+
return (await Promise.all(
|
|
197
|
+
Object.values(props.resource.columns).map(async (column) => {
|
|
198
|
+
if (column.foreignResource) {
|
|
199
|
+
const list = await callAdminForthApi({
|
|
200
|
+
method: 'POST',
|
|
201
|
+
path: `/get_resource_foreign_data`,
|
|
202
|
+
body: {
|
|
203
|
+
resourceId: router.currentRoute.value.params.resourceId,
|
|
204
|
+
column: column.name,
|
|
205
|
+
limit: 1000,
|
|
206
|
+
offset: 0,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
return { [column.name]: list.items };
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
)).reduce((acc, val) => Object.assign(acc, val), {})
|
|
213
|
+
|
|
214
|
+
}, {});
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
const editableColumns = computed(() => {
|
|
218
|
+
return props.resource?.columns?.filter(column => column.showIn.includes(mode.value));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const isValid = computed(() => {
|
|
222
|
+
return editableColumns.value?.every(column => !columnError(column));
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
const groups = computed(() => {
|
|
227
|
+
let fieldGroupType;
|
|
228
|
+
if (mode.value === 'edit' && coreStore.resource.options?.editFieldGroups !== undefined) {
|
|
229
|
+
fieldGroupType = coreStore.resource.options.editFieldGroups;
|
|
230
|
+
} else if (mode.value === 'create' && coreStore.resource.options?.createFieldGroups !== undefined) {
|
|
231
|
+
fieldGroupType = coreStore.resource.options.createFieldGroups;
|
|
232
|
+
} else {
|
|
233
|
+
fieldGroupType = coreStore.resource.options?.fieldGroups;
|
|
234
|
+
}
|
|
235
|
+
return fieldGroupType ?? [];
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const groupedColumns = computed(() => {
|
|
239
|
+
if (!groups.value || groups.value.length === 0) return [];
|
|
240
|
+
|
|
241
|
+
return groups.value.map(group => ({
|
|
242
|
+
...group,
|
|
243
|
+
columns: props.resource.columns.filter(col => group.columns.includes(col.name) && editableColumns.value.includes(col))
|
|
244
|
+
}));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const getOtherColumns = () => {
|
|
248
|
+
if (!groups.value || groups.value.length === 0) return;
|
|
249
|
+
|
|
250
|
+
const groupedColumnNames = new Set(groupedColumns.value.flatMap(group => group.columns.map(col => col.name)));
|
|
251
|
+
return editableColumns.value.filter(col => !groupedColumnNames.has(col.name));
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const otherColumns = getOtherColumns();
|
|
255
|
+
|
|
256
|
+
watch(() => isValid.value, (value) => {
|
|
257
|
+
emit('update:isValid', value);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
</script>
|