adminforth 1.1.18 → 1.1.20
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 +33 -1
- package/dist/modules/codeInjector.js +1 -1
- package/dist/spa/spa/src/components/ResourceListTable.vue +4 -2
- package/index.ts +37 -1
- package/modules/codeInjector.ts +1 -1
- package/package.json +1 -1
- package/spa/src/components/ResourceListTable.vue +4 -2
- package/types/AdminForthConfig.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -568,13 +568,45 @@ class AdminForth {
|
|
|
568
568
|
[this.config.auth.usernameField]: username,
|
|
569
569
|
[this.config.auth.userFullNameField]: userFullName
|
|
570
570
|
};
|
|
571
|
+
const checkIsMenuItemVisible = (menuItem) => {
|
|
572
|
+
if (typeof menuItem.visible === 'function') {
|
|
573
|
+
const toReturn = menuItem.visible(adminUser);
|
|
574
|
+
if (typeof toReturn !== 'boolean') {
|
|
575
|
+
throw new Error(`'visible' function of ${menuItem.label || menuItem.type} must return boolean value`);
|
|
576
|
+
}
|
|
577
|
+
return toReturn;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
let newMenu = [];
|
|
581
|
+
for (let menuItem of this.config.menu) {
|
|
582
|
+
let newMenuItem = Object.assign({}, menuItem);
|
|
583
|
+
if (menuItem.visible) {
|
|
584
|
+
if (!checkIsMenuItemVisible(menuItem)) {
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (menuItem.children) {
|
|
589
|
+
let newChildren = [];
|
|
590
|
+
for (let child of menuItem.children) {
|
|
591
|
+
let newChild = Object.assign({}, child);
|
|
592
|
+
if (child.visible) {
|
|
593
|
+
if (!checkIsMenuItemVisible(child)) {
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
newChildren.push(newChild);
|
|
598
|
+
}
|
|
599
|
+
newMenuItem = Object.assign(Object.assign({}, newMenuItem), { children: newChildren });
|
|
600
|
+
}
|
|
601
|
+
newMenu.push(newMenuItem);
|
|
602
|
+
}
|
|
571
603
|
return {
|
|
572
604
|
user: userData,
|
|
573
605
|
resources: this.config.resources.map((res) => ({
|
|
574
606
|
resourceId: res.resourceId,
|
|
575
607
|
label: res.label,
|
|
576
608
|
})),
|
|
577
|
-
menu:
|
|
609
|
+
menu: newMenu,
|
|
578
610
|
config: {
|
|
579
611
|
brandName: this.config.customization.brandName,
|
|
580
612
|
brandLogo: this.config.customization.brandLogo,
|
|
@@ -140,7 +140,7 @@ class CodeInjector {
|
|
|
140
140
|
routes += `{
|
|
141
141
|
path: '${item.path}',
|
|
142
142
|
name: '${item.path}',
|
|
143
|
-
component: () => import('${item.component}'),
|
|
143
|
+
component: () => import('${item.component}'),
|
|
144
144
|
meta: { title: '${(_d = item === null || item === void 0 ? void 0 : item.meta) === null || _d === void 0 ? void 0 : _d.title}'
|
|
145
145
|
},\n`;
|
|
146
146
|
}
|
|
@@ -358,9 +358,11 @@ async function selectAll(value) {
|
|
|
358
358
|
const totalPages = computed(() => Math.ceil(props.totalRows / props.pageSize));
|
|
359
359
|
|
|
360
360
|
|
|
361
|
+
|
|
362
|
+
|
|
361
363
|
const allFromThisPageChecked = computed(() => {
|
|
362
|
-
if (!props.rows
|
|
363
|
-
return props.rows.
|
|
364
|
+
if (!props.rows) return false;
|
|
365
|
+
return props.rows.every((r) => props.checkboxes.includes(r.id));
|
|
364
366
|
});
|
|
365
367
|
const ascArr = computed(() => sort.value.filter((s) => s.direction === 'asc').map((s) => s.field));
|
|
366
368
|
const descArr = computed(() => sort.value.filter((s) => s.direction === 'desc').map((s) => s.field));
|
package/index.ts
CHANGED
|
@@ -648,13 +648,49 @@ class AdminForth implements AdminForthClass {
|
|
|
648
648
|
[this.config.auth.usernameField]: username,
|
|
649
649
|
[this.config.auth.userFullNameField]: userFullName
|
|
650
650
|
};
|
|
651
|
+
const checkIsMenuItemVisible = (menuItem) => {
|
|
652
|
+
if (typeof menuItem.visible === 'function') {
|
|
653
|
+
const toReturn = menuItem.visible( adminUser );
|
|
654
|
+
if (typeof toReturn !== 'boolean') {
|
|
655
|
+
throw new Error(`'visible' function of ${menuItem.label || menuItem.type } must return boolean value`);
|
|
656
|
+
}
|
|
657
|
+
return toReturn;
|
|
658
|
+
}}
|
|
659
|
+
let newMenu = []
|
|
660
|
+
for (let menuItem of this.config.menu) {
|
|
661
|
+
let newMenuItem = {...menuItem,}
|
|
662
|
+
if (menuItem.visible){
|
|
663
|
+
if (!checkIsMenuItemVisible(menuItem)){
|
|
664
|
+
continue
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (menuItem.children){
|
|
668
|
+
let newChildren = []
|
|
669
|
+
for (let child of menuItem.children){
|
|
670
|
+
let newChild = {...child,}
|
|
671
|
+
if (child.visible){
|
|
672
|
+
if (!checkIsMenuItemVisible(child)){
|
|
673
|
+
continue
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
newChildren.push(newChild)
|
|
677
|
+
}
|
|
678
|
+
newMenuItem = {...newMenuItem, children: newChildren}
|
|
679
|
+
}
|
|
680
|
+
newMenu.push(newMenuItem)
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
651
687
|
return {
|
|
652
688
|
user: userData,
|
|
653
689
|
resources: this.config.resources.map((res) => ({
|
|
654
690
|
resourceId: res.resourceId,
|
|
655
691
|
label: res.label,
|
|
656
692
|
})),
|
|
657
|
-
menu:
|
|
693
|
+
menu: newMenu,
|
|
658
694
|
config: {
|
|
659
695
|
brandName: this.config.customization.brandName,
|
|
660
696
|
brandLogo: this.config.customization.brandLogo,
|
package/modules/codeInjector.ts
CHANGED
|
@@ -149,7 +149,7 @@ class CodeInjector implements CodeInjectorType {
|
|
|
149
149
|
routes += `{
|
|
150
150
|
path: '${item.path}',
|
|
151
151
|
name: '${item.path}',
|
|
152
|
-
component: () => import('${item.component}'),
|
|
152
|
+
component: () => import('${item.component}'),
|
|
153
153
|
meta: { title: '${item?.meta?.title}'
|
|
154
154
|
},\n`
|
|
155
155
|
|
package/package.json
CHANGED
|
@@ -358,9 +358,11 @@ async function selectAll(value) {
|
|
|
358
358
|
const totalPages = computed(() => Math.ceil(props.totalRows / props.pageSize));
|
|
359
359
|
|
|
360
360
|
|
|
361
|
+
|
|
362
|
+
|
|
361
363
|
const allFromThisPageChecked = computed(() => {
|
|
362
|
-
if (!props.rows
|
|
363
|
-
return props.rows.
|
|
364
|
+
if (!props.rows) return false;
|
|
365
|
+
return props.rows.every((r) => props.checkboxes.includes(r.id));
|
|
364
366
|
});
|
|
365
367
|
const ascArr = computed(() => sort.value.filter((s) => s.direction === 'asc').map((s) => s.field));
|
|
366
368
|
const descArr = computed(() => sort.value.filter((s) => s.direction === 'desc').map((s) => s.field));
|
|
@@ -283,6 +283,12 @@ export type AdminForthConfigMenuItem = {
|
|
|
283
283
|
meta?: {
|
|
284
284
|
title?: string,
|
|
285
285
|
},
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Optional callback which will be called before rendering the menu for each item.
|
|
289
|
+
* You can use it to hide menu items depending on some user
|
|
290
|
+
*/
|
|
291
|
+
visible?: (user: AdminUser) => boolean,
|
|
286
292
|
}
|
|
287
293
|
|
|
288
294
|
|