From 7f367d83aa782a3761f5deffdb59f88293edc967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peer=20Sch=C3=BCtt?= <20603780+peerschuett@users.noreply.github.com> Date: Thu, 24 Jul 2025 15:10:11 +0200 Subject: [PATCH] Created custom CopyToClipboard button and made refinements --- .../Components/MudCopyClipboardButton.razor | 5 + .../MudCopyClipboardButton.razor.cs | 42 +++++++++ app/MindWork AI Studio/Pages/About.razor | 93 +++++++++---------- app/MindWork AI Studio/Pages/About.razor.cs | 50 +++------- 4 files changed, 100 insertions(+), 90 deletions(-) create mode 100644 app/MindWork AI Studio/Components/MudCopyClipboardButton.razor create mode 100644 app/MindWork AI Studio/Components/MudCopyClipboardButton.razor.cs diff --git a/app/MindWork AI Studio/Components/MudCopyClipboardButton.razor b/app/MindWork AI Studio/Components/MudCopyClipboardButton.razor new file mode 100644 index 00000000..6f12d927 --- /dev/null +++ b/app/MindWork AI Studio/Components/MudCopyClipboardButton.razor @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/MudCopyClipboardButton.razor.cs b/app/MindWork AI Studio/Components/MudCopyClipboardButton.razor.cs new file mode 100644 index 00000000..91a3bc0b --- /dev/null +++ b/app/MindWork AI Studio/Components/MudCopyClipboardButton.razor.cs @@ -0,0 +1,42 @@ +using AIStudio.Pages; +using AIStudio.Tools.PluginSystem; +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +public partial class MudCopyClipboardButton : ComponentBase +{ + private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(About).Namespace, nameof(About)); + + /// + /// The string that will be copied when the button is clicked. + /// + [Parameter] + public required string CopyableContent { get; set; } + + /// + /// The tooltip that should be shown to the user. + /// + [Parameter] + public string ToolTipMessage { get; set; } = TB("Copies the content to the clipboard"); + + [Inject] + private IJSRuntime JsRuntime { get; set; } = null!; + + [Inject] + private ISnackbar Snackbar { get; init; } = null!; + + private async Task CopyToClipboard(string text) + { + try + { + await this.JsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text); + this.Snackbar.Add(TB("Successfully copied the content to your clipboard"), Severity.Success); + } + catch (Exception) + { + this.Snackbar.Add(TB("Failed to copy the content to your clipboard"), Severity.Error); + } + } + +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Pages/About.razor b/app/MindWork AI Studio/Pages/About.razor index fee1a535..97ec88f4 100644 --- a/app/MindWork AI Studio/Pages/About.razor +++ b/app/MindWork AI Studio/Pages/About.razor @@ -1,6 +1,4 @@ @attribute [Route(Routes.ABOUT)] -@using AIStudio.Tools.PluginSystem -@using AIStudio.Tools.Services @inherits MSGComponentBase
@@ -26,57 +24,50 @@ - @{ - var configPlug = PluginFactory.AvailablePlugins.FirstOrDefault(x => x.Type is PluginType.CONFIGURATION); - var currentEnvironment = EnterpriseEnvironmentService.CURRENT_ENVIRONMENT; - } - - @if (!currentEnvironment.IsActive && configPlug is null) + @switch (currentEnvironment.IsActive) { - @T("AI Studio runs without an enterprise configuration.") + case false when configPlug is null: + @T("AI Studio runs without an enterprise configuration.") + break; + case false: + @T("AI Studio runs with an enterprise configuration using the configuration plugin, without central configuration management.") + + @T("Configuration Plugin ID:") @configPlug!.Id + + + + break; + case true when configPlug is null: + @T("AI Studio runs with an enterprise configuration and a configuration server. The configuration plugin is not yet available.") + + @T("Configuration Plugin ID:") @currentEnvironment.ConfigurationId + + + + @T("Configuration Server:") @currentEnvironment.ConfigurationServerUrl + + + + break; + case true: + @T("AI Studio runs with an enterprise configuration and a configuration server. The configuration plugin is active.") + + @T("Configuration Plugin ID:") @currentEnvironment.ConfigurationId + + + + @T("Configuration Server:") @currentEnvironment.ConfigurationServerUrl + + + + break; } - else if (!currentEnvironment.IsActive) - { - @T("AI Studio runs with an enterprise configuration using the configuration plugin.") - - Plugin ID: @configPlug!.Id - - } - else if (currentEnvironment.IsActive && configPlug is null) - { - @T("AI Studio runs with an enterprise configuration. The configuration plugin is not yet available.") - - Config ID: @currentEnvironment.ConfigurationId - Server URL: @currentEnvironment.ConfigurationServerUrl - - } - else if (currentEnvironment.IsActive) - { - @T("AI Studio runs with an enterprise configuration. The configuration plugin is active.") - -
- Config ID: @currentEnvironment.ConfigurationId - -
-
- Server URL: @currentEnvironment.ConfigurationServerUrl - -
-
- } - - - @(showConfigDetails ? "Hide Details" : "Show Details") + + + @(showConfigDetails ? @T("Hide Details") : @T("Show Details"))
diff --git a/app/MindWork AI Studio/Pages/About.razor.cs b/app/MindWork AI Studio/Pages/About.razor.cs index 38526e8f..0d48690f 100644 --- a/app/MindWork AI Studio/Pages/About.razor.cs +++ b/app/MindWork AI Studio/Pages/About.razor.cs @@ -58,6 +58,12 @@ public partial class About : MSGComponentBase private GetLogPathsResponse logPaths; + private bool showConfigDetails = false; + + private IPluginMetadata? configPlug = PluginFactory.AvailablePlugins.FirstOrDefault(x => x.Type is PluginType.CONFIGURATION); + + private EnterpriseEnvironment currentEnvironment = EnterpriseEnvironmentService.CURRENT_ENVIRONMENT; + #region Overrides of ComponentBase protected override async Task OnInitializedAsync() @@ -119,49 +125,15 @@ public partial class About : MSGComponentBase await dialogReference.Result; await this.DeterminePandocVersion(); } - - private bool showConfigDetails = false; - private void ToggleConfigDetails() + private void ToggleEnterpriseConfigDetails() { + // can configPlug and currentEnvironment change? + this.configPlug = PluginFactory.AvailablePlugins.FirstOrDefault(x => x.Type is PluginType.CONFIGURATION); + this.currentEnvironment = EnterpriseEnvironmentService.CURRENT_ENVIRONMENT; + this.showConfigDetails = !this.showConfigDetails; } - - [Inject] private IJSRuntime JSRuntime { get; set; } = default!; - - private async Task CopyToClipboard(string text) - { - try - { - await this.JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text); - this.Snackbar.Add("Copied to clipboard!", Severity.Success); - } - catch (Exception) - { - this.Snackbar.Add("Failed to copy to clipboard", Severity.Error); - } - } - - private string GetEnterpriseEnvironment() - { - var configPlug = PluginFactory.AvailablePlugins.FirstOrDefault(x => x.Type is PluginType.CONFIGURATION); - var currentEnvironment = EnterpriseEnvironmentService.CURRENT_ENVIRONMENT; - - switch (currentEnvironment) - { - case { IsActive: false } when configPlug is null: - return T("AI Studio runs without an enterprise configuration."); - - case { IsActive: false }: - return string.Format(T("AI Studio runs with an enterprise configuration using the configuration plugin '{0}', without central configuration management."), configPlug.Id); - - case { IsActive: true } when configPlug is null: - return string.Format(T("AI Studio runs with an enterprise configuration id '{0}' and configuration server URL '{1}'. The configuration plugin is not yet available."), currentEnvironment.ConfigurationId, currentEnvironment.ConfigurationServerUrl); - - case { IsActive: true }: - return string.Format(T("AI Studio runs with an enterprise configuration id '{0}' and configuration server URL '{1}'. The configuration plugin is active."), currentEnvironment.ConfigurationId, currentEnvironment.ConfigurationServerUrl); - } - } private async Task CopyStartupLogPath() {