Browse Source
Merge pull request #4813 from abpframework/feat/4812
Added getFeature method to ConfigStateService
pull/4823/head
Levent Arman Özak
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
34 additions and
1 deletions
docs/en/UI/Angular/Config-State.md
npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
npm/ng-packs/packages/core/src/lib/states/config.state.ts
npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts
@ -127,6 +127,17 @@ const defaultLang = this.config.getSetting("Abp.Localization.DefaultLanguage");
// 'en'
```
### How to Get a Specific Feature From the Store
You can use the `getFeature` method of `ConfigStateService` to get a specific feature from the configuration state. Here is an example:
```js
// this.config is instance of ConfigStateService
const isChatEnabled = this.config.getFeature("Chat.Enable");
// 'en'
```
### How to Get a Specific Permission From the Store
You can use the `getGrantedPolicy` method of `ConfigStateService` to get a specific permission from the configuration state. For that, you should pass a policy key as parameter to the method.
@ -29,6 +29,10 @@ export class ConfigStateService {
return this . store . selectSnapshot ( ConfigState . getApiUrl ( . . . args ) ) ;
}
getFeature ( . . . args : Parameters < typeof ConfigState.getFeature > ) {
return this . store . selectSnapshot ( ConfigState . getFeature ( . . . args ) ) ;
}
getSetting ( . . . args : Parameters < typeof ConfigState.getSetting > ) {
return this . store . selectSnapshot ( ConfigState . getSetting ( . . . args ) ) ;
}
@ -65,6 +65,14 @@ export class ConfigState {
return selector ;
}
static getFeature ( key : string ) {
const selector = createSelector ( [ ConfigState ] , ( state : Config.State ) = > {
return snq ( ( ) = > state . features . values [ key ] ) ;
} ) ;
return selector ;
}
static getSetting ( key : string ) {
const selector = createSelector ( [ ConfigState ] , ( state : Config.State ) = > {
return snq ( ( ) = > state . setting . values [ key ] ) ;
@ -93,7 +93,9 @@ export const CONFIG_STATE_DATA = {
roles : [ ] ,
} ,
features : {
values : { } ,
values : {
'Chat.Enable' : 'True' ,
} ,
} ,
} as Config . State ;
@ -163,6 +165,14 @@ describe('ConfigState', () => {
} ) ;
} ) ;
describe ( '#getFeature' , ( ) = > {
it ( 'should return a setting' , ( ) = > {
expect ( ConfigState . getFeature ( 'Chat.Enable' ) ( CONFIG_STATE_DATA ) ) . toEqual (
CONFIG_STATE_DATA . features . values [ 'Chat.Enable' ] ,
) ;
} ) ;
} ) ;
describe ( '#getSetting' , ( ) = > {
it ( 'should return a setting' , ( ) = > {
expect ( ConfigState . getSetting ( 'Abp.Localization.DefaultLanguage' ) ( CONFIG_STATE_DATA ) ) . toEqual (