mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Refactoring Modules and Themes AdminMenu
Allowing menus to collapse when Url or RouteValues are not provided by some sources --HG-- branch : dev extra : transplant_source : al3%E5%F9%C8%B02%AB%20%2B8%B3%7B%AFa%CD%3Eo%1D
This commit is contained in:
@@ -6,15 +6,15 @@ namespace Orchard.Modules {
|
|||||||
public class AdminMenu : INavigationProvider {
|
public class AdminMenu : INavigationProvider {
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public string MenuName { get { return "admin"; } }
|
public string MenuName {
|
||||||
|
get { return "admin"; }
|
||||||
|
}
|
||||||
|
|
||||||
public void GetNavigation(NavigationBuilder builder) {
|
public void GetNavigation(NavigationBuilder builder) {
|
||||||
builder.AddImageSet("modules")
|
builder.AddImageSet("modules")
|
||||||
.Add(T("Modules"), "20", menu => menu
|
.Add(T("Modules"), "20", menu => menu.Action("Features", "Admin", new {area = "Orchard.Modules"}).Permission(Permissions.ManageFeatures)
|
||||||
.Add(T("Features"), "0", item => item.Action("Features", "Admin", new { area = "Orchard.Modules" })
|
.Add(T("Features"), "0", item => item.Action("Features", "Admin", new {area = "Orchard.Modules"}).Permission(Permissions.ManageFeatures).LocalNav())
|
||||||
.Permission(Permissions.ManageFeatures).LocalNav())
|
.Add(T("Installed"), "1", item => item.Action("Index", "Admin", new {area = "Orchard.Modules"}).Permission(StandardPermissions.SiteOwner).LocalNav()));
|
||||||
.Add(T("Installed"), "1", item => item.Action("Index", "Admin", new { area = "Orchard.Modules" })
|
|
||||||
.Permission(StandardPermissions.SiteOwner).LocalNav().Default()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,7 +8,7 @@ namespace Orchard.Themes {
|
|||||||
|
|
||||||
public void GetNavigation(NavigationBuilder builder) {
|
public void GetNavigation(NavigationBuilder builder) {
|
||||||
builder.AddImageSet("themes")
|
builder.AddImageSet("themes")
|
||||||
.Add(T("Themes"), "25", menu => menu
|
.Add(T("Themes"), "25", menu => menu.Action("Index", "Admin", new { area = "Orchard.Themes" }).Permission(Permissions.ApplyTheme)
|
||||||
.Add(T("Installed"), "0", item => item.Action("Index", "Admin", new { area = "Orchard.Themes" }).Permission(Permissions.ApplyTheme).LocalNav()));
|
.Add(T("Installed"), "0", item => item.Action("Index", "Admin", new { area = "Orchard.Themes" }).Permission(Permissions.ApplyTheme).LocalNav()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,16 +4,15 @@ using System.Linq;
|
|||||||
namespace Orchard.UI.Navigation {
|
namespace Orchard.UI.Navigation {
|
||||||
public class MenuItemComparer : IEqualityComparer<MenuItem> {
|
public class MenuItemComparer : IEqualityComparer<MenuItem> {
|
||||||
public bool Equals(MenuItem x, MenuItem y) {
|
public bool Equals(MenuItem x, MenuItem y) {
|
||||||
if (!string.Equals(x.Text, y.Text)) {
|
if (!string.Equals(x.TextHint, y.TextHint)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(x.Url) && !string.IsNullOrWhiteSpace(y.Url)) {
|
||||||
if (!string.Equals(x.Url, y.Url)) {
|
if (!string.Equals(x.Url, y.Url)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (x.RouteValues != null || y.RouteValues != null) {
|
|
||||||
if (x.RouteValues == null || y.RouteValues == null) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
if (x.RouteValues != null && y.RouteValues != null) {
|
||||||
if (x.RouteValues.Keys.Any(key => y.RouteValues.ContainsKey(key) == false)) {
|
if (x.RouteValues.Keys.Any(key => y.RouteValues.ContainsKey(key) == false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -32,21 +31,8 @@ namespace Orchard.UI.Navigation {
|
|||||||
|
|
||||||
public int GetHashCode(MenuItem obj) {
|
public int GetHashCode(MenuItem obj) {
|
||||||
var hash = 0;
|
var hash = 0;
|
||||||
if (obj.Text != null) {
|
if (obj.TextHint != null) {
|
||||||
hash ^= obj.Text.GetHashCode();
|
hash ^= obj.TextHint.GetHashCode();
|
||||||
}
|
|
||||||
if (obj.Url != null) {
|
|
||||||
hash ^= obj.Url.GetHashCode();
|
|
||||||
}
|
|
||||||
if (obj.RouteValues != null) {
|
|
||||||
foreach (var item in obj.RouteValues) {
|
|
||||||
if (item.Key != null) {
|
|
||||||
hash ^= item.Key.GetHashCode();
|
|
||||||
}
|
|
||||||
if (item.Value != null) {
|
|
||||||
hash ^= item.Value.GetHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@@ -127,16 +127,16 @@ namespace Orchard.UI.Navigation {
|
|||||||
var joined = new MenuItem {
|
var joined = new MenuItem {
|
||||||
Text = items.First().Text,
|
Text = items.First().Text,
|
||||||
TextHint = items.First().TextHint,
|
TextHint = items.First().TextHint,
|
||||||
IdHint = items.First().IdHint,
|
IdHint = items.Select(x => x.IdHint).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||||
Url = items.First().Url,
|
Url = items.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||||
Href = items.First().Href,
|
Href = items.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||||
LinkToFirstChild = items.First().LinkToFirstChild,
|
LinkToFirstChild = items.First().LinkToFirstChild,
|
||||||
RouteValues = items.First().RouteValues,
|
RouteValues = items.Select(x => x.RouteValues).FirstOrDefault(x => x != null),
|
||||||
LocalNav = items.Any(x => x.LocalNav),
|
LocalNav = items.Any(x => x.LocalNav),
|
||||||
Default = items.First().Default,
|
Default = items.First().Default,
|
||||||
Items = Merge(items.Select(x => x.Items)).ToArray(),
|
Items = Merge(items.Select(x => x.Items)).ToArray(),
|
||||||
Position = SelectBestPositionValue(items.Select(x => x.Position)),
|
Position = SelectBestPositionValue(items.Select(x => x.Position)),
|
||||||
Permissions = items.SelectMany(x => x.Permissions)
|
Permissions = items.SelectMany(x => x.Permissions).Distinct(),
|
||||||
};
|
};
|
||||||
return joined;
|
return joined;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user