mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00

committed by
Sebastien Ros

parent
1086aaf0b7
commit
f3169400bc
@@ -6,6 +6,8 @@ using Orchard.Localization;
|
||||
using Orchard.Taxonomies.Models;
|
||||
using Orchard.Taxonomies.Services;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.Taxonomies.Helpers;
|
||||
|
||||
|
||||
namespace Orchard.Taxonomies.Navigation {
|
||||
/// <summary>
|
||||
@@ -32,21 +34,53 @@ namespace Orchard.Taxonomies.Navigation {
|
||||
|
||||
var rootTerm = _taxonomyService.GetTerm(taxonomyNavigationPart.TermId);
|
||||
|
||||
List<int> positionList = new List<int>();
|
||||
|
||||
var allTerms = rootTerm != null
|
||||
? _taxonomyService.GetChildren(rootTerm).ToArray()
|
||||
: _taxonomyService.GetTerms(taxonomyNavigationPart.TaxonomyId).ToArray();
|
||||
|
||||
var rootlevel = rootTerm == null ? 0 : rootTerm.GetLevels();
|
||||
|
||||
positionList.Add(0);
|
||||
|
||||
var menuPosition = item.Position;
|
||||
var rootPath = rootTerm == null ? "" : rootTerm.FullPath;
|
||||
int parentLevel = rootlevel;
|
||||
|
||||
foreach (var contentItem in allTerms) {
|
||||
if (contentItem != null) {
|
||||
var part = contentItem;
|
||||
|
||||
if (taxonomyNavigationPart.HideEmptyTerms == true && part.Count == 0) {
|
||||
continue;
|
||||
}
|
||||
string termPosition = "";
|
||||
if (part.GetLevels() - rootlevel > parentLevel) {
|
||||
positionList.Add(0);
|
||||
parentLevel = positionList.Count - 1;
|
||||
}
|
||||
else
|
||||
if ((part.GetLevels() - rootlevel) == parentLevel) {
|
||||
positionList[parentLevel]++;
|
||||
}
|
||||
else {
|
||||
positionList.RemoveRange(1, positionList.Count - 1);
|
||||
parentLevel = positionList.Count - 1;
|
||||
positionList[parentLevel]++;
|
||||
}
|
||||
|
||||
termPosition = positionList.First().ToString();
|
||||
foreach (var position in positionList.Skip(1)) {
|
||||
termPosition = termPosition + "." + position.ToString();
|
||||
}
|
||||
|
||||
|
||||
var menuText = _contentManager.GetItemMetadata(part).DisplayText;
|
||||
var routes = _contentManager.GetItemMetadata(part).DisplayRouteValues;
|
||||
|
||||
var positions = contentItem.FullPath.Substring(rootPath.Length).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Select(x => allTerms.First(t => t.Id == Int32.Parse(x)).Weight).ToArray();
|
||||
if (taxonomyNavigationPart.DisplayContentCount) {
|
||||
menuText = String.Format(menuText + " ({0})", part.Count.ToString());
|
||||
}
|
||||
|
||||
var inserted = new MenuItem {
|
||||
Text = new LocalizedString(menuText),
|
||||
@@ -58,7 +92,7 @@ namespace Orchard.Taxonomies.Navigation {
|
||||
RouteValues = routes,
|
||||
LocalNav = item.LocalNav,
|
||||
Items = new MenuItem[0],
|
||||
Position = menuPosition + ":" + String.Join(".", positions.Select(x => x.ToString()).ToArray()),
|
||||
Position = menuPosition + ":" + termPosition,
|
||||
Permissions = item.Permissions,
|
||||
Content = part
|
||||
};
|
||||
|
Reference in New Issue
Block a user