diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index c3f973faac..31c14e00ad 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -38,5 +38,5 @@ + iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" sortOrder="10" />--> \ No newline at end of file diff --git a/src/Umbraco.Web/Trees/ApplicationTreeController.cs b/src/Umbraco.Web/Trees/ApplicationTreeController.cs index bd3d08b963..321108742d 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeController.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.Trees var rootId = Constants.System.Root.ToString(CultureInfo.InvariantCulture); //find all tree definitions that have the current application alias - var appTrees = ApplicationContext.Current.Services.ApplicationTreeService.GetApplicationTrees(application).Where(x => x.Initialize).ToArray(); + var appTrees = ApplicationContext.Current.Services.ApplicationTreeService.GetApplicationTrees(application, true).ToArray(); if (appTrees.Count() == 1) { return GetRootForSingleAppTree( diff --git a/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs b/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs index ca3f67cddc..622136a1ac 100644 --- a/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs +++ b/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs @@ -7,8 +7,11 @@ using System.Web; using System.Web.Http.Routing; using Umbraco.Core; using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Services; using Umbraco.Web.Trees.Menu; using umbraco; +using umbraco.BusinessLogic; using umbraco.BusinessLogic.Actions; using umbraco.cms.helpers; using umbraco.cms.presentation.Trees; @@ -17,6 +20,13 @@ using umbraco.interfaces; namespace Umbraco.Web.Trees { + /// + /// This attribute is used purely to maintain some compatibility with legacy webform tree pickers + /// + /// + /// This allows us to attribute new trees with their legacy counterparts and when a legacy tree is loaded this will indicate + /// on the new tree which legacy tree to load (it won't actually render using the new tree) + /// [AttributeUsage(AttributeTargets.Class)] internal sealed class LegacyBaseTreeAttribute : Attribute { @@ -32,80 +42,59 @@ namespace Umbraco.Web.Trees BaseTreeType = baseTreeType; } } - - internal class LegacyBaseTreeWrapper : BaseTree - { - - private readonly string _treeAlias; - private readonly TreeNodeCollection _children; - private readonly TreeNode _root; - - public LegacyBaseTreeWrapper(string treeAlias, string application, TreeNode root, TreeNodeCollection children = null) - : base(application) - { - _treeAlias = treeAlias; - _root = root; - _children = children; - } - - public override void RenderJS(ref StringBuilder javascript) - { - - } - - public override void Render(ref XmlTree tree) - { - foreach (var c in _children) - { - var node = XmlTreeNode.Create(this); - LegacyTreeDataConverter.ConvertToLegacyNode(node, c, _treeAlias); - node.Source = IsDialog == false ? GetTreeServiceUrl(int.Parse(node.NodeID)) : GetTreeDialogUrl(int.Parse(node.NodeID)); - tree.Add(node); - } - } - - protected override void CreateRootNode(ref XmlTreeNode rootNode) - { - rootNode.NodeID = _root.NodeId; - rootNode.Icon = _root.IconIsClass ? _root.Icon.EnsureStartsWith('.') : _root.IconFilePath; - rootNode.HasChildren = _root.HasChildren; - rootNode.NodeID = _root.NodeId; - rootNode.Text = _root.Title; - rootNode.NodeType = _root.NodeType; - rootNode.OpenIcon = _root.IconIsClass ? _root.Icon.EnsureStartsWith('.') : _root.IconFilePath; - } - - public override string TreeAlias - { - get { return _treeAlias; } - } - } - + /// /// Converts the legacy tree data to the new format /// internal class LegacyTreeDataConverter { - - internal static FormDataCollection ConvertFromLegacyTreeParams(TreeRequestParams treeParams) + /// + /// This is used by any legacy services that require rendering a BaseTree, if a new controller tree is detected it will try to invoke it's legacy predecessor. + /// + /// + /// + /// + internal static BaseTree GetLegacyTreeForLegacyServices(ApplicationTreeService appTreeService, string treeType) { - return new FormDataCollection(new Dictionary + BaseTree tree; + + //first get the app tree definition so we can then figure out if we need to load by legacy or new + //now we'll look up that tree + var appTree = appTreeService.GetByAlias(treeType); + if (appTree == null) + throw new InvalidOperationException("No tree found with alias " + treeType); + + var controllerAttempt = appTree.TryGetControllerTree(); + if (controllerAttempt.Success) + { + var legacyAtt = controllerAttempt.Result.GetCustomAttribute(false); + if (legacyAtt == null) { - {TreeQueryStringParameters.Application, treeParams.Application}, - {TreeQueryStringParameters.DialogMode, treeParams.IsDialog.ToString()}, - }); - } + LogHelper.Warn("Cannot render tree: " + treeType + ". Cannot render a " + typeof(TreeApiController) + " tree type with the legacy web services unless attributed with " + typeof(LegacyBaseTreeAttribute)); + return null; + } - internal static void ConvertToLegacyNode(XmlTreeNode legacy, TreeNode node, string treeType) - { - legacy.Action = node.AdditionalData.ContainsKey("legacyDialogAction") ? node.AdditionalData["legacyDialogAction"].ToString() : ""; - legacy.HasChildren = node.HasChildren; - legacy.Icon = node.IconIsClass ? node.Icon.EnsureStartsWith('.') : node.IconFilePath; - legacy.NodeID = node.NodeId; - legacy.NodeType = node.NodeType; - legacy.OpenIcon = node.IconIsClass ? node.Icon.EnsureStartsWith('.') : node.IconFilePath; - legacy.Text = node.Title; - legacy.TreeType = treeType; + var treeDef = new TreeDefinition( + legacyAtt.BaseTreeType, + new ApplicationTree(false, true, appTree.SortOrder, appTree.ApplicationAlias, appTree.Alias, appTree.Title, appTree.IconClosed, appTree.IconOpened, "", legacyAtt.BaseTreeType.GetFullNameWithAssembly(), ""), + new Application(treeType, treeType, "", 0)); + + tree = treeDef.CreateInstance(); + tree.TreeAlias = appTree.Alias; + + } + else + { + //get the tree that we need to render + var treeDef = TreeDefinitionCollection.Instance.FindTree(treeType); + if (treeDef == null) + { + return null; + } + tree = treeDef.CreateInstance(); + } + + return tree; } /// diff --git a/src/Umbraco.Web/Trees/MediaTreeController.cs b/src/Umbraco.Web/Trees/MediaTreeController.cs index 7eebed8181..65a15dc2e9 100644 --- a/src/Umbraco.Web/Trees/MediaTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTreeController.cs @@ -8,11 +8,13 @@ using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web.Mvc; using Umbraco.Web.Trees.Menu; +using umbraco; using umbraco.BusinessLogic.Actions; using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { + [LegacyBaseTree(typeof(loadMedia))] [Tree(Constants.Applications.Media, Constants.Trees.Media, "Media")] [PluginController("UmbracoTrees")] public class MediaTreeController : ContentTreeControllerBase diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs index 886eb71c89..8f71d235c0 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs @@ -69,80 +69,8 @@ namespace umbraco.presentation.webservices } else { - BaseTree tree = null; - var xTree = new XmlTree(); + var tree = LegacyTreeDataConverter.GetLegacyTreeForLegacyServices(Services.ApplicationTreeService, treeType); - //first get the app tree definition so we can then figure out if we need to load by legacy or new - //now we'll look up that tree - var appTree = Services.ApplicationTreeService.GetByAlias(treeType); - if (appTree == null) - throw new InvalidOperationException("No tree found with alias " + treeType); - - var controllerAttempt = appTree.TryGetControllerTree(); - if (controllerAttempt.Success) - { - var legacyAtt = controllerAttempt.Result.GetCustomAttribute(false); - if (legacyAtt == null) - { - throw new InvalidOperationException("Cannot render a " + typeof (TreeApiController) + " tree type with the legacy web services unless attributed with " + typeof (LegacyBaseTreeAttribute)); - } - - var treeDef = new TreeDefinition( - legacyAtt.BaseTreeType, - new ApplicationTree(false, true, appTree.SortOrder, appTree.ApplicationAlias, appTree.Alias, appTree.Title, appTree.IconClosed, appTree.IconOpened, "", legacyAtt.BaseTreeType.GetFullNameWithAssembly(), ""), - new Application(treeType, treeType, "", 0)); - - tree = treeDef.CreateInstance(); - tree.TreeAlias = appTree.Alias; - - //var queryStrings = new FormDataCollection(new Dictionary - // { - // {TreeQueryStringParameters.Application, app}, - // {TreeQueryStringParameters.DialogMode, isDialog.ToString()} - // }); - - //var context = WebApiHelper.CreateContext(new HttpMethod("GET"), Context.Request.Url, new HttpContextWrapper(Context)); - - //var rootAttempt = appTree.TryGetRootNodeFromControllerTree( - // queryStrings, - // context); - - //if (rootAttempt.Success) - //{ - // tree = new LegacyBaseTreeWrapper(treeType, app, rootAttempt.Result); - //} - } - else - { - //get the tree that we need to render - - var treeDef = TreeDefinitionCollection.Instance.FindTree(treeType); - //if (treeDef == null) - //{ - // // Load all LEGACY Trees by attribute and add them to the XML config - // var legacyTreeTypes = PluginManager.Current.ResolveAttributedTrees(); - // var found = legacyTreeTypes - // .Select(x => new { att = x.GetCustomAttribute(false), type = x }) - // .FirstOrDefault(x => x.att.Alias == treeType); - // if (found == null) - // { - // throw new InvalidOperationException("The " + GetType() + " service can only return data for legacy tree types"); - // } - // treeDef = new TreeDefinition( - // found.type, - // new ApplicationTree(found.att.Silent, found.att.Initialize, (byte)found.att.SortOrder, found.att.ApplicationAlias, found.att.Alias, found.att.Title, found.att.IconClosed, found.att.IconOpen, "", found.type.GetFullNameWithAssembly(), found.att.Action), - // new Application(treeType, treeType, "", 0)); - - // tree = treeDef.CreateInstance(); - //} - //else - //{ - // tree = treeDef.CreateInstance(); - //} - - tree = treeDef.CreateInstance(); - } - tree.ShowContextMenu = showContextMenu; tree.IsDialog = isDialog; tree.DialogMode = dialogMode; @@ -152,6 +80,7 @@ namespace umbraco.presentation.webservices //tree.StartNodeID = //now render it's start node + var xTree = new XmlTree(); xTree.Add(tree.RootNode); returnVal.Add("json", xTree.ToString()); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeDataService.ashx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeDataService.ashx.cs index dbc7113c0d..d4de749989 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeDataService.ashx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeDataService.ashx.cs @@ -81,14 +81,15 @@ namespace umbraco.presentation.webservices /// private void LoadAppTrees(TreeRequestParams treeParams, HttpContext context) { - //find all tree definitions that have the current application alias - List treeDefs = TreeDefinitionCollection.Instance.FindActiveTrees(treeParams.Application); - - foreach (TreeDefinition treeDef in treeDefs) + var appTrees = Services.ApplicationTreeService.GetApplicationTrees(treeParams.Application, true); + foreach (var appTree in appTrees) { - BaseTree bTree = treeDef.CreateInstance(); - bTree.SetTreeParameters(treeParams); - _xTree.Add(bTree.RootNode); + var tree = LegacyTreeDataConverter.GetLegacyTreeForLegacyServices(Services.ApplicationTreeService, appTree.Alias); + if (tree != null) + { + tree.SetTreeParameters(treeParams); + _xTree.Add(tree.RootNode); + } } } @@ -99,64 +100,17 @@ namespace umbraco.presentation.webservices /// private void LoadTree(TreeRequestParams treeParams, HttpContext httpContext) { - - var appTree = Services.ApplicationTreeService.GetByAlias(treeParams.TreeType); - if (appTree == null) - throw new InvalidOperationException("No tree found with alias " + treeParams.TreeType); - - var controllerAttempt = appTree.TryGetControllerTree(); - if (controllerAttempt.Success) + var tree = LegacyTreeDataConverter.GetLegacyTreeForLegacyServices(Services.ApplicationTreeService, treeParams.TreeType); + if (tree != null) { - var legacyAtt = controllerAttempt.Result.GetCustomAttribute(false); - if (legacyAtt == null) - { - throw new InvalidOperationException("Cannot render a " + typeof(TreeApiController) + " tree type with the legacy web services unless attributed with " + typeof(LegacyBaseTreeAttribute)); - } - - var treeDef = new TreeDefinition( - legacyAtt.BaseTreeType, - new ApplicationTree(false, true, appTree.SortOrder, appTree.ApplicationAlias, appTree.Alias, appTree.Title, appTree.IconClosed, appTree.IconOpened, "", legacyAtt.BaseTreeType.GetFullNameWithAssembly(), ""), - new Application(treeParams.TreeType, treeParams.TreeType, "", 0)); - - var tree = treeDef.CreateInstance(); - tree.TreeAlias = appTree.Alias; tree.SetTreeParameters(treeParams); tree.Render(ref _xTree); - - //var context = WebApiHelper.CreateContext(new HttpMethod("GET"), httpContext.Request.Url, new HttpContextWrapper(httpContext)); - - //var rootAttempt = appTree.TryGetRootNodeFromControllerTree( - // LegacyTreeDataConverter.ConvertFromLegacyTreeParams(treeParams), - // context); - - //var nodesAttempt = appTree.TryLoadFromControllerTree( - // treeParams.StartNodeID.ToInvariantString(), - // LegacyTreeDataConverter.ConvertFromLegacyTreeParams(treeParams), - // context); - - //if (rootAttempt.Success && nodesAttempt.Success) - //{ - // var tree = new LegacyBaseTreeWrapper(treeParams.TreeType, treeParams.Application, rootAttempt.Result, nodesAttempt.Result); - // tree.SetTreeParameters(treeParams); - // tree.Render(ref _xTree); - //} } else { - var treeDef = TreeDefinitionCollection.Instance.FindTree(treeParams.TreeType); - - if (treeDef != null) - { - var bTree = treeDef.CreateInstance(); - bTree.SetTreeParameters(treeParams); - bTree.Render(ref _xTree); - } - else - LoadNullTree(treeParams); + LoadNullTree(treeParams); } - - - + } ///