diff --git a/WebDoorCreator.Data/DbModels/DoorOpModel.cs b/WebDoorCreator.Data/DbModels/DoorOpModel.cs index b8b9442..58575a3 100644 --- a/WebDoorCreator.Data/DbModels/DoorOpModel.cs +++ b/WebDoorCreator.Data/DbModels/DoorOpModel.cs @@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; // // 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 CurrVals + { + get + { + Dictionary answ = new Dictionary(); + if (!string.IsNullOrEmpty(JsoncActVal)) + { + try + { + var deserialized = JsonConvert.DeserializeObject>(JsoncActVal); + answ = deserialized ?? new Dictionary(); + } + catch + { } + } + return answ; + } + set + { + JsoncActVal = JsonConvert.SerializeObject(value); + } + } + [NotMapped] + public Dictionary> GraphicParams + { + get + { + Dictionary> answ = new Dictionary>(); + if (!string.IsNullOrEmpty(JsoncConfigVal)) + { + try + { + var deserialized = JsonConvert.DeserializeObject>>(JsoncConfigVal); + answ = deserialized ?? new Dictionary>(); + } + catch + { } + } + return answ; + } + set + { + JsoncConfigVal = JsonConvert.SerializeObject(value); + } + } + /// + /// COmparazione tra il dizionario currVal corrente e quello ricevuto + /// + /// Dizionario x comparazione + /// + public bool JsoncActValEquals(Dictionary newDict) + { + string JsonNewVal = JsonConvert.SerializeObject(newDict); + bool answ = JsoncActVal.Equals(JsonNewVal); + return answ; + } + /// + /// Comparazione tra il dizionario configurazioni corrente e quello ricevuto + /// + /// Dizionario x comparazione + /// + public bool JsoncConfigValEquals(Dictionary> newDict) + { + string JsonNewVal = JsonConvert.SerializeObject(newDict); + bool answ = JsoncConfigVal.Equals(JsonNewVal); + return answ; + } + + } } diff --git a/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor b/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor index 7c976cd..4bfdacf 100644 --- a/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor +++ b/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor @@ -4,7 +4,7 @@ @foreach (var item in DoorOpList) {
- +
} diff --git a/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs b/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs index b2a57f1..51f8bf9 100644 --- a/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs +++ b/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs @@ -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 } } - /// - /// Gestione aggiornamento selezione template da oggetto sottostante - /// - /// - /// - 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(); diff --git a/WebDoorCreator.UI/Components/Hardware/HwSingleInstance.razor.cs b/WebDoorCreator.UI/Components/Hardware/HwSingleInstance.razor.cs index 535c865..cbf985c 100644 --- a/WebDoorCreator.UI/Components/Hardware/HwSingleInstance.razor.cs +++ b/WebDoorCreator.UI/Components/Hardware/HwSingleInstance.razor.cs @@ -14,17 +14,9 @@ namespace WebDoorCreator.UI.Components.Hardware [Parameter] public DoorOpModel DoorOpInst { get; set; } = null!; - [Parameter] - public EventCallback E_selTemplate { get; set; } - [Parameter] public EventCallback E_recordUpdate { get; set; } -#if false - [CascadingParameter] - public EventCallback 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(); +#if false if (!string.IsNullOrEmpty(DoorOpInst.JsoncActVal)) - { + { +#endif + currVal = DoorOpInst.CurrVals; +#if false + currValToCompare = DoorOpInst.CurrVals; var deserialized = JsonConvert.DeserializeObject>(DoorOpInst.JsoncActVal!); var deserializedToComp = JsonConvert.DeserializeObject>(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>>(DoorOpInst.JsoncConfigVal!); if (deserialized != null) { graphicParams = deserialized; } +#endif } #endregion Public Methods @@ -74,7 +75,9 @@ namespace WebDoorCreator.UI.Components.Hardware /// protected Dictionary currVal { get; set; } = null!; - protected Dictionary? currValToCompare { get; set; } +#if false + protected Dictionary? 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!; - } } diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index 287c50e..a02a4c0 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -976,6 +976,73 @@ namespace WebDoorCreator.UI.Data return currDoorOp; } + /// + /// Restitusice i CurrVals + GraphParams aggiornati dati valori Folder/template + /// + /// Obj x cui รจ richiesto il ricalcolo parametri + /// Dizionario dei valori attuali + /// Dizionario di obj x GraphParams + /// + public async Task<(Dictionary, Dictionary>)> DoorOpGetUpdatedVals(string ObjectId, Dictionary currVal, Dictionary> currParams) + { + await Task.Delay(1); + // duplico oggetti da tornare + Dictionary currValUpd = new Dictionary(); + Dictionary> currParamsUpd = new Dictionary>(); + 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 listDefVal = new List(); + 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() { item.DefaultVal.Trim().Split("/")[0] }; + currValUpd.Add(item.Value.Trim(), item.DefaultVal.Trim().Split("/")[0]); + } + else + { + listDefVal = new List() { 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 ListValuesLuaNgeInsert(string rootPath) { List values = new List();