From 10d735c01c2057da20aea6c2757773cc97e42013 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 22 Oct 2020 15:37:10 +0800 Subject: [PATCH] Define abp.features API to abp.js --- .../UI/AspNetCore/JavaScript-API/Features.md | 22 +++++++++++++++---- npm/packs/core/src/abp.js | 15 +++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/en/UI/AspNetCore/JavaScript-API/Features.md b/docs/en/UI/AspNetCore/JavaScript-API/Features.md index e3cd2be445..8d58347f49 100644 --- a/docs/en/UI/AspNetCore/JavaScript-API/Features.md +++ b/docs/en/UI/AspNetCore/JavaScript-API/Features.md @@ -6,10 +6,24 @@ ## Basic Usage -`abp.features.values` can be used to access to the all feature values. - ````js -var excelExportFeatureValue = abp.features.values["ExportingToExcel"]; +//Gets a value as string. +var value = abp.features.get('ExportingToExcel'); + +//Check the feature is enabled +var enabled = abp.features.isEnabled('ExportingToExcel.Enabled'); ```` -Then you can check the value of the feature to perform your logic. \ No newline at end of file +## All Values + +`abp.features.values` can be used to access to the all feature values. + +An example value of this object is shown below: + +````js +{ + Identity.TwoFactor: "Optional", + ExportingToExcel.Enabled: "true", + ... +} +```` \ No newline at end of file diff --git a/npm/packs/core/src/abp.js b/npm/packs/core/src/abp.js index 72af4bd106..9405310771 100644 --- a/npm/packs/core/src/abp.js +++ b/npm/packs/core/src/abp.js @@ -750,5 +750,20 @@ var abp = abp || {}; return toUtc(date); } }; + + /* FEATURES *************************************************/ + abp.features = abp.features || {}; + + abp.features.values = abp.features.values || {}; + + abp.features.isEnabled = function(name){ + var value = abp.features.get(name); + return value == 'true' || value == 'True'; + } + + abp.features.get = function (name) { + return abp.features.values[name]; + }; + })();