diff --git a/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor b/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor index 24899fee..dc4f8149 100644 --- a/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor +++ b/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor @@ -1,7 +1,7 @@ @inherits ConfigurationBase - - + + @(this.State() ? this.LabelOn : this.LabelOff) \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor.cs b/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor.cs index 68d5cd4d..874fbd38 100644 --- a/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/ConfigurationOption.razor.cs @@ -1,3 +1,5 @@ +using AIStudio.Tools; + using Microsoft.AspNetCore.Components; namespace AIStudio.Components.Blocks; @@ -5,7 +7,7 @@ namespace AIStudio.Components.Blocks; /// /// Configuration component for any boolean option. /// -public partial class ConfigurationOption : ConfigurationBase +public partial class ConfigurationOption : ConfigurationBase, IMessageBusReceiver { /// /// Text to display when the option is true. @@ -30,6 +32,25 @@ public partial class ConfigurationOption : ConfigurationBase /// [Parameter] public Action StateUpdate { get; set; } = _ => { }; + + /// + /// Is the option disabled? + /// + [Parameter] + public Func Disabled { get; set; } = () => false; + + #region Overrides of ComponentBase + + protected override async Task OnInitializedAsync() + { + // Register this component with the message bus: + this.MessageBus.RegisterComponent(this); + this.MessageBus.ApplyFilters(this, [], [ Event.CONFIGURATION_CHANGED ]); + + await base.OnInitializedAsync(); + } + + #endregion private async Task OptionChanged(bool updatedState) { @@ -37,4 +58,25 @@ public partial class ConfigurationOption : ConfigurationBase await this.SettingsManager.StoreSettings(); await this.InformAboutChange(); } + + #region Implementation of IMessageBusReceiver + + public Task ProcessMessage(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data) + { + switch (triggeredEvent) + { + case Event.CONFIGURATION_CHANGED: + this.StateHasChanged(); + break; + } + + return Task.CompletedTask; + } + + public Task ProcessMessageWithResult(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) + { + return Task.FromResult(default); + } + + #endregion } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor b/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor index 29dccb67..45e64119 100644 --- a/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor +++ b/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor.cs b/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor.cs index 8898c8bb..66a2efdd 100644 --- a/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/ConfigurationProviderSelection.razor.cs @@ -16,6 +16,12 @@ public partial class ConfigurationProviderSelection : ComponentBase, IMessageBus [Parameter] public IEnumerable> Data { get; set; } = new List>(); + /// + /// Is the selection component disabled? + /// + [Parameter] + public Func Disabled { get; set; } = () => false; + [Inject] private SettingsManager SettingsManager { get; init; } = null!; diff --git a/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor b/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor index 3cae9b50..cc9ef065 100644 --- a/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor +++ b/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor @@ -1,7 +1,7 @@ @inherits ConfigurationBase @typeparam T - + @foreach (var data in this.Data) { diff --git a/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor.cs b/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor.cs index 4f0fe496..616a4864 100644 --- a/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/ConfigurationSelect.razor.cs @@ -1,4 +1,5 @@ using AIStudio.Settings; +using AIStudio.Tools; using Microsoft.AspNetCore.Components; @@ -8,7 +9,7 @@ namespace AIStudio.Components.Blocks; /// Configuration component for selecting a value from a list. /// /// The type of the value to select. -public partial class ConfigurationSelect : ConfigurationBase +public partial class ConfigurationSelect : ConfigurationBase, IMessageBusReceiver { /// /// The data to select from. @@ -28,6 +29,25 @@ public partial class ConfigurationSelect : ConfigurationBase [Parameter] public Action SelectionUpdate { get; set; } = _ => { }; + /// + /// Is the selection component disabled? + /// + [Parameter] + public Func Disabled { get; set; } = () => false; + + #region Overrides of ComponentBase + + protected override async Task OnInitializedAsync() + { + // Register this component with the message bus: + this.MessageBus.RegisterComponent(this); + this.MessageBus.ApplyFilters(this, [], [ Event.CONFIGURATION_CHANGED ]); + + await base.OnInitializedAsync(); + } + + #endregion + private async Task OptionChanged(T updatedValue) { this.SelectionUpdate(updatedValue); @@ -36,4 +56,25 @@ public partial class ConfigurationSelect : ConfigurationBase } private static string GetClass => $"{MARGIN_CLASS} rounded-lg"; + + #region Implementation of IMessageBusReceiver + + public Task ProcessMessage(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data) + { + switch (triggeredEvent) + { + case Event.CONFIGURATION_CHANGED: + this.StateHasChanged(); + break; + } + + return Task.CompletedTask; + } + + public Task ProcessMessageWithResult(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) + { + return Task.FromResult(default); + } + + #endregion } \ No newline at end of file