Updates lots of trees for searching and gets results grouped
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -18,6 +19,7 @@ using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.presentation.Trees;
|
||||
using Umbraco.Core.Services;
|
||||
using ApplicationTree = Umbraco.Core.Models.ApplicationTree;
|
||||
using IAuthorizationFilter = System.Web.Http.Filters.IAuthorizationFilter;
|
||||
using UrlHelper = System.Web.Http.Routing.UrlHelper;
|
||||
@@ -26,6 +28,48 @@ namespace Umbraco.Web.Trees
|
||||
{
|
||||
internal static class ApplicationTreeExtensions
|
||||
{
|
||||
|
||||
private static readonly ConcurrentDictionary<Type, TreeAttribute> TreeAttributeCache = new ConcurrentDictionary<Type, TreeAttribute>();
|
||||
|
||||
internal static TreeAttribute GetTreeAttribute(this Type treeControllerType)
|
||||
{
|
||||
return TreeAttributeCache.GetOrAdd(treeControllerType, type =>
|
||||
{
|
||||
//Locate the tree attribute
|
||||
var treeAttributes = type
|
||||
.GetCustomAttributes<TreeAttribute>(false)
|
||||
.ToArray();
|
||||
|
||||
if (treeAttributes.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute");
|
||||
}
|
||||
|
||||
//assign the properties of this object to those of the metadata attribute
|
||||
return treeAttributes[0];
|
||||
});
|
||||
}
|
||||
|
||||
internal static TreeAttribute GetTreeAttribute(this ApplicationTree tree)
|
||||
{
|
||||
return tree.GetRuntimeType().GetTreeAttribute();
|
||||
}
|
||||
|
||||
internal static string GetRootNodeDisplayName(this TreeAttribute attribute, ILocalizedTextService textService)
|
||||
{
|
||||
//if title is defined, return that
|
||||
if (string.IsNullOrEmpty(attribute.Title) == false)
|
||||
return attribute.Title;
|
||||
|
||||
|
||||
//try to look up a tree header matching the tree alias
|
||||
var localizedLabel = textService.Localize("treeHeaders/" + attribute.Alias);
|
||||
if (string.IsNullOrEmpty(localizedLabel) == false)
|
||||
return localizedLabel;
|
||||
|
||||
//is returned to signal that a label was not found
|
||||
return "[" + attribute.Alias + "]";
|
||||
}
|
||||
|
||||
internal static Attempt<Type> TryGetControllerTree(this ApplicationTree appTree)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user