mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-07-27 21:42:56 +00:00
Created custom CopyToClipboard button and made refinements
This commit is contained in:
parent
739bdb1068
commit
7f367d83aa
@ -0,0 +1,5 @@
|
||||
<MudTooltip Text=@ToolTipMessage>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy"
|
||||
Size="Size.Small"
|
||||
OnClick="@(() => CopyToClipboard(this.CopyableContent))"/>
|
||||
</MudTooltip>
|
@ -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));
|
||||
|
||||
/// <summary>
|
||||
/// The string that will be copied when the button is clicked.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public required string CopyableContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The tooltip that should be shown to the user.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
@attribute [Route(Routes.ABOUT)]
|
||||
@using AIStudio.Tools.PluginSystem
|
||||
@using AIStudio.Tools.Services
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<div class="inner-scrolling-context">
|
||||
@ -26,57 +24,50 @@
|
||||
<MudListItem T="string" Icon="@Icons.Material.Outlined.Memory" Text="@TauriVersion"/>
|
||||
<MudListItem T="string" Icon="@Icons.Material.Outlined.Translate" Text="@this.OSLanguage"/>
|
||||
<MudListItem T="string" Icon="@Icons.Material.Outlined.Business">
|
||||
@{
|
||||
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)
|
||||
{
|
||||
<MudText>@T("AI Studio runs without an enterprise configuration.")</MudText>
|
||||
case false when configPlug is null:
|
||||
<MudText>@T("AI Studio runs without an enterprise configuration.")</MudText>
|
||||
break;
|
||||
case false:
|
||||
<MudText>@T("AI Studio runs with an enterprise configuration using the configuration plugin, without central configuration management.")</MudText>
|
||||
<MudCollapse Expanded="@showConfigDetails">
|
||||
<MudText>@T("Configuration Plugin ID:") @configPlug!.Id
|
||||
<MudCopyClipboardButton CopyableContent=@configPlug!.Id.ToString()/>
|
||||
</MudText>
|
||||
</MudCollapse>
|
||||
break;
|
||||
case true when configPlug is null:
|
||||
<MudText>@T("AI Studio runs with an enterprise configuration and a configuration server. The configuration plugin is not yet available.")</MudText>
|
||||
<MudCollapse Expanded="@showConfigDetails">
|
||||
<MudText>@T("Configuration Plugin ID:") @currentEnvironment.ConfigurationId
|
||||
<MudCopyClipboardButton ToolTipMessage="@T("Copies the config ID to the clipboard")" CopyableContent=@currentEnvironment.ConfigurationId.ToString()/>
|
||||
</MudText>
|
||||
|
||||
<MudText>@T("Configuration Server:") @currentEnvironment.ConfigurationServerUrl
|
||||
<MudCopyClipboardButton ToolTipMessage="@T("Copies the server URL to the clipboard")" CopyableContent=@currentEnvironment.ConfigurationServerUrl/>
|
||||
</MudText>
|
||||
</MudCollapse>
|
||||
break;
|
||||
case true:
|
||||
<MudText>@T("AI Studio runs with an enterprise configuration and a configuration server. The configuration plugin is active.")</MudText>
|
||||
<MudCollapse Expanded="@showConfigDetails">
|
||||
<MudText Class="ml-4">@T("Configuration Plugin ID:") @currentEnvironment.ConfigurationId
|
||||
<MudCopyClipboardButton ToolTipMessage="@T("Copies the config ID to the clipboard")" CopyableContent=@currentEnvironment.ConfigurationId.ToString()/>
|
||||
</MudText>
|
||||
|
||||
<MudText Class="ml-4">@T("Configuration Server:") @currentEnvironment.ConfigurationServerUrl
|
||||
<MudCopyClipboardButton ToolTipMessage="@T("Copies the server URL to the clipboard")" CopyableContent=@currentEnvironment.ConfigurationServerUrl/>
|
||||
</MudText>
|
||||
</MudCollapse>
|
||||
break;
|
||||
}
|
||||
else if (!currentEnvironment.IsActive)
|
||||
{
|
||||
<MudText>@T("AI Studio runs with an enterprise configuration using the configuration plugin.")</MudText>
|
||||
<MudCollapse Expanded="@showConfigDetails">
|
||||
<MudText Typo="Typo.caption" Class="mt-2">Plugin ID: @configPlug!.Id</MudText>
|
||||
</MudCollapse>
|
||||
}
|
||||
else if (currentEnvironment.IsActive && configPlug is null)
|
||||
{
|
||||
<MudText>@T("AI Studio runs with an enterprise configuration. The configuration plugin is not yet available.")</MudText>
|
||||
<MudCollapse Expanded="@showConfigDetails">
|
||||
<MudText Typo="Typo.caption">Config ID: @currentEnvironment.ConfigurationId</MudText>
|
||||
<MudText Typo="Typo.caption">Server URL: @currentEnvironment.ConfigurationServerUrl</MudText>
|
||||
</MudCollapse>
|
||||
}
|
||||
else if (currentEnvironment.IsActive)
|
||||
{
|
||||
<MudText>@T("AI Studio runs with an enterprise configuration. The configuration plugin is active.")</MudText>
|
||||
<MudCollapse Expanded="@showConfigDetails">
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudText Typo="Typo.caption">Config ID: @currentEnvironment.ConfigurationId</MudText>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy"
|
||||
Size="Size.Small"
|
||||
OnClick="@(() => CopyToClipboard(currentEnvironment.ConfigurationId.ToString()))"
|
||||
Title="Copy Config ID" />
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudText Typo="Typo.caption">Server URL: @currentEnvironment.ConfigurationServerUrl</MudText>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy"
|
||||
Size="Size.Small"
|
||||
OnClick="@(() => CopyToClipboard(currentEnvironment.ConfigurationServerUrl))"
|
||||
Title="Copy Server URL" />
|
||||
</div>
|
||||
</MudCollapse>
|
||||
}
|
||||
|
||||
<MudButton StartIcon="@(showConfigDetails ? Icons.Material.Filled.ExpandLess : Icons.Material.Filled.ExpandMore)"
|
||||
Size="Size.Small"
|
||||
Variant="Variant.Text"
|
||||
Class="mt-1"
|
||||
OnClick="@this.ToggleConfigDetails">
|
||||
@(showConfigDetails ? "Hide Details" : "Show Details")
|
||||
|
||||
<MudButton StartIcon="@(showConfigDetails ? Icons.Material.Filled.ExpandLess : Icons.Material.Filled.ExpandMore)"
|
||||
Size="Size.Small"
|
||||
Variant="Variant.Text"
|
||||
OnClick="@this.ToggleEnterpriseConfigDetails">
|
||||
@(showConfigDetails ? @T("Hide Details") : @T("Show Details"))
|
||||
</MudButton>
|
||||
</MudListItem>
|
||||
</MudList>
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user