Fixes boolean conversion logic in ColorPickerConfigurationEditor, Fixes tree grouping logic and moves groups cache to the ApplicationTreeService, fix other merge issues

This commit is contained in:
Shannon
2018-10-23 18:28:55 +11:00
parent d9a4d1fa97
commit 9dadecdcc1
7 changed files with 90 additions and 64 deletions

View File

@@ -21,20 +21,7 @@ namespace Umbraco.Web.Trees
[AngularJsonOnlyConfiguration]
[PluginController("UmbracoTrees")]
public class ApplicationTreeController : UmbracoAuthorizedApiController
{
/// <summary>
/// Fetches all registered trees and groups them together if they have a [CoreTree]
/// Attribute with a 'TreeGroup' property set
/// This allows the settings section trees to be grouped by Settings, Templating & Other
/// </summary>
private static readonly Lazy<IReadOnlyCollection<IGrouping<string, (Type, string)>>> CoreTrees
= new Lazy<IReadOnlyCollection<IGrouping<string, (Type, string)>>>(() =>
Current.Services.ApplicationTreeService.GetAllTypes()
.Select(x => (TreeType: x, TreeGroup: x.GetCustomAttribute<CoreTreeAttribute>(false)?.TreeGroup))
.GroupBy(x => x.TreeGroup)
.ToList());
{
/// <summary>
/// Returns the tree nodes for an application
/// </summary>
@@ -51,13 +38,14 @@ namespace Umbraco.Web.Trees
if (string.IsNullOrEmpty(application)) throw new HttpResponseException(HttpStatusCode.NotFound);
//find all tree definitions that have the current application alias
var appTrees = Services.ApplicationTreeService.GetApplicationTrees(application, onlyInitialized).ToArray();
var groupedTrees = Services.ApplicationTreeService.GetGroupedApplicationTrees(application, onlyInitialized);
var allTrees = groupedTrees.Values.SelectMany(x => x).ToList();
if (string.IsNullOrEmpty(tree) == false || appTrees.Length <= 1)
if (string.IsNullOrEmpty(tree) == false || allTrees.Count <= 1)
{
var apptree = string.IsNullOrEmpty(tree) == false
? appTrees.SingleOrDefault(x => x.Alias == tree)
: appTrees.SingleOrDefault();
var apptree = !tree.IsNullOrWhiteSpace()
? allTrees.FirstOrDefault(x => x.Alias == tree)
: allTrees.FirstOrDefault();
if (apptree == null) throw new HttpResponseException(HttpStatusCode.NotFound);
@@ -74,22 +62,22 @@ namespace Umbraco.Web.Trees
}
}
var collection = new TreeNodeCollection();
foreach (var apptree in appTrees)
{
//return the root nodes for each tree in the app
var rootNode = await GetRootForMultipleAppTree(apptree, queryStrings);
//This could be null if the tree decides not to return it's root (i.e. the member type tree does this when not in umbraco membership mode)
if (rootNode != null)
{
collection.Add(rootNode);
}
}
//Don't apply fancy grouping logic futher down, if we only have one group of items
var hasGroups = CoreTrees.Value.Count > 0;
var hasGroups = groupedTrees.Count > 1;
if (!hasGroups)
{
var collection = new TreeNodeCollection();
foreach (var apptree in allTrees)
{
//return the root nodes for each tree in the app
var rootNode = await GetRootForMultipleAppTree(apptree, queryStrings);
//This could be null if the tree decides not to return it's root (i.e. the member type tree does this when not in umbraco membership mode)
if (rootNode != null)
{
collection.Add(rootNode);
}
}
var multiTree = TreeRootNode.CreateMultiTreeRoot(collection);
multiTree.Name = Services.TextService.Localize("sections/" + application);
@@ -99,32 +87,23 @@ namespace Umbraco.Web.Trees
var rootNodeGroups = new List<TreeRootNode>();
//Group trees by [CoreTree] attribute with a TreeGroup property
foreach (var treeSectionGroup in CoreTrees.Value)
foreach (var treeSectionGroup in groupedTrees)
{
var treeGroupName = treeSectionGroup.Key;
var groupNodeCollection = new TreeNodeCollection();
foreach (var treeItem in treeSectionGroup)
foreach (var appTree in treeSectionGroup.Value)
{
//Item1 tuple - is the type from all tree types
var treeItemType = treeItem.Item1;
var findAppTree = appTrees.FirstOrDefault(x => x.GetRuntimeType() == treeItemType);
if (findAppTree != null)
var rootNode = await GetRootForMultipleAppTree(appTree, queryStrings);
if (rootNode != null)
{
//Now we need to get the 'TreeNode' which is in 'collection'
var treeItemNode = collection.FirstOrDefault(x => x.AdditionalData["treeAlias"].ToString() == findAppTree.Alias);
if (treeItemNode != null)
{
//Add to a new list/collection
groupNodeCollection.Add(treeItemNode);
}
//Add to a new list/collection
groupNodeCollection.Add(rootNode);
}
}
//If treeGroupName == null then its third party
if (treeGroupName == null)
if (treeGroupName.IsNullOrWhiteSpace())
{
//This is used for the localisation key
//treeHeaders/thirdPartyGroup