Browse Source

Merge pull request #12660 from abpframework/issue-12546

Global features Angular Api added
pull/12738/head
Mahmut Gundogdu 4 years ago
committed by GitHub
parent
commit
762a5a7eda
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      docs/en/UI/Angular/GlobalFeatures.md
  2. 4
      docs/en/docs-nav.json
  3. 4
      npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts
  4. 21491
      npm/ng-packs/packages/core/src/lib/proxy/generate-proxy.json
  5. 32
      npm/ng-packs/packages/core/src/lib/proxy/pages/abp/multi-tenancy/abp-tenant.service.ts
  6. 21
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/api-exploring/abp-api-definition.service.ts
  7. 19
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service.ts
  8. 15
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/application-configurations/models.ts
  9. 1
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/application-configurations/object-extending/models.ts
  10. 1
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/multi-tenancy/models.ts
  11. 11
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/http/modeling/models.ts
  12. 1
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/localization/models.ts
  13. 1
      npm/ng-packs/packages/core/src/lib/proxy/volo/abp/models.ts
  14. 24
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
  15. 6
      npm/ng-packs/packages/core/src/lib/services/multi-tenancy.service.ts

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

@ -0,0 +1,47 @@
# Angular: Global Features API
The `ConfigStateService.getGlobalFeatures` API allows you to get the enabled features of the [Global Features](../../Global-Features.md) on the client side.
> This document only explains the JavaScript API. See the [Global Features](../../Global-Features.md) document to understand the ABP Global Features system.
## Usage
````js
import { ConfigStateService } from '@abp/ng.core';
import { Component, OnInit } from '@angular/core';
@Component({
/* class metadata here */
})
class DemoComponent implements OnInit {
constructor(private config: ConfigStateService) {}
ngOnInit(): void {
// Gets all enabled global features.
const getGlobalFeatures = this.config.getGlobalFeatures();
//Example result is: `{ enabledFeatures: [ 'Shopping.Payment', 'Ecommerce.Subscription' ] }`
// or
this.config.getGlobalFeatures$().subscribe(getGlobalFeatures => {
// use getGlobalFeatures here
})
// Check the global feature is enabled
this.config.getGlobalFeatureIsEnabled('Ecommerce.Subscription')
//Example result is `true`
this.config.getGlobalFeatureIsEnabled('My.Subscription')
//Example result is `false`
// or
this.config.getGlobalFeatureIsEnabled$('Ecommerce.Subscription').subscribe((isEnabled:boolean) => {
// use isEnabled here
})
}
}

4
docs/en/docs-nav.json

@ -975,6 +975,10 @@
"text": "Features", "text": "Features",
"path": "UI/Angular/Features.md" "path": "UI/Angular/Features.md"
}, },
{
"text": "Global Features",
"path": "UI/Angular/GlobalFeatures.md"
},
{ {
"text": "Permission Management", "text": "Permission Management",
"path": "UI/Angular/Permission-Management.md" "path": "UI/Angular/Permission-Management.md"

4
npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts

@ -23,7 +23,7 @@ export class TenantBoxService {
private tenantService: AbpTenantService, private tenantService: AbpTenantService,
private sessionState: SessionStateService, private sessionState: SessionStateService,
private configState: ConfigStateService, private configState: ConfigStateService,
) {} ) { }
onSwitch() { onSwitch() {
const tenant = this.sessionState.getTenant(); const tenant = this.sessionState.getTenant();
@ -40,7 +40,7 @@ export class TenantBoxService {
this.modalBusy = true; this.modalBusy = true;
this.tenantService this.tenantService
.findTenantByName(this.name, {}) .findTenantByName(this.name)
.pipe(finalize(() => (this.modalBusy = false))) .pipe(finalize(() => (this.modalBusy = false)))
.subscribe(({ success, tenantId: id, ...tenant }) => { .subscribe(({ success, tenantId: id, ...tenant }) => {
if (!success) { if (!success) {

21491
npm/ng-packs/packages/core/src/lib/proxy/generate-proxy.json

File diff suppressed because it is too large

32
npm/ng-packs/packages/core/src/lib/proxy/pages/abp/multi-tenancy/abp-tenant.service.ts

@ -1,5 +1,5 @@
import { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { RestService } from '../../../../services/rest.service';
import type { FindTenantResultDto } from '../../../volo/abp/asp-net-core/mvc/multi-tenancy/models'; import type { FindTenantResultDto } from '../../../volo/abp/asp-net-core/mvc/multi-tenancy/models';
@Injectable({ @Injectable({
@ -8,25 +8,19 @@ import type { FindTenantResultDto } from '../../../volo/abp/asp-net-core/mvc/mul
export class AbpTenantService { export class AbpTenantService {
apiName = 'abp'; apiName = 'abp';
findTenantById = (id: string, headers: Record<string, string>) => findTenantById = (id: string) =>
this.restService.request<any, FindTenantResultDto>( this.restService.request<any, FindTenantResultDto>({
{ method: 'GET',
method: 'GET', url: `/api/abp/multi-tenancy/tenants/by-id/${id}`,
url: `/api/abp/multi-tenancy/tenants/by-id/${id}`, },
headers, { apiName: this.apiName });
},
{ apiName: this.apiName },
);
findTenantByName = (name: string, headers: Record<string, string>) => findTenantByName = (name: string) =>
this.restService.request<any, FindTenantResultDto>( this.restService.request<any, FindTenantResultDto>({
{ method: 'GET',
method: 'GET', url: `/api/abp/multi-tenancy/tenants/by-name/${name}`,
url: `/api/abp/multi-tenancy/tenants/by-name/${name}`, },
headers, { apiName: this.apiName });
},
{ apiName: this.apiName },
);
constructor(private restService: RestService) {} constructor(private restService: RestService) {}
} }

21
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/api-exploring/abp-api-definition.service.ts

@ -1,9 +1,6 @@
import { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { RestService } from '../../../../../../services/rest.service'; import type { ApplicationApiDescriptionModel, ApplicationApiDescriptionModelRequestDto } from '../../../http/modeling/models';
import type {
ApplicationApiDescriptionModel,
ApplicationApiDescriptionModelRequestDto,
} from '../../../http/modeling/models';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -12,14 +9,12 @@ export class AbpApiDefinitionService {
apiName = 'abp'; apiName = 'abp';
getByModel = (model: ApplicationApiDescriptionModelRequestDto) => getByModel = (model: ApplicationApiDescriptionModelRequestDto) =>
this.restService.request<any, ApplicationApiDescriptionModel>( this.restService.request<any, ApplicationApiDescriptionModel>({
{ method: 'GET',
method: 'GET', url: '/api/abp/api-definition',
url: '/api/abp/api-definition', params: { includeTypes: model.includeTypes },
params: { includeTypes: model.includeTypes }, },
}, { apiName: this.apiName });
{ apiName: this.apiName },
);
constructor(private restService: RestService) {} constructor(private restService: RestService) {}
} }

19
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service.ts

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { RestService } from '../../../../../../services/rest.service';
import type { ApplicationConfigurationDto } from './models'; import type { ApplicationConfigurationDto } from './models';
import { RestService } from '@abp/ng.core';
import { Injectable } from '@angular/core';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -8,15 +8,12 @@ import type { ApplicationConfigurationDto } from './models';
export class AbpApplicationConfigurationService { export class AbpApplicationConfigurationService {
apiName = 'abp'; apiName = 'abp';
get() { get = () =>
return this.restService.request<any, ApplicationConfigurationDto>( this.restService.request<any, ApplicationConfigurationDto>({
{ method: 'GET',
method: 'GET', url: '/api/abp/application-configuration',
url: '/api/abp/application-configuration', },
}, { apiName: this.apiName });
{ apiName: this.apiName },
);
}
constructor(private restService: RestService) {} constructor(private restService: RestService) {}
} }

15
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/application-configurations/models.ts

@ -1,7 +1,7 @@
import type { LanguageInfo } from '../../../localization/models';
import type { NameValue } from '../../../models';
import type { CurrentTenantDto, MultiTenancyInfoDto } from '../multi-tenancy/models'; import type { CurrentTenantDto, MultiTenancyInfoDto } from '../multi-tenancy/models';
import type { ObjectExtensionsDto } from './object-extending/models'; import type { ObjectExtensionsDto } from './object-extending/models';
import type { LanguageInfo } from '../../../localization/models';
import type { NameValue } from '../../../models';
export interface ApplicationAuthConfigurationDto { export interface ApplicationAuthConfigurationDto {
policies: Record<string, boolean>; policies: Record<string, boolean>;
@ -14,6 +14,7 @@ export interface ApplicationConfigurationDto {
setting: ApplicationSettingConfigurationDto; setting: ApplicationSettingConfigurationDto;
currentUser: CurrentUserDto; currentUser: CurrentUserDto;
features: ApplicationFeatureConfigurationDto; features: ApplicationFeatureConfigurationDto;
globalFeatures: ApplicationGlobalFeatureConfigurationDto;
multiTenancy: MultiTenancyInfoDto; multiTenancy: MultiTenancyInfoDto;
currentTenant: CurrentTenantDto; currentTenant: CurrentTenantDto;
timing: TimingDto; timing: TimingDto;
@ -25,6 +26,10 @@ export interface ApplicationFeatureConfigurationDto {
values: Record<string, string>; values: Record<string, string>;
} }
export interface ApplicationGlobalFeatureConfigurationDto {
enabledFeatures: string[];
}
export interface ApplicationLocalizationConfigurationDto { export interface ApplicationLocalizationConfigurationDto {
values: Record<string, Record<string, string>>; values: Record<string, Record<string, string>>;
languages: LanguageInfo[]; languages: LanguageInfo[];
@ -58,6 +63,10 @@ export interface CurrentUserDto {
isAuthenticated: boolean; isAuthenticated: boolean;
id?: string; id?: string;
tenantId?: string; tenantId?: string;
impersonatorUserId?: string;
impersonatorTenantId?: string;
impersonatorUserName?: string;
impersonatorTenantName?: string;
userName?: string; userName?: string;
name?: string; name?: string;
surName?: string; surName?: string;
@ -66,8 +75,6 @@ export interface CurrentUserDto {
phoneNumber?: string; phoneNumber?: string;
phoneNumberVerified: boolean; phoneNumberVerified: boolean;
roles: string[]; roles: string[];
impersonatorUserId?: string;
impersonatorTenantId?: string;
} }
export interface DateTimeFormatDto { export interface DateTimeFormatDto {

1
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/application-configurations/object-extending/models.ts

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-types */
export interface EntityExtensionDto { export interface EntityExtensionDto {
properties: Record<string, ExtensionPropertyDto>; properties: Record<string, ExtensionPropertyDto>;

1
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/asp-net-core/mvc/multi-tenancy/models.ts

@ -1,3 +1,4 @@
export interface FindTenantResultDto { export interface FindTenantResultDto {
success: boolean; success: boolean;
tenantId?: string; tenantId?: string;

11
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/http/modeling/models.ts

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-types */
export interface ActionApiDescriptionModel { export interface ActionApiDescriptionModel {
uniqueName?: string; uniqueName?: string;
@ -9,6 +8,8 @@ export interface ActionApiDescriptionModel {
parametersOnMethod: MethodParameterApiDescriptionModel[]; parametersOnMethod: MethodParameterApiDescriptionModel[];
parameters: ParameterApiDescriptionModel[]; parameters: ParameterApiDescriptionModel[];
returnValue: ReturnValueApiDescriptionModel; returnValue: ReturnValueApiDescriptionModel;
allowAnonymous?: boolean;
implementFrom?: string;
} }
export interface ApplicationApiDescriptionModel { export interface ApplicationApiDescriptionModel {
@ -22,6 +23,9 @@ export interface ApplicationApiDescriptionModelRequestDto {
export interface ControllerApiDescriptionModel { export interface ControllerApiDescriptionModel {
controllerName?: string; controllerName?: string;
controllerGroupName?: string;
isRemoteService: boolean;
apiVersion?: string;
type?: string; type?: string;
interfaces: ControllerInterfaceApiDescriptionModel[]; interfaces: ControllerInterfaceApiDescriptionModel[];
actions: Record<string, ActionApiDescriptionModel>; actions: Record<string, ActionApiDescriptionModel>;
@ -65,6 +69,11 @@ export interface PropertyApiDescriptionModel {
type?: string; type?: string;
typeSimple?: string; typeSimple?: string;
isRequired: boolean; isRequired: boolean;
minLength?: number;
maxLength?: number;
minimum?: string;
maximum?: string;
regex?: string;
} }
export interface ReturnValueApiDescriptionModel { export interface ReturnValueApiDescriptionModel {

1
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/localization/models.ts

@ -1,3 +1,4 @@
export interface LanguageInfo { export interface LanguageInfo {
cultureName?: string; cultureName?: string;
uiCultureName?: string; uiCultureName?: string;

1
npm/ng-packs/packages/core/src/lib/proxy/volo/abp/models.ts

@ -1,3 +1,4 @@
export interface NameValue<T = string> { export interface NameValue<T = string> {
name?: string; name?: string;
value: T; value: T;

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

@ -138,6 +138,30 @@ export class ConfigStateService {
}), }),
); );
} }
getGlobalFeatures() {
return this.store.state.globalFeatures;
}
getGlobalFeatures$() {
return this.store.sliceState(state => state.globalFeatures);
}
private isGlobalFeatureEnabled(key: string, globalFeatures: ApplicationGlobalFeatureConfigurationDto) {
const features = globalFeatures.enabledFeatures || []
return features.some(f => key === f);
}
getGlobalFeatureIsEnabled(key: string) {
return this.isGlobalFeatureEnabled(key, this.store.state.globalFeatures);
}
getGlobalFeatureIsEnabled$(key: string) {
return this.store.sliceState(state => this.isGlobalFeatureEnabled(key, state.globalFeatures));
}
} }
function splitKeys(keys: string[] | string): string[] { function splitKeys(keys: string[] | string): string[] {

6
npm/ng-packs/packages/core/src/lib/services/multi-tenancy.service.ts

@ -29,17 +29,17 @@ export class MultiTenancyService {
private tenantService: AbpTenantService, private tenantService: AbpTenantService,
private configStateService: ConfigStateService, private configStateService: ConfigStateService,
@Inject(TENANT_KEY) public tenantKey: string, @Inject(TENANT_KEY) public tenantKey: string,
) {} ) { }
setTenantByName(tenantName: string) { setTenantByName(tenantName: string) {
return this.tenantService return this.tenantService
.findTenantByName(tenantName, { [this.tenantKey]: '' }) .findTenantByName(tenantName)
.pipe(switchMap(this.setTenantToState)); .pipe(switchMap(this.setTenantToState));
} }
setTenantById(tenantId: string) { setTenantById(tenantId: string) {
return this.tenantService return this.tenantService
.findTenantById(tenantId, { [this.tenantKey]: '' }) .findTenantById(tenantId)
.pipe(switchMap(this.setTenantToState)); .pipe(switchMap(this.setTenantToState));
} }
} }

Loading…
Cancel
Save