mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-21 04:12:56 +00:00
Add ManagePandocDependency component
This commit is contained in:
parent
f16594f7eb
commit
ebc8c2b12a
@ -0,0 +1,10 @@
|
|||||||
|
@inherits MSGComponentBase
|
||||||
|
|
||||||
|
<MudStack Row="false" Class="mb-3 pa-3 border-dashed border rounded-lg">
|
||||||
|
<MudJustifiedText Typo="Typo.body1">
|
||||||
|
@this.DetermineIntroText()
|
||||||
|
</MudJustifiedText>
|
||||||
|
<MudButton Color="Color.Default" Variant="Variant.Filled" OnClick="() => this.ShowPandocDialogAsync()">
|
||||||
|
@this.DetermineButtonText()
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
@ -0,0 +1,79 @@
|
|||||||
|
using AIStudio.Dialogs;
|
||||||
|
using AIStudio.Tools.Services;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
||||||
|
|
||||||
|
namespace AIStudio.Components;
|
||||||
|
|
||||||
|
public partial class ManagePandocDependency : MSGComponentBase
|
||||||
|
{
|
||||||
|
[Parameter]
|
||||||
|
public string IntroText { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private IDialogService DialogService { get; init; } = null!;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private RustService RustService { get; init; } = null!;
|
||||||
|
|
||||||
|
private PandocInstallation pandocInstallation;
|
||||||
|
|
||||||
|
#region Overrides of MSGComponentBase
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private string DetermineButtonText()
|
||||||
|
{
|
||||||
|
if(this.pandocInstallation == default)
|
||||||
|
return T("Please wait while we check the availability of Pandoc.");
|
||||||
|
|
||||||
|
switch (this.pandocInstallation)
|
||||||
|
{
|
||||||
|
case { CheckWasSuccessful: true, IsAvailable: true }:
|
||||||
|
return T("Check your Pandoc installation");
|
||||||
|
|
||||||
|
case { CheckWasSuccessful: true, IsAvailable: false }:
|
||||||
|
return T("Update Pandoc");
|
||||||
|
|
||||||
|
case { CheckWasSuccessful: false }:
|
||||||
|
return T("Install Pandoc");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string DetermineIntroText()
|
||||||
|
{
|
||||||
|
if (this.pandocInstallation == default)
|
||||||
|
return $"{this.IntroText} {T("Please wait while we check the availability of Pandoc.")}";
|
||||||
|
|
||||||
|
switch (this.pandocInstallation)
|
||||||
|
{
|
||||||
|
case { CheckWasSuccessful: true, IsAvailable: true }:
|
||||||
|
return $"{this.IntroText} {T("Your Pandoc installation meets the requirements.")}";
|
||||||
|
|
||||||
|
case { CheckWasSuccessful: true, IsAvailable: false }:
|
||||||
|
return $"{this.IntroText} {T("Your Pandoc installation is outdated. Please update it to the latest version to ensure compatibility with all features.")}";
|
||||||
|
|
||||||
|
case { CheckWasSuccessful: false }:
|
||||||
|
return $"{this.IntroText} {T("Pandoc is not installed or not available. Please install it to use the features that require Pandoc.")}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowPandocDialogAsync()
|
||||||
|
{
|
||||||
|
var dialogReference = await this.DialogService.ShowAsync<PandocDialog>(T("Pandoc Installation"), DialogOptions.FULLSCREEN);
|
||||||
|
await dialogReference.Result;
|
||||||
|
|
||||||
|
// Refresh the availability of Pandoc after the dialog is closed:
|
||||||
|
this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false);
|
||||||
|
|
||||||
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user