mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-22 03:37:25 +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 Localizer T { get; set; }
|
||||
|
||||
public string MenuName { get { return "admin"; } }
|
||||
public string MenuName {
|
||||
get { return "admin"; }
|
||||
}
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.AddImageSet("modules")
|
||||
.Add(T("Modules"), "20", menu => menu
|
||||
.Add(T("Features"), "0", item => item.Action("Features", "Admin", new { area = "Orchard.Modules" })
|
||||
.Permission(Permissions.ManageFeatures).LocalNav())
|
||||
.Add(T("Installed"), "1", item => item.Action("Index", "Admin", new { area = "Orchard.Modules" })
|
||||
.Permission(StandardPermissions.SiteOwner).LocalNav().Default()));
|
||||
.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"}).Permission(Permissions.ManageFeatures).LocalNav())
|
||||
.Add(T("Installed"), "1", item => item.Action("Index", "Admin", new {area = "Orchard.Modules"}).Permission(StandardPermissions.SiteOwner).LocalNav()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ namespace Orchard.Themes {
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
@@ -4,16 +4,15 @@ using System.Linq;
|
||||
namespace Orchard.UI.Navigation {
|
||||
public class MenuItemComparer : IEqualityComparer<MenuItem> {
|
||||
public bool Equals(MenuItem x, MenuItem y) {
|
||||
if (!string.Equals(x.Text, y.Text)) {
|
||||
if (!string.Equals(x.TextHint, y.TextHint)) {
|
||||
return false;
|
||||
}
|
||||
if (!string.Equals(x.Url, y.Url)) {
|
||||
return false;
|
||||
}
|
||||
if (x.RouteValues != null || y.RouteValues != null) {
|
||||
if (x.RouteValues == null || y.RouteValues == null) {
|
||||
if (!string.IsNullOrWhiteSpace(x.Url) && !string.IsNullOrWhiteSpace(y.Url)) {
|
||||
if (!string.Equals(x.Url, y.Url)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (x.RouteValues != null && y.RouteValues != null) {
|
||||
if (x.RouteValues.Keys.Any(key => y.RouteValues.ContainsKey(key) == false)) {
|
||||
return false;
|
||||
}
|
||||
@@ -32,21 +31,8 @@ namespace Orchard.UI.Navigation {
|
||||
|
||||
public int GetHashCode(MenuItem obj) {
|
||||
var hash = 0;
|
||||
if (obj.Text != null) {
|
||||
hash ^= obj.Text.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();
|
||||
}
|
||||
}
|
||||
if (obj.TextHint != null) {
|
||||
hash ^= obj.TextHint.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
@@ -127,16 +127,16 @@ namespace Orchard.UI.Navigation {
|
||||
var joined = new MenuItem {
|
||||
Text = items.First().Text,
|
||||
TextHint = items.First().TextHint,
|
||||
IdHint = items.First().IdHint,
|
||||
Url = items.First().Url,
|
||||
Href = items.First().Href,
|
||||
IdHint = items.Select(x => x.IdHint).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||
Url = items.Select(x => x.Url).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||
Href = items.Select(x => x.Href).FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)),
|
||||
LinkToFirstChild = items.First().LinkToFirstChild,
|
||||
RouteValues = items.First().RouteValues,
|
||||
RouteValues = items.Select(x => x.RouteValues).FirstOrDefault(x => x != null),
|
||||
LocalNav = items.Any(x => x.LocalNav),
|
||||
Default = items.First().Default,
|
||||
Items = Merge(items.Select(x => x.Items)).ToArray(),
|
||||
Position = SelectBestPositionValue(items.Select(x => x.Position)),
|
||||
Permissions = items.SelectMany(x => x.Permissions)
|
||||
Permissions = items.SelectMany(x => x.Permissions).Distinct(),
|
||||
};
|
||||
return joined;
|
||||
}
|
||||
|
Reference in New Issue
Block a user