adminforth 1.0.44 → 1.0.45
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 +11 -2
- package/dist/spa/spa/src/components/MenuLink.vue +1 -1
- package/index.ts +12 -2
- package/package.json +1 -1
- package/spa/src/components/MenuLink.vue +1 -1
package/dist/index.js
CHANGED
|
@@ -88,6 +88,12 @@ class AdminForth {
|
|
|
88
88
|
if (res.itemLabel && typeof res.itemLabel !== 'function') {
|
|
89
89
|
errors.push(`Resource "${res.dataSource}" itemLabel is not a function`);
|
|
90
90
|
}
|
|
91
|
+
if (!res.itemLabel) {
|
|
92
|
+
res.itemLabel = (item) => {
|
|
93
|
+
const pkVal = item[res.columns.find((col) => col.primaryKey).name];
|
|
94
|
+
return `${res.label} ${pkVal}`;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
91
97
|
res.resourceId = res.resourceId || res.table;
|
|
92
98
|
res.label = res.label || res.table.charAt(0).toUpperCase() + res.table.slice(1);
|
|
93
99
|
if (!res.dataSource) {
|
|
@@ -519,7 +525,7 @@ class AdminForth {
|
|
|
519
525
|
});
|
|
520
526
|
const targetDataMap = targetData.data.reduce((acc, item) => {
|
|
521
527
|
acc[item[targetResourcePkField]] = {
|
|
522
|
-
label: targetResource.itemLabel
|
|
528
|
+
label: targetResource.itemLabel(item),
|
|
523
529
|
pk: item[targetResourcePkField],
|
|
524
530
|
};
|
|
525
531
|
return acc;
|
|
@@ -528,6 +534,9 @@ class AdminForth {
|
|
|
528
534
|
item[col.name] = targetDataMap[item[col.name]];
|
|
529
535
|
});
|
|
530
536
|
})));
|
|
537
|
+
data.data.forEach((item) => {
|
|
538
|
+
item._label = resource.itemLabel(item);
|
|
539
|
+
});
|
|
531
540
|
if ((_o = (_m = resource.hooks) === null || _m === void 0 ? void 0 : _m[source]) === null || _o === void 0 ? void 0 : _o.afterDatasourceRequest) {
|
|
532
541
|
const resp = yield ((_q = (_p = resource.hooks) === null || _p === void 0 ? void 0 : _p[source]) === null || _q === void 0 ? void 0 : _q.afterDatasourceRequest({ resource, response: data.data, adminUser }));
|
|
533
542
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
@@ -584,7 +593,7 @@ class AdminForth {
|
|
|
584
593
|
});
|
|
585
594
|
const items = dbDataItems.data.map((item) => {
|
|
586
595
|
const pk = item[targetResource.columns.find((col) => col.primaryKey).name];
|
|
587
|
-
const labler = targetResource.itemLabel
|
|
596
|
+
const labler = targetResource.itemLabel;
|
|
588
597
|
return {
|
|
589
598
|
value: pk,
|
|
590
599
|
label: labler(item),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<RouterLink
|
|
3
3
|
:to="{name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {}}"
|
|
4
|
-
class="flex items-center py-2 text-
|
|
4
|
+
class="flex items-center py-2 text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem"
|
|
5
5
|
:class="{
|
|
6
6
|
'px-4': isChild,
|
|
7
7
|
'px-2': !isChild,
|
package/index.ts
CHANGED
|
@@ -110,6 +110,12 @@ class AdminForth {
|
|
|
110
110
|
if (res.itemLabel && typeof res.itemLabel !== 'function') {
|
|
111
111
|
errors.push(`Resource "${res.dataSource}" itemLabel is not a function`);
|
|
112
112
|
}
|
|
113
|
+
if (!res.itemLabel) {
|
|
114
|
+
res.itemLabel = (item) => {
|
|
115
|
+
const pkVal = item[res.columns.find((col) => col.primaryKey).name];
|
|
116
|
+
return `${res.label} ${pkVal}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
113
119
|
|
|
114
120
|
|
|
115
121
|
res.resourceId = res.resourceId || res.table;
|
|
@@ -589,7 +595,7 @@ class AdminForth {
|
|
|
589
595
|
});
|
|
590
596
|
const targetDataMap = targetData.data.reduce((acc, item) => {
|
|
591
597
|
acc[item[targetResourcePkField]] = {
|
|
592
|
-
label: targetResource.itemLabel
|
|
598
|
+
label: targetResource.itemLabel(item),
|
|
593
599
|
pk: item[targetResourcePkField],
|
|
594
600
|
}
|
|
595
601
|
return acc;
|
|
@@ -600,6 +606,10 @@ class AdminForth {
|
|
|
600
606
|
})
|
|
601
607
|
);
|
|
602
608
|
|
|
609
|
+
data.data.forEach((item) => {
|
|
610
|
+
item._label = resource.itemLabel(item)
|
|
611
|
+
})
|
|
612
|
+
|
|
603
613
|
|
|
604
614
|
if (resource.hooks?.[source]?.afterDatasourceRequest) {
|
|
605
615
|
const resp = await resource.hooks?.[source]?.afterDatasourceRequest({ resource, response: data.data, adminUser });
|
|
@@ -659,7 +669,7 @@ class AdminForth {
|
|
|
659
669
|
});
|
|
660
670
|
const items = dbDataItems.data.map((item) => {
|
|
661
671
|
const pk = item[targetResource.columns.find((col) => col.primaryKey).name];
|
|
662
|
-
const labler = targetResource.itemLabel
|
|
672
|
+
const labler = targetResource.itemLabel;
|
|
663
673
|
return {
|
|
664
674
|
value: pk,
|
|
665
675
|
label: labler(item),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<RouterLink
|
|
3
3
|
:to="{name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {}}"
|
|
4
|
-
class="flex items-center py-2 text-
|
|
4
|
+
class="flex items-center py-2 text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem"
|
|
5
5
|
:class="{
|
|
6
6
|
'px-4': isChild,
|
|
7
7
|
'px-2': !isChild,
|