From f70e21c40e23047545fa53568bcda765cbc63d87 Mon Sep 17 00:00:00 2001 From: Ankitkumar Satapara Date: Wed, 22 Apr 2026 00:48:39 +0530 Subject: [PATCH] Fixed save load issues in the variable types of nodes --- Examples/Nodify.Calculator/GraphSerializer.cs | 57 +++++++++++++++++-- .../Models/SaveGraphModel.cs | 10 ++++ .../Operations/OperationFactory.cs | 5 +- .../SystemOperationViewModel.cs | 4 ++ 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/Examples/Nodify.Calculator/GraphSerializer.cs b/Examples/Nodify.Calculator/GraphSerializer.cs index aa43cd3..15b44be 100644 --- a/Examples/Nodify.Calculator/GraphSerializer.cs +++ b/Examples/Nodify.Calculator/GraphSerializer.cs @@ -59,12 +59,12 @@ namespace Nodify.Calculator case SystemOperationViewModel sys: nodeData.NodeType = "System"; nodeData.SystemOp = sys.SystemOperationType.ToString(); - // For GET_SET nodes, derive ClassName from title + // For GET_SET nodes, save ClassName and variable metadata if (sys.SystemOperationType == SystemOperations.GET_SET) { - var title = sys.Title ?? ""; - if (title.StartsWith("GET ")) nodeData.ClassName = title.Substring(4).Trim(); - else if (title.StartsWith("SET ")) nodeData.ClassName = title.Substring(4).Trim(); + nodeData.ClassName = sys.ClassName ?? string.Empty; + nodeData.IsSimpleVariable = sys.IsSimpleVariable; + nodeData.VariableType = sys.VariableType ?? string.Empty; } break; case APIOperationViewModel api: @@ -113,6 +113,20 @@ namespace Nodify.Calculator }); } + // Serialize function definitions from the left panel + foreach (var funcInfo in calculator.OperationsMenu.AvailableFunctions) + { + var funcDef = new FunctionDefinitionData + { + Name = funcInfo.Title ?? string.Empty + }; + foreach (var inp in funcInfo.FunctionInputs) + funcDef.Inputs.Add(new FunctionParamData { Name = inp.Name, Type = inp.Type }); + foreach (var outp in funcInfo.FunctionOutputs) + funcDef.Outputs.Add(new FunctionParamData { Name = outp.Name, Type = outp.Type }); + graph.FunctionDefinitions.Add(funcDef); + } + // Save to LiteDB using var db = new LiteDbHelper("Graph"); db.DeleteMany(_ => true); @@ -138,6 +152,30 @@ namespace Nodify.Calculator calculator.Connections.Clear(); calculator.Operations.Clear(); + // Restore function definitions to the left panel + opsMenu.AvailableFunctions.Clear(); + if (graph.FunctionDefinitions != null) + { + foreach (var funcDef in graph.FunctionDefinitions) + { + var funcInfo = new OperationInfoViewModel + { + Title = funcDef.Name, + Type = OperationType.System, + sysOp = SystemOperations.FUNCTION, + IsFlowNode = true, + IsFunction = true, + FunctionInputs = new System.Collections.Generic.List(), + FunctionOutputs = new System.Collections.Generic.List() + }; + foreach (var inp in funcDef.Inputs) + funcInfo.FunctionInputs.Add(new FunctionParameterInfo { Name = inp.Name, Type = inp.Type }); + foreach (var outp in funcDef.Outputs) + funcInfo.FunctionOutputs.Add(new FunctionParameterInfo { Name = outp.Name, Type = outp.Type }); + opsMenu.AvailableFunctions.Add(funcInfo); + } + } + calculator.IsLoading = true; try { @@ -226,8 +264,14 @@ namespace Nodify.Calculator if (sysOp == SystemOperations.GET_SET && !string.IsNullOrEmpty(nd.ClassName)) { - info.IsModelNode = true; info.ClassName = nd.ClassName; + info.IsSimpleVariable = nd.IsSimpleVariable; + info.VariableType = nd.VariableType ?? string.Empty; + info.IsModelNode = true; + // Extract just "GET" or "SET" prefix so the factory doesn't re-append ClassName + var savedTitle = nd.Title ?? ""; + if (savedTitle.StartsWith("GET ")) info.Title = "GET"; + else if (savedTitle.StartsWith("SET ")) info.Title = "SET"; } // Set up inputs/outputs based on system operation type @@ -263,6 +307,9 @@ namespace Nodify.Calculator case SystemOperations.KNOT: // Knot nodes manage their own connectors; don't add any here break; + case SystemOperations.GET_SET: + // GET_SET nodes build their own connectors in OperationFactory + break; default: info.Output.Add(""); info.IsFlowNode = true; diff --git a/Examples/Nodify.Calculator/Models/SaveGraphModel.cs b/Examples/Nodify.Calculator/Models/SaveGraphModel.cs index 7f4beac..d4e2e13 100644 --- a/Examples/Nodify.Calculator/Models/SaveGraphModel.cs +++ b/Examples/Nodify.Calculator/Models/SaveGraphModel.cs @@ -8,6 +8,7 @@ namespace Nodify.Calculator.Models public int Id { get; set; } = 1; public List Nodes { get; set; } = new List(); public List Connections { get; set; } = new List(); + public List FunctionDefinitions { get; set; } = new List(); } public class NodeData @@ -29,6 +30,8 @@ namespace Nodify.Calculator.Models // System node properties public string SystemOp { get; set; } = string.Empty; public string ClassName { get; set; } = string.Empty; + public bool IsSimpleVariable { get; set; } + public string VariableType { get; set; } = string.Empty; // Auth node properties public string AuthBaseUrl { get; set; } = string.Empty; @@ -74,6 +77,13 @@ namespace Nodify.Calculator.Models public string Type { get; set; } = string.Empty; } + public class FunctionDefinitionData + { + public string Name { get; set; } = string.Empty; + public List Inputs { get; set; } = new List(); + public List Outputs { get; set; } = new List(); + } + // Keep legacy for compatibility public class SaveNodes { diff --git a/Examples/Nodify.Calculator/Operations/OperationFactory.cs b/Examples/Nodify.Calculator/Operations/OperationFactory.cs index ac9c1ba..bf20aa2 100644 --- a/Examples/Nodify.Calculator/Operations/OperationFactory.cs +++ b/Examples/Nodify.Calculator/Operations/OperationFactory.cs @@ -554,7 +554,10 @@ namespace Nodify.Calculator var sysOp = new SystemOperationViewModel { Title = info.Title, - SystemOperationType = info.sysOp + SystemOperationType = info.sysOp, + IsSimpleVariable = info.IsSimpleVariable, + VariableType = info.VariableType ?? string.Empty, + ClassName = info.ClassName ?? string.Empty }; if (info.sysOp == SystemOperations.COPY) diff --git a/Examples/Nodify.Calculator/SystemOperationViewModel.cs b/Examples/Nodify.Calculator/SystemOperationViewModel.cs index 9c322d0..c6e4c31 100644 --- a/Examples/Nodify.Calculator/SystemOperationViewModel.cs +++ b/Examples/Nodify.Calculator/SystemOperationViewModel.cs @@ -35,5 +35,9 @@ namespace Nodify.Calculator get => _systemOperation; set => SetProperty(ref _systemOperation, value); } + + public bool IsSimpleVariable { get; set; } + public string VariableType { get; set; } = string.Empty; + public string ClassName { get; set; } = string.Empty; } }