OK gestione IMG x template row (prodotto a catalogo)

This commit is contained in:
Samuele Locatelli
2026-03-13 12:29:36 +01:00
parent 5d072b15a2
commit 4b55421d74
7 changed files with 169 additions and 82 deletions
@@ -58,7 +58,7 @@ namespace EgwCoreLib.Lux.Data.DbModel.Sales
[NotMapped]
public string ImgUID
{
get => ImgUrl(TemplateRowID);
get => ImgType == ImageType.Fixed ? FileName : ImgUrl(TemplateRowID);
}
/// <summary>
@@ -8,8 +8,8 @@
<select @bind="@CurrRecord.Envir" class="form-select">
<option value="NULL">--- Sel. Envir ---</option>
@foreach (var item in Enum.GetValues(typeof(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS))
.Cast<EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS>()
.Where(e => Convert.ToInt32(e) != 0))
.Cast<EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS>()
.Where(e => Convert.ToInt32(e) != 0))
{
<option value="@item">@item</option>
}
@@ -41,66 +41,70 @@
<div class="col-md-2">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.ExtItemCode" disabled="@CurrRecord.IsProtected">
<label class="small bg-opacity-50">ItemCode</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.SupplCode" disabled="@CurrRecord.IsProtected">
<label class="small bg-opacity-50">Suppl.Code</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<InputDouble CssClass="form-control form-control-lg text-end" Decimals="2" Step="0.05" @bind-Value="@CurrRecord.Cost"></InputDouble>
<label class="small bg-opacity-50">Costo</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<InputPercent CssClass="form-control form-control-lg text-end" ForceInvariantParsing="true" Decimals="1" @bind-Value="@MarginDec"></InputPercent>
<label class="small bg-opacity-50">Margine</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<input type="text" class="form-control text-end" @bind="@CurrRecord.UM">
<label class="small bg-opacity-50">UM</label>
</div>
</div>
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Description" disabled="@CurrRecord.IsProtected">
<label class="small bg-opacity-50">Descrizione</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<InputFile class="form-control" OnChange="UploadFile" style="min-width: 24rem;" />
<label class="small bg-opacity-50">Descrizione</label>
</div>
</div>
<div class="col-md-3">
<div class="form-floating">
<select @bind="@CurrRecord.JobID" class="form-select" disabled="@CurrRecord.IsProtected">
@foreach (var jType in ListJobTask)
{
<option value="@jType.JobID">@jType.Description</option>
}
</select>
<label class="small bg-opacity-50">Job Task</label>
</div>
</div>
<div class="col-md-3">
<div class="row g-1 py-1">
<div class="col-md-6">
<button class="btn btn-lg btn-success w-100" @onclick="DoSave">Save</button>
</div>
<div class="col-md-6">
<button class="btn btn-lg btn-warning w-100" @onclick="DoCancel">Cancel</button>
<label class="small bg-opacity-50">ItemCode</label>
</div>
</div>
</div>
</div>
}
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.SupplCode" disabled="@CurrRecord.IsProtected">
<label class="small bg-opacity-50">Suppl.Code</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<InputDouble CssClass="form-control form-control-lg text-end" Decimals="2" Step="0.05" @bind-Value="@CurrRecord.Cost"></InputDouble>
<label class="small bg-opacity-50">Costo</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<InputPercent CssClass="form-control form-control-lg text-end" ForceInvariantParsing="true" Decimals="1" @bind-Value="@MarginDec"></InputPercent>
<label class="small bg-opacity-50">Margine</label>
</div>
</div>
<div class="col-md-1">
<div class="form-floating">
<input type="text" class="form-control text-end" @bind="@CurrRecord.UM">
<label class="small bg-opacity-50">UM</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Description" disabled="@CurrRecord.IsProtected">
<label class="small bg-opacity-50">Descrizione</label>
</div>
</div>
<div class="col-md-3">
<div class="form-floating">
<select @bind="@CurrRecord.JobID" class="form-select" disabled="@CurrRecord.IsProtected">
@foreach (var jType in ListJobTask)
{
<option value="@jType.JobID">@jType.Description</option>
}
</select>
<label class="small bg-opacity-50">Job Task</label>
</div>
</div>
<div class="col-md-3">
<div class="form-floating">
<InputFile class="form-control" OnChange="UploadFile" />
<label class="small bg-opacity-50">Carica Immagine</label>
</div>
</div>
<div class="col-md-3">
</div>
<div class="col-md-6">
<div class="row g-1 py-1">
<div class="col-md-6">
<button class="btn btn-lg btn-success w-100" @onclick="DoSave">Save</button>
</div>
<div class="col-md-6">
<button class="btn btn-lg btn-warning w-100" @onclick="DoCancel">Cancel</button>
</div>
</div>
</div>
<div class="col-md-3">
</div>
</div>
}
</div>
@@ -71,15 +71,8 @@ namespace Lux.UI.Components.Compo.Item
return EC_Updated.InvokeAsync(CurrRecord);
}
/// <summary>
/// Path da parent record
/// </summary>
/// <param name="objID"></param>
/// <returns></returns>
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}";
@@ -100,22 +100,22 @@ else
{
if (item.SellingItemNav?.SourceType == ItemSourceType.Jwd)
{
<img class="img-fluid image-hover-pop p-1" src="@(imgUrl(item.TemplateRowUID, $"{item.Envir}"))" width="64" @onclick="() => DoEditJwd(item)" title="Edit Item" />
<img class="img-fluid image-hover-pop p-1" src="@(imgUrl(item.ImgType, item.TemplateRowUID, $"{item.Envir}"))" width="64" @onclick="() => DoEditJwd(item)" title="Edit Item" />
}
else
{
<img class="img-fluid p-1" src="@(imgUrl(item.TemplateRowUID, $"{item.Envir}"))" width="64" title="No Edit" />
<img class="img-fluid p-1" src="@(imgUrl(item.ImgType, item.ImgUID, $"{item.Envir}"))" width="64" title="No Edit" />
}
}
else
{
if (item.SellingItemNav?.SourceType == ItemSourceType.FileBTL)
{
<img class="img-fluid image-hover-pop" src="@(imgUrl(item.TemplateRowUID, $"{item.Envir}"))" width="150" @onclick="() => DoEditFile(item)" title="Edit Item" />
<img class="img-fluid image-hover-pop" src="@(imgUrl(item.ImgType, item.TemplateRowUID, $"{item.Envir}"))" width="150" @onclick="() => DoEditFile(item)" title="Edit Item" />
}
else
{
<img class="img-fluid p-1" src="@(imgUrl(item.TemplateRowUID, $"{item.Envir}"))" width="64" title="No Edit" />
<img class="img-fluid p-1" src="@(imgUrl(item.ImgType, item.ImgUID, $"{item.Envir}"))" width="64" title="No Edit" />
}
}
</td>
@@ -739,6 +739,7 @@ namespace Lux.UI.Components.Compo.Templates
return $"TP-{objID:X8}";
}
#if false
/// <summary>
/// Calcolo URL immagine
/// </summary>
@@ -752,6 +753,36 @@ namespace Lux.UI.Components.Compo.Templates
Enum.TryParse(env, out envir);
return ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, imgUid, envir);
}
#endif
/// <summary>
/// Calcolo URL immagine
/// </summary>
/// <param name="tipoImg"></param>
/// <param name="imgUid"></param>
/// <param name="env"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Restituisce il contenuto del file salvato
@@ -19,6 +19,15 @@
<label class="small">Nome</label>
</div>
</div>
<div class="col-8">
<div class="form-floating">
<InputFile class="form-control" OnChange="UploadFile" />
<label class="small bg-opacity-50">Carica Immagine</label>
</div>
</div>
<div class="col-4">
<button class="btn btn-lg btn-info w-100" @onclick="() => DoClearImg()"><i class="fa-solid fa-eraser"></i> ClearImage</button>
</div>
<div class="col-6">
<button class="btn btn-lg btn-success w-100" @onclick="() => DoSave()"><i class="fa-solid fa-floppy-disk"></i> Save</button>
</div>
@@ -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<bool> EC_Close { get; set; }
[Parameter]
public List<SellingItemModel> ListSellinglItems { get; set; } = null!;
/// <summary>
/// Callback invocato al salvataggio con record aggiornato
/// </summary>
[Parameter]
public EventCallback<TemplateRowModel> EC_Updated { get; set; }
[Parameter]
public List<SellingItemModel> ListSellinglItems { get; set; } = null!;
#endregion Public Properties
#region Private Fields
/// <summary>
/// Path da parent record
/// </summary>
/// <param name="objID"></param>
/// <returns></returns>
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
}
}
}