Browse Source

Implement PR comments #12660

pull/12660/head
Mahmut Gundogdu 4 years ago
parent
commit
aab71394a6
  1. 2
      docs/en/UI/Angular/Config-State-Service.md
  2. 40
      docs/en/UI/Angular/GlobalFeatures.md
  3. 19
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

2
docs/en/UI/Angular/Config-State-Service.md

@ -13,7 +13,7 @@ import { ConfigStateService } from '@abp/ng.core';
/* class metadata here */
})
class DemoComponent {
constructor(private config: \) {}
constructor(private config: ConfigStateService) {}
}
```

40
docs/en/UI/Angular/GlobalFeatures.md

@ -9,35 +9,39 @@
````js
import { ConfigStateService } from '@abp/ng.core';
import { Component, OnInit } from '@angular/core';
@Component({
/* class metadata here */
})
class DemoComponent {
class DemoComponent implements OnInit {
constructor(private config: ConfigStateService) {}
}
ngOnInit(): void {
// Gets all enabled global features.
const getGlobalFeatures = this.config.getGlobalFeatures();
// Gets all enabled global features.
const getGlobalFeatures = this.config.getGlobalFeatures ();
//Example result is: `{ enabledFeatures: [ 'Shopping.Payment', 'Ecommerce.Subscription' ] }`
// { enabledFeatures: [ 'Shopping.Payment', 'Ecommerce.Subscription' ] }
// or
this.config.getGlobalFeatures$().subscribe(getGlobalFeatures => {
// use getGlobalFeatures here
})
// or
this.config.getGlobalFeatures$().subscribe(getGlobalFeatures => {
// use getGlobalFeatures here
})
// Check the global feature is enabled
this.config.getGlobalFeatureIsEnabled('Ecommerce.Subscription')
// Check the global feature is enabled
this.config.getGlobalFeatureIsEnabled('Ecommerce.Subscription')
//Example result is `true`
true
this.config.getGlobalFeatureIsEnabled('My.Subscription')
> this.config.getGlobalFeatureIsEnabled('My.Subscription')
//Example result is `false`
false
// or
this.config.getGlobalFeatureIsEnabled$('Ecommerce.Subscription').subscribe((isEnabled:boolean) => {
// use isEnabled here
})
}
}
// or
this.config.getGlobalFeatureIsEnabled$('Ecommerce.Subscription').subscribe((isEnabled:boolean) => {
// use isEnabled here
})

19
npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

@ -147,22 +147,21 @@ export class ConfigStateService {
return this.store.sliceState(state => state.globalFeatures);
}
getGlobalFeatureIsEnabled(key: string) {
const globalFeatures = this.store.state.globalFeatures;
if (!(globalFeatures?.enabledFeatures)) { return false };
private isGlobalFeatureEnabled(key: string, globalFeatures: ApplicationGlobalFeatureConfigurationDto) {
const features = globalFeatures.enabledFeatures || []
return features.some(f => key === f);
}
return globalFeatures.enabledFeatures.indexOf(key) != -1;
getGlobalFeatureIsEnabled(key: string) {
return this.isGlobalFeatureEnabled(key, this.store.state.globalFeatures);
}
getGlobalFeatureIsEnabled$(key: string) {
return this.store.sliceState(state => {
debugger
if (!(state.globalFeatures?.enabledFeatures)) { return false };
return state.globalFeatures.enabledFeatures.indexOf(key) != -1 || true;
});
return this.store.sliceState(state => this.isGlobalFeatureEnabled(key, state.globalFeatures));
}
}
function splitKeys(keys: string[] | string): string[] {

Loading…
Cancel
Save