From 328f906a3040463986c083a7a1b5e20707bbe764 Mon Sep 17 00:00:00 2001 From: Loretta Date: Sat, 24 Jan 2026 10:19:36 +0100 Subject: [PATCH] Add FileSubPath to Files; improve PDF rendering logic Added FileSubPath property to Files entity and IFiles interface for sub-path storage. Updated IFiles to include FileHash and IsCompressed. Refactored GridShippingDocumentInfoPanel.razor to select and render PDFs only when associated files exist, with improved type checks and null handling. Performed minor code cleanup. --- FruitBank.Common/Entities/Files.cs | 1 + FruitBank.Common/Interfaces/IFiles.cs | 3 +++ .../GridShippingDocumentInfoPanel.razor | 26 +++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/FruitBank.Common/Entities/Files.cs b/FruitBank.Common/Entities/Files.cs index aef8544..bae6a05 100644 --- a/FruitBank.Common/Entities/Files.cs +++ b/FruitBank.Common/Entities/Files.cs @@ -9,6 +9,7 @@ namespace FruitBank.Common.Entities; public class Files : MgEntityBase, IFiles { public string FileName { get; set; } + public string FileSubPath { get; set; } public string FileExtension { get; set; } public string RawText { get; set; } public string FileHash { get; set; } diff --git a/FruitBank.Common/Interfaces/IFiles.cs b/FruitBank.Common/Interfaces/IFiles.cs index 9ff7cfc..cd3329f 100644 --- a/FruitBank.Common/Interfaces/IFiles.cs +++ b/FruitBank.Common/Interfaces/IFiles.cs @@ -6,6 +6,9 @@ namespace FruitBank.Common.Interfaces; public interface IFiles: IEntityInt, ITimeStampInfo { public string FileName { get; set; } + public string FileSubPath { get; set; } public string FileExtension { get; set; } public string RawText { get; set; } + public string FileHash { get; set; } + public bool IsCompressed { get; set; } } \ No newline at end of file diff --git a/FruitBankHybrid.Shared/Components/Grids/ShippingDocuments/GridShippingDocumentInfoPanel.razor b/FruitBankHybrid.Shared/Components/Grids/ShippingDocuments/GridShippingDocumentInfoPanel.razor index 9a0cc4d..b20b4ea 100644 --- a/FruitBankHybrid.Shared/Components/Grids/ShippingDocuments/GridShippingDocumentInfoPanel.razor +++ b/FruitBankHybrid.Shared/Components/Grids/ShippingDocuments/GridShippingDocumentInfoPanel.razor @@ -94,7 +94,7 @@ { private readonly string[] _pdfFiles = [ - "1_Albaran_AH25007715.pdf", + "1_Albaran_AH25007715.pdf", "2_BANK FRA.pdf", "3_BP-30M35_20251113_163816.pdf" ]; @@ -110,16 +110,26 @@ private async Task OnDataItemChangedAsync(object? dataItem) { - @if (dataItem is not ShippingDocument && dataItem is not ShippingItem) return; + if (dataItem is not ShippingDocument && dataItem is not ShippingItem) return; - // Store the PDF to render - _randomPdf = _pdfFiles[Random.Shared.Next(_pdfFiles.Length)]; - _currentPdfToRender = $"_content/FruitBankHybrid.Shared/uploads/{_randomPdf}"; + ShippingDocument? shippingDocument = null; + + if (dataItem is ShippingItem shippingItem) shippingDocument = shippingItem.ShippingDocument; + else shippingDocument = dataItem as ShippingDocument; - // If MgLazyLoadContent is already visible, render the PDF immediately - if (_lazyContentRef is { IsVisible: true }) + if (shippingDocument == null) return; + + if (shippingDocument.ShippingDocumentToFiles?.Count > 0) { - await _lazyContentRef.TriggerContentVisibleAsync(); + // Store the PDF to render + _randomPdf = _pdfFiles[Random.Shared.Next(_pdfFiles.Length)]; + _currentPdfToRender = $"_content/FruitBankHybrid.Shared/uploads/{_randomPdf}"; + + // If MgLazyLoadContent is already visible, render the PDF immediately + if (_lazyContentRef is { IsVisible: true }) + { + await _lazyContentRef.TriggerContentVisibleAsync(); + } } }