mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Converting local navs to a new core shape (AKA making louis happy :))
--HG-- branch : dev
This commit is contained in:
@@ -77,10 +77,10 @@ namespace Orchard.Tests.UI.Navigation {
|
|||||||
menu => menu
|
menu => menu
|
||||||
.Add(new LocalizedString("A"), "0", subMenu => subMenu.Action("Index", "Admin", new { area = "Area" })
|
.Add(new LocalizedString("A"), "0", subMenu => subMenu.Action("Index", "Admin", new { area = "Area" })
|
||||||
.Add(new LocalizedString("B"), "0", item => item.Action("Index", "Admin", new { area = "Area" }))
|
.Add(new LocalizedString("B"), "0", item => item.Action("Index", "Admin", new { area = "Area" }))
|
||||||
.Add(new LocalizedString("C"), "1", item => item.Action("Index", "Admin", new { area = "Area" }).LocalTask())))
|
.Add(new LocalizedString("C"), "1", item => item.Action("Index", "Admin", new { area = "Area" }).LocalNav())))
|
||||||
.Add(new LocalizedString("D"), "1", subMenu => subMenu.Action("Index", "Admin", new { area = "Area" }).LocalTask()
|
.Add(new LocalizedString("D"), "1", subMenu => subMenu.Action("Index", "Admin", new { area = "Area" }).LocalNav()
|
||||||
.Add(new LocalizedString("E"), "0", item => item.Action("Index", "Admin", new { area = "Area" }))
|
.Add(new LocalizedString("E"), "0", item => item.Action("Index", "Admin", new { area = "Area" }))
|
||||||
.Add(new LocalizedString("F"), "1", item => item.Action("Index", "Admin", new { area = "Area" }).LocalTask()));
|
.Add(new LocalizedString("F"), "1", item => item.Action("Index", "Admin", new { area = "Area" }).LocalNav()));
|
||||||
|
|
||||||
return navigationBuilder;
|
return navigationBuilder;
|
||||||
}
|
}
|
||||||
@@ -92,11 +92,11 @@ namespace Orchard.Tests.UI.Navigation {
|
|||||||
.Add(new LocalizedString("A"), "0", item => item.Action(SecondLevel1Action, "Admin", new { area = "Area" }))
|
.Add(new LocalizedString("A"), "0", item => item.Action(SecondLevel1Action, "Admin", new { area = "Area" }))
|
||||||
.Add(new LocalizedString("B"), "1",
|
.Add(new LocalizedString("B"), "1",
|
||||||
subMenu => subMenu
|
subMenu => subMenu
|
||||||
.Add(new LocalizedString("C"), "0", item => item.Action(ThirdLevel1Action, "Admin", new { area = "Area" }).LocalTask())
|
.Add(new LocalizedString("C"), "0", item => item.Action(ThirdLevel1Action, "Admin", new { area = "Area" }).LocalNav())
|
||||||
.Add(new LocalizedString("D"), "1",
|
.Add(new LocalizedString("D"), "1",
|
||||||
subSubMenu => subSubMenu.LocalTask()
|
subSubMenu => subSubMenu.LocalNav()
|
||||||
.Add(new LocalizedString("E"), "0", item => item.Action(FourthLevel1Action, "Admin", new { area = "Area" }).LocalTask())
|
.Add(new LocalizedString("E"), "0", item => item.Action(FourthLevel1Action, "Admin", new { area = "Area" }).LocalNav())
|
||||||
.Add(new LocalizedString("F"), "1", item => item.Action(FourthLevel2Action, "Admin", new { area = "Area" }).LocalTask())
|
.Add(new LocalizedString("F"), "1", item => item.Action(FourthLevel2Action, "Admin", new { area = "Area" }).LocalNav())
|
||||||
.Add(new LocalizedString("G"), "2", item => item.Action(FourthLevel3Action, "Admin", new { area = "Area" }))
|
.Add(new LocalizedString("G"), "2", item => item.Action(FourthLevel3Action, "Admin", new { area = "Area" }))
|
||||||
.Add(new LocalizedString("W"), "3", item => item.Action(FourthLevel4Action, "Admin", new { area = "Area" })))));
|
.Add(new LocalizedString("W"), "3", item => item.Action(FourthLevel4Action, "Admin", new { area = "Area" })))));
|
||||||
|
|
||||||
|
@@ -372,6 +372,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Shapes\Views\ShapeResult\Display.cshtml" />
|
<Content Include="Shapes\Views\ShapeResult\Display.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Shapes\Views\LocalMenu.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Shapes\Views\LocalMenuItem.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
@@ -85,6 +85,22 @@ namespace Orchard.Core.Shapes {
|
|||||||
menuItem.Metadata.Alternates.Add("MenuItem__" + menu.MenuName);
|
menuItem.Metadata.Alternates.Add("MenuItem__" + menu.MenuName);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Describe("LocalMenu")
|
||||||
|
.OnDisplaying(displaying => {
|
||||||
|
var menu = displaying.Shape;
|
||||||
|
string menuName = menu.MenuName;
|
||||||
|
menu.Classes.Add("localmenu-" + menuName.HtmlClassify());
|
||||||
|
menu.Classes.Add("localmenu");
|
||||||
|
menu.Metadata.Alternates.Add("LocalMenu__" + menuName);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Describe("LocalMenuItem")
|
||||||
|
.OnDisplaying(displaying => {
|
||||||
|
var menuItem = displaying.Shape;
|
||||||
|
var menu = menuItem.Menu;
|
||||||
|
menuItem.Metadata.Alternates.Add("LocalMenuItem__" + menu.MenuName);
|
||||||
|
});
|
||||||
|
|
||||||
// 'List' shapes start with several empty collections
|
// 'List' shapes start with several empty collections
|
||||||
builder.Describe("List")
|
builder.Describe("List")
|
||||||
.OnCreated(created => {
|
.OnCreated(created => {
|
||||||
|
10
src/Orchard.Web/Core/Shapes/Views/LocalMenu.cshtml
Normal file
10
src/Orchard.Web/Core/Shapes/Views/LocalMenu.cshtml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
@{
|
||||||
|
// Model is Model.Menu from the layout (Layout.Menu)
|
||||||
|
var tag = Tag(Model, "ul");
|
||||||
|
}
|
||||||
|
<nav>
|
||||||
|
@tag.StartElement
|
||||||
|
@* see MenuItem shape template *@
|
||||||
|
@DisplayChildren(Model)
|
||||||
|
@tag.EndElement
|
||||||
|
</nav>
|
22
src/Orchard.Web/Core/Shapes/Views/LocalMenuItem.cshtml
Normal file
22
src/Orchard.Web/Core/Shapes/Views/LocalMenuItem.cshtml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
@{
|
||||||
|
// odd formatting in this file is to cause more attractive results in the output.
|
||||||
|
var items = (IEnumerable<dynamic>)Enumerable.Cast<dynamic>(Model);
|
||||||
|
}
|
||||||
|
@{
|
||||||
|
if (!HasText(Model.Text)) {
|
||||||
|
@DisplayChildren(Model)
|
||||||
|
} else {
|
||||||
|
if (Model.Href.TrimEnd('/').ToUpperInvariant() == Request.Path.TrimEnd('/').ToUpperInvariant()) {
|
||||||
|
Model.Classes.Add("current");
|
||||||
|
}
|
||||||
|
var tag = Tag(Model, "li");
|
||||||
|
@tag.StartElement
|
||||||
|
<a href="@Model.Href">@Model.Text</a>
|
||||||
|
if (items.Any()) {
|
||||||
|
<ul>
|
||||||
|
@DisplayChildren(Model)
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
@tag.EndElement
|
||||||
|
}
|
||||||
|
}
|
@@ -301,12 +301,15 @@ form.link button:hover {
|
|||||||
padding:.4em 0 0 .4em;
|
padding:.4em 0 0 .4em;
|
||||||
font-size:1.308em;
|
font-size:1.308em;
|
||||||
}
|
}
|
||||||
.menu-local-admin li {
|
.localmenu li {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
.menu-local-admin li.middle {
|
.localmenu li.middle {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
|
.localmenu li.selected {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
.section-new {
|
.section-new {
|
||||||
border-top:1px solid #d3d3d3;
|
border-top:1px solid #d3d3d3;
|
||||||
border-bottom:1px solid #d3d3d3;
|
border-bottom:1px solid #d3d3d3;
|
||||||
|
@@ -120,7 +120,7 @@
|
|||||||
<Content Include="TheThemeMachine\Placement.info" />
|
<Content Include="TheThemeMachine\Placement.info" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="TheAdmin\Views\Menu__local_admin.cshtml" />
|
<Content Include="TheAdmin\Views\LocalMenu.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
|
@@ -46,12 +46,19 @@ namespace Orchard.UI.Navigation {
|
|||||||
workContext.Layout.Navigation.Add(menuShape);
|
workContext.Layout.Navigation.Add(menuShape);
|
||||||
|
|
||||||
// Populate local nav
|
// Populate local nav
|
||||||
dynamic localMenuShape = _shapeFactory.Menu().MenuName(string.Format("local_{0}", menuName));
|
dynamic localMenuShape = _shapeFactory.LocalMenu().MenuName(string.Format("local_{0}", menuName));
|
||||||
PopulateLocalMenu(_shapeFactory, localMenuShape, localMenuShape, selectedPath);
|
PopulateLocalMenu(_shapeFactory, localMenuShape, localMenuShape, selectedPath);
|
||||||
workContext.Layout.LocalNavigation.Add(localMenuShape);
|
workContext.Layout.LocalNavigation.Add(localMenuShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateMenu(dynamic shapeFactory, dynamic parentShape, dynamic menu, IEnumerable<MenuItem> menuItems) {
|
/// <summary>
|
||||||
|
/// Populates the menu shapes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shapeFactory">The shape factory.</param>
|
||||||
|
/// <param name="parentShape">The menu parent shape.</param>
|
||||||
|
/// <param name="menu">The menu shape.</param>
|
||||||
|
/// <param name="menuItems">The current level to populate.</param>
|
||||||
|
protected void PopulateMenu(dynamic shapeFactory, dynamic parentShape, dynamic menu, IEnumerable<MenuItem> menuItems) {
|
||||||
foreach (MenuItem menuItem in menuItems) {
|
foreach (MenuItem menuItem in menuItems) {
|
||||||
dynamic menuItemShape = BuildMenuItemShape(shapeFactory, parentShape, menu, menuItem);
|
dynamic menuItemShape = BuildMenuItemShape(shapeFactory, parentShape, menu, menuItem);
|
||||||
|
|
||||||
@@ -75,7 +82,26 @@ namespace Orchard.UI.Navigation {
|
|||||||
|
|
||||||
// find childs tabs and expand them
|
// find childs tabs and expand them
|
||||||
if (parentMenuItem != null && parentMenuItem.Items != null && parentMenuItem.Items.Any()) {
|
if (parentMenuItem != null && parentMenuItem.Items != null && parentMenuItem.Items.Any()) {
|
||||||
PopulateMenu(shapeFactory, parentShape, menu, parentMenuItem.Items);
|
PopulateLocalMenu(shapeFactory, parentShape, menu, parentMenuItem.Items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Populates the local menu shapes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shapeFactory">The shape factory.</param>
|
||||||
|
/// <param name="parentShape">The menu parent shape.</param>
|
||||||
|
/// <param name="menu">The menu shape.</param>
|
||||||
|
/// <param name="menuItems">The current level to populate.</param>
|
||||||
|
protected void PopulateLocalMenu(dynamic shapeFactory, dynamic parentShape, dynamic menu, IEnumerable<MenuItem> menuItems) {
|
||||||
|
foreach (MenuItem menuItem in menuItems) {
|
||||||
|
dynamic menuItemShape = BuildLocalMenuItemShape(shapeFactory, parentShape, menu, menuItem);
|
||||||
|
|
||||||
|
if (menuItem.Items != null && menuItem.Items.Any()) {
|
||||||
|
PopulateLocalMenu(shapeFactory, menuItemShape, menu, menuItem.Items);
|
||||||
|
}
|
||||||
|
|
||||||
|
parentShape.Add(menuItemShape, menuItem.Position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +191,27 @@ namespace Orchard.UI.Navigation {
|
|||||||
.Parent(parentShape);
|
.Parent(parentShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds a local menu item shape.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shapeFactory">The shape factory.</param>
|
||||||
|
/// <param name="parentShape">The parent shape.</param>
|
||||||
|
/// <param name="menu">The menu shape.</param>
|
||||||
|
/// <param name="menuItem">The menu item to build the shape for.</param>
|
||||||
|
/// <returns>The menu item shape.</returns>
|
||||||
|
protected dynamic BuildLocalMenuItemShape(dynamic shapeFactory, dynamic parentShape, dynamic menu, MenuItem menuItem) {
|
||||||
|
return shapeFactory.LocalMenuItem()
|
||||||
|
.Text(menuItem.Text)
|
||||||
|
.Href(menuItem.Href)
|
||||||
|
.LinkToFirstChild(menuItem.LinkToFirstChild)
|
||||||
|
.LocalNav(menuItem.LocalNav)
|
||||||
|
.Selected(menuItem.Selected)
|
||||||
|
.RouteValues(menuItem.RouteValues)
|
||||||
|
.Item(menuItem)
|
||||||
|
.Menu(menu)
|
||||||
|
.Parent(parentShape);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnResultExecuted(ResultExecutedContext filterContext) { }
|
public void OnResultExecuted(ResultExecutedContext filterContext) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -38,7 +38,7 @@ namespace Orchard.UI.Navigation {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigationItemBuilder LocalTask(bool value = true) {
|
public NavigationItemBuilder LocalNav(bool value = true) {
|
||||||
_item.LocalNav = value;
|
_item.LocalNav = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user