adminforth 1.0.38 → 1.0.40
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.js +19 -3
- package/dist/spa/spa/src/components/Dropdown.vue +4 -0
- package/dist/spa/spa/src/components/ResourceForm.vue +1 -0
- package/dist/spa/spa/src/views/EditView.vue +14 -2
- package/index.ts +20 -3
- package/package.json +1 -1
- package/spa/src/components/Dropdown.vue +4 -0
- package/spa/src/components/ResourceForm.vue +1 -0
- package/spa/src/views/EditView.vue +14 -2
package/dist/index.js
CHANGED
|
@@ -221,6 +221,20 @@ class AdminForth {
|
|
|
221
221
|
if (errors.length > 0) {
|
|
222
222
|
throw new Error(`Invalid AdminForth config: ${errors.join(', ')}`);
|
|
223
223
|
}
|
|
224
|
+
// check is all custom components files exists
|
|
225
|
+
for (const resource of this.config.resources) {
|
|
226
|
+
for (const column of resource.columns) {
|
|
227
|
+
if (column.component) {
|
|
228
|
+
for (const [key, value] of Object.entries(column.component)) {
|
|
229
|
+
// console.log(`${key}: ${value}`);
|
|
230
|
+
const path = value.replace('@@', this.config.customization.customComponentsDir);
|
|
231
|
+
if (!fs.existsSync(path)) {
|
|
232
|
+
throw new Error(`Component file ${path} does not exist`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
224
238
|
}
|
|
225
239
|
postProcessAfterDiscover(resource) {
|
|
226
240
|
resource.columns.forEach((column) => {
|
|
@@ -519,11 +533,14 @@ class AdminForth {
|
|
|
519
533
|
}
|
|
520
534
|
const resource = this.config.resources.find((res) => res.resourceId == resourceId);
|
|
521
535
|
if (!resource) {
|
|
522
|
-
return { error: `Resource ${resourceId} not found` };
|
|
536
|
+
return { error: `Resource '${resourceId}' not found` };
|
|
523
537
|
}
|
|
524
538
|
const columnConfig = resource.columns.find((col) => col.name == column);
|
|
539
|
+
if (!columnConfig) {
|
|
540
|
+
return { error: `Column "${column}' not found in resource with resourceId '${resourceId}'` };
|
|
541
|
+
}
|
|
525
542
|
if (!columnConfig.foreignResource) {
|
|
526
|
-
return { error: `Column ${column} in resource ${resourceId} is not a foreign key` };
|
|
543
|
+
return { error: `Column '${column}' in resource '${resourceId}' is not a foreign key` };
|
|
527
544
|
}
|
|
528
545
|
const targetResourceId = columnConfig.foreignResource.resourceId;
|
|
529
546
|
const targetResource = this.config.resources.find((res) => res.resourceId == targetResourceId);
|
|
@@ -672,7 +689,6 @@ class AdminForth {
|
|
|
672
689
|
path: '/update_record',
|
|
673
690
|
handler: (_7) => __awaiter(this, [_7], void 0, function* ({ body, adminUser }) {
|
|
674
691
|
var _8, _9, _10, _11, _12, _13, _14, _15;
|
|
675
|
-
console.log('update_record', body);
|
|
676
692
|
const resource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
677
693
|
if (!resource) {
|
|
678
694
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
<ResourceForm
|
|
25
25
|
v-else
|
|
26
|
-
:record="
|
|
26
|
+
:record="editableRecord"
|
|
27
27
|
:resourceColumns="coreStore.resourceColumns"
|
|
28
28
|
@update:record="onUpdateRecord"
|
|
29
29
|
@update:isValid="isValid = $event"
|
|
@@ -43,7 +43,7 @@ import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
|
|
|
43
43
|
import { useCoreStore } from '@/stores/core';
|
|
44
44
|
import { callAdminForthApi } from '@/utils';
|
|
45
45
|
import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
|
|
46
|
-
import { defineAsyncComponent, onMounted, ref } from 'vue';
|
|
46
|
+
import { defineAsyncComponent, onMounted, ref, computed } from 'vue';
|
|
47
47
|
import { useRoute, useRouter } from 'vue-router';
|
|
48
48
|
|
|
49
49
|
const coreStore = useCoreStore();
|
|
@@ -65,6 +65,18 @@ async function onUpdateRecord(newRecord) {
|
|
|
65
65
|
record.value = newRecord;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
const editableRecord = computed(() => {
|
|
69
|
+
const newRecord = { ...coreStore.record };
|
|
70
|
+
if (!coreStore.resourceColumns) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
coreStore.resourceColumns.forEach(column => {
|
|
74
|
+
if (column.foreignResource) {
|
|
75
|
+
newRecord[column.name] = newRecord[column.name]?.pk
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return newRecord;
|
|
79
|
+
})
|
|
68
80
|
|
|
69
81
|
onMounted(async () => {
|
|
70
82
|
loading.value = true;
|
package/index.ts
CHANGED
|
@@ -267,6 +267,21 @@ class AdminForth {
|
|
|
267
267
|
if (errors.length > 0) {
|
|
268
268
|
throw new Error(`Invalid AdminForth config: ${errors.join(', ')}`);
|
|
269
269
|
}
|
|
270
|
+
|
|
271
|
+
// check is all custom components files exists
|
|
272
|
+
for (const resource of this.config.resources) {
|
|
273
|
+
for (const column of resource.columns) {
|
|
274
|
+
if (column.component) {
|
|
275
|
+
for (const [key, value] of Object.entries(column.component)) {
|
|
276
|
+
// console.log(`${key}: ${value}`);
|
|
277
|
+
const path = value.replace('@@', this.config.customization.customComponentsDir);
|
|
278
|
+
if (!fs.existsSync(path)) {
|
|
279
|
+
throw new Error(`Component file ${path} does not exist`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
270
285
|
}
|
|
271
286
|
|
|
272
287
|
postProcessAfterDiscover(resource) {
|
|
@@ -588,11 +603,14 @@ class AdminForth {
|
|
|
588
603
|
}
|
|
589
604
|
const resource = this.config.resources.find((res) => res.resourceId == resourceId);
|
|
590
605
|
if (!resource) {
|
|
591
|
-
return { error: `Resource ${resourceId} not found` };
|
|
606
|
+
return { error: `Resource '${resourceId}' not found` };
|
|
592
607
|
}
|
|
593
608
|
const columnConfig = resource.columns.find((col) => col.name == column);
|
|
609
|
+
if (!columnConfig) {
|
|
610
|
+
return { error: `Column "${column}' not found in resource with resourceId '${resourceId}'` };
|
|
611
|
+
}
|
|
594
612
|
if (!columnConfig.foreignResource) {
|
|
595
|
-
return { error: `Column ${column} in resource ${resourceId} is not a foreign key` };
|
|
613
|
+
return { error: `Column '${column}' in resource '${resourceId}' is not a foreign key` };
|
|
596
614
|
}
|
|
597
615
|
const targetResourceId = columnConfig.foreignResource.resourceId;
|
|
598
616
|
const targetResource = this.config.resources.find((res) => res.resourceId == targetResourceId);
|
|
@@ -751,7 +769,6 @@ class AdminForth {
|
|
|
751
769
|
method: 'POST',
|
|
752
770
|
path: '/update_record',
|
|
753
771
|
handler: async ({ body, adminUser }) => {
|
|
754
|
-
console.log('update_record', body);
|
|
755
772
|
const resource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
756
773
|
if (!resource) {
|
|
757
774
|
return { error: `Resource '${body['resourceId']}' not found` };
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
<ResourceForm
|
|
25
25
|
v-else
|
|
26
|
-
:record="
|
|
26
|
+
:record="editableRecord"
|
|
27
27
|
:resourceColumns="coreStore.resourceColumns"
|
|
28
28
|
@update:record="onUpdateRecord"
|
|
29
29
|
@update:isValid="isValid = $event"
|
|
@@ -43,7 +43,7 @@ import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
|
|
|
43
43
|
import { useCoreStore } from '@/stores/core';
|
|
44
44
|
import { callAdminForthApi } from '@/utils';
|
|
45
45
|
import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
|
|
46
|
-
import { defineAsyncComponent, onMounted, ref } from 'vue';
|
|
46
|
+
import { defineAsyncComponent, onMounted, ref, computed } from 'vue';
|
|
47
47
|
import { useRoute, useRouter } from 'vue-router';
|
|
48
48
|
|
|
49
49
|
const coreStore = useCoreStore();
|
|
@@ -65,6 +65,18 @@ async function onUpdateRecord(newRecord) {
|
|
|
65
65
|
record.value = newRecord;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
const editableRecord = computed(() => {
|
|
69
|
+
const newRecord = { ...coreStore.record };
|
|
70
|
+
if (!coreStore.resourceColumns) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
coreStore.resourceColumns.forEach(column => {
|
|
74
|
+
if (column.foreignResource) {
|
|
75
|
+
newRecord[column.name] = newRecord[column.name]?.pk
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return newRecord;
|
|
79
|
+
})
|
|
68
80
|
|
|
69
81
|
onMounted(async () => {
|
|
70
82
|
loading.value = true;
|