From 4b55421d7448380e8a2016ff4bcf899bcbc4ac95 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 13 Mar 2026 12:29:36 +0100 Subject: [PATCH] OK gestione IMG x template row (prodotto a catalogo) --- .../DbModel/Sales/TemplateRowModel.cs | 2 +- .../Compo/Item/SellingItemEdit.razor | 130 +++++++++--------- .../Compo/Item/SellingItemEdit.razor.cs | 12 +- .../Compo/Templates/TemplateRowList.razor | 8 +- .../Compo/Templates/TemplateRowList.razor.cs | 31 +++++ .../Compo/Templates/TemplateRowMan.razor | 9 ++ .../Compo/Templates/TemplateRowMan.razor.cs | 59 +++++++- 7 files changed, 169 insertions(+), 82 deletions(-) diff --git a/EgwCoreLib.Lux.Data/DbModel/Sales/TemplateRowModel.cs b/EgwCoreLib.Lux.Data/DbModel/Sales/TemplateRowModel.cs index 266c33e..6d59f53 100644 --- a/EgwCoreLib.Lux.Data/DbModel/Sales/TemplateRowModel.cs +++ b/EgwCoreLib.Lux.Data/DbModel/Sales/TemplateRowModel.cs @@ -58,7 +58,7 @@ namespace EgwCoreLib.Lux.Data.DbModel.Sales [NotMapped] public string ImgUID { - get => ImgUrl(TemplateRowID); + get => ImgType == ImageType.Fixed ? FileName : ImgUrl(TemplateRowID); } /// diff --git a/Lux.UI/Components/Compo/Item/SellingItemEdit.razor b/Lux.UI/Components/Compo/Item/SellingItemEdit.razor index 339222f..efb676f 100644 --- a/Lux.UI/Components/Compo/Item/SellingItemEdit.razor +++ b/Lux.UI/Components/Compo/Item/SellingItemEdit.razor @@ -8,8 +8,8 @@ - - - -
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
- -
-
- +
-
- - } - +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+ + } + diff --git a/Lux.UI/Components/Compo/Item/SellingItemEdit.razor.cs b/Lux.UI/Components/Compo/Item/SellingItemEdit.razor.cs index fd90838..76717f7 100644 --- a/Lux.UI/Components/Compo/Item/SellingItemEdit.razor.cs +++ b/Lux.UI/Components/Compo/Item/SellingItemEdit.razor.cs @@ -71,15 +71,8 @@ namespace Lux.UI.Components.Compo.Item return EC_Updated.InvokeAsync(CurrRecord); } - /// - /// Path da parent record - /// - /// - /// - private string FolderPath() - { - return "static"; - } + + private string folderPath = "static"; private async Task UploadFile(InputFileChangeEventArgs e) { @@ -89,7 +82,6 @@ namespace Lux.UI.Components.Compo.Item if (CurrRecord is null) return; - string folderPath = FolderPath(); string extension = Path.GetExtension(file.Name); string newFileName = $"{SellingItemModel.ImgUrl(CurrRecord.SellingItemID)}{extension}"; diff --git a/Lux.UI/Components/Compo/Templates/TemplateRowList.razor b/Lux.UI/Components/Compo/Templates/TemplateRowList.razor index c5bed4f..4572eb0 100644 --- a/Lux.UI/Components/Compo/Templates/TemplateRowList.razor +++ b/Lux.UI/Components/Compo/Templates/TemplateRowList.razor @@ -100,22 +100,22 @@ else { if (item.SellingItemNav?.SourceType == ItemSourceType.Jwd) { - + } else { - + } } else { if (item.SellingItemNav?.SourceType == ItemSourceType.FileBTL) { - + } else { - + } } diff --git a/Lux.UI/Components/Compo/Templates/TemplateRowList.razor.cs b/Lux.UI/Components/Compo/Templates/TemplateRowList.razor.cs index f75e470..f639656 100644 --- a/Lux.UI/Components/Compo/Templates/TemplateRowList.razor.cs +++ b/Lux.UI/Components/Compo/Templates/TemplateRowList.razor.cs @@ -739,6 +739,7 @@ namespace Lux.UI.Components.Compo.Templates return $"TP-{objID:X8}"; } +#if false /// /// Calcolo URL immagine /// @@ -752,6 +753,36 @@ namespace Lux.UI.Components.Compo.Templates Enum.TryParse(env, out envir); return ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, imgUid, envir); } +#endif + + /// + /// Calcolo URL immagine + /// + /// + /// + /// + /// + private string imgUrl(Enums.ImageType tipoImg, string imgUid, string env) + { + string answ = ""; + switch (tipoImg) + { + case Enums.ImageType.ND: + case Enums.ImageType.Calculated: + // cast string su env.. + EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; + Enum.TryParse(env, out envir); + answ = ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, imgUid, envir); + break; + case Enums.ImageType.Fixed: + answ = $"{apiUrl}/{imgBasePath}/static/{imgUid}"; + break; + default: + break; + } + + return answ; + } /// /// Restituisce il contenuto del file salvato diff --git a/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor b/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor index 1954ed7..026b945 100644 --- a/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor +++ b/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor @@ -19,6 +19,15 @@ +
+
+ + +
+
+
+ +
diff --git a/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor.cs b/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor.cs index 7989fef..7dfa7bd 100644 --- a/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor.cs +++ b/Lux.UI/Components/Compo/Templates/TemplateRowMan.razor.cs @@ -1,6 +1,8 @@ using EgwCoreLib.Lux.Data.DbModel.Items; using EgwCoreLib.Lux.Data.DbModel.Sales; +using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; namespace Lux.UI.Components.Compo.Templates { @@ -20,17 +22,35 @@ namespace Lux.UI.Components.Compo.Templates [Parameter] public EventCallback EC_Close { get; set; } - [Parameter] - public List ListSellinglItems { get; set; } = null!; - /// /// Callback invocato al salvataggio con record aggiornato /// [Parameter] public EventCallback EC_Updated { get; set; } + [Parameter] + public List ListSellinglItems { get; set; } = null!; + #endregion Public Properties + #region Private Fields + + /// + /// Path da parent record + /// + /// + /// + private string folderPath = "static"; + + #endregion Private Fields + + #region Private Properties + + [Inject] + private FileService FService { get; set; } = null!; + + #endregion Private Properties + #region Private Methods private Task DoCancel() @@ -38,12 +58,43 @@ namespace Lux.UI.Components.Compo.Templates return EC_Close.InvokeAsync(true); } + private Task DoClearImg() + { + CurrRecord.ImgType = EgwCoreLib.Lux.Core.Enums.ImageType.ND; + CurrRecord.FileName = ""; + return EC_Updated.InvokeAsync(CurrRecord); + } + private Task DoSave() { // richiesta update con salvataggio record return EC_Updated.InvokeAsync(CurrRecord); } + private async Task UploadFile(InputFileChangeEventArgs e) + { + IBrowserFile file = e.File; + var maxAllowedSize = 10 * 1024 * 1024; + + if (CurrRecord is null) + return; + + string extension = Path.GetExtension(file.Name); + string newFileName = $"{TemplateRowModel.ImgUrl(CurrRecord.TemplateRowID)}{extension}"; + + // elimino vecchio file + FService.DeleteOldFile(folderPath, CurrRecord.FileName); + + // salvo nuovo file (stream → file) + using var stream = file.OpenReadStream(maxAllowedSize); + await FService.SaveFileStreamAsync(folderPath, newFileName, stream); + + CurrRecord.ImgType = EgwCoreLib.Lux.Core.Enums.ImageType.Fixed; + CurrRecord.FileName = newFileName; + + await EC_Updated.InvokeAsync(CurrRecord); + } + #endregion Private Methods } -} +} \ No newline at end of file