Browse Source

Add `TimeZoneSettingGroupViewComponent`

pull/19/head
Jadyn 2 years ago
parent
commit
dc39c4eaf9
  1. 1
      modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/AbpSettingManagementBlazorAntDesignModule.cs
  2. 20
      modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/Pages/SettingManagement/TimeZoneSettingGroup/TimeZoneSettingGroupViewComponent.razor
  3. 61
      modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/Pages/SettingManagement/TimeZoneSettingGroup/TimeZoneSettingGroupViewComponent.razor.cs
  4. 38
      modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/Settings/AntDesignTimeZonePageContributor.cs
  5. 21
      samples/BookStore/src/BookStore.BlazorServer/BookStoreBlazorModule.cs

1
modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/AbpSettingManagementBlazorAntDesignModule.cs

@ -40,6 +40,7 @@ public class AbpSettingManagementBlazorAntDesignModule : AbpModule
Configure<SettingManagementComponentOptions>(options =>
{
options.Contributors.Add(new AntDesignSettingDefultPageContributor());
options.Contributors.Add(new AntDesignTimeZonePageContributor());
});
}
}

20
modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/Pages/SettingManagement/TimeZoneSettingGroup/TimeZoneSettingGroupViewComponent.razor

@ -0,0 +1,20 @@
@using Volo.Abp.SettingManagement.Localization
@inherits Volo.Abp.AspNetCore.Components.AbpComponentBase
@inject AbpBlazorMessageLocalizerHelper<AbpSettingManagementResource> LH
<Form Layout="@FormLayout.Vertical" Model="@TimezoneSettings">
<FormItem Label="@L["DisplayName:Timezone"]">
<Select DataSource="@context.TimeZoneItems"
ValueName="@nameof(Volo.Abp.NameValue.Value)"
LabelName="@nameof(Volo.Abp.NameValue.Name)"
@bind-Value="@context.Timezone">
</Select>
</FormItem>
<FormItem WrapperColOffset="8">
<Button Type="@ButtonType.Primary" HtmlType="submit" OnClick="@UpdateSettingsAsync">
@L["Submit"]
</Button>
</FormItem>
</Form>

61
modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/Pages/SettingManagement/TimeZoneSettingGroup/TimeZoneSettingGroupViewComponent.razor.cs

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Volo.Abp;
using Volo.Abp.AspNetCore.Components.Web.Configuration;
using Volo.Abp.SettingManagement;
using Volo.Abp.SettingManagement.Localization;
namespace Lsw.Abp.SettingManagement.Blazor.AntDesignUI.Pages.SettingManagement.TimeZoneSettingGroup;
public partial class TimeZoneSettingGroupViewComponent
{
[Inject]
protected ITimeZoneSettingsAppService TimeZoneSettingsAppService { get; set; }
[Inject]
protected ICurrentApplicationConfigurationCacheResetService CurrentApplicationConfigurationCacheResetService { get; set; }
protected UpdateTimezoneSettingsViewModel TimezoneSettings = new();
public TimeZoneSettingGroupViewComponent()
{
ObjectMapperContext = typeof(AbpSettingManagementBlazorAntDesignModule);
LocalizationResource = typeof(AbpSettingManagementResource);
}
protected override async Task OnInitializedAsync()
{
try
{
TimezoneSettings.Timezone = await TimeZoneSettingsAppService.GetAsync();
TimezoneSettings.TimeZoneItems = await TimeZoneSettingsAppService.GetTimezonesAsync();
}
catch (Exception ex)
{
await HandleErrorAsync(ex);
}
}
protected virtual async Task UpdateSettingsAsync()
{
try
{
await TimeZoneSettingsAppService.UpdateAsync(TimezoneSettings.Timezone);
await CurrentApplicationConfigurationCacheResetService.ResetAsync();
await Message.Success(L["SuccessfullySaved"]);
}
catch (Exception ex)
{
await HandleErrorAsync(ex);
}
}
public class UpdateTimezoneSettingsViewModel
{
public string Timezone { get; set; }
public List<NameValue> TimeZoneItems { get; set; }
}
}

38
modules/SettingManagement/Lsw.Abp.SettingManagement.Blazor.AntDesignUI/Settings/AntDesignTimeZonePageContributor.cs

@ -0,0 +1,38 @@
using System.Threading.Tasks;
using Lsw.Abp.SettingManagement.Blazor.AntDesignUI.Pages.SettingManagement.TimeZoneSettingGroup;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.Abp.SettingManagement;
using Volo.Abp.SettingManagement.Blazor;
using Volo.Abp.SettingManagement.Localization;
using Volo.Abp.Timing;
namespace Lsw.Abp.SettingManagement.Blazor.AntDesignUI.Settings;
public class AntDesignTimeZonePageContributor : ISettingComponentContributor
{
public virtual async Task<bool> CheckPermissionsAsync(SettingComponentCreationContext context)
{
var authorizationService = context.ServiceProvider.GetRequiredService<IAuthorizationService>();
return await authorizationService.IsGrantedAsync(SettingManagementPermissions.TimeZone);
}
public virtual Task ConfigureAsync(SettingComponentCreationContext context)
{
var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<AbpSettingManagementResource>>();
if (context.ServiceProvider.GetRequiredService<IClock>().SupportsMultipleTimezone)
{
context.Groups.Add(
new SettingComponentGroup(
"Volo.Abp.TimeZone",
l["Menu:TimeZone"],
typeof(TimeZoneSettingGroupViewComponent)
)
);
}
return Task.CompletedTask;
}
}

21
samples/BookStore/src/BookStore.BlazorServer/BookStoreBlazorModule.cs

@ -34,6 +34,7 @@ using Volo.Abp.Swashbuckle;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.VirtualFileSystem;
using Volo.Abp.Timing;
namespace BookStore.Blazor;
@ -73,6 +74,8 @@ public class BookStoreBlazorModule : AbpModule
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
Configure<AbpClockOptions>(options => options.Kind = DateTimeKind.Utc);
ConfigureUrls(configuration);
ConfigureBundles();
ConfigureAuthentication(context, configuration);
@ -107,15 +110,15 @@ public class BookStoreBlazorModule : AbpModule
);
//BLAZOR UI
options.StyleBundles.Configure(
BlazorAntDesignThemeBundles.Styles.Global,
bundle =>
{
bundle.AddFiles("/blazor-global-styles.css");
//You can remove the following line if you don't use Blazor CSS isolation for components
bundle.AddFiles("/BookStore.BlazorServer.styles.css");
}
);
options.StyleBundles.Configure(
BlazorAntDesignThemeBundles.Styles.Global,
bundle =>
{
bundle.AddFiles("/blazor-global-styles.css");
//You can remove the following line if you don't use Blazor CSS isolation for components
bundle.AddFiles("/BookStore.BlazorServer.styles.css");
}
);
});
}

Loading…
Cancel
Save