From a3f461ee3858965c36451840e68f3307d19cbf40 Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Fri, 4 Oct 2024 17:05:31 +0300 Subject: [PATCH] update: add feature enable check functions for the config state service --- .../src/lib/services/config-state.service.ts | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts index 97fcdbc40b..5a5f244d43 100644 --- a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts @@ -5,6 +5,7 @@ import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-co import { AbpApplicationLocalizationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-localization.service'; import { ApplicationConfigurationDto, + ApplicationFeatureConfigurationDto, ApplicationGlobalFeatureConfigurationDto, } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models'; import { INCUDE_LOCALIZATION_RESOURCES_TOKEN } from '../tokens/include-localization-resources.token'; @@ -71,10 +72,10 @@ export class ConfigStateService { } refreshLocalization(lang: string): Observable { - if(this.includeLocalizationResources){ + if (this.includeLocalizationResources) { return this.refreshAppState().pipe(map(() => null)); } - + return this.getlocalizationResource(lang) .pipe( tap(result => @@ -145,7 +146,7 @@ export class ConfigStateService { return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {}); } - getFeatures$(keys: string[]): Observable<{ [key: string]: string; } | undefined> { + getFeatures$(keys: string[]): Observable<{ [key: string]: string } | undefined> { return this.store.sliceState(({ features }) => { if (!features?.values) return; @@ -153,6 +154,18 @@ export class ConfigStateService { }); } + private isFeatureEnabled(key: string, features: ApplicationFeatureConfigurationDto) { + return features.values[key] === 'true'; + } + + getFeatureIsEnabled(key: string) { + return this.isFeatureEnabled(key, this.store.state.features); + } + + getFeatureIsEnabled$(key: string) { + return this.store.sliceState(state => this.isFeatureEnabled(key, state.features)); + } + getSetting(key: string) { return this.store.state.setting?.values?.[key]; } @@ -168,10 +181,13 @@ export class ConfigStateService { const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1); - return keysFound.reduce((acc, key) => { - acc[key] = settings[key]; - return acc; - }, {} as Record); + return keysFound.reduce( + (acc, key) => { + acc[key] = settings[key]; + return acc; + }, + {} as Record, + ); } getSettings$(keyword?: string) { @@ -183,10 +199,13 @@ export class ConfigStateService { const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1); - return keysFound.reduce((acc, key) => { - acc[key] = settings[key]; - return acc; - }, {} as Record); + return keysFound.reduce( + (acc, key) => { + acc[key] = settings[key]; + return acc; + }, + {} as Record, + ); }), ); }