diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js b/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js index b12dd051a..e7478c3dc 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js @@ -4,7 +4,6 @@ if (!window.shapeTracingMetadataHost) { window.shapeTracingMetadataHost.placement = { 'n/a': 'n/a' }; - window.shapeTracingMetadataHost.references = {}; } jQuery(function ($) { @@ -407,7 +406,7 @@ jQuery(function ($) { }); // open the root node (Model) - openExpando(shapeTracingMetaContent.find('.expando-glyph-container:first')) + shapeTracingMetaContent.find('.expando-glyph-container:first').click(); defaultTab = displayTabModel; }; diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs index 24edc99a4..9f4679693 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using System.Xml.Linq; using ClaySharp; using ClaySharp.Behaviors; @@ -11,25 +10,22 @@ using Orchard.ContentManagement; using Orchard.DisplayManagement; namespace Orchard.DesignerTools.Services { - + public class ObjectDumper { private const int MaxStringLength = 60; private readonly Stack _parents = new Stack(); private readonly Stack _currents = new Stack(); private readonly int _levels; - private readonly Dictionary _local; - private readonly Dictionary _global; private readonly XDocument _xdoc; private XElement _current; // object/key/dump - public ObjectDumper(int levels, Dictionary local, Dictionary global) { + public ObjectDumper(int levels) + { _levels = levels; - _local = local; - _global = global; _xdoc = new XDocument(); _xdoc.Add(_current = new XElement("ul")); } @@ -40,6 +36,7 @@ namespace Orchard.DesignerTools.Services { } _parents.Push(o); + // starts a new container EnterNode("li"); @@ -51,20 +48,11 @@ namespace Orchard.DesignerTools.Services { DumpValue(o, name); } else { - int hashCode = RuntimeHelpers.GetHashCode(o); - // if the object has already been processed, return a named ref to it - if (_global.ContainsKey(hashCode)) { - _current.Add( - new XElement("h1", new XText(name)), - new XElement("span", FormatType(o)), - new XElement("a", new XAttribute("href", hashCode.ToString())) - ); - } - else { - _global.Add(hashCode, _current); - _local.Add(hashCode, _current); - DumpObject(o, name); + if (_parents.Count >= _levels) { + return _current; } + + DumpObject(o, name); } } finally { @@ -87,29 +75,31 @@ namespace Orchard.DesignerTools.Services { _current.Add( new XElement("h1", new XText(name)), new XElement("span", FormatType(o)) - ); + ); + + EnterNode("ul"); - if (_parents.Count >= _levels) { - return; - } + try { + if (o is IDictionary) { + DumpDictionary((IDictionary) o); + } + else if (o is IShape) { + DumpShape((IShape) o); - if (o is IDictionary) { - DumpDictionary((IDictionary)o); - } - else if (o is IShape) { - DumpShape((IShape)o); - - // a shape can also be IEnumerable - if (o is IEnumerable) { + // a shape can also be IEnumerable + if (o is IEnumerable) { + DumpEnumerable((IEnumerable) o); + } + } + else if (o is IEnumerable) { DumpEnumerable((IEnumerable) o); } + else { + DumpMembers(o); + } } - else if (o is IEnumerable) - { - DumpEnumerable((IEnumerable)o); - } - else { - DumpMembers(o); + finally { + RestoreCurrentNode(); } } @@ -124,55 +114,41 @@ namespace Orchard.DesignerTools.Services { return; } - EnterNode("ul"); - - try{ - foreach (var member in members) { - if (o is ContentItem && member.Name == "ContentManager" - || o is Delegate) { - continue; - } - SafeCall(() => DumpMember(o, member)); + foreach (var member in members) { + if (o is ContentItem && member.Name == "ContentManager" + || o is Delegate) { + continue; } + SafeCall(() => DumpMember(o, member)); + } - // process ContentItem.Parts specifically - foreach (var member in members) { - if (o is ContentItem && member.Name == "Parts") { - foreach (var part in ((ContentItem) o).Parts) { - SafeCall(() => Dump(part, part.PartDefinition.Name)); - } - } - } - - foreach (var member in members) { - // process ContentPart.Fields specifically - if (o is ContentPart && member.Name == "Fields") { - foreach (var field in ((ContentPart) o).Fields) { - SafeCall(() => Dump(field, field.Name)); - } + // process ContentItem.Parts specifically + foreach (var member in members) { + if (o is ContentItem && member.Name == "Parts") { + foreach (var part in ((ContentItem) o).Parts) { + SafeCall(() => Dump(part, part.PartDefinition.Name)); } } } - finally { - RestoreCurrentNode(); + + foreach (var member in members) { + // process ContentPart.Fields specifically + if (o is ContentPart && member.Name == "Fields") { + foreach (var field in ((ContentPart) o).Fields) { + SafeCall(() => Dump(field, field.Name)); + } + } } } private void DumpEnumerable(IEnumerable enumerable) { - if(!enumerable.GetEnumerator().MoveNext()) { + if (!enumerable.GetEnumerator().MoveNext()) { return; } - EnterNode("ul"); - - try { - int i = 0; - foreach (var child in enumerable) { - Dump(child, string.Format("[{0}]", i++)); - } - } - finally { - RestoreCurrentNode(); + int i = 0; + foreach (var child in enumerable) { + Dump(child, string.Format("[{0}]", i++)); } } @@ -181,21 +157,14 @@ namespace Orchard.DesignerTools.Services { return; } - EnterNode("ul"); - - try { - foreach (var key in dictionary.Keys) { - Dump(dictionary[key], string.Format("[\"{0}\"]", key)); - } - } - finally { - RestoreCurrentNode(); + foreach (var key in dictionary.Keys) { + Dump(dictionary[key], string.Format("[\"{0}\"]", key)); } } private void DumpShape(IShape shape) { - var b = ((IClayBehaviorProvider)(dynamic)shape).Behavior as ClayBehaviorCollection; + var b = ((IClayBehaviorProvider) (dynamic) shape).Behavior as ClayBehaviorCollection; if (b == null) return; @@ -216,19 +185,12 @@ namespace Orchard.DesignerTools.Services { return; } - EnterNode("ul"); - - try { - foreach (var key in props.Keys) { - // ignore private members (added dynmically by the shape wrapper) - if (key.ToString().StartsWith("_")) { - continue; - } - Dump(props[key], key.ToString()); + foreach (var key in props.Keys) { + // ignore private members (added dynmically by the shape wrapper) + if (key.ToString().StartsWith("_")) { + continue; } - } - finally { - RestoreCurrentNode(); + Dump(props[key], key.ToString()); } } @@ -305,9 +267,22 @@ namespace Orchard.DesignerTools.Services { _current = _currents.Pop(); } - private void EnterNode(string tag) { + private XElement EnterNode(string tag) { SaveCurrentNode(); _current.Add(_current = new XElement(tag)); + return _current; + } + + private int MaxNodesLength(XElement el) { + int max = 1; + var local = 0; + foreach(var node in el.Elements()) { + local = Math.Max(local, MaxNodesLength(node)); + } + + return max + local; } } + + public class DumpMap : Dictionary {} } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs index 80530069e..f169f8ed6 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs @@ -23,7 +23,7 @@ namespace Orchard.DesignerTools.Services { private readonly IWebSiteFolder _webSiteFolder; private readonly IAuthorizer _authorizer; private int _shapeId; - private readonly Dictionary _dumped = new Dictionary(1000); + private readonly DumpMap _dumped = new DumpMap(); public ShapeTracingFactory( WorkContext workContext, @@ -96,17 +96,11 @@ namespace Orchard.DesignerTools.Services { var descriptor = shapeTable.Descriptors[shapeMetadata.Type]; // dump the Shape's content - var local = new Dictionary(); - new ObjectDumper(6, local, _dumped).Dump(context.Shape, "Model"); - context.Shape.Reference = RuntimeHelpers.GetHashCode(context.Shape); + var dump = new ObjectDumper(6).Dump(context.Shape, "Model"); var sb = new StringBuilder(); - context.Shape.LocalReferences = new Dictionary(); - foreach (var key in local.Keys) { - sb.Clear(); - ConvertToJSon(local[key], sb); - ((Dictionary) context.Shape.LocalReferences)[key] = sb.ToString(); - } + ConvertToJSon(dump, sb); + shape.Dump = sb.ToString(); shape.Template = null; shape.OriginalTemplate = descriptor.BindingSource; @@ -158,7 +152,7 @@ namespace Orchard.DesignerTools.Services { public void Displayed(ShapeDisplayedContext context) { } - private static void ConvertToJSon(XElement x, StringBuilder sb) { + public static void ConvertToJSon(XElement x, StringBuilder sb) { if(x == null) { return; } @@ -177,21 +171,18 @@ namespace Orchard.DesignerTools.Services { sb.AppendFormat("name: \"{0}\", ", FormatJsonValue(name)); sb.AppendFormat("value: \"{0}\"", FormatJsonValue(value)); - var a = x.Element("a"); - if (a != null) { - sb.AppendFormat(", children: shapeTracingMetadataHost.references[{0}]", a.Attribute("href").Value); - } - var ul = x.Element("ul"); - if (ul != null) { + if (ul != null && ul.Descendants().Any()) { sb.Append(", children: ["); foreach (var li in ul.Elements()) { sb.Append("{ "); ConvertToJSon(li, sb); - sb.Append(" },"); + sb.Append(" }"); + sb.Append(", "); } sb.Append("]"); } + break; } } diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml index a52d4d669..d861c8aef 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml @@ -20,10 +20,6 @@