Files
AI-Studio/app/MindWork AI Studio/Components/ProfileFormSelection.razor.cs
T

57 lines
2.0 KiB
C#
Raw Normal View History

2025-05-25 13:27:22 +02:00
using AIStudio.Dialogs.Settings;
2024-09-09 15:08:16 +02:00
using AIStudio.Settings;
using Microsoft.AspNetCore.Components;
2025-05-25 13:27:22 +02:00
using DialogOptions = AIStudio.Dialogs.DialogOptions;
2024-09-09 15:08:16 +02:00
namespace AIStudio.Components;
2025-04-27 09:06:05 +02:00
public partial class ProfileFormSelection : MSGComponentBase
2024-09-09 15:08:16 +02:00
{
[Parameter]
2026-09-07 16:09:00 +02:00
public HashSet<string> ProfileIds { get; set; } = [];
2024-09-09 15:08:16 +02:00
[Parameter]
2026-09-07 16:09:00 +02:00
public EventCallback<HashSet<string>> ProfileIdsChanged { get; set; }
2024-09-09 15:08:16 +02:00
[Parameter]
2026-09-07 16:09:00 +02:00
public Func<HashSet<string>, string?> Validation { get; set; } = _ => null;
[Parameter]
public bool Disabled { get; set; }
2024-09-09 15:08:16 +02:00
2025-05-25 13:27:22 +02:00
[Inject]
public IDialogService DialogService { get; init; } = null!;
2026-09-07 16:09:00 +02:00
private async Task SelectionChanged(IEnumerable<string?>? profileIds)
2024-09-09 15:08:16 +02:00
{
2026-09-07 16:09:00 +02:00
var selection = profileIds is null
? []
: profileIds.Where(profileId => !string.IsNullOrWhiteSpace(profileId)).Select(profileId => profileId!).ToHashSet(StringComparer.OrdinalIgnoreCase);
this.ProfileIds = selection;
await this.ProfileIdsChanged.InvokeAsync(selection);
}
private string? ValidateSelection(IEnumerable<string?>? profileIds) => this.Validation(
profileIds is null
? []
: profileIds.Where(profileId => !string.IsNullOrWhiteSpace(profileId)).Select(profileId => profileId!).ToHashSet(StringComparer.OrdinalIgnoreCase));
private string GetSelectionText(List<string?>? profileIds)
{
var profiles = this.SettingsManager.ResolveProfiles(profileIds?.Where(profileId => profileId is not null).Select(profileId => profileId!));
return profiles.Count switch
{
0 => T("No profiles selected"),
1 => profiles[0].GetSafeName(),
_ => string.Format(T("{0} profiles"), profiles.Count),
};
2024-09-09 15:08:16 +02:00
}
2025-05-25 13:27:22 +02:00
private async Task OpenSettingsDialog()
{
var dialogParameters = new DialogParameters();
await this.DialogService.ShowAsync<SettingsDialogProfiles>(T("Open Profile Options"), dialogParameters, DialogOptions.FULLSCREEN);
}
2026-09-07 16:09:00 +02:00
}