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

107 lines
3.3 KiB
C#
Raw Normal View History

2025-05-25 13:27:22 +02:00
using AIStudio.Dialogs.Settings;
2024-09-08 21:01:51 +02:00
using AIStudio.Settings;
2025-05-24 12:27:00 +02:00
using AIStudio.Tools.PluginSystem;
2024-09-08 21:01:51 +02:00
using Microsoft.AspNetCore.Components;
2025-05-25 13:27:22 +02:00
using DialogOptions = AIStudio.Dialogs.DialogOptions;
2024-09-08 21:01:51 +02:00
namespace AIStudio.Components;
2025-04-27 09:06:05 +02:00
public partial class ProfileSelection : MSGComponentBase
2024-09-08 21:01:51 +02:00
{
2025-05-24 19:11:28 +02:00
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ProfileSelection).Namespace, nameof(ProfileSelection));
2025-05-24 12:27:00 +02:00
2024-09-08 21:01:51 +02:00
[Parameter]
2026-09-07 16:09:00 +02:00
public HashSet<string> SelectedProfileIds { get; set; } = [];
2024-09-08 21:01:51 +02:00
[Parameter]
2026-09-07 16:09:00 +02:00
public EventCallback<HashSet<string>> SelectedProfileIdsChanged { get; set; }
2024-09-08 21:01:51 +02:00
[Parameter]
public string MarginLeft { get; set; } = "ml-3";
[Parameter]
public string MarginRight { get; set; } = string.Empty;
2024-09-08 21:01:51 +02:00
2025-05-24 12:27:00 +02:00
[Parameter]
public bool Disabled { get; set; }
[Parameter]
public string DisabledText { get; set; } = string.Empty;
2025-05-25 13:27:22 +02:00
[Inject]
private IDialogService DialogService { get; init; } = null!;
2025-05-24 12:27:00 +02:00
2026-09-07 16:09:00 +02:00
private readonly string defaultToolTipText = TB("You can select your profiles here");
2025-05-24 12:27:00 +02:00
2026-09-07 16:09:00 +02:00
private IReadOnlyList<Profile> SelectedProfiles => this.SettingsManager.ResolveProfiles(this.SelectedProfileIds);
private string SelectionLabel => this.SelectedProfiles.Count switch
{
0 => string.Empty,
1 => this.SelectedProfiles[0].GetSafeName(),
_ => string.Format(TB("{0} profiles"), this.SelectedProfiles.Count),
};
private string ToolTipText => this.Disabled
? this.DisabledText
: this.SelectedProfiles.Count > 1
? string.Join(", ", this.SelectedProfiles.Select(profile => profile.GetSafeName()))
: this.defaultToolTipText;
2025-05-24 12:27:00 +02:00
private string MarginClass => $"{this.MarginLeft} {this.MarginRight}";
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
await base.OnInitializedAsync();
}
#endregion
2026-09-07 16:09:00 +02:00
private string ProfileIcon(Profile profile)
{
if (profile.IsEnterpriseConfiguration)
return Icons.Material.Filled.Business;
2026-09-07 16:09:00 +02:00
return Icons.Material.Filled.Person4;
}
2026-09-07 16:09:00 +02:00
private async Task SelectionChanged(Profile profile, bool selected)
{
var updatedSelection = new HashSet<string>(this.SelectedProfileIds, StringComparer.OrdinalIgnoreCase);
if (selected)
updatedSelection.Add(profile.Id);
else
updatedSelection.Remove(profile.Id);
this.SelectedProfileIds = updatedSelection;
await this.SelectedProfileIdsChanged.InvokeAsync(updatedSelection);
}
private async Task ClearSelection()
2024-09-08 21:01:51 +02:00
{
2026-09-07 16:09:00 +02:00
this.SelectedProfileIds = [];
await this.SelectedProfileIdsChanged.InvokeAsync([]);
2024-09-08 21:01:51 +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);
}
#region Overrides of MSGComponentBase
protected override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
{
if (triggeredEvent is Event.CONFIGURATION_CHANGED or Event.PLUGINS_RELOADED)
this.StateHasChanged();
return Task.CompletedTask;
}
#endregion
2026-09-07 16:09:00 +02:00
}