OK gestione update grafico

This commit is contained in:
Samuele Locatelli
2023-04-28 10:44:23 +02:00
parent eec4608919
commit f96ea5bd62
5 changed files with 194 additions and 54 deletions
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
@@ -81,5 +82,77 @@ namespace WebDoorCreator.Data.DbModels
//[ForeignKey("DoorOpTypId")]
//public virtual DoorOpTypeModel? DoorOpTypeNav { get; set; }
[NotMapped]
public Dictionary<string, string> CurrVals
{
get
{
Dictionary<string, string> answ = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(JsoncActVal))
{
try
{
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsoncActVal);
answ = deserialized ?? new Dictionary<string, string>();
}
catch
{ }
}
return answ;
}
set
{
JsoncActVal = JsonConvert.SerializeObject(value);
}
}
[NotMapped]
public Dictionary<string, List<string>> GraphicParams
{
get
{
Dictionary<string, List<string>> answ = new Dictionary<string, List<string>>();
if (!string.IsNullOrEmpty(JsoncConfigVal))
{
try
{
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(JsoncConfigVal);
answ = deserialized ?? new Dictionary<string, List<string>>();
}
catch
{ }
}
return answ;
}
set
{
JsoncConfigVal = JsonConvert.SerializeObject(value);
}
}
/// <summary>
/// COmparazione tra il dizionario currVal corrente e quello ricevuto
/// </summary>
/// <param name="newDict">Dizionario x comparazione</param>
/// <returns></returns>
public bool JsoncActValEquals(Dictionary<string, string> newDict)
{
string JsonNewVal = JsonConvert.SerializeObject(newDict);
bool answ = JsoncActVal.Equals(JsonNewVal);
return answ;
}
/// <summary>
/// Comparazione tra il dizionario configurazioni corrente e quello ricevuto
/// </summary>
/// <param name="newDict">Dizionario x comparazione</param>
/// <returns></returns>
public bool JsoncConfigValEquals(Dictionary<string, List<string>> newDict)
{
string JsonNewVal = JsonConvert.SerializeObject(newDict);
bool answ = JsoncConfigVal.Equals(JsonNewVal);
return answ;
}
}
}
@@ -4,7 +4,7 @@
@foreach (var item in DoorOpList)
{
<div class="col-4" style="min-height: 20rem;">
<HwSingleInstance instanceN="@(instNum++)" Lingua="@Lingua" DoorOpInst="@item" HwCode="@HwCode" E_recordUpdate="manageUpdate" E_selTemplate="manageTemplate"></HwSingleInstance>
<HwSingleInstance instanceN="@(instNum++)" Lingua="@Lingua" DoorOpInst="@item" HwCode="@HwCode" E_recordUpdate="manageUpdate"></HwSingleInstance>
</div>
}
</div>
@@ -1,7 +1,5 @@
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.Migrations.WDCData;
using WebDoorCreator.UI.Data;
namespace WebDoorCreator.UI.Components.Hardware
@@ -68,31 +66,6 @@ namespace WebDoorCreator.UI.Components.Hardware
}
}
/// <summary>
/// Gestione aggiornamento selezione template da oggetto sottostante
/// </summary>
/// <param name="currItem"></param>
/// <returns></returns>
protected async Task manageTemplate(DoorOpModel currItem)
{
await Task.Delay(1);
#if false
// rigenera dal template l'elenco graphicsParameters associati
var updItem = await WDCService.DoorOpSetupGraphParams(currItem);
#endif
// aggiorna nelle DoorOpList...
if (DoorOpList != null)
{
var item2rem = DoorOpList.Where(x => x.DoorOpId == currItem.DoorOpId).FirstOrDefault();
if (item2rem != null)
{
DoorOpList.Remove(item2rem);
}
await Task.Delay(1);
DoorOpList.Add(currItem);
}
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
@@ -14,17 +14,9 @@ namespace WebDoorCreator.UI.Components.Hardware
[Parameter]
public DoorOpModel DoorOpInst { get; set; } = null!;
[Parameter]
public EventCallback<DoorOpModel> E_selTemplate { get; set; }
[Parameter]
public EventCallback<DoorOpModel> E_recordUpdate { get; set; }
#if false
[CascadingParameter]
public EventCallback<bool> E_SetParamChanged { get; set; }
#endif
[Parameter]
public string HwCode { get; set; } = "";
@@ -44,8 +36,13 @@ namespace WebDoorCreator.UI.Components.Hardware
public void setupCurrValues()
{
//currVal = new Dictionary<string, string>();
#if false
if (!string.IsNullOrEmpty(DoorOpInst.JsoncActVal))
{
{
#endif
currVal = DoorOpInst.CurrVals;
#if false
currValToCompare = DoorOpInst.CurrVals;
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, string>>(DoorOpInst.JsoncActVal!);
var deserializedToComp = JsonConvert.DeserializeObject<Dictionary<string, string>>(DoorOpInst.JsoncActVal!);
if (deserialized != null)
@@ -54,15 +51,19 @@ namespace WebDoorCreator.UI.Components.Hardware
currValToCompare = deserializedToComp;
}
}
#endif
}
public void setupGraphicParams()
{
graphicParams = DoorOpInst.GraphicParams;
#if false
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(DoorOpInst.JsoncConfigVal!);
if (deserialized != null)
{
graphicParams = deserialized;
}
#endif
}
#endregion Public Methods
@@ -74,7 +75,9 @@ namespace WebDoorCreator.UI.Components.Hardware
/// </summary>
protected Dictionary<string, string> currVal { get; set; } = null!;
protected Dictionary<string, string>? currValToCompare { get; set; }
#if false
protected Dictionary<string, string>? currValToCompare { get; set; }
#endif
protected string folderName
{
@@ -122,11 +125,20 @@ namespace WebDoorCreator.UI.Components.Hardware
var pUpd = Task.Run(async () =>
{
// aggiorno direttamente i graphics parameters...
var updItem = await WDCService.DoorOpSetupGraphParams(DoorOpInst);
#if false
var updItem = await WDCService.DoorOpSetupGraphParams(DoorOpInst);
#endif
var newData = await WDCService.DoorOpGetUpdatedVals(DoorOpInst.ObjectId, currVal, graphicParams);
currVal = newData.Item1;
graphicParams = newData.Item2;
#if false
DoorOpInst = updItem;
currVal = DoorOpInst.CurrVals;
#endif
#if false
// chiamo evento notifica cambio template
await E_selTemplate.InvokeAsync(updItem);
await E_selTemplate.InvokeAsync(updItem);
#endif
await SetSelectedData();
@@ -164,7 +176,16 @@ namespace WebDoorCreator.UI.Components.Hardware
protected bool doCheckVal()
{
bool answ = false;
bool answ = DoorOpInst.JsoncActValEquals(currVal);
if (answ)
{
DoorOpInst.JsoncActVal = JsonConvert.SerializeObject(currVal);
Task.Run(async () =>
{
await E_recordUpdate.InvokeAsync(DoorOpInst);
});
}
#if false
if (currValToCompare != null)
{
foreach (var item in currVal)
@@ -185,7 +206,8 @@ namespace WebDoorCreator.UI.Components.Hardware
}
}
}
}
}
#endif
return answ;
}
@@ -216,9 +238,16 @@ namespace WebDoorCreator.UI.Components.Hardware
{
DoorOpInst.userConfirm = userId;
DoorOpInst.DtConfirm = DateTime.Now;
// salvo i NUOVI valori...
DoorOpInst.CurrVals = currVal;
DoorOpInst.GraphicParams = graphicParams;
#if false
// ri-serializzo i graphics parameters...
string serVal = JsonConvert.SerializeObject(currVal);
DoorOpInst.JsoncActVal = serVal;
#endif
// salvo!
await WDCService.DoorOpUpdate(DoorOpInst);
}
@@ -274,17 +303,6 @@ namespace WebDoorCreator.UI.Components.Hardware
return answ;
}
#endregion Protected Methods
#region Private Methods
private async Task FullReloadData()
{
setupCurrValues();
setupGraphicParams();
await SetSelectedData();
}
protected string tryGetCurrVal(string key)
{
string answ = "";
@@ -295,6 +313,16 @@ namespace WebDoorCreator.UI.Components.Hardware
return answ;
}
#endregion Protected Methods
#region Private Methods
private async Task FullReloadData()
{
setupCurrValues();
setupGraphicParams();
await SetSelectedData();
}
private async Task SetSelectedData()
{
@@ -313,7 +341,6 @@ namespace WebDoorCreator.UI.Components.Hardware
if (listValuesFname != null)
{
folderName = listValuesFname.FirstOrDefault()?.Label!;
}
}
@@ -976,6 +976,73 @@ namespace WebDoorCreator.UI.Data
return currDoorOp;
}
/// <summary>
/// Restitusice i CurrVals + GraphParams aggiornati dati valori Folder/template
/// </summary>
/// <param name="ObjectId">Obj x cui è richiesto il ricalcolo parametri</param>
/// <param name="currVal">Dizionario dei valori attuali</param>
/// <param name="currParams">Dizionario di obj x GraphParams</param>
/// <returns></returns>
public async Task<(Dictionary<string, string>, Dictionary<string, List<string>>)> DoorOpGetUpdatedVals(string ObjectId, Dictionary<string, string> currVal, Dictionary<string, List<string>> currParams)
{
await Task.Delay(1);
// duplico oggetti da tornare
Dictionary<string, string> currValUpd = new Dictionary<string, string>();
Dictionary<string, List<string>> currParamsUpd = new Dictionary<string, List<string>>();
string default2Design = "";
// cerco il setup del template selezionato
var listRecordTmp = await ListValuesGetAll(ObjectId, "template");
if (listRecordTmp != null && currVal.ContainsKey("Folder") && currVal.ContainsKey("template"))
{
string actKey = currVal["template"];
var firstTemplate = listRecordTmp.Where(x => x.Value == actKey).FirstOrDefault();
if (firstTemplate != null)
{
if (firstTemplate.DefaultVal != "")
{
default2Design = firstTemplate.DefaultVal;
}
else
{
default2Design = "1";
}
}
// elimino dai valori di setup e attuali quanto non sia template/folder...
currValUpd = currVal.Where(x => x.Key == "Folder" || x.Key == "template").ToDictionary(x => x.Key, x => x.Value);
// preparo setup valori
List<string> listDefVal = new List<string>();
var listRecordGP = await ListValuesGetAll(ObjectId, $"Graphic Parameters{default2Design}");
if (listRecordGP != null)
{
foreach (var item in listRecordGP)
{
if (item.isSerializable && item.DefaultVal.Contains(","))
{
listDefVal = item.DefaultVal.Trim().Split(",").ToList();
currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split(",")[0].Split("/")[0]);
}
else
{
if (item.DefaultVal.Contains("/"))
{
listDefVal = new List<string>() { item.DefaultVal.Trim().Split("/")[0] };
currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split("/")[0]);
}
else
{
listDefVal = new List<string>() { item.DefaultVal.Trim() };
currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim());
}
}
//defaultParamsList.Add(listDefVal);
currParamsUpd.Add(item.Value.Trim(), listDefVal);
}
}
}
return (currValUpd, currParamsUpd);
}
public async Task<bool> ListValuesLuaNgeInsert(string rootPath)
{
List<ListValuesTempModel> values = new List<ListValuesTempModel>();