Skip to content

Commit ad1c47e

Browse files
authored
Merge pull request #120 from Lan2Play/feature/Andy_SystemSettings
Add system settings
2 parents ea8b523 + 617a366 commit ad1c47e

58 files changed

Lines changed: 846 additions & 339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test_and_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ jobs:
8686
- name: dotnet build
8787
run: dotnet build --no-restore
8888
- name: dotnet test
89-
continue-on-error: true
9089
run: dotnet test --no-build --no-restore --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
9190
- name: stop sonarscanner
91+
if: always()
9292
env:
9393
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9494
SONAR_TOKEN: ${{ secrets.NETEVENT_SONAR_TOKEN }}

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ else
4242
rm -rf NetEvent/Server/netevent.db-wal
4343
endif
4444

45+
#remove development objects
46+
remove-dev-objects:
47+
ifeq ($(OS),Windows_NT)
48+
if exist NetEvent\Client\bin rmdir /S/Q NetEvent\Client\bin
49+
if exist NetEvent\Client\obj rmdir /S/Q NetEvent\Client\obj
50+
if exist NetEvent\Server\bin rmdir /S/Q NetEvent\Server\bin
51+
if exist NetEvent\Server\obj rmdir /S/Q NetEvent\Server\obj
52+
if exist NetEvent\Server.Tests\bin rmdir /S/Q NetEvent\Server.Tests\bin
53+
if exist NetEvent\Server.Tests\obj rmdir /S/Q NetEvent\Server.Tests\obj
54+
if exist NetEvent\Shared\bin rmdir /S/Q NetEvent\Shared\bin
55+
if exist NetEvent\Shared\obj rmdir /S/Q NetEvent\Shared\obj
56+
57+
else
58+
rm -rf NetEvent/Client/bin
59+
rm -rf NetEvent/Client/obj
60+
rm -rf NetEvent/Server/bin
61+
rm -rf NetEvent/Server/obj
62+
rm -rf NetEvent/Server.Tests/bin
63+
rm -rf NetEvent/Server.Tests/obj
64+
rm -rf NetEvent/Shared/bin
65+
rm -rf NetEvent/Shared/obj
66+
endif
67+
4568
# Make Documentation
4669
docs-html:
4770
ifeq ($(OS),Windows_NT)

NetEvent/Client/Extensions/WebAssemblyHostExtension.cs renamed to NetEvent/Client/Extensions/DefaultCultureExtension.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Globalization;
3-
using System.Linq;
44
using System.Threading;
55
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Components;
67
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
910
using NetEvent.Client.Services;
10-
using NetEvent.Shared.Constants;
11+
using NetEvent.Shared.Config;
1112

1213
namespace NetEvent.Client.Extensions;
1314

14-
public static class WebAssemblyHostExtension
15+
[ExcludeFromCodeCoverage(Justification = "Ignore UI Extensions")]
16+
public static class DefaultCultureExtension
1517
{
1618
public static async Task SetDefaultCultureAsync(this WebAssemblyHost app)
1719
{
18-
var organizationDataService = app.Services.GetRequiredService<IOrganizationDataService>();
20+
var organizationDataService = app.Services.GetRequiredService<ISystemSettingsDataService>();
1921
var logger = app.Services.GetRequiredService<ILogger<WebAssemblyHost>>();
2022

2123
try
2224
{
2325
using var cancellationTokenSource = new CancellationTokenSource();
2426

25-
var orgData = await organizationDataService.GetOrganizationDataAsync(cancellationTokenSource.Token).ConfigureAwait(false);
26-
27-
var organizationCulture = orgData.FirstOrDefault(a => a.Key.Equals(OrganizationDataConstants.CultureKey));
27+
var organizationCulture = await organizationDataService.GetSystemSettingAsync(
28+
SystemSettingGroup.OrganizationData,
29+
SystemSettings.DataCultureInfo,
30+
newCulture =>
31+
{
32+
if (CultureInfo.DefaultThreadCurrentCulture?.Name.Equals(newCulture.Value, StringComparison.OrdinalIgnoreCase) != true)
33+
{
34+
var navigationManager = app.Services.GetRequiredService<NavigationManager>();
35+
navigationManager.NavigateTo(navigationManager.Uri, true);
36+
}
37+
},
38+
cancellationTokenSource.Token).ConfigureAwait(false);
2839

2940
if (organizationCulture == null)
3041
{

NetEvent/Client/NetEvent.Client.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<PropertyGroup>
11-
<BlazorLinkOnBuild Condition="'$(Configuration)'!='Release'">false</BlazorLinkOnBuild>
11+
<BlazorLinkOnBuild Condition="'$(Configuration)'!='Release'">false</BlazorLinkOnBuild>
1212
</PropertyGroup>
1313

1414
<ItemGroup>
@@ -44,6 +44,7 @@
4444

4545
<ItemGroup>
4646
<Folder Include="Components\Administration\" />
47+
<Folder Include="Extensions\" />
4748
</ItemGroup>
4849

4950
<PropertyGroup>

NetEvent/Client/Pages/Administration/AdminMenu.razor

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
<MudButton Variant="Variant.Text" DisableElevation="true" Color="Color.Default" Href="administration" Match="NavLinkMatch.Prefix">@Localize["Administration.AdminMenu.Dashboard"]</MudButton>
55
<MudDivider />
6-
<AuthorizeView Policy="Admin.Users.Read">
6+
<AuthorizeView Policy="Admin.Users.*">
77
<Authorized>
88
<MudButton Variant="Variant.Text" DisableElevation="true" Color="Color.Default" Href="administration/users" Match="NavLinkMatch.Prefix">@Localize["Administration.AdminMenu.Users"]</MudButton>
99
<MudDivider />
1010
</Authorized>
1111
</AuthorizeView>
12-
12+
<MudDivider />
13+
<AuthorizeView Policy="Admin.Settings.*">
14+
<Authorized>
15+
<MudButton Variant="Variant.Text" DisableElevation="true" Color="Color.Default" Href="administration/settings" Match="NavLinkMatch.Prefix">@Localize["Administration.AdminMenu.Settings"]</MudButton>
16+
<MudDivider />
17+
</Authorized>
18+
</AuthorizeView>
Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
@page "/administration/settings"
2-
@using Microsoft.AspNetCore.Authorization
2+
@attribute [Authorize(Policy = "Admin.Settings.*")]
33
@inject Microsoft.Extensions.Localization.IStringLocalizer<App> Localize
44

5+
@using Microsoft.AspNetCore.Authorization
6+
@using NetEvent.Shared.Config
57

6-
@attribute [Authorize(Roles = "Admin")]
7-
8-
8+
<MudTabs Elevation="2" Rounded="true" ApplyEffectsToContainer="true" PanelClass="pa-6">
99

10+
<AuthorizeView Policy="Admin.Settings.Organization.*">
11+
<Authorized>
12+
<MudTabPanel Text="@Localize["Administration.Settings.Organization"]">
13+
@if (_Loading)
14+
{
15+
<div>@Localize["Administration.Settings.LoadingData"]</div>
16+
}
17+
else
18+
{
19+
<MudGrid>
20+
@foreach (var systemSetting in _SystemSettings.OrganizationData)
21+
{
22+
<MudItem xs="12" md="6">
23+
@switch (systemSetting.ValueType)
24+
{
25+
@case StringValueType svt:
26+
<MudTextField T="string" Value="@GetValue(systemSetting.Key)" ValueChanged="@(v => OnSettingsValueChanged(systemSetting, v))" Label="@Localize[systemSetting.LabelKey]" HelperText="@(string.IsNullOrEmpty(systemSetting.DescriptionKey) ? string.Empty : Localize[systemSetting.DescriptionKey])" Variant="Variant.Outlined" />
27+
break;
28+
@case EnumValueType<string> esvt:
29+
<MudSelect T="string" Value="@GetValue(systemSetting.Key)" ValueChanged="@(v => OnSettingsValueChanged(systemSetting, v))" Label="@Localize[systemSetting.LabelKey]" HelperText="@(string.IsNullOrEmpty(systemSetting.DescriptionKey) ? string.Empty : Localize[systemSetting.DescriptionKey])" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomCenter">
30+
@foreach (var enumItem in esvt.EnumItems)
31+
{
32+
<MudSelectItem Value="@enumItem" />
33+
}
34+
</MudSelect>
35+
break;
36+
@default:
37+
<div>Missing InputType @systemSetting.ValueType.GetType().Name for Setting @systemSetting.Key with Value- @_OrganizationData.First(x=>x.Key == systemSetting.Key).Value</div>
38+
break;
39+
}
40+
</MudItem>
41+
}
42+
</MudGrid>
43+
}
44+
</MudTabPanel>
45+
</Authorized>
46+
</AuthorizeView>
47+
</MudTabs>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Components;
7+
using NetEvent.Client.Services;
8+
using NetEvent.Shared.Config;
9+
using NetEvent.Shared.Dto;
10+
11+
namespace NetEvent.Client.Pages.Administration
12+
{
13+
public partial class Settings
14+
{
15+
#region Injects
16+
17+
[Inject]
18+
private ISystemSettingsDataService _SystemSettingsDataService { get; set; } = default!;
19+
20+
#endregion
21+
22+
private readonly SystemSettings _SystemSettings = SystemSettings.Instance;
23+
private bool _Loading = true;
24+
private IList<SystemSettingValueDto> _OrganizationData = new List<SystemSettingValueDto>();
25+
26+
protected override async Task OnInitializedAsync()
27+
{
28+
var cts = new CancellationTokenSource();
29+
_OrganizationData = await _SystemSettingsDataService.GetSystemSettingsAsync(SystemSettingGroup.OrganizationData, cts.Token);
30+
_Loading = false;
31+
}
32+
33+
private string? GetValue(string key)
34+
{
35+
return _OrganizationData.FirstOrDefault(x => x.Key.Equals(key, StringComparison.Ordinal))?.Value;
36+
}
37+
38+
private async Task OnSettingsValueChanged(SystemSetting setting, object? value)
39+
{
40+
if (value is null)
41+
{
42+
return;
43+
}
44+
45+
var result = await _SystemSettingsDataService.UpdateSystemSetting(setting.SettingType, new SystemSettingValueDto(setting.Key, value.ToString() ?? string.Empty), CancellationToken.None);
46+
if (result.Successful)
47+
{
48+
var existingData = _OrganizationData.FirstOrDefault(x => x.Key.Equals(setting.Key, StringComparison.OrdinalIgnoreCase));
49+
if (existingData != null)
50+
{
51+
existingData.Value = value.ToString() ?? string.Empty;
52+
}
53+
}
54+
}
55+
}
56+
}

NetEvent/Client/Pages/Administration/Users.razor

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
@inject Microsoft.Extensions.Localization.IStringLocalizer<App> Localize
1212

13-
14-
1513
<MudTabs Elevation="1" Rounded="true">
1614
<MudTabPanel Text="@Localize["Administration.Users.Title"]">
1715
<NetEventDataGrid T="AdminUserDto"

NetEvent/Client/Pages/Index.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
@inject Microsoft.Extensions.Localization.IStringLocalizer<App> Localize
44

5-
<PageTitle>@Localize["Index.Title"]</PageTitle>
65

76
<h1>@Localize["Index.Hello"]</h1>
87

NetEvent/Client/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Microsoft.AspNetCore.Components.Authorization;
3+
using Microsoft.AspNetCore.Components.Web;
34
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
45
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
56
using Microsoft.Extensions.DependencyInjection;
@@ -13,6 +14,7 @@
1314
var builder = WebAssemblyHostBuilder.CreateDefault(args);
1415

1516
builder.RootComponents.Add<App>("#app");
17+
builder.RootComponents.Add<HeadOutlet>("head::after");
1618

1719
builder.Services.AddOptions();
1820
builder.Services.AddAuthorizationCore(config => config.AddPolicies());
@@ -21,7 +23,7 @@
2123
builder.Services.AddScoped<IAuthService, AuthService>();
2224

2325
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
24-
builder.Services.AddScoped<IOrganizationDataService, OrganizationDataService>();
26+
builder.Services.AddScoped<ISystemSettingsDataService, SystemSettingsService>();
2527
builder.Services.AddScoped<IUserService, UserService>();
2628
builder.Services.AddScoped<IThemeService, ThemeService>();
2729
builder.Services.AddScoped<IRoleService, RoleService>();

0 commit comments

Comments
 (0)