using Microsoft.AspNetCore.Components; namespace AIStudio.Components; /// /// A base class for configuration options. /// public partial class ConfigurationBase : MSGComponentBase { /// /// The description of the option, i.e., the name. Should be /// as short as possible. /// [Parameter] public string OptionDescription { get; set; } = string.Empty; /// /// A helpful text that explains the option in more detail. /// [Parameter] public string OptionHelp { get; set; } = string.Empty; /// /// Is the option disabled? /// [Parameter] public Func Disabled { get; set; } = () => false; /// /// Is the option locked by a configuration plugin? /// [Parameter] public Func IsLocked { get; set; } = () => false; protected bool IsDisabled => this.Disabled() || this.IsLocked(); private protected virtual RenderFragment? Body => null; protected const string MARGIN_CLASS = "mb-6"; protected static readonly Dictionary SPELLCHECK_ATTRIBUTES = new(); #region Overrides of ComponentBase protected override async Task OnInitializedAsync() { this.SettingsManager.InjectSpellchecking(SPELLCHECK_ATTRIBUTES); this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]); await base.OnInitializedAsync(); } #endregion private string TB(string fallbackEN) => this.T(fallbackEN, typeof(ConfigurationBase).Namespace, nameof(ConfigurationBase)); protected async Task InformAboutChange() => await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); #region Overrides of MSGComponentBase protected override Task ProcessIncomingMessage(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default { switch (triggeredEvent) { case Event.CONFIGURATION_CHANGED: this.StateHasChanged(); break; } return Task.CompletedTask; } #endregion }