From 1667e914cd4354f9edcb45cedeaf0d4b3108faad Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 17 Jan 2019 18:38:55 +1100 Subject: [PATCH] Allows the tree collection to be manipulated by devs on startup, renames some things --- src/Umbraco.Web/Runtime/WebRuntimeComposer.cs | 13 +++++-------- src/Umbraco.Web/Services/ITreeService.cs | 8 ++++---- src/Umbraco.Web/Services/TreeService.cs | 8 ++++---- .../Trees/ApplicationTreeController.cs | 2 +- .../Trees/BackOfficeSectionCollectionBuilder.cs | 9 ++------- src/Umbraco.Web/Trees/ITree.cs | 3 ++- src/Umbraco.Web/Trees/Tree.cs | 2 +- src/Umbraco.Web/Trees/TreeCollectionBuilder.cs | 15 +++++++-------- 8 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs b/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs index f21c040a37..1a0bf8d1b0 100644 --- a/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs +++ b/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs @@ -1,15 +1,13 @@ -using System.Web; +using System.Linq; +using System.Web; using System.Web.Security; using Examine; using Microsoft.AspNet.SignalR; using Umbraco.Core; using Umbraco.Core.Components; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Dictionary; using Umbraco.Core.Events; -using Umbraco.Core.Models; -using Umbraco.Core.Models.ContentEditing; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.ValueConverters; @@ -23,9 +21,7 @@ using Umbraco.Web.Dictionary; using Umbraco.Web.Editors; using Umbraco.Web.Features; using Umbraco.Web.HealthCheck; -using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Models.PublishedContent; -using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; @@ -207,12 +203,13 @@ namespace Umbraco.Web.Runtime .Append(); // register back office trees - foreach (var treeControllerType in umbracoApiControllerTypes) + foreach (var treeControllerType in umbracoApiControllerTypes + .Where(x => typeof(TreeControllerBase).IsAssignableFrom(x))) { var attribute = treeControllerType.GetCustomAttribute(false); if (attribute == null) continue; var tree = new Tree(attribute.SortOrder, attribute.ApplicationAlias, attribute.TreeAlias, attribute.TreeTitle, treeControllerType, attribute.IsSingleNodeTree); - composition.WithCollectionBuilder().AddTree(tree); + composition.WithCollectionBuilder().Trees.Add(tree); } } } diff --git a/src/Umbraco.Web/Services/ITreeService.cs b/src/Umbraco.Web/Services/ITreeService.cs index 5172e4b7b7..96787086c6 100644 --- a/src/Umbraco.Web/Services/ITreeService.cs +++ b/src/Umbraco.Web/Services/ITreeService.cs @@ -26,16 +26,16 @@ namespace Umbraco.Web.Services /// /// Gets the application tree for the applcation with the specified alias /// - /// The application alias. + /// The application alias. /// Returns a ApplicationTree Array - IEnumerable GetApplicationTrees(string applicationAlias); + IEnumerable GetTrees(string sectionAlias); /// /// Gets the grouped application trees for the application with the specified alias /// - /// + /// /// - IDictionary> GetGroupedApplicationTrees(string applicationAlias); + IDictionary> GetGroupedTrees(string sectionAlias); } } diff --git a/src/Umbraco.Web/Services/TreeService.cs b/src/Umbraco.Web/Services/TreeService.cs index 8389c27a19..f58dce59bc 100644 --- a/src/Umbraco.Web/Services/TreeService.cs +++ b/src/Umbraco.Web/Services/TreeService.cs @@ -24,13 +24,13 @@ namespace Umbraco.Web.Services public IEnumerable GetAll() => _treeCollection; /// - public IEnumerable GetApplicationTrees(string applicationAlias) - => GetAll().Where(x => x.ApplicationAlias.InvariantEquals(applicationAlias)).OrderBy(x => x.SortOrder).ToList(); + public IEnumerable GetTrees(string sectionAlias) + => GetAll().Where(x => x.ApplicationAlias.InvariantEquals(sectionAlias)).OrderBy(x => x.SortOrder).ToList(); - public IDictionary> GetGroupedApplicationTrees(string applicationAlias) + public IDictionary> GetGroupedTrees(string sectionAlias) { var result = new Dictionary>(); - var foundTrees = GetApplicationTrees(applicationAlias).ToList(); + var foundTrees = GetTrees(sectionAlias).ToList(); foreach(var treeGroup in _groupedTrees.Value) { List resultGroup = null; diff --git a/src/Umbraco.Web/Trees/ApplicationTreeController.cs b/src/Umbraco.Web/Trees/ApplicationTreeController.cs index 5a0f72c8dc..5433f3c157 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeController.cs @@ -60,7 +60,7 @@ namespace Umbraco.Web.Trees if (string.IsNullOrEmpty(application)) throw new HttpResponseException(HttpStatusCode.NotFound); //find all tree definitions that have the current application alias - var groupedTrees = _treeService.GetGroupedApplicationTrees(application); + var groupedTrees = _treeService.GetGroupedTrees(application); var allTrees = groupedTrees.Values.SelectMany(x => x).ToList(); if (string.IsNullOrEmpty(tree) == false || allTrees.Count == 1) diff --git a/src/Umbraco.Web/Trees/BackOfficeSectionCollectionBuilder.cs b/src/Umbraco.Web/Trees/BackOfficeSectionCollectionBuilder.cs index ec5833f79c..3228cd309f 100644 --- a/src/Umbraco.Web/Trees/BackOfficeSectionCollectionBuilder.cs +++ b/src/Umbraco.Web/Trees/BackOfficeSectionCollectionBuilder.cs @@ -12,12 +12,6 @@ namespace Umbraco.Web.Trees { protected override BackOfficeSectionCollectionBuilder This => this; - // need to inject dependencies in the collection, so override creation - public override BackOfficeSectionCollection CreateCollection(IFactory factory) - { - return new BackOfficeSectionCollection(CreateItems(factory)); - } - protected override IEnumerable CreateItems(IFactory factory) { // get the manifest parser just-in-time - injecting it in the ctor would mean that @@ -25,7 +19,8 @@ namespace Umbraco.Web.Trees // its dependencies too, and that can create cycles or other oddities var manifestParser = factory.GetInstance(); - return base.CreateItems(factory).Concat(manifestParser.Manifest.Sections.Select(x => new ManifestBackOfficeSection(x.Key, x.Value))); + return base.CreateItems(factory) + .Concat(manifestParser.Manifest.Sections.Select(x => new ManifestBackOfficeSection(x.Key, x.Value))); } private class ManifestBackOfficeSection : IBackOfficeSection diff --git a/src/Umbraco.Web/Trees/ITree.cs b/src/Umbraco.Web/Trees/ITree.cs index f408ce5e60..867beda20e 100644 --- a/src/Umbraco.Web/Trees/ITree.cs +++ b/src/Umbraco.Web/Trees/ITree.cs @@ -1,7 +1,8 @@ namespace Umbraco.Web.Trees { //fixme - we don't really use this, it is nice to have the treecontroller, attribute and ApplicationTree streamlined to implement this but it's not used - public interface ITree + //leave as internal for now, maybe we'll use in the future, means we could pass around ITree + internal interface ITree { /// /// Gets or sets the sort order. diff --git a/src/Umbraco.Web/Trees/Tree.cs b/src/Umbraco.Web/Trees/Tree.cs index 3bac5bae58..39f5cec1eb 100644 --- a/src/Umbraco.Web/Trees/Tree.cs +++ b/src/Umbraco.Web/Trees/Tree.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.Trees public Type TreeControllerType { get; } - public static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService) + internal static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService) { var label = $"[{tree.TreeAlias}]"; diff --git a/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs b/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs index 143b8e308b..ae2675bac9 100644 --- a/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs +++ b/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs @@ -3,16 +3,15 @@ using Umbraco.Core.Composing; namespace Umbraco.Web.Trees { - //fixme - how will we allow users to modify these items? they will need to be able to change the ApplicationTree's registered (i.e. sort order, section) - public class TreeCollectionBuilder : CollectionBuilderBase + public class TreeCollectionBuilder : ICollectionBuilder { - private readonly List _instances = new List(); + /// + /// expose the list of trees which developers can manipulate before the collection is created + /// + public List Trees { get; } = new List(); - public void AddTree(Tree tree) - { - _instances.Add(tree); - } + public TreeCollection CreateCollection(IFactory factory) => new TreeCollection(Trees); - protected override IEnumerable CreateItems(IFactory factory) => _instances; + public void RegisterWith(IRegister register) => register.Register(CreateCollection, Lifetime.Singleton); } }