diff --git a/docfx/framework/toc.yml b/docfx/framework/toc.yml index 2057d03a7..13e7e1ae4 100644 --- a/docfx/framework/toc.yml +++ b/docfx/framework/toc.yml @@ -6,4 +6,7 @@ items: - name: Inspectors href: ../inspectors/docs/index.html - name: Timers - href: ../timers/docs/index.html \ No newline at end of file + href: ../timers/docs/index.html + - name: Application Template + href: ../templates.simple/docs/index.html + \ No newline at end of file diff --git a/src/base/src/AXOpen.Logging/AXOpen.Logging.Serilog.csproj b/src/base/src/AXOpen.Logging/AXOpen.Logging.Serilog.csproj index ff1806753..7348f04f2 100644 --- a/src/base/src/AXOpen.Logging/AXOpen.Logging.Serilog.csproj +++ b/src/base/src/AXOpen.Logging/AXOpen.Logging.Serilog.csproj @@ -1,6 +1,5 @@ - - + enable enable diff --git a/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.csproj b/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.csproj index ea59f54ca..bdb71b868 100644 --- a/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.csproj +++ b/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.csproj @@ -17,6 +17,7 @@ + diff --git a/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.sln b/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.sln new file mode 100644 index 000000000..149fe7e63 --- /dev/null +++ b/src/base/src/AXOpen.VisualComposer/AXOpen.VisualComposer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXOpen.VisualComposer", "AXOpen.VisualComposer.csproj", "{691CAEAB-2761-415E-971F-39C4F48C175F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {691CAEAB-2761-415E-971F-39C4F48C175F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {691CAEAB-2761-415E-971F-39C4F48C175F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {691CAEAB-2761-415E-971F-39C4F48C175F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {691CAEAB-2761-415E-971F-39C4F48C175F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0A82BB85-D037-40A6-B4B4-0821E6B304DF} + EndGlobalSection +EndGlobal diff --git a/src/base/src/AXOpen.VisualComposer/AccordionComponent.razor b/src/base/src/AXOpen.VisualComposer/AccordionComponent.razor new file mode 100644 index 000000000..15295fd41 --- /dev/null +++ b/src/base/src/AXOpen.VisualComposer/AccordionComponent.razor @@ -0,0 +1,41 @@ +@using AXSharp.Connector; + +
+
+
+ + +
+
+
+
+
    + @foreach (var item in AccordionContent.GetChildren()) + { + @if (!item.GetChildren().Any()) + { +
  • +

    @item.HumanReadable

    + +
  • + } + else + { + + } + } +
+
+
+
+ + +@code { + [Parameter] + public ITwinObject AccordionContent { get; set; } + + [Parameter] + public VisualComposerContainer Parent { get; set; } +} \ No newline at end of file diff --git a/src/base/src/AXOpen.VisualComposer/Serializing/SerializableVisualComposerItem.cs b/src/base/src/AXOpen.VisualComposer/Serializing/SerializableVisualComposerItem.cs index c0a561a9b..237b4e4d5 100644 --- a/src/base/src/AXOpen.VisualComposer/Serializing/SerializableVisualComposerItem.cs +++ b/src/base/src/AXOpen.VisualComposer/Serializing/SerializableVisualComposerItem.cs @@ -2,12 +2,11 @@ { internal class SerializableVisualComposerItem { - public SerializableVisualComposerItem(string id, double ratioImgX, double ratioImgY, bool show, string transform, string presentation, double width, double height, int zIndex) + public SerializableVisualComposerItem(string id, double ratioImgX, double ratioImgY, string transform, string presentation, double width, double height, int zIndex) { Id = id; RatioImgX = ratioImgX; RatioImgY = ratioImgY; - Show = show; Transform = transform; Presentation = presentation; Width = width; @@ -18,7 +17,6 @@ public SerializableVisualComposerItem(string id, double ratioImgX, double ratioI public string Id { get; set; } public double RatioImgX { get; set; } = 10; public double RatioImgY { get; set; } = 10; - public bool Show { get; set; } = false; public string Transform { get; set; } = "TopCenter"; public string Presentation { get; set; } = "Status-Display"; public double Width { get; set; } = -1; diff --git a/src/base/src/AXOpen.VisualComposer/Serializing/Serialize.cs b/src/base/src/AXOpen.VisualComposer/Serializing/Serialize.cs index cd8182e41..266953c70 100644 --- a/src/base/src/AXOpen.VisualComposer/Serializing/Serialize.cs +++ b/src/base/src/AXOpen.VisualComposer/Serializing/Serialize.cs @@ -2,9 +2,9 @@ namespace AXOpen.VisualComposer.Serializing { - internal static class Serializing + internal static class Serializing { - internal static void Serialize(string filePath, List serialize) + internal static void Serialize(string filePath, List serialize) { try { @@ -19,17 +19,17 @@ internal static void Serialize(string filePath, List? Deserialize(string filePath) + internal static List? Deserialize(string filePath) { if (!File.Exists(filePath)) return null; - List? deserialize = null; + List? deserialize = null; try { using (FileStream fs = File.OpenRead(filePath)) { - deserialize = JsonSerializer.Deserialize>(fs); + deserialize = JsonSerializer.Deserialize>(fs); } } catch (Exception ex) diff --git a/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor b/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor index 0ef2ca7e5..210f84e26 100644 --- a/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor +++ b/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor @@ -1,15 +1,39 @@ - +@using AXSharp.Connector; + +
- @ChildContent + @foreach (VisualComposerItem child in _children) + { + + } - - + + +
+ +
+ + + + + + + diff --git a/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor.cs b/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor.cs index 03cf71e53..11a42db88 100644 --- a/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor.cs +++ b/src/base/src/AXOpen.VisualComposer/VisualComposerContainer.razor.cs @@ -1,86 +1,185 @@ -using AXOpen.VisualComposer.Serializing; +using AXOpen.Core; +using AXOpen.VisualComposer.Serializing; +using AXSharp.Connector; using Microsoft.AspNetCore.Components; +using System.Xml.Linq; +using AXOpen.ToolBox.Extensions; namespace AXOpen.VisualComposer { public partial class VisualComposerContainer { [Parameter] - public RenderFragment? ChildContent { get; set; } + public AxoObject AxoObject { get; set; } [Parameter] public string? ImgSrc { get; set; } - private string? _id; - - [Parameter] - public string? Id - { - get => _id; - set - { - _id = value?.Replace('.', '_'); - } - } + public string Id { get; set; } private Guid _imgId = Guid.NewGuid(); private List _children = new(); + private IEnumerable _childrenOfAxoObject { get; set; } + + public string FileName { get; set; } = ""; + + protected override void OnInitialized() + { + Id = AxoObject.HumanReadable.Replace(".", "_").Replace(" ", "_"); + } + protected override void OnAfterRender(bool firstRender) { if (firstRender) + { + _childrenOfAxoObject = AxoObject.GetChildren().Flatten(p => p.GetChildren()).ToList(); + _childrenOfAxoObject = _childrenOfAxoObject.Concat(AxoObject.RetrievePrimitives()); + Load(); + } + } + + public void AddChildren(ITwinElement item) + { + _children.Add(new VisualComposerItem() + { + UniqueGuid = Guid.NewGuid(), + TwinElement = item + }); + + StateHasChanged(); + } + + public void AddChildren(VisualComposerItem item) + { + if (!_children.Contains(item)) + { + VisualComposerItem? find = _children.Find(p => p.UniqueGuid == item.UniqueGuid); + if (find != null) + _children.Remove(find); + + _children.Add(item); + } } - public void AddChild(VisualComposerItem child) + public void RemoveChildren(VisualComposerItem item) { - if (!_children.Contains(child)) - _children.Add(child); + _children.Remove(_children.Find(p => p.UniqueGuid == item.UniqueGuid)); + + StateHasChanged(); } - public void Save() + public void Save(string fileName = "Default") { + foreach (char c in Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars())) + { + fileName = fileName.Replace(c, '_'); + } + List serializableChildren = new List(); foreach (var child in _children) { - if(child.ratioImgX == 10 && child.ratioImgY == 10 && !child.Show && child.Transform.Value == Types.TransformType.TopCenter.Value && child.Presentation == Types.PresentationType.StatusDisplay.Value) - continue; + serializableChildren.Add(new SerializableVisualComposerItem(child.Id, child.ratioImgX, child.ratioImgY, child.Transform.ToString(), child.Presentation, child.Width, child.Height, child.ZIndex)); + } - serializableChildren.Add(new SerializableVisualComposerItem(child.Id, child.ratioImgX, child.ratioImgY, child.Show, child.Transform.ToString(), child.Presentation, child.Width, child.Height, child.ZIndex)); + if (!Directory.Exists("VisualComposerSerialize/" + Id)) + { + Directory.CreateDirectory("VisualComposerSerialize/" + Id); } - Serializing.Serializing.Serialize(Id + ".json", serializableChildren); + Serializing.Serializing.Serialize("VisualComposerSerialize/" + Id + "/" + fileName + ".json", serializableChildren); } - public void Load() + public void Load(string? fileName = "Default") { - List? deserialize = Serializing.Serializing.Deserialize(Id + ".json"); + List? deserialize = Serializing.Serializing.Deserialize("VisualComposerSerialize/" + Id + "/" + fileName + ".json"); - if(deserialize != null) + if (deserialize != null) { + _children.Clear(); + foreach (var item in deserialize) { - var child = _children.Find(x => x.Id == item.Id); - if (child != null) + var a = _childrenOfAxoObject.FirstOrDefault(p => p.HumanReadable.Replace(".", "_").Replace(" ", "_") == item.Id); + _children.Add(new VisualComposerItem() { - child.ratioImgX = item.RatioImgX; - child.ratioImgY = item.RatioImgY; - child.Show = item.Show; - child.Transform = Types.TransformType.FromString(item.Transform); - child.Presentation = item.Presentation; - child.Width = item.Width; - child.Height = item.Height; - child.ZIndex = item.ZIndex; - } + UniqueGuid = Guid.NewGuid(), + TwinElement = _childrenOfAxoObject.FirstOrDefault(p => p.HumanReadable.Replace(".", "_").Replace(" ", "_") == item.Id), + ratioImgX = item.RatioImgX, + ratioImgY = item.RatioImgY, + Transform = Types.TransformType.FromString(item.Transform), + Presentation = item.Presentation, + Width = item.Width, + Height = item.Height, + ZIndex = item.ZIndex + }); } } StateHasChanged(); } - private void Check(VisualComposerItem visualComposerItem) + public void Remove(string fileName) + { + if (File.Exists("VisualComposerSerialize/" + Id + "/" + fileName + ".json")) + { + File.Delete("VisualComposerSerialize/" + Id + "/" + fileName + ".json"); + } + } + + public List GetAllFiles() { - visualComposerItem.Show = !visualComposerItem.Show; + List files = new(); + + if (!Directory.Exists("VisualComposerSerialize/" + Id)) + return files; + + try + { + Directory.GetFiles("VisualComposerSerialize/" + Id + "/", "*.json").ToList().ForEach(p => files.Add(Path.GetFileNameWithoutExtension(p))); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + + if (files.Contains("Default")) + { + // Move "Default" to the first position + files.Remove("Default"); + files.Insert(0, "Default"); + } + + return files; + } + + public string? SearchValue { get; set; } = null; + public List? SearchResult { get; set; } = null; + public void Search() + { + if (SearchValue is null || SearchValue == "") + { + SearchResult = null; + } + else + { + SearchResult = AxoObject.GetChildren().Flatten(p => p.GetChildren()).ToList().FindAll(p => p.HumanReadable.Contains(SearchValue, StringComparison.OrdinalIgnoreCase)); + } + } + + public string? SearchValuePrimitive { get; set; } = null; + public List? SearchResultPrimitive { get; set; } = null; + public void SearchPrimitive() + { + if (SearchValuePrimitive is null || SearchValuePrimitive == "") + { + SearchResult = null; + } + else + { + SearchResultPrimitive = AxoObject.RetrievePrimitives().ToList().FindAll(p => p.HumanReadable.Contains(SearchValuePrimitive)); + } } } } diff --git a/src/base/src/AXOpen.VisualComposer/VisualComposerItem.razor b/src/base/src/AXOpen.VisualComposer/VisualComposerItem.razor index ed7151ec8..c078ead59 100644 --- a/src/base/src/AXOpen.VisualComposer/VisualComposerItem.razor +++ b/src/base/src/AXOpen.VisualComposer/VisualComposerItem.razor @@ -1,95 +1,80 @@ -@if (Show) -{ - - -
- @if (ChildContent == null) - { - - } - else - { - @ChildContent - } - - -
+ + +
+ + + +
-