Browse Source

feat: add hasChildren method to RoutesService

pull/4546/head
Arman Ozak 6 years ago
parent
commit
58b2cae823
  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

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)); 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 { hasInvisibleChild(identifier: string): boolean {
const node = this.find(item => item[this.id] === identifier); const node = this.find(item => item[this.id] === identifier);
return node?.children?.some(child => child.invisible); 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', () => { describe('#hasInvisibleChild', () => {
it('should return if node has invisible child', () => { it('should return if node has invisible child', () => {
service.add(routes); service.add(routes);

Loading…
Cancel
Save