mirror of https://github.com/abpframework/abp.git
committed by
GitHub
5 changed files with 103 additions and 26 deletions
@ -0,0 +1,39 @@ |
|||
import { ConfigStateService, featuresFactory, noop } from '@abp/ng.core'; |
|||
import { APP_INITIALIZER, inject, InjectionToken } from '@angular/core'; |
|||
import { Observable } from 'rxjs'; |
|||
import { map } from 'rxjs/operators'; |
|||
|
|||
export const SETTING_MANAGEMENT_FEATURES = new InjectionToken<Observable<{ enable: boolean }>>( |
|||
'SETTING_MANAGEMENT_FEATURES', |
|||
{ |
|||
providedIn: 'root', |
|||
factory: () => { |
|||
const configState = inject(ConfigStateService); |
|||
const featureKey = 'SettingManagement.Enable'; |
|||
const mapFn = features => ({ |
|||
enable: features[featureKey].toLowerCase() !== 'false', |
|||
}); |
|||
return featuresFactory(configState, [featureKey], mapFn); |
|||
}, |
|||
}, |
|||
); |
|||
|
|||
export const SETTING_MANAGEMENT_ROUTE_VISIBILITY = new InjectionToken<Observable<boolean>>( |
|||
'SETTING_MANAGEMENT_ROUTE_VISIBILITY', |
|||
{ |
|||
providedIn: 'root', |
|||
factory: () => { |
|||
const stream = inject(SETTING_MANAGEMENT_FEATURES); |
|||
return stream.pipe(map(features => features.enable)); |
|||
}, |
|||
}, |
|||
); |
|||
|
|||
export const SETTING_MANAGEMENT_FEATURES_PROVIDERS = [ |
|||
{ |
|||
provide: APP_INITIALIZER, |
|||
useFactory: noop, |
|||
deps: [SETTING_MANAGEMENT_ROUTE_VISIBILITY], |
|||
multi: true, |
|||
}, |
|||
]; |
|||
@ -1,2 +1,3 @@ |
|||
export * from './route.provider'; |
|||
export * from './setting-tab.provider'; |
|||
export * from './visible.provider'; |
|||
|
|||
@ -0,0 +1,30 @@ |
|||
import { APP_INITIALIZER, Injector } from '@angular/core'; |
|||
import { combineLatest } from 'rxjs'; |
|||
import { RoutesService } from '@abp/ng.core'; |
|||
import { SETTING_MANAGEMENT_HAS_SETTING } from './route.provider'; |
|||
import { SETTING_MANAGEMENT_ROUTE_VISIBILITY } from './features.token'; |
|||
import { eSettingManagementRouteNames } from '../enums'; |
|||
|
|||
export const SETTING_MANAGEMENT_VISIBLE_PROVIDERS = [ |
|||
{ |
|||
provide: APP_INITIALIZER, |
|||
useFactory: setSettingManagementVisibility, |
|||
deps: [Injector], |
|||
multi: true, |
|||
}, |
|||
]; |
|||
|
|||
export function setSettingManagementVisibility(injector: Injector) { |
|||
return () => { |
|||
const settingManagementHasSetting$ = injector.get(SETTING_MANAGEMENT_HAS_SETTING); |
|||
const isSettingManagementFeatureEnable$ = injector.get(SETTING_MANAGEMENT_ROUTE_VISIBILITY); |
|||
const routes = injector.get(RoutesService); |
|||
combineLatest([settingManagementHasSetting$, isSettingManagementFeatureEnable$]).subscribe( |
|||
([settingManagementHasSetting, isSettingManagementFeatureEnable]) => { |
|||
routes.patch(eSettingManagementRouteNames.Settings, { |
|||
invisible: !(settingManagementHasSetting && isSettingManagementFeatureEnable), |
|||
}); |
|||
}, |
|||
); |
|||
}; |
|||
} |
|||
Loading…
Reference in new issue