Rendering the Model as a tree in shape tracing

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2011-02-25 23:52:45 -08:00
parent ca6736525d
commit a395b47e66
8 changed files with 139 additions and 42 deletions

View File

@@ -60,6 +60,7 @@
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Styles\images\menu-glyph.png" />
<Content Include="Scripts\orchard-designertools-shapetracing.js" /> <Content Include="Scripts\orchard-designertools-shapetracing.js" />
<Content Include="Styles\orchard-designertools-shapetracing.css" /> <Content Include="Styles\orchard-designertools-shapetracing.css" />
<Content Include="Web.config"> <Content Include="Web.config">

View File

@@ -59,7 +59,7 @@
function bindTab(selector) { function bindTab(selector) {
$('li' + selector).click(function () { $('li' + selector).click(function () {
var _this = $(this); var _this = $(this);
// toggle the selected class on the tab li // toggle the selected class on the tab li
_this.parent().children('li').toggleClass('selected', false); _this.parent().children('li').toggleClass('selected', false);
_this.toggleClass('selected', true); _this.toggleClass('selected', true);
@@ -71,11 +71,33 @@
}); });
} }
var glyph = $("<span class=\"expando-glyph-container closed\"><span class=\"expando-glyph\"></span>&#8203;</span>");
$('div.model div.type').prev().prepend(glyph);
$('div.model ul ul').toggle(false);
$('span.expando-glyph-container').click(function () {
var __this = $(this);
if (__this.hasClass("closed") || __this.hasClass("closing")) {
__this.parent().parent().parent().children('ul').slideDown(300, function () { __this.removeClass("opening").removeClass("closed").addClass("open"); });
__this.addClass("opening");
}
else {
__this.parent().parent().parent().children('ul').slideUp(300, function () { __this.removeClass("closing").removeClass("open").addClass("closed"); });
__this.addClass("closing");
}
return false;
});
bindTab('.shape'); bindTab('.shape');
bindTab('.model'); bindTab('.model');
bindTab('.placement'); bindTab('.placement');
bindTab('.templates'); bindTab('.templates');
bindTab('.source'); bindTab('.source');
bindTab('.html'); bindTab('.html');
}); });
})(jQuery); })(jQuery);

View File

@@ -62,15 +62,19 @@ namespace Orchard.DesignerTools.Services {
private void DumpValue(object o, string name) { private void DumpValue(object o, string name) {
string formatted = FormatValue(o); string formatted = FormatValue(o);
_node.Add( _node.Add(
new XElement("div", new XAttribute("class", "name"), name), new XElement("h3",
new XElement("div", new XAttribute("class", "value"), formatted) new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "value"), formatted)
)
); );
} }
private void DumpObject(object o, string name) { private void DumpObject(object o, string name) {
_node.Add( _node.Add(
new XElement("div", new XAttribute("class", "name"), name), new XElement("h3",
new XElement("div", new XAttribute("class", "type"), FormatType(o.GetType())) new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "type"), FormatType(o.GetType()))
)
); );
if (_parents.Count >= _levels) { if (_parents.Count >= _levels) {
@@ -168,6 +172,10 @@ namespace Orchard.DesignerTools.Services {
_node.Add(_node = new XElement("ul")); _node.Add(_node = new XElement("ul"));
foreach (var key in props.Keys) { 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()); Dump(props[key], key.ToString());
} }
_node = _node.Parent; _node = _node.Parent;

View File

@@ -33,58 +33,56 @@ namespace Orchard.DesignerTools.Services {
&& context.ShapeType != "PlaceChildContent" && context.ShapeType != "PlaceChildContent"
&& context.ShapeType != "ContentZone" && context.ShapeType != "ContentZone"
&& context.ShapeType != "ShapeTracingMeta") { && context.ShapeType != "ShapeTracingMeta") {
var shape = context.Shape;
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata; var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext); var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id); var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
if(!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type)) { if (!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type)) {
return; return;
} }
var descriptor = shapeTable.Descriptors[shapeMetadata.Type];
shapeMetadata.Wrappers.Add("ShapeTracingWrapper"); shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
shape.Definition = descriptor.BindingSource;
try {
if (_webSiteFolder.FileExists(descriptor.BindingSource)) {
shape.DefinitionContent = _webSiteFolder.ReadFile(descriptor.BindingSource);
}
}
catch {
// the url might be invalid in case of a code shape
}
shape.Dump = DumpObject(shape);
}
}
static string DumpObject(object o) {
var dumper = new ObjectDumper(6);
var el = dumper.Dump(o, "Model");
using (var sw = new StringWriter()) {
el.WriteTo(new XmlTextWriter(sw) { Formatting = Formatting.Indented });
return sw.ToString();
} }
} }
public void Displaying(ShapeDisplayingContext context) { public void Displaying(ShapeDisplayingContext context) {
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata; var shape = context.Shape;
var shapeMetadata = (ShapeMetadata) context.Shape.Metadata;
if(!shapeMetadata.Wrappers.Contains("ShapeTracingWrapper")) { var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
if (!shapeMetadata.Wrappers.Contains("ShapeTracingWrapper")) {
return; return;
} }
if( shapeMetadata.PlacementSource != null && _webSiteFolder.FileExists(shapeMetadata.PlacementSource)) { var descriptor = shapeTable.Descriptors[shapeMetadata.Type];
// dump the Shape's content
var dumper = new ObjectDumper(6);
var el = dumper.Dump(context.Shape, "Model");
using (var sw = new StringWriter()) {
el.WriteTo(new XmlTextWriter(sw) {Formatting = Formatting.Indented});
context.Shape._Dump = sw.ToString();
}
shape._Definition = descriptor.BindingSource;
try {
if (_webSiteFolder.FileExists(descriptor.BindingSource)) {
shape._DefinitionContent = _webSiteFolder.ReadFile(descriptor.BindingSource);
}
}
catch {
// the url might be invalid in case of a code shape
}
if (shapeMetadata.PlacementSource != null && _webSiteFolder.FileExists(shapeMetadata.PlacementSource)) {
context.Shape.PlacementContent = _webSiteFolder.ReadFile(shapeMetadata.PlacementSource); context.Shape.PlacementContent = _webSiteFolder.ReadFile(shapeMetadata.PlacementSource);
} }
} }
public void Displayed(ShapeDisplayedContext context) { public void Displayed(ShapeDisplayedContext context) {
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

View File

@@ -138,3 +138,71 @@ ul.debuggerMenu { margin:8px 0 -8px 0; }
-webkit-border-radius: 3px; -webkit-border-radius: 3px;
-moz-border-radius: 3px; -moz-border-radius: 3px;
} }
.meta .model div.name
{
display:block;
float:left;
width:30%;
}
.meta .model ul
{
padding:0;
margin-left:-15px;
margin:0;
list-style-type:none;
}
.meta .model ul li
{
padding-left:15px;
}
.meta .model h3
{
margin:0;
padding:0;
}
h3:hover
{
background-color: #eee;
}
.expando-glyph {
background:transparent no-repeat 0 -19px;
background-image:url(images/menu-glyph.png);
line-height:12px;
padding-left:15px;
margin-left:-15px;
}
.expando-glyph:hover {
background-image:url(images/menu-glyph.png);
}
.expando-glyph-container.closed .expando-glyph {
background-image:url(images/menu-glyph.png);
background-position:0 3px;
}
.expando-glyph-container.closed .expando-glyph:hover {
background-image:url(images/menu-glyph.png);
}
.expando-glyph-container.closing .expando-glyph {
-webkit-transition:all .2s ease-in-out;
-moz-transition:all .2s ease-in-out;
transition:all .2s ease-in-out;
-webkit-transform:rotate(-90deg) translate(3px, -3px);
-moz-transform:rotate(-90deg) translate(3px, -3px);
transform:rotate(-90deg) translate(3px, -3px);
}
.expando-glyph-container.opening .expando-glyph {
-webkit-transition:all .2s ease-in-out;
-moz-transition:all .2s ease-in-out;
transition:all .2s ease-in-out;
-webkit-transform:rotate(90deg) translate(3px, 3px);
-moz-transform:rotate(90deg) translate(3px, 3px);
transform:rotate(90deg) translate(3px, 3px);
}

View File

@@ -24,7 +24,7 @@
</div> </div>
<div class="model" style="display:none"> <div class="model" style="display:none">
<pre>@Model.Dump</pre> @(new MvcHtmlString(@Model.Dump))
</div> </div>
<div class="placement" style="display:none"> <div class="placement" style="display:none">

View File

@@ -15,12 +15,12 @@
Layout.Zones["Tail"].Add( Layout.Zones["Tail"].Add(
New.ShapeTracingMeta( New.ShapeTracingMeta(
ShapeType: Model.Metadata.Type, ShapeType: Model.Metadata.Type,
Definition: Model.Definition, Definition: Model._Definition,
DefinitionContent: Model.DefinitionContent, DefinitionContent: Model._DefinitionContent,
DisplayType: Model.Metadata.DisplayType, DisplayType: Model.Metadata.DisplayType,
Position: Model.Metadata.Position, Position: Model.Metadata.Position,
PlacementSource: Model.Metadata.PlacementSource, PlacementSource: Model.Metadata.PlacementSource,
Dump: Model.Dump, Dump: Model._Dump,
PlacementContent: Model.PlacementContent, PlacementContent: Model.PlacementContent,
Alternates: Model.Metadata.Alternates, Alternates: Model.Metadata.Alternates,
Wrappers: Model.Metadata.Wrappers, Wrappers: Model.Metadata.Wrappers,