Added settings & settings manager

This commit is contained in:
tsommer committed 2024-04-19 21:25:44 +02:00
1 parent 6cbbcbc1e1
commit cc75df4a15
8 files changed
+202

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
namespace AIStudio.Settings;
public sealed class Data
{
public Version Version { get; init; }
public List<Provider> Providers { get; init; } = new();
}
@@ -0,0 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Settings;
public readonly record struct Provider(string Id, string InstanceName, Providers UsedProvider);
@@ -0,0 +1,46 @@
@using AIStudio.Provider
@using MudBlazor
<MudDialog>
<DialogContent>
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
<MudTextField
T="string"
@bind-Text="@this.dataInstanceName"
Label="Instance Name"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Lightbulb"
AdornmentColor="Color.Info"
Required="@true"
RequiredError="Please add an instance name."
/>
@* ReSharper disable once CSharpWarnings::CS8974 *@
<MudSelect @bind-Value="@this.dataProvider" Label="Provider" OpenIcon="@Icons.Material.Filled.AccountBalance" AdornmentColor="Color.Info" Adornment="Adornment.Start" Validation="@this.ValidatingProvider">
@foreach (Providers provider in Enum.GetValues(typeof(Providers)))
{
<MudSelectItem Value="@provider">@provider</MudSelectItem>
}
</MudSelect>
</MudForm>
@if (this.dataIssues.Any())
{
<MudPaper Class="pa-2 mt-3">
<MudText Typo="Typo.h6">Issues</MudText>
<MudList Clickable="@true">
@foreach (var issue in this.dataIssues)
{
<MudListItem Icon="@Icons.Material.Filled.Error" IconColor="Color.Error">
@issue
</MudListItem>
}
</MudList>
</MudPaper>
}
</DialogContent>
<DialogActions>
<MudButton OnClick="@this.Cancel">Cancel</MudButton>
<MudButton OnClick="@this.Add" Color="Color.Primary">Add</MudButton>
</DialogActions>
</MudDialog>
@@ -0,0 +1,46 @@
using AIStudio.Provider;
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace AIStudio.Settings;
public partial class ProviderDialog : ComponentBase
{
[CascadingParameter]
private MudDialogInstance MudDialog { get; set; } = null!;
private bool dataIsValid;
private string[] dataIssues = [];
private string dataInstanceName = string.Empty;
private Providers dataProvider = Providers.NONE;
private MudForm form = null!;
private async Task Add()
{
await this.form.Validate();
if (!this.dataIsValid)
return;
var addedProvider = new Provider
{
Id = Guid.NewGuid().ToString(),
InstanceName = this.dataInstanceName,
UsedProvider = this.dataProvider,
};
this.MudDialog.Close(DialogResult.Ok(addedProvider));
}
private string? ValidatingProvider(Providers provider)
{
if (provider == Providers.NONE)
return "Please select a provider.";
return null;
}
private void Cancel() => this.MudDialog.Cancel();
}
@@ -0,0 +1,7 @@
namespace AIStudio.Settings;
public enum Version
{
UNKNOWN,
V1,
}