mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-14 12:21:37 +00:00
Moved FileLoading to a static class for DRY principle.
This commit is contained in:
parent
311092ec5e
commit
1b7cdf7bcf
@ -1801,12 +1801,6 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROFILESELECTION::T918741365"] = "You can
|
|||||||
-- Provider
|
-- Provider
|
||||||
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROVIDERSELECTION::T900237532"] = "Provider"
|
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROVIDERSELECTION::T900237532"] = "Provider"
|
||||||
|
|
||||||
-- Pandoc Installation
|
|
||||||
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T185447014"] = "Pandoc Installation"
|
|
||||||
|
|
||||||
-- Pandoc may be required for importing files.
|
|
||||||
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T2596465560"] = "Pandoc may be required for importing files."
|
|
||||||
|
|
||||||
-- Videos are not supported yet
|
-- Videos are not supported yet
|
||||||
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T2928927510"] = "Videos are not supported yet"
|
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READFILECONTENT::T2928927510"] = "Videos are not supported yet"
|
||||||
|
|
||||||
@ -5875,6 +5869,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4174900468"] = "Sources pro
|
|||||||
-- Sources provided by the AI
|
-- Sources provided by the AI
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4261248356"] = "Sources provided by the AI"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4261248356"] = "Sources provided by the AI"
|
||||||
|
|
||||||
|
-- Pandoc Installation
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::USERFILE::T185447014"] = "Pandoc Installation"
|
||||||
|
|
||||||
|
-- Pandoc may be required for importing files.
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::USERFILE::T2596465560"] = "Pandoc may be required for importing files."
|
||||||
|
|
||||||
-- The hostname is not a valid HTTP(S) URL.
|
-- The hostname is not a valid HTTP(S) URL.
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "The hostname is not a valid HTTP(S) URL."
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "The hostname is not a valid HTTP(S) URL."
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,7 @@
|
|||||||
</MudText>
|
</MudText>
|
||||||
@foreach (var fileInfo in this.DocumentPaths.Select(file => new FileInfo(file)))
|
@foreach (var fileInfo in this.DocumentPaths.Select(file => new FileInfo(file)))
|
||||||
{
|
{
|
||||||
<MudBadge Origin="Origin.TopCenter" Icon="@Icons.Material.Filled.Search" Color="Color.Primary" Overlap="true" Bordered="true" OnClick="@(() => this.InvestigateFile(@fileInfo))">
|
<MudChip T="string" Color="Color.Dark" Text="@fileInfo.Name" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(@fileInfo))" OnClose="@(() => this.RemoveDocumentPathFromDocumentPaths(@fileInfo))"/>
|
||||||
<MudChip T="string" Color="Color.Dark" Text="@fileInfo.Name" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(@fileInfo))" OnClose="@(() => this.RemoveDocumentPathFromDocumentPaths(@fileInfo))"/>
|
|
||||||
</MudBadge>
|
|
||||||
}
|
}
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
</MudLink>
|
</MudLink>
|
||||||
|
|||||||
@ -172,14 +172,15 @@ public partial class AttachDocuments : MSGComponentBase
|
|||||||
/// <param name="file">The file to check.</param>
|
/// <param name="file">The file to check.</param>
|
||||||
private async Task InvestigateFile(FileInfo file)
|
private async Task InvestigateFile(FileInfo file)
|
||||||
{
|
{
|
||||||
# warning Implement Investigation of file
|
var dialogParameters = new DialogParameters<PandocDocumentCheckDialog>
|
||||||
|
{
|
||||||
var dialogParameters = new DialogParameters<PandocDocumentCheckDialog>{};
|
{ x => x.FilePath, file.FullName },
|
||||||
|
};
|
||||||
|
|
||||||
var dialogReference = await this.DialogService.ShowAsync<PandocDocumentCheckDialog>(T("Pandoc Load Document Preview"), dialogParameters, DialogOptions.FULLSCREEN);
|
var dialogReference = await this.DialogService.ShowAsync<PandocDocumentCheckDialog>(T("Pandoc Load Document Preview"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
var dialogResult = await dialogReference.Result;
|
var dialogResult = await dialogReference.Result;
|
||||||
if (dialogResult is null || dialogResult.Canceled)
|
//if (dialogResult is null || dialogResult.Canceled)
|
||||||
return;
|
// return;
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,8 +4,6 @@ using AIStudio.Tools.Services;
|
|||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
|
||||||
|
|
||||||
namespace AIStudio.Components;
|
namespace AIStudio.Components;
|
||||||
|
|
||||||
public partial class ReadFileContent : MSGComponentBase
|
public partial class ReadFileContent : MSGComponentBase
|
||||||
@ -56,27 +54,7 @@ public partial class ReadFileContent : MSGComponentBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that Pandoc is installed and ready:
|
var fileContent = await UserFile.LoadFileData(selectedFile.SelectedFilePath, this.RustService, this.DialogService, this.Logger);
|
||||||
var pandocState = await Pandoc.CheckAvailabilityAsync(this.RustService, showSuccessMessage: false);
|
|
||||||
if (!pandocState.IsAvailable)
|
|
||||||
{
|
|
||||||
var dialogParameters = new DialogParameters<PandocDialog>
|
|
||||||
{
|
|
||||||
{ x => x.ShowInitialResultInSnackbar, false },
|
|
||||||
};
|
|
||||||
|
|
||||||
var dialogReference = await this.DialogService.ShowAsync<PandocDialog>(T("Pandoc Installation"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
||||||
await dialogReference.Result;
|
|
||||||
|
|
||||||
pandocState = await Pandoc.CheckAvailabilityAsync(this.RustService, showSuccessMessage: true);
|
|
||||||
if (!pandocState.IsAvailable)
|
|
||||||
{
|
|
||||||
this.Logger.LogError("Pandoc is not available after installation attempt.");
|
|
||||||
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Cancel, T("Pandoc may be required for importing files.")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileContent = await this.RustService.ReadArbitraryFileData(selectedFile.SelectedFilePath, int.MaxValue);
|
|
||||||
await this.FileContentChanged.InvokeAsync(fileContent);
|
await this.FileContentChanged.InvokeAsync(fileContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,14 +6,23 @@
|
|||||||
<PreviewPrototype/>
|
<PreviewPrototype/>
|
||||||
|
|
||||||
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||||
@T("Test how Pandoc loads your document. See the raw content it produces before further processing.")
|
@T("Test how Pandoc loads your file. Check the raw content it produces before further processing.")
|
||||||
</MudJustifiedText>
|
</MudJustifiedText>
|
||||||
|
|
||||||
<ReadFileContent Text="@T("Load document")" @bind-FileContent="@this.documentContent"/>
|
@if (FilePath == string.Empty)
|
||||||
|
{
|
||||||
|
<ReadFileContent Text="@T("Load file")" @bind-FileContent="@this.FileContent"/>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
|
||||||
|
@T("Loaded file path:") @FilePath
|
||||||
|
</MudJustifiedText>
|
||||||
|
}
|
||||||
|
|
||||||
<MudTextField
|
<MudTextField
|
||||||
T="string"
|
T="string"
|
||||||
@bind-Text="@this.documentContent"
|
@bind-Text="@this.FileContent"
|
||||||
AdornmentIcon="@Icons.Material.Filled.Article"
|
AdornmentIcon="@Icons.Material.Filled.Article"
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
Immediate="@true"
|
Immediate="@true"
|
||||||
@ -23,7 +32,7 @@
|
|||||||
AutoGrow="@true"
|
AutoGrow="@true"
|
||||||
MaxLines="25"
|
MaxLines="25"
|
||||||
Class="mt-10"
|
Class="mt-10"
|
||||||
HelperText="@T("This is the content Pandoc loaded from your document — including headings, lists, and formatting. Use this to verify your document loads as expected.")"
|
HelperText="@T("This is the content Pandoc loaded from your file — including headings, lists, and formatting. Use this to verify your file loads as expected.")"
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System.Formats.Asn1;
|
using System.Formats.Asn1;
|
||||||
using AIStudio.Components;
|
using AIStudio.Components;
|
||||||
|
using AIStudio.Tools.Services;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace AIStudio.Dialogs;
|
namespace AIStudio.Dialogs;
|
||||||
@ -13,8 +13,32 @@ public partial class PandocDocumentCheckDialog : MSGComponentBase
|
|||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
private string documentContent = string.Empty;
|
public string FilePath { get; set; } = string.Empty;
|
||||||
|
|
||||||
private void Cancel() => this.MudDialog.Cancel();
|
private void Cancel() => this.MudDialog.Cancel();
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string FileContent { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private RustService RustService { get; init; } = null!;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private IDialogService DialogService { get; init; } = null!;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private ILogger<ReadFileContent> Logger { get; init; } = null!;
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender && !string.IsNullOrEmpty(this.FilePath))
|
||||||
|
{
|
||||||
|
var fileContent = await UserFile.LoadFileData(this.FilePath, this.RustService, this.DialogService, this.Logger);
|
||||||
|
this.FileContent = fileContent;
|
||||||
|
this.StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user