Browse Source

Merge pull request #1440 from colinin/timezone-settings

feat: TimeZoneSettings Support
pull/1442/head
yx lin 2 weeks ago
committed by GitHub
parent
commit
6ce2019d64
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs
  2. 67
      aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs
  3. 42
      aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.HttpApi/LINGYUN/Abp/SettingManagement/TimeZoneSettingsController.cs

7
aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs

@ -145,7 +145,12 @@ public class SettingAppService : ApplicationService, ISettingAppService, ISettin
providerName)
?.AddOptions(LocalizationOptions.Languages.Select(l => new OptionDto(l.DisplayName, l.CultureName)));
// 时区
var timezones = TimeZoneHelper.GetTimezones(TimezoneProvider.GetWindowsTimezones());
var timezones = TimeZoneHelper.GetTimezones(TimezoneProvider.GetIanaTimezones());
timezones.Insert(0, new NameValue
{
Name = L["DefaultTimeZone"],
Value = "Unspecified"
});
var timingSetting = sysSettingGroup.AddSetting(L["DisplayName:System.Timing"], L["Description:System.Timing"]);
timingSetting.AddDetail(
await SettingDefinitionManager.GetAsync(TimingSettingNames.TimeZone),

67
aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/TimeZoneSettingsAppService.cs

@ -0,0 +1,67 @@
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.MultiTenancy;
using Volo.Abp.SettingManagement;
using Volo.Abp.Timing;
namespace LINGYUN.Abp.SettingManagement;
[Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)]
public class TimeZoneSettingsAppService : SettingManagementAppServiceBase, ITimeZoneSettingsAppService
{
protected ISettingManager SettingManager { get; }
protected ITimezoneProvider TimezoneProvider { get; }
private const string UnspecifiedTimeZone = "Unspecified";
public TimeZoneSettingsAppService(ISettingManager settingManager, ITimezoneProvider timezoneProvider)
{
SettingManager = settingManager;
TimezoneProvider = timezoneProvider;
}
public virtual async Task<string> GetAsync()
{
var timezone = CurrentTenant.GetMultiTenancySide() == MultiTenancySides.Host
? await SettingManager.GetOrNullGlobalAsync(TimingSettingNames.TimeZone)
: await SettingManager.GetOrNullForCurrentTenantAsync(TimingSettingNames.TimeZone);
if (timezone.IsNullOrWhiteSpace())
{
timezone = UnspecifiedTimeZone;
}
return timezone;
}
public virtual Task<List<NameValue>> GetTimezonesAsync()
{
var timezones = TimeZoneHelper.GetTimezones(TimezoneProvider.GetIanaTimezones());
timezones.Insert(0, new NameValue
{
Name = L["DefaultTimeZone"],
Value = UnspecifiedTimeZone
});
return Task.FromResult(timezones);
}
public virtual async Task UpdateAsync(string timezone)
{
if (timezone.Equals(UnspecifiedTimeZone, StringComparison.OrdinalIgnoreCase))
{
timezone = null;
}
if (CurrentTenant.GetMultiTenancySide() == MultiTenancySides.Host)
{
await SettingManager.SetGlobalAsync(TimingSettingNames.TimeZone, timezone);
}
else
{
await SettingManager.SetForCurrentTenantAsync(TimingSettingNames.TimeZone, timezone);
}
}
}

42
aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.HttpApi/LINGYUN/Abp/SettingManagement/TimeZoneSettingsController.cs

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.SettingManagement;
namespace LINGYUN.Abp.SettingManagement;
[RemoteService(Name = AbpSettingManagementRemoteServiceConsts.RemoteServiceName)]
[Area(AbpSettingManagementRemoteServiceConsts.ModuleName)]
[Route("api/setting-management/timezone")]
[Authorize(Volo.Abp.SettingManagement.SettingManagementPermissions.TimeZone)]
public class TimeZoneSettingsController : AbpControllerBase, ITimeZoneSettingsAppService
{
private readonly ITimeZoneSettingsAppService _service;
public TimeZoneSettingsController(ITimeZoneSettingsAppService service)
{
_service = service;
}
[HttpGet]
public virtual Task<string> GetAsync()
{
return _service.GetAsync();
}
[HttpGet]
[Route("timezones")]
public virtual Task<List<NameValue>> GetTimezonesAsync()
{
return _service.GetTimezonesAsync();
}
[HttpPost]
public virtual Task UpdateAsync(string timezone)
{
return _service.UpdateAsync(timezone);
}
}
Loading…
Cancel
Save