LANCommander/LANCommander.Server/UI/Pages/Settings/Library.razor
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

61 lines
2.1 KiB
Text

@page "/Settings/Library"
@using LANCommander.Server.Settings
@using Microsoft.Extensions.Options
@inject IMessageService MessageService
@inject ILogger<Servers> Logger
@inject IOptions<Settings> Settings
@inject SettingsProvider<Settings> SettingsProvider
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Library" />
<PageContent>
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
<FormItem Label="Enable User Libraries">
<HelpButton>
<Description>
Allows users to manage the games they see in their library. This also enables the Depot!
</Description>
<ChildContent>
<Switch @bind-Checked="context.Server.Library.EnableUserLibraries"/>
</ChildContent>
</HelpButton>
</FormItem>
<FormItem Label="Restrict Games By Collection">
<HelpButton>
<Description>
Restricts the games that users can see in their library and the depot based on their role. Visit Settings / Roles to assign collections to roles.
</Description>
<ChildContent>
<Switch @bind-Checked="context.Server.Roles.RestrictGamesByCollection"/>
</ChildContent>
</HelpButton>
</FormItem>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
</PageContent>
@code {
void Save()
{
try
{
SettingsProvider.Update(s =>
{
s.Server.Library = Settings.Value.Server.Library;
s.Server.Roles.RestrictGamesByCollection = Settings.Value.Server.Roles.RestrictGamesByCollection;
});
MessageService.Success("Settings saved!");
}
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
Logger.LogError(ex, "An unknown error occurred.");
}
}
}