68 lines
No EOL
2.4 KiB
Text
68 lines
No EOL
2.4 KiB
Text
@page "/Settings/Scripts"
|
|
@using LANCommander.SDK.Enums
|
|
@using LANCommander.Server.Settings
|
|
@using Microsoft.Extensions.Options
|
|
@inject MessageService MessageService
|
|
@inject ILogger<Scripts> Logger
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Scripts">
|
|
<PageHeaderExtra>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Storage Path">
|
|
<FilePicker Root="@RootPath" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@context.Server.Scripts.Snippets.StoragePath" OkText="Select Path" Title="Choose Path" OnSelected="OnPathSelected" />
|
|
</FormItem>
|
|
<FormItem Label="Automatically Repackage">
|
|
<Switch @bind-Checked="context.Server.Scripts.EnableAutomaticRepackaging"/>
|
|
</FormItem>
|
|
<FormItem Label="Repackage Every">
|
|
<Flex Direction="FlexDirection.Horizontal" Gap="FlexGap.Small" Align="FlexAlign.Center">
|
|
<AntDesign.InputNumber @bind-Value="context.Server.Scripts.RepackageEvery" Min="1" DefaultValue="24"/>
|
|
<Text>Hours</Text>
|
|
</Flex>
|
|
</FormItem>
|
|
</Form>
|
|
|
|
<Divider Text="System Scripts" />
|
|
|
|
<ScriptEditor AllowedTypes="new[] { ScriptType.UserLogin, ScriptType.UserRegistration }"/>
|
|
</PageContent>
|
|
|
|
@code {
|
|
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
|
|
|
|
void Save()
|
|
{
|
|
try
|
|
{
|
|
SettingsProvider.Update(s =>
|
|
{
|
|
s.Server.Scripts = Settings.Value.Server.Scripts;
|
|
});
|
|
|
|
MessageService.Success("Settings saved!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
|
|
void OnPathSelected(string path)
|
|
{
|
|
var appPath = Directory.GetCurrentDirectory();
|
|
|
|
if (path != null && path.StartsWith(appPath))
|
|
path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
|
|
|
|
Settings.Value.Server.Scripts.Snippets.StoragePath = path;
|
|
}
|
|
} |