From 1b7cdf7bcfe607d54708cce52627727cb71a6f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peer=20Sch=C3=BCtt?= <20603780+peerschuett@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:06:32 +0100 Subject: [PATCH] Moved FileLoading to a static class for DRY principle. --- .../Assistants/I18N/allTexts.lua | 12 ++++---- .../Components/AttachDocuments.razor | 4 +-- .../Components/AttachDocuments.razor.cs | 13 ++++---- .../Components/ReadFileContent.razor.cs | 24 +-------------- .../Dialogs/PandocDocumentCheckDialog.razor | 21 +++++++++---- .../PandocDocumentCheckDialog.razor.cs | 30 +++++++++++++++++-- 6 files changed, 57 insertions(+), 47 deletions(-) diff --git a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua index c2b1cc0b..ca35e5fa 100644 --- a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua +++ b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua @@ -1801,12 +1801,6 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::PROFILESELECTION::T918741365"] = "You can -- 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 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 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. UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "The hostname is not a valid HTTP(S) URL." diff --git a/app/MindWork AI Studio/Components/AttachDocuments.razor b/app/MindWork AI Studio/Components/AttachDocuments.razor index aa89ebe3..f0ef8d13 100644 --- a/app/MindWork AI Studio/Components/AttachDocuments.razor +++ b/app/MindWork AI Studio/Components/AttachDocuments.razor @@ -8,9 +8,7 @@ @foreach (var fileInfo in this.DocumentPaths.Select(file => new FileInfo(file))) { - - - + } diff --git a/app/MindWork AI Studio/Components/AttachDocuments.razor.cs b/app/MindWork AI Studio/Components/AttachDocuments.razor.cs index 7b885842..1ee3c7bb 100644 --- a/app/MindWork AI Studio/Components/AttachDocuments.razor.cs +++ b/app/MindWork AI Studio/Components/AttachDocuments.razor.cs @@ -172,14 +172,15 @@ public partial class AttachDocuments : MSGComponentBase /// The file to check. private async Task InvestigateFile(FileInfo file) { - # warning Implement Investigation of file - - var dialogParameters = new DialogParameters{}; + var dialogParameters = new DialogParameters + { + { x => x.FilePath, file.FullName }, + }; var dialogReference = await this.DialogService.ShowAsync(T("Pandoc Load Document Preview"), dialogParameters, DialogOptions.FULLSCREEN); var dialogResult = await dialogReference.Result; - if (dialogResult is null || dialogResult.Canceled) - return; - return; + //if (dialogResult is null || dialogResult.Canceled) + // return; + //return; } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs index c4019fa2..c9f1c3b6 100644 --- a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs +++ b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs @@ -4,8 +4,6 @@ using AIStudio.Tools.Services; using Microsoft.AspNetCore.Components; -using DialogOptions = AIStudio.Dialogs.DialogOptions; - namespace AIStudio.Components; public partial class ReadFileContent : MSGComponentBase @@ -56,27 +54,7 @@ public partial class ReadFileContent : MSGComponentBase return; } - // Ensure that Pandoc is installed and ready: - var pandocState = await Pandoc.CheckAvailabilityAsync(this.RustService, showSuccessMessage: false); - if (!pandocState.IsAvailable) - { - var dialogParameters = new DialogParameters - { - { x => x.ShowInitialResultInSnackbar, false }, - }; - - var dialogReference = await this.DialogService.ShowAsync(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); + var fileContent = await UserFile.LoadFileData(selectedFile.SelectedFilePath, this.RustService, this.DialogService, this.Logger); await this.FileContentChanged.InvokeAsync(fileContent); } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor b/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor index 50e81235..f1d4d04e 100644 --- a/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor +++ b/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor @@ -6,14 +6,23 @@ - @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.") - - - + + @if (FilePath == string.Empty) + { + + } + else + { + + @T("Loaded file path:") @FilePath + + } + diff --git a/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor.cs b/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor.cs index 361342d4..49f0e567 100644 --- a/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/PandocDocumentCheckDialog.razor.cs @@ -1,6 +1,6 @@ using System.Formats.Asn1; using AIStudio.Components; - +using AIStudio.Tools.Services; using Microsoft.AspNetCore.Components; namespace AIStudio.Dialogs; @@ -12,9 +12,33 @@ public partial class PandocDocumentCheckDialog : MSGComponentBase { [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!; - - private string documentContent = string.Empty; + [Parameter] + public string FilePath { get; set; } = string.Empty; 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 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(); + } + } + } \ No newline at end of file