diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor b/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor index ef5c8751ae..14074f60fe 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor @@ -1,9 +1,7 @@ -@using Microsoft.Extensions.Localization -@using Volo.Abp.FeatureManagement.Localization -@using Volo.Abp.Validation.StringValues -@inject IStringLocalizer L +@using Volo.Abp.Validation.StringValues +@using Microsoft.Extensions.Localization - + @@ -12,15 +10,15 @@ - @if (_groups == null) + @if (Groups == null) { @L["NoFeatureFoundMessage"] } else { - + - @foreach (var group in _groups) + @foreach (var group in Groups) { @group.DisplayName @@ -28,7 +26,7 @@ } - @foreach (var group in _groups) + @foreach (var group in Groups) {

@group.DisplayName

@@ -58,10 +56,14 @@ @feature.DisplayName - @foreach (var item in items) { - @item.DisplayText + + @CreateStringLocalizer(item.DisplayText.ResourceName).GetString(item.DisplayText.Name) + } @@ -70,7 +72,7 @@ if (feature.ValueType is ToggleStringValueType) { - @feature.DisplayName + @feature.DisplayName } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor.cs index f1805a620f..c4b31d7262 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Blazor/Components/FeatureManagementModal.razor.cs @@ -3,74 +3,102 @@ using System.Linq; using System.Threading.Tasks; using Blazorise; using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Components.WebAssembly; +using Volo.Abp.FeatureManagement.Localization; using Volo.Abp.Features; +using Volo.Abp.Localization; using Volo.Abp.Validation.StringValues; namespace Volo.Abp.FeatureManagement.Blazor.Components { public partial class FeatureManagementModal { - [Inject] private IFeatureAppService FeatureAppService { get; set; } + [Inject] protected IFeatureAppService FeatureAppService { get; set; } [Inject] protected IUiMessageService UiMessageService { get; set; } + + [Inject] protected IStringLocalizer L { get; set; } + + [Inject] protected IStringLocalizerFactory HtmlLocalizerFactory { get; set; } + + [Inject] protected IOptions LocalizationOptions { get; set; } - private Modal _modal; + protected Modal Modal; - private string _providerName; - private string _providerKey; + protected string ProviderName; + protected string ProviderKey; - private List _groups { get; set; } + protected List Groups { get; set; } - private Dictionary _toggleValues; + protected Dictionary ToggleValues; + + protected Dictionary SelectionStringValues; - public async Task OpenAsync(string providerName, string providerKey) + public virtual async Task OpenAsync(string providerName, string providerKey) { - _providerName = providerName; - _providerKey = providerKey; - - _groups = (await FeatureAppService.GetAsync(_providerName, _providerKey)).Groups; + ProviderName = providerName; + ProviderKey = providerKey; - _toggleValues = _groups - .SelectMany(x => x.Features) - .Where(x => x.ValueType is ToggleStringValueType) - .ToDictionary(x => x.Name, x => bool.Parse(x.Value)); + ToggleValues = new Dictionary(); + SelectionStringValues = new Dictionary(); - _modal.Show(); + Groups = (await FeatureAppService.GetAsync(ProviderName, ProviderKey)).Groups; + + foreach (var featureGroupDto in Groups) + { + foreach (var featureDto in featureGroupDto.Features) + { + if (featureDto.ValueType is ToggleStringValueType) + { + ToggleValues.Add(featureDto.Name, bool.Parse(featureDto.Value)); + } + + if (featureDto.ValueType is SelectionStringValueType) + { + SelectionStringValues.Add(featureDto.Name, featureDto.Value); + } + } + } + + Modal.Show(); } - private void CloseModal() + public virtual Task CloseModal() { - _modal.Hide(); + Modal.Hide(); + return Task.CompletedTask; } - private async Task SaveAsync() + protected virtual async Task SaveAsync() { var features = new UpdateFeaturesDto { - Features = _groups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto + Features = Groups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto { Name = f.Name, - Value = f.ValueType is ToggleStringValueType ? _toggleValues[f.Name].ToString() : f.Value + Value = f.ValueType is ToggleStringValueType ? ToggleValues[f.Name].ToString() : + f.ValueType is SelectionStringValueType ? SelectionStringValues[f.Name] : f.Value }).ToList() }; - await FeatureAppService.UpdateAsync(_providerName, _providerKey, features); + await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); - _modal.Hide(); + Modal.Hide(); } - public string GetNormalizedGroupName(string name) + protected virtual string GetNormalizedGroupName(string name) { return "FeatureGroup_" + name.Replace(".", "_"); } - public virtual bool IsDisabled(string providerName) + protected virtual bool IsDisabled(string providerName) { - return providerName != _providerName && providerName != DefaultValueFeatureValueProvider.ProviderName; + return providerName != ProviderName && providerName != DefaultValueFeatureValueProvider.ProviderName; } - private async Task OnFeatureValueChangedAsync(string value, FeatureDto feature) + protected virtual async Task OnFeatureValueChangedAsync(string value, FeatureDto feature) { if (feature.ValueType.Validator.IsValid(value)) { @@ -81,5 +109,16 @@ namespace Volo.Abp.FeatureManagement.Blazor.Components await UiMessageService.WarnAsync(L["Volo.Abp.FeatureManagement:InvalidFeatureValue", feature.DisplayName]); } } + + protected virtual void SelectedValueChanged(string featureName, string value) + { + SelectionStringValues[featureName] = value; + } + + protected virtual IStringLocalizer CreateStringLocalizer(string resourceName) + { + var resource = LocalizationOptions.Value.Resources.Values.FirstOrDefault(x => x.ResourceName == resourceName); + return HtmlLocalizerFactory.Create(resource != null ? resource.ResourceType : LocalizationOptions.Value.DefaultResourceType); + } } } \ No newline at end of file