Fix the sort order of dictionary items in both the tree and list view

This commit is contained in:
Kenn Jacobsen
2018-11-18 13:31:10 +01:00
committed by Sebastiaan Janssen
parent 4e887b843b
commit fe26239f73
2 changed files with 10 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
@@ -194,7 +195,7 @@ namespace Umbraco.Web.Editors
const int level = 0;
foreach (var dictionaryItem in Services.LocalizationService.GetRootDictionaryItems())
foreach (var dictionaryItem in Services.LocalizationService.GetRootDictionaryItems().OrderBy(ItemSort()))
{
var item = Mapper.Map<IDictionaryItem, DictionaryOverviewDisplay>(dictionaryItem);
item.Level = 0;
@@ -220,8 +221,7 @@ namespace Umbraco.Web.Editors
/// </param>
private void GetChildItemsForList(IDictionaryItem dictionaryItem, int level, List<DictionaryOverviewDisplay> list)
{
foreach (var childItem in Services.LocalizationService.GetDictionaryItemChildren(
dictionaryItem.Key))
foreach (var childItem in Services.LocalizationService.GetDictionaryItemChildren(dictionaryItem.Key).OrderBy(ItemSort()))
{
var item = Mapper.Map<IDictionaryItem, DictionaryOverviewDisplay>(childItem);
item.Level = level;
@@ -230,5 +230,7 @@ namespace Umbraco.Web.Editors
GetChildItemsForList(childItem, level + 1, list);
}
}
private Func<IDictionaryItem, string> ItemSort() => item => item.ItemKey;
}
}

View File

@@ -3,6 +3,7 @@ using System.Linq;
using System.Net.Http.Formatting;
using umbraco.BusinessLogic.Actions;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.WebApi.Filters;
@@ -50,10 +51,12 @@ namespace Umbraco.Web.Trees
var nodes = new TreeNodeCollection();
Func<IDictionaryItem, string> ItemSort() => item => item.ItemKey;
if (id == Constants.System.Root.ToInvariantString())
{
nodes.AddRange(
Services.LocalizationService.GetRootDictionaryItems().Select(
Services.LocalizationService.GetRootDictionaryItems().OrderBy(ItemSort()).Select(
x => CreateTreeNode(
x.Id.ToInvariantString(),
id,
@@ -69,7 +72,7 @@ namespace Umbraco.Web.Trees
if (parentDictionary == null)
return nodes;
nodes.AddRange(Services.LocalizationService.GetDictionaryItemChildren(parentDictionary.Key).ToList().OrderByDescending(item => item.Key).Select(
nodes.AddRange(Services.LocalizationService.GetDictionaryItemChildren(parentDictionary.Key).ToList().OrderBy(ItemSort()).Select(
x => CreateTreeNode(
x.Id.ToInvariantString(),
id,