Browse Source

Merge pull request #4546 from abpframework/feat/4545

Hid Menu Items When Permission Check For All Children Fail
pull/4552/head
Mehmet Erim 6 years ago
committed by GitHub
parent
commit
bac2545812
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      npm/ng-packs/packages/core/src/lib/services/routes.service.ts
  2. 10
      npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts
  3. 2
      npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.ts

5
npm/ng-packs/packages/core/src/lib/services/routes.service.ts

@ -151,6 +151,11 @@ export abstract class AbstractNavTreeService<T extends ABP.Nav> extends Abstract
return this.store.selectSnapshot(ConfigState.getGrantedPolicy(requiredPolicy));
}
hasChildren(identifier: string): boolean {
const node = this.find(item => item[this.id] === identifier);
return Boolean(node?.children?.length);
}
hasInvisibleChild(identifier: string): boolean {
const node = this.find(item => item[this.id] === identifier);
return node?.children?.some(child => child.invisible);

10
npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts

@ -68,6 +68,16 @@ describe('Routes Service', () => {
});
});
describe('#hasChildren', () => {
it('should return if node has invisible child', () => {
service.add(routes);
expect(service.hasChildren('foo')).toBe(true);
expect(service.hasChildren('bar')).toBe(true);
expect(service.hasChildren('baz')).toBe(false);
});
});
describe('#hasInvisibleChild', () => {
it('should return if node has invisible child', () => {
service.add(routes);

2
npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.ts

@ -13,6 +13,6 @@ export class RoutesComponent {
constructor(public readonly routes: RoutesService) {}
isDropdown(node: TreeNode<ABP.Route>) {
return !node.isLeaf || this.routes.hasInvisibleChild(node.name);
return !node.isLeaf || this.routes.hasChildren(node.name);
}
}

Loading…
Cancel
Save