From c6def6681e560145a68ae4ac3386ee64775cab8a Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 22 Feb 2011 18:09:27 -0800 Subject: [PATCH] Adding placement source information in shape tracing --HG-- branch : dev --- .../Views/ShapeTracing.Wrapper.cshtml | 1 + .../ContentManagement/DefaultContentDisplay.cs | 13 +++++++++++-- .../ContentManagement/Drivers/ContentShapeResult.cs | 13 +++++++------ .../ContentManagement/Handlers/BuildShapeContext.cs | 6 ++++-- .../DisplayManagement/Descriptors/PlacementInfo.cs | 6 ++++++ .../Descriptors/ShapeAlterationBuilder.cs | 1 + .../ShapePlacementParsingStrategy.cs | 12 ++++++++++-- .../DisplayManagement/Shapes/ShapeMetadata.cs | 1 + src/Orchard/Orchard.Framework.csproj | 1 + 9 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 src/Orchard/DisplayManagement/Descriptors/PlacementInfo.cs diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracing.Wrapper.cshtml b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracing.Wrapper.cshtml index e0f45bfdb..761b1face 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracing.Wrapper.cshtml +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracing.Wrapper.cshtml @@ -37,6 +37,7 @@ Definition: @descriptor.BindingSource
Display Type: @(Model.Metadata.DisplayType ?? "n/a")
Position: @(Model.Metadata.Position ?? "n/a")
+ Placement Source: @(Model.Metadata.PlacementSource ?? "n/a")
diff --git a/src/Orchard/ContentManagement/DefaultContentDisplay.cs b/src/Orchard/ContentManagement/DefaultContentDisplay.cs index 4eb409277..f71b80ae5 100644 --- a/src/Orchard/ContentManagement/DefaultContentDisplay.cs +++ b/src/Orchard/ContentManagement/DefaultContentDisplay.cs @@ -112,10 +112,19 @@ namespace Orchard.ContentManagement { Differentiator = differentiator, Path = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.ToAppRelative(request.Path)) // get the current app-relative path, i.e. ~/my-blog/foo }; + var location = descriptor.Placement(placementContext); - return location ?? defaultLocation; + if (location != null) { + return new PlacementInfo { + Location = location, + Source = placementContext.Source + }; + } } - return defaultLocation; + return new PlacementInfo { + Location = defaultLocation, + Source = String.Empty + }; }; } } diff --git a/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs b/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs index 1f902d072..6f86f3217 100644 --- a/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs +++ b/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs @@ -25,8 +25,8 @@ namespace Orchard.ContentManagement.Drivers { } private void ApplyImplementation(BuildShapeContext context, string displayType) { - var location = context.FindPlacement(_shapeType, _differentiator, _defaultLocation); - if (string.IsNullOrEmpty(location) || location == "-") + var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation); + if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-") return; dynamic parentShape = context.Shape; @@ -34,14 +34,15 @@ namespace Orchard.ContentManagement.Drivers { ShapeMetadata newShapeMetadata = newShape.Metadata; newShapeMetadata.Prefix = _prefix; newShapeMetadata.DisplayType = displayType; + newShapeMetadata.PlacementSource = placement.Source; - var delimiterIndex = location.IndexOf(':'); + var delimiterIndex = placement.Location.IndexOf(':'); if (delimiterIndex < 0) { - parentShape.Zones[location].Add(newShape); + parentShape.Zones[placement.Location].Add(newShape); } else { - var zoneName = location.Substring(0, delimiterIndex); - var position = location.Substring(delimiterIndex + 1); + var zoneName = placement.Location.Substring(0, delimiterIndex); + var position = placement.Location.Substring(delimiterIndex + 1); parentShape.Zones[zoneName].Add(newShape, position); } } diff --git a/src/Orchard/ContentManagement/Handlers/BuildShapeContext.cs b/src/Orchard/ContentManagement/Handlers/BuildShapeContext.cs index 15d890bfe..43ee5d11a 100644 --- a/src/Orchard/ContentManagement/Handlers/BuildShapeContext.cs +++ b/src/Orchard/ContentManagement/Handlers/BuildShapeContext.cs @@ -1,5 +1,7 @@ using System; using Orchard.DisplayManagement; +using Orchard.DisplayManagement.Descriptors; +using Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy; namespace Orchard.ContentManagement.Handlers { public class BuildShapeContext { @@ -7,13 +9,13 @@ namespace Orchard.ContentManagement.Handlers { Shape = shape; ContentItem = content.ContentItem; New = shapeFactory; - FindPlacement = (partType, differentiator, defaultLocation) => defaultLocation; + FindPlacement = (partType, differentiator, defaultLocation) => new PlacementInfo {Location = defaultLocation, Source = String.Empty}; } public dynamic Shape { get; private set; } public ContentItem ContentItem { get; private set; } public dynamic New { get; private set; } - public Func FindPlacement { get; set; } + public Func FindPlacement { get; set; } } } \ No newline at end of file diff --git a/src/Orchard/DisplayManagement/Descriptors/PlacementInfo.cs b/src/Orchard/DisplayManagement/Descriptors/PlacementInfo.cs new file mode 100644 index 000000000..6ac999f6e --- /dev/null +++ b/src/Orchard/DisplayManagement/Descriptors/PlacementInfo.cs @@ -0,0 +1,6 @@ +namespace Orchard.DisplayManagement.Descriptors { + public class PlacementInfo { + public string Location { get; set; } + public string Source { get; set; } + } +} diff --git a/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs b/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs index f5799ac8d..eff4fb95b 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ShapeAlterationBuilder.cs @@ -112,5 +112,6 @@ namespace Orchard.DisplayManagement.Descriptors { public string DisplayType { get; set; } public string Differentiator { get; set; } public string Path { get; set; } + public string Source { get; set; } } } diff --git a/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs b/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs index b8e10e720..a9fdeaff0 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ShapePlacementStrategy/ShapePlacementParsingStrategy.cs @@ -65,12 +65,20 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy { } if (matches.Any()) { - predicate = matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate); + predicate = matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate); } builder.Describe(shapeType) .From(feature) - .Placement(predicate, shapeLocation.Location); + .Placement(ctx => { + var hit = predicate(ctx); + // generate 'debugging' information to trace which file originated the actual location + if (hit) { + var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info"; + ctx.Source = virtualPath; + } + return hit; + }, shapeLocation.Location); } } diff --git a/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs b/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs index 994c0a671..f514d0411 100644 --- a/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs +++ b/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs @@ -16,6 +16,7 @@ namespace Orchard.DisplayManagement.Shapes { public string Type { get; set; } public string DisplayType { get; set; } public string Position { get; set; } + public string PlacementSource { get; set; } public string Prefix { get; set; } public IList Wrappers { get; set; } public IList Alternates { get; set; } diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 5f9a0f167..8cbc50d78 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -158,6 +158,7 @@ +