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 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` };
@@ -97,6 +97,10 @@ onMounted(() => {
97
97
  updateFromProps();
98
98
  });
99
99
 
100
+ watch(() => props.options, () => {
101
+ updateFromProps();
102
+ });
103
+
100
104
  addClickListener();
101
105
 
102
106
  });
@@ -44,6 +44,7 @@
44
44
  </div>
45
45
  </td>
46
46
  <td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap relative">
47
+
47
48
  <Dropdown
48
49
  single
49
50
  v-if="column.foreignResource"
@@ -23,7 +23,7 @@
23
23
 
24
24
  <ResourceForm
25
25
  v-else
26
- :record="coreStore.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -97,6 +97,10 @@ onMounted(() => {
97
97
  updateFromProps();
98
98
  });
99
99
 
100
+ watch(() => props.options, () => {
101
+ updateFromProps();
102
+ });
103
+
100
104
  addClickListener();
101
105
 
102
106
  });
@@ -44,6 +44,7 @@
44
44
  </div>
45
45
  </td>
46
46
  <td class="px-6 py-4 whitespace-nowrap whitespace-pre-wrap relative">
47
+
47
48
  <Dropdown
48
49
  single
49
50
  v-if="column.foreignResource"
@@ -23,7 +23,7 @@
23
23
 
24
24
  <ResourceForm
25
25
  v-else
26
- :record="coreStore.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;