From f4d630e2f601678f62bc3fc1248d89e0aa259a89 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sun, 19 Jul 2015 19:50:07 +0100 Subject: [PATCH] Simplified tabs harvesting and implemented sorting by shape position. --- .../Core/Contents/Views/Content.Edit.cshtml | 23 +++++++----------- src/Orchard.Web/Core/Shapes/CoreShapes.cs | 24 +++++++++++++++++++ .../Drivers/ContentShapeResult.cs | 18 +++----------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/Orchard.Web/Core/Contents/Views/Content.Edit.cshtml b/src/Orchard.Web/Core/Contents/Views/Content.Edit.cshtml index 31d40e223..293cdf522 100644 --- a/src/Orchard.Web/Core/Contents/Views/Content.Edit.cshtml +++ b/src/Orchard.Web/Core/Contents/Views/Content.Edit.cshtml @@ -1,13 +1,6 @@ -@{ - var tabs = ((IEnumerable)Model.Tabs).ToList(); - - // If we have any tabs, make sure we have at least the Content tab and that it is the first one, - // since that's where we will put antyhing else not part of a tab. - if (tabs.Any()) { - tabs.Remove("Content"); - tabs.Insert(0, "Content"); - } - +@using Orchard.Core.Shapes +@{ + var tabs = (IEnumerable)CoreShapes.HarvestAndSortTabs(Model.Content); Display.LocalNavigation(Tabs: tabs); }
@@ -19,11 +12,6 @@ }
- @if (Model.Actions != null) { -
- @Display(Model.Actions) -
- } @if (Model.Sidebar != null) {
@Display(Model.Sidebar) @@ -31,6 +19,11 @@ }
+@if (Model.Actions != null) { +
+ @Display(Model.Actions) +
+} @if (!String.IsNullOrWhiteSpace(Request.QueryString["returnUrl"])) { @Html.Hidden("returnUrl", Request.QueryString["returnUrl"]) diff --git a/src/Orchard.Web/Core/Shapes/CoreShapes.cs b/src/Orchard.Web/Core/Shapes/CoreShapes.cs index 1f01e168a..3e5172010 100644 --- a/src/Orchard.Web/Core/Shapes/CoreShapes.cs +++ b/src/Orchard.Web/Core/Shapes/CoreShapes.cs @@ -345,6 +345,30 @@ namespace Orchard.Core.Shapes { return ordering.Select(ordered => ordered.item).ToList(); } + public static IEnumerable HarvestAndSortTabs(IEnumerable shapes) { + var orderedShapes = Order(shapes).ToArray(); + var tabs = new List(); + + foreach (var shape in orderedShapes) { + var tab = (string)shape.Metadata.Tab; + + if (String.IsNullOrEmpty(tab)) + continue; + + if(!tabs.Contains(tab)) + tabs.Add(tab); + } + + // If we have any tabs, make sure we have at least the Content tab and that it is the first one, + // since that's where we will put anything else not part of a tab. + if (tabs.Any()) { + tabs.Remove("Content"); + tabs.Insert(0, "Content"); + } + + return tabs; + } + [Shape] public void HeadScripts(dynamic Display, TextWriter Output) { WriteResources(Display, Output, "script", ResourceLocation.Head, null); diff --git a/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs b/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs index 468782a81..5a1c4a2ca 100644 --- a/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs +++ b/src/Orchard/ContentManagement/Drivers/ContentShapeResult.cs @@ -28,7 +28,7 @@ namespace Orchard.ContentManagement.Drivers { private void ApplyImplementation(BuildShapeContext context, string displayType) { var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation); - if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-") + if (String.IsNullOrEmpty(placement.Location) || placement.Location == "-") return; // Parse group placement. @@ -37,7 +37,7 @@ namespace Orchard.ContentManagement.Drivers { _groupId = group; } - if (!string.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase)) + if (!String.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase)) return; dynamic parentShape = context.Shape; @@ -65,19 +65,7 @@ namespace Orchard.ContentManagement.Drivers { newShapeMetadata.DisplayType = displayType; newShapeMetadata.PlacementSource = placement.Source; newShapeMetadata.Tab = placement.GetTab(); - - // If a tab name is specified, add it to the list of tabs on the parent shape so it can render them. - var tabs = (HashSet)parentShape.Tabs; - - if (tabs == null) { - tabs = new HashSet(); - parentShape.Tabs = tabs; - } - - if (!String.IsNullOrEmpty(newShapeMetadata.Tab)) { - tabs.Add(newShapeMetadata.Tab); - } - + // If a specific shape is provided, remove all previous alternates and wrappers. if (!String.IsNullOrEmpty(placement.ShapeType)) { newShapeMetadata.Type = placement.ShapeType;