Simplified tabs harvesting and implemented sorting by shape position.

This commit is contained in:
Sipke Schoorstra
2015-07-19 19:50:07 +01:00
parent 3c8e39a7c5
commit f4d630e2f6
3 changed files with 35 additions and 30 deletions

View File

@@ -1,13 +1,6 @@
@{
var tabs = ((IEnumerable<string>)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<string>)CoreShapes.HarvestAndSortTabs(Model.Content);
Display.LocalNavigation(Tabs: tabs);
}
<div class="edit-item">
@@ -19,11 +12,6 @@
}
</div>
<div class="edit-item-secondary group">
@if (Model.Actions != null) {
<div class="edit-item-actions">
@Display(Model.Actions)
</div>
}
@if (Model.Sidebar != null) {
<div class="edit-item-sidebar group">
@Display(Model.Sidebar)
@@ -31,6 +19,11 @@
}
</div>
</div>
@if (Model.Actions != null) {
<div class="edit-item-actions">
@Display(Model.Actions)
</div>
}
@if (!String.IsNullOrWhiteSpace(Request.QueryString["returnUrl"])) {
@Html.Hidden("returnUrl", Request.QueryString["returnUrl"])

View File

@@ -345,6 +345,30 @@ namespace Orchard.Core.Shapes {
return ordering.Select(ordered => ordered.item).ToList();
}
public static IEnumerable<string> HarvestAndSortTabs(IEnumerable<dynamic> shapes) {
var orderedShapes = Order(shapes).ToArray();
var tabs = new List<string>();
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);

View File

@@ -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<string>)parentShape.Tabs;
if (tabs == null) {
tabs = new HashSet<string>();
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;