From 21e3d9aac5864e1336b6b9f1fcf51f4f4c412173 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Wed, 17 Jun 2020 19:24:59 +0300 Subject: [PATCH] feat: add route provider to setting management config --- .../config/src/providers/index.ts | 1 + .../config/src/providers/route.provider.ts | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 npm/ng-packs/packages/setting-management/config/src/providers/index.ts create mode 100644 npm/ng-packs/packages/setting-management/config/src/providers/route.provider.ts diff --git a/npm/ng-packs/packages/setting-management/config/src/providers/index.ts b/npm/ng-packs/packages/setting-management/config/src/providers/index.ts new file mode 100644 index 0000000000..fe08efba8c --- /dev/null +++ b/npm/ng-packs/packages/setting-management/config/src/providers/index.ts @@ -0,0 +1 @@ +export * from './route.provider'; diff --git a/npm/ng-packs/packages/setting-management/config/src/providers/route.provider.ts b/npm/ng-packs/packages/setting-management/config/src/providers/route.provider.ts new file mode 100644 index 0000000000..3ed75d33b0 --- /dev/null +++ b/npm/ng-packs/packages/setting-management/config/src/providers/route.provider.ts @@ -0,0 +1,42 @@ +import { eLayoutType, RoutesService, SettingTabsService } from '@abp/ng.core'; +import { eThemeSharedRouteNames } from '@abp/ng.theme.shared'; +import { APP_INITIALIZER } from '@angular/core'; +import { debounceTime, map } from 'rxjs/operators'; +import { eSettingManagementRouteNames } from '../enums/route-names'; + +export const SETTING_MANAGEMENT_ROUTE_PROVIDERS = [ + { provide: APP_INITIALIZER, useFactory: configureRoutes, deps: [RoutesService], multi: true }, + { + provide: APP_INITIALIZER, + useFactory: hideRoutes, + deps: [RoutesService, SettingTabsService], + multi: true, + }, +]; + +export function configureRoutes(routes: RoutesService) { + return () => { + routes.add([ + { + name: eSettingManagementRouteNames.Settings, + path: '/setting-management', + parentName: eThemeSharedRouteNames.Administration, + requiredPolicy: 'AbpAccount.SettingManagement', + layout: eLayoutType.application, + order: 6, + iconClass: 'fa fa-cog', + }, + ]); + }; +} + +export function hideRoutes(routes: RoutesService, tabs: SettingTabsService) { + return () => { + tabs.visible$ + .pipe( + debounceTime(0), + map(nodes => !nodes.length), + ) + .subscribe(invisible => routes.patch('AbpSettingManagement::Settings', { invisible })); + }; +}