Merge pull request #12660 from abpframework/issue-12546

Global features Angular Api added
pull/12738/head
Mahmut Gundogdu 3 years ago committed by GitHub
commit 762a5a7eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
})
}
}

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

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

File diff suppressed because it is too large Load Diff

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

@ -1,9 +1,6 @@
import { RestService } from '@abp/ng.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({
providedIn: 'root',
@ -12,14 +9,12 @@ export class AbpApiDefinitionService {
apiName = 'abp';
getByModel = (model: ApplicationApiDescriptionModelRequestDto) =>
this.restService.request<any, ApplicationApiDescriptionModel>(
{
method: 'GET',
url: '/api/abp/api-definition',
params: { includeTypes: model.includeTypes },
},
{ apiName: this.apiName },
);
this.restService.request<any, ApplicationApiDescriptionModel>({
method: 'GET',
url: '/api/abp/api-definition',
params: { includeTypes: model.includeTypes },
},
{ apiName: this.apiName });
constructor(private restService: RestService) {}
}

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

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

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

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

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

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

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

@ -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[] {

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

Loading…
Cancel
Save