From cecc2c1baa53675906bbd96ac27e476783821bad Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 16 May 2022 16:45:03 +0800 Subject: [PATCH] Add `abp.globalFeatures.isEnabled` to `abp.js` --- .../en/UI/AspNetCore/JavaScript-API/GlobalFeatures.md | 11 +++++++---- .../ApplicationGlobalFeatureConfigurationDto.cs | 3 --- .../AbpApplicationConfigurationAppService.cs | 6 ------ npm/packs/core/src/abp.js | 10 ++++++++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/en/UI/AspNetCore/JavaScript-API/GlobalFeatures.md b/docs/en/UI/AspNetCore/JavaScript-API/GlobalFeatures.md index 2f226724b8..7b451addcd 100644 --- a/docs/en/UI/AspNetCore/JavaScript-API/GlobalFeatures.md +++ b/docs/en/UI/AspNetCore/JavaScript-API/GlobalFeatures.md @@ -7,15 +7,18 @@ ## Usage ````js +//Gets all enabled global features. > abp.globalFeatures.enabledFeatures [ 'Shopping.Payment', 'Ecommerce.Subscription' ] -> abp.globalFeatures.moduleEnabledFeatures -{ Ecommerce } +//Check the global feature is enabled +> abp.globalFeatures.isEnabled('Ecommerce.Subscription') -> abp.globalFeatures.moduleEnabledFeatures.Ecommerce +true -[ 'Ecommerce.Subscription', 'Ecommerce.Invoice' ] +> abp.globalFeatures.isEnabled('My.Subscription') + +false ```` diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationGlobalFeatureConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationGlobalFeatureConfigurationDto.cs index e911cd911d..9854e85315 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationGlobalFeatureConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationGlobalFeatureConfigurationDto.cs @@ -8,11 +8,8 @@ public class ApplicationGlobalFeatureConfigurationDto { public HashSet EnabledFeatures { get; set; } - public Dictionary> ModuleEnabledFeatures { get; set; } - public ApplicationGlobalFeatureConfigurationDto() { EnabledFeatures = new HashSet(); - ModuleEnabledFeatures = new Dictionary>(); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index bfa2e6a285..b80a288e81 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -295,15 +295,9 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp result.EnabledFeatures.AddIfNotContains(enabledFeatureName); } - foreach (var module in GlobalFeatureManager.Instance.Modules) - { - result.ModuleEnabledFeatures.AddIfNotContains(new KeyValuePair>(module.Key, module.Value.GetFeatures().Select(x => x.FeatureName).ToList())); - } - return Task.FromResult(result); } - protected virtual async Task GetTimingConfigAsync() { var windowsTimeZoneId = await _settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone); diff --git a/npm/packs/core/src/abp.js b/npm/packs/core/src/abp.js index 7cb0782f1a..f715b5004c 100644 --- a/npm/packs/core/src/abp.js +++ b/npm/packs/core/src/abp.js @@ -773,4 +773,14 @@ var abp = abp || {}; return abp.features.values[name]; }; + /* GLOBAL FEATURES *************************************************/ + + abp.globalFeatures = abp.globalFeatures || {}; + + abp.globalFeatures.enabledFeatures = abp.globalFeatures.enabledFeatures || {}; + + abp.globalFeatures.isEnabled = function(name){ + return abp.globalFeatures.enabledFeatures.indexOf(name) != -1; + } + })();