mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Some work on letting modules be responsible for their own piece of the menu (wrt menu item icons & style)
--HG-- branch : dev
This commit is contained in:
@@ -8,8 +8,11 @@ namespace Orchard.Core.Dashboard {
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add(T("Dashboard"), "-5",
|
||||
menu => menu.Add(T("Orchard"), "-5", item => item.Action("Index", "Admin", new { area = "Dashboard" })
|
||||
builder.AddImageSet("dashboard.menu")
|
||||
.Add(T("Dashboard"), "-5",
|
||||
menu => menu.Add(T("Orchard"), "-5",
|
||||
item => item
|
||||
.Action("Index", "Admin", new { area = "Dashboard" })
|
||||
.Permission(StandardPermissions.AccessAdminPanel)));
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +0,0 @@
|
||||
#menu .menu-admin .section-dashboard h3 a {
|
||||
background-image:url(images/menu-dashboard.png);
|
||||
background-position:0 5px;
|
||||
}
|
||||
#menu .menu-admin .section-dashboard h3 a:hover {
|
||||
background-position:0 -16px;
|
||||
}
|
7
src/Orchard.Web/Core/Dashboard/styles/dashboard.menu.css
Normal file
7
src/Orchard.Web/Core/Dashboard/styles/dashboard.menu.css
Normal file
@@ -0,0 +1,7 @@
|
||||
.navicon-dashboard {
|
||||
background-image:url(images/dashboard.menu.png) !important;
|
||||
background-position:0 2px !important;
|
||||
}
|
||||
.navicon-dashboard:hover {
|
||||
background-position:0 -30px !important;
|
||||
}
|
@@ -9,7 +9,8 @@ namespace Orchard.Core.Navigation {
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
//todo: - add new menu? and list menus? ...and remove hard-coded menu name here
|
||||
builder.Add(T("Navigation"), "8",
|
||||
menu => menu.Add(T("Main Menu"), "0", item => item.Action("Index", "Admin", new { area = "Navigation" })
|
||||
menu => menu
|
||||
.Add(T("Main Menu"), "0", item => item.Action("Index", "Admin", new { area = "Navigation" })
|
||||
.Permission(Permissions.ManageMainMenu)));
|
||||
}
|
||||
}
|
||||
|
@@ -239,6 +239,8 @@
|
||||
<Content Include="Contents\Views\Admin\Create.cshtml" />
|
||||
<Content Include="Contents\Views\Admin\Edit.cshtml" />
|
||||
<Content Include="Contents\Views\Admin\List.cshtml" />
|
||||
<Content Include="Dashboard\styles\dashboard.menu.css" />
|
||||
<Content Include="Dashboard\styles\images\dashboard.menu.png" />
|
||||
<Content Include="Feeds\Views\Feed.cshtml" />
|
||||
<Content Include="Contents\Views\Parts.Contents.Publish.cshtml" />
|
||||
<Content Include="Contents\Views\Parts.Contents.Publish.SummaryAdmin.cshtml" />
|
||||
@@ -378,6 +380,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Shapes\Views\LocalMenuItem.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Dashboard\styles\Web.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.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.
|
||||
|
13
src/Orchard.Web/Modules/Orchard.Pages/AdminMenu.cs
Normal file
13
src/Orchard.Web/Modules/Orchard.Pages/AdminMenu.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Dashboard {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
public Localizer T { get; set; }
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.AddImageSet("page.menu");
|
||||
}
|
||||
}
|
||||
}
|
@@ -37,6 +37,7 @@
|
||||
<Reference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
@@ -54,8 +55,13 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Styles\page.menu.css" />
|
||||
<Content Include="Styles\images\page.menu.png" />
|
||||
<Content Include="web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Styles\Web.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
<ProjectExtensions>
|
||||
|
21
src/Orchard.Web/Modules/Orchard.Pages/Styles/Web.config
Normal file
21
src/Orchard.Web/Modules/Orchard.Pages/Styles/Web.config
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="webpages:Enabled" value="false" />
|
||||
</appSettings>
|
||||
<system.web>
|
||||
<httpHandlers>
|
||||
<!-- iis6 - for any request in this location, return via managed static file handler -->
|
||||
<add path="*" verb="*" type="System.Web.StaticFileHandler" />
|
||||
</httpHandlers>
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<handlers accessPolicy="Script,Read">
|
||||
<!--
|
||||
iis7 - for any request to a file exists on disk, return it via native http module.
|
||||
accessPolicy 'Script' is to allow for a managed 404 page.
|
||||
-->
|
||||
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
</configuration>
|
@@ -0,0 +1,7 @@
|
||||
.navicon-dashboard {
|
||||
background-image:url(images/dashboard.menu.png) !important;
|
||||
background-position:0 2px !important;
|
||||
}
|
||||
.navicon-dashboard:hover {
|
||||
background-position:0 -30px !important;
|
||||
}
|
@@ -343,19 +343,20 @@ form.link button:hover {
|
||||
padding:0 0 0 10px;
|
||||
}
|
||||
#menu .menu-admin li h3 a {
|
||||
background:url(images/menu-all.png) no-repeat 0 5px;
|
||||
background:url(images/menu-all.png) no-repeat 0 4px;
|
||||
padding:0 0 0 16px;
|
||||
}
|
||||
#menu .menu-admin li h3 a:hover {
|
||||
background-position:0 -17px;
|
||||
color:#fff;
|
||||
}
|
||||
/* todo: (heskew) pull out into the appropriate modules somehow when this is baked */
|
||||
/* todo: (heskew) pull out into the appropriate modules somehow when this is baked * /
|
||||
#menu .menu-admin .section-dashboard h3 a { background-position:0 -36px; }
|
||||
#menu .menu-admin .section-dashboard h3 a:hover { background-position:0 -56px; }
|
||||
/* todo: need to get the "New" sub items */
|
||||
/* todo: need to get the "New" sub items * /
|
||||
#menu .menu-admin .section-content h3 a { background-position:0 -247px; }
|
||||
#menu .menu-admin .section-content h3 a:hover { background-position:0 -268px; }
|
||||
/* todo: need an icon for "Blogs" */
|
||||
/* todo: need an icon for "Blogs" * /
|
||||
#menu .menu-admin .section-comments h3 a { background-position:0 -539px; }
|
||||
#menu .menu-admin .section-comments h3 a:hover { background-position:0 -559px; }
|
||||
#menu .menu-admin .section-lists h3 a { background-position:0 -289px; }
|
||||
@@ -374,7 +375,7 @@ form.link button:hover {
|
||||
#menu .menu-admin .section-themes h3 a:hover { background-position:0 -518px; }
|
||||
#menu .menu-admin .section-users h3 a { background-position:0 -619px; }
|
||||
#menu .menu-admin .section-users h3 a:hover { background-position:0 -640px; }
|
||||
|
||||
*/
|
||||
#menu .menu-admin li h3 a, #menu .menu-admin li h3 span {
|
||||
line-height:16px;
|
||||
color:#aec3ce;
|
||||
|
@@ -5,6 +5,10 @@
|
||||
Script.Include("admin.js");
|
||||
IEnumerable<dynamic> firstLevelMenuItems = Model;
|
||||
|
||||
foreach (var imageSet in Model.ImageSets) {
|
||||
RegisterImageSet(imageSet, Model.MenuName /* style */, 16 /* bounding box */);
|
||||
}
|
||||
|
||||
Model.Attributes.Add("role", "navigation");
|
||||
var tag = Tag(Model, "ul");
|
||||
}
|
||||
@@ -14,11 +18,28 @@
|
||||
|
||||
string sectionHeaderText = firstLevelMenuItem.Text;
|
||||
var firstOfTheSecond = secondLevelMenuItems.FirstOrDefault();
|
||||
var sectionHeaderMarkup = firstLevelMenuItem.RouteValues != null || HasText(firstLevelMenuItem.Url)
|
||||
? Html.Link(sectionHeaderText, (string)firstLevelMenuItem.Href)
|
||||
: firstOfTheSecond != null && firstLevelMenuItem.LinkToFirstChild
|
||||
? Html.Link(sectionHeaderText, (string)firstOfTheSecond.Href)
|
||||
: new HtmlString(string.Format("<span>{0}</span>", Html.Encode(sectionHeaderText)));
|
||||
|
||||
var imageClassName = "navicon-" + sectionHeaderText.TextHint.HtmlClassify();
|
||||
var imageId = HasText(firstLevelMenuItem.ImageId)
|
||||
? "navicon-" + firstLevelMenuItem.ImageId
|
||||
: null;
|
||||
|
||||
IHtmlString sectionHeaderMarkup;
|
||||
if (firstLevelMenuItem.RouteValues != null || HasText(firstLevelMenuItem.Url)) {
|
||||
sectionHeaderMarkup = HasText(imageId)
|
||||
? Html.Link(sectionHeaderText, (string)firstLevelMenuItem.Href, new { @class = imageClassName, id = imageId })
|
||||
: Html.Link(sectionHeaderText, (string)firstLevelMenuItem.Href, new { @class = imageClassName });
|
||||
}
|
||||
else if (firstOfTheSecond != null && firstLevelMenuItem.LinkToFirstChild && (firstOfTheSecond.RouteValues != null || HasText(firstOfTheSecond.Url))) {
|
||||
sectionHeaderMarkup = HasText(imageId)
|
||||
? Html.Link(sectionHeaderText, (string)firstOfTheSecond.Href, new { @class = imageClassName, id = imageId })
|
||||
: Html.Link(sectionHeaderText, (string)firstOfTheSecond.Href, new { @class = imageClassName });
|
||||
}
|
||||
else {
|
||||
sectionHeaderMarkup = HasText(imageId)
|
||||
? new HtmlString(string.Format(@"<span class=""{1}"" id=""{2}"">{0}</span>", Html.Encode(sectionHeaderText), Html.Encode(imageClassName), Html.Encode(imageId)))
|
||||
: new HtmlString(string.Format(@"<span class=""{1}"">{0}</span>", Html.Encode(sectionHeaderText), Html.Encode(imageClassName)));
|
||||
}
|
||||
|
||||
if (firstLevelMenuItem == firstLevelMenuItems.First()) {
|
||||
firstLevelMenuItem.Classes.Add("first");
|
||||
@@ -26,12 +47,11 @@
|
||||
if (firstLevelMenuItem == firstLevelMenuItems.Last()) {
|
||||
firstLevelMenuItem.Classes.Add("last");
|
||||
}
|
||||
|
||||
if (firstLevelMenuItem.Selected) {
|
||||
firstLevelMenuItem.Classes.Add("selected");
|
||||
}
|
||||
|
||||
firstLevelMenuItem.Classes.Add("section-" + sectionHeaderText.HtmlClassify());
|
||||
firstLevelMenuItem.Classes.Add("section-" + sectionHeaderText.TextHint.HtmlClassify());
|
||||
var firstLevelTag = Tag(firstLevelMenuItem, "li");
|
||||
@firstLevelTag.StartElement
|
||||
<h3>@sectionHeaderMarkup</h3>
|
||||
@@ -39,7 +59,7 @@
|
||||
<ul class="menuItems">
|
||||
@foreach (var secondLevelMenuItem in secondLevelMenuItems.Where(menuItem => !menuItem.LocalNav)) {
|
||||
if (secondLevelMenuItem.Selected) {
|
||||
secondLevelMenuItem.Classes.Add("selected");
|
||||
secondLevelMenuItem.Classes.Add("selected");
|
||||
}
|
||||
var secondLevelTag = Tag(secondLevelMenuItem, "li");
|
||||
@secondLevelTag.StartElement
|
||||
|
@@ -48,6 +48,10 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterImageSet(string imageSet, string style = "", int size = 16) {
|
||||
Style.Include(imageSet + ".css");
|
||||
}
|
||||
|
||||
public virtual void RegisterLink(LinkEntry link) {
|
||||
Html.Resolve<IResourceManager>().RegisterLink(link);
|
||||
}
|
||||
|
@@ -182,6 +182,7 @@ namespace Orchard.UI.Navigation {
|
||||
return shapeFactory.MenuItem()
|
||||
.Text(menuItem.Text)
|
||||
.Href(menuItem.Href)
|
||||
.Id(menuItem.Id)
|
||||
.LinkToFirstChild(menuItem.LinkToFirstChild)
|
||||
.LocalNav(menuItem.LocalNav)
|
||||
.Selected(menuItem.Selected)
|
||||
@@ -203,6 +204,7 @@ namespace Orchard.UI.Navigation {
|
||||
return shapeFactory.LocalMenuItem()
|
||||
.Text(menuItem.Text)
|
||||
.Href(menuItem.Href)
|
||||
.Id(menuItem.Id)
|
||||
.LinkToFirstChild(menuItem.LinkToFirstChild)
|
||||
.LocalNav(menuItem.LocalNav)
|
||||
.Selected(menuItem.Selected)
|
||||
|
@@ -17,6 +17,7 @@ namespace Orchard.UI.Navigation {
|
||||
public bool LinkToFirstChild { get; set; }
|
||||
public bool LocalNav { get; set; }
|
||||
public bool Selected { get; set; }
|
||||
public string Id { get; set; }
|
||||
public RouteValueDictionary RouteValues { get; set; }
|
||||
public IEnumerable<MenuItem> Items { get; set; }
|
||||
public IEnumerable<Permission> Permissions { get; set; }
|
||||
|
@@ -5,6 +5,7 @@ using Orchard.Localization;
|
||||
|
||||
namespace Orchard.UI.Navigation {
|
||||
public class NavigationBuilder {
|
||||
private readonly IList<string> _imageSets = new List<string>();
|
||||
IEnumerable<MenuItem> Contained { get; set; }
|
||||
|
||||
public NavigationBuilder Add(LocalizedString caption, string position, Action<NavigationItemBuilder> itemBuilder) {
|
||||
@@ -30,8 +31,16 @@ namespace Orchard.UI.Navigation {
|
||||
return Add(caption, null, x => { });
|
||||
}
|
||||
|
||||
public NavigationBuilder AddImageSet(string imageSet) {
|
||||
_imageSets.Add(imageSet);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IEnumerable<MenuItem> Build() {
|
||||
return (Contained ?? Enumerable.Empty<MenuItem>()).ToList();
|
||||
}
|
||||
public IEnumerable<string> BuildImageSets() {
|
||||
return _imageSets.Distinct();
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,6 +28,11 @@ namespace Orchard.UI.Navigation {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationItemBuilder Id(string id) {
|
||||
_item.Id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationItemBuilder LinkToFirstChild(bool value) {
|
||||
_item.LinkToFirstChild = value;
|
||||
return this;
|
||||
|
@@ -24,6 +24,10 @@ namespace Orchard.UI.Navigation {
|
||||
return FinishMenu(Crop(Reduce(Merge(sources))).ToArray());
|
||||
}
|
||||
|
||||
public IEnumerable<string> BuildImageSets(string menuName) {
|
||||
return GetImageSets(menuName).SelectMany(imageSets => imageSets.Distinct()).Distinct();
|
||||
}
|
||||
|
||||
private IEnumerable<MenuItem> FinishMenu(IEnumerable<MenuItem> menuItems) {
|
||||
foreach (var menuItem in menuItems) {
|
||||
menuItem.Href = GetUrl(menuItem.Url, menuItem.RouteValues);
|
||||
@@ -71,6 +75,7 @@ namespace Orchard.UI.Navigation {
|
||||
LocalNav = item.LocalNav,
|
||||
Text = item.Text,
|
||||
Url = item.Url,
|
||||
Id = item.Id,
|
||||
LinkToFirstChild = item.LinkToFirstChild,
|
||||
Href = item.Href
|
||||
};
|
||||
@@ -88,6 +93,16 @@ namespace Orchard.UI.Navigation {
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<IEnumerable<string>> GetImageSets(string menuName) {
|
||||
foreach (var provider in _providers) {
|
||||
if (provider.MenuName == menuName) {
|
||||
var builder = new NavigationBuilder();
|
||||
provider.GetNavigation(builder);
|
||||
yield return builder.BuildImageSets();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<MenuItem> Merge(IEnumerable<IEnumerable<MenuItem>> sources) {
|
||||
var comparer = new MenuItemComparer();
|
||||
var orderer = new FlatPositionComparer();
|
||||
@@ -105,8 +120,10 @@ namespace Orchard.UI.Navigation {
|
||||
Text = items.First().Text,
|
||||
Url = items.First().Url,
|
||||
Href = items.First().Href,
|
||||
Id = items.First().Id,
|
||||
LinkToFirstChild = items.First().LinkToFirstChild,
|
||||
RouteValues = items.First().RouteValues,
|
||||
LocalNav = items.Any(x => x.LocalNav),
|
||||
Items = Merge(items.Select(x => x.Items)).ToArray(),
|
||||
Position = SelectBestPositionValue(items.Select(x => x.Position)),
|
||||
Permissions = items.SelectMany(x => x.Permissions)
|
||||
|
Reference in New Issue
Block a user