Got application level trees working (rendering) now, now to see how to render an iframe!
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
/// The integer identifier for media's recycle bin.
|
||||
/// </summary>
|
||||
public const int RecycleBinMedia = -21;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace Umbraco.Core.Trees
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Umbraco.Core.Trees
|
||||
{
|
||||
[DebuggerDisplay("Tree - {Title} ({ApplicationAlias})")]
|
||||
internal class ApplicationTree
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,6 @@ using Umbraco.Core.Trees;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using umbraco.cms.presentation.Trees;
|
||||
|
||||
namespace Umbraco.Web.Trees
|
||||
{
|
||||
@@ -49,12 +48,11 @@ namespace Umbraco.Web.Trees
|
||||
var collection = new TreeNodeCollection();
|
||||
foreach (var tree in appTrees)
|
||||
{
|
||||
var rootNodes = GetNodeCollection(tree, "-1", queryStrings);
|
||||
//return the root nodes for each tree in the app
|
||||
//collection.Add(); //GetNodeCollection(tree, "-1", queryStrings);
|
||||
|
||||
var rootNode = GetRoot(tree, queryStrings);
|
||||
collection.Add(rootNode);
|
||||
}
|
||||
return null;
|
||||
return collection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,6 +75,23 @@ namespace Umbraco.Web.Trees
|
||||
return GetNodeCollection(foundConfigTree, id, queryStrings);
|
||||
}
|
||||
|
||||
private TreeNode GetRoot(ApplicationTree configTree, FormDataCollection queryStrings)
|
||||
{
|
||||
if (configTree == null) throw new ArgumentNullException("configTree");
|
||||
var byControllerAttempt = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext, Request);
|
||||
if (byControllerAttempt.Success)
|
||||
{
|
||||
return byControllerAttempt.Result;
|
||||
}
|
||||
var legacyAttempt = configTree.TryGetRootNodeFromLegacyTree(queryStrings, Url);
|
||||
if (legacyAttempt.Success)
|
||||
{
|
||||
return legacyAttempt.Result;
|
||||
}
|
||||
|
||||
throw new ApplicationException("Could not get root node for tree type " + configTree.Alias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the node collection for the tree, try loading from new controllers first, then from legacy trees
|
||||
/// </summary>
|
||||
@@ -102,16 +117,7 @@ namespace Umbraco.Web.Trees
|
||||
}
|
||||
|
||||
|
||||
//Temporary, but necessary until we refactor trees in general
|
||||
internal class TreeParams : ITreeService
|
||||
{
|
||||
public string NodeKey { get; set; }
|
||||
public int StartNodeID { get; set; }
|
||||
public bool ShowContextMenu { get; set; }
|
||||
public bool IsDialog { get; set; }
|
||||
public TreeDialogModes DialogMode { get; set; }
|
||||
public string FunctionToCall { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Management.Instrumentation;
|
||||
using System.Net.Http;
|
||||
@@ -20,7 +21,7 @@ namespace Umbraco.Web.Trees
|
||||
internal static class ApplicationTreeExtensions
|
||||
{
|
||||
|
||||
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request)
|
||||
private static Attempt<Type> TryGetControllerTree(this ApplicationTree appTree)
|
||||
{
|
||||
//get reference to all TreeApiControllers
|
||||
var controllerTrees = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers
|
||||
@@ -31,8 +32,38 @@ namespace Umbraco.Web.Trees
|
||||
var foundControllerTree = controllerTrees.FirstOrDefault(x => x.GetFullNameWithAssembly() == appTree.Type);
|
||||
if (foundControllerTree == null)
|
||||
{
|
||||
return new Attempt<TreeNodeCollection>(new InstanceNotFoundException("Could not find tree of type " + appTree.Type + " in any loaded DLLs"));
|
||||
return new Attempt<Type>(new InstanceNotFoundException("Could not find tree of type " + appTree.Type + " in any loaded DLLs"));
|
||||
}
|
||||
return new Attempt<Type>(true, foundControllerTree);
|
||||
}
|
||||
|
||||
internal static Attempt<TreeNode> TryGetRootNodeFromControllerTree(this ApplicationTree appTree, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request)
|
||||
{
|
||||
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
|
||||
if (foundControllerTreeAttempt.Success == false)
|
||||
{
|
||||
return new Attempt<TreeNode>(foundControllerTreeAttempt.Error);
|
||||
}
|
||||
var foundControllerTree = foundControllerTreeAttempt.Result;
|
||||
//instantiate it, since we are proxying, we need to setup the instance with our current context
|
||||
var instance = (TreeApiController)DependencyResolver.Current.GetService(foundControllerTree);
|
||||
instance.ControllerContext = controllerContext;
|
||||
instance.Request = request;
|
||||
//return the root
|
||||
var nodes = instance.GetNodes(Constants.System.Root.ToString(CultureInfo.InvariantCulture), formCollection);
|
||||
return nodes.Any() == false
|
||||
? new Attempt<TreeNode>(new InvalidOperationException("Could not return a root node for tree " + appTree.Type))
|
||||
: new Attempt<TreeNode>(true, nodes.First());
|
||||
}
|
||||
|
||||
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request)
|
||||
{
|
||||
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
|
||||
if (foundControllerTreeAttempt.Success == false)
|
||||
{
|
||||
return new Attempt<TreeNodeCollection>(foundControllerTreeAttempt.Error);
|
||||
}
|
||||
var foundControllerTree = foundControllerTreeAttempt.Result;
|
||||
|
||||
//instantiate it, since we are proxying, we need to setup the instance with our current context
|
||||
var instance = (TreeApiController)DependencyResolver.Current.GetService(foundControllerTree);
|
||||
@@ -42,17 +73,40 @@ namespace Umbraco.Web.Trees
|
||||
return new Attempt<TreeNodeCollection>(true, instance.GetNodes(id, formCollection));
|
||||
}
|
||||
|
||||
internal static Attempt<TreeNodeCollection> TryLoadFromLegacyTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, UrlHelper urlHelper)
|
||||
internal static Attempt<TreeNode> TryGetRootNodeFromLegacyTree(this ApplicationTree appTree, FormDataCollection formCollection, UrlHelper urlHelper)
|
||||
{
|
||||
var treeDefAttempt = appTree.TryGetLegacyTreeDef();
|
||||
if (treeDefAttempt.Success == false)
|
||||
{
|
||||
return new Attempt<TreeNode>(treeDefAttempt.Error);
|
||||
}
|
||||
var treeDef = treeDefAttempt.Result;
|
||||
var bTree = treeDef.CreateInstance();
|
||||
var treeParams = new LegacyTreeParams(formCollection);
|
||||
bTree.SetTreeParameters(treeParams);
|
||||
return new Attempt<TreeNode>(true, LegacyTreeDataAdapter.ConvertFromLegacy(bTree.RootNode, urlHelper));
|
||||
}
|
||||
|
||||
private static Attempt<TreeDefinition> TryGetLegacyTreeDef(this ApplicationTree appTree)
|
||||
{
|
||||
//This is how the legacy trees worked....
|
||||
var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias);
|
||||
if (treeDef == null)
|
||||
{
|
||||
return new Attempt<TreeNodeCollection>(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias));
|
||||
}
|
||||
return treeDef == null
|
||||
? new Attempt<TreeDefinition>(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias))
|
||||
: new Attempt<TreeDefinition>(true, treeDef);
|
||||
}
|
||||
|
||||
internal static Attempt<TreeNodeCollection> TryLoadFromLegacyTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, UrlHelper urlHelper)
|
||||
{
|
||||
var treeDefAttempt = appTree.TryGetLegacyTreeDef();
|
||||
if (treeDefAttempt.Success == false)
|
||||
{
|
||||
return new Attempt<TreeNodeCollection>(treeDefAttempt.Error);
|
||||
}
|
||||
var treeDef = treeDefAttempt.Result;
|
||||
//This is how the legacy trees worked....
|
||||
var bTree = treeDef.CreateInstance();
|
||||
var treeParams = new ApplicationTreeApiController.TreeParams();
|
||||
var treeParams = new LegacyTreeParams(formCollection);
|
||||
|
||||
//we currently only support an integer id or a string id, we'll refactor how this works
|
||||
//later but we'll get this working first
|
||||
|
||||
@@ -11,6 +11,28 @@ namespace Umbraco.Web.Trees
|
||||
internal class LegacyTreeDataAdapter
|
||||
{
|
||||
|
||||
internal static TreeNode ConvertFromLegacy(XmlTreeNode xmlTreeNode, UrlHelper urlHelper)
|
||||
{
|
||||
// /umbraco/tree.aspx?rnd=d0d0ff11a1c347dabfaa0fc75effcc2a&id=1046&treeType=content&contextMenu=false&isDialog=false
|
||||
|
||||
//we need to convert the node source to our legacy tree controller
|
||||
var source = urlHelper.GetUmbracoApiService<LegacyTreeApiController>("GetNodes");
|
||||
//append the query strings
|
||||
var query = xmlTreeNode.Source.IsNullOrWhiteSpace()
|
||||
? new string[] { }
|
||||
: xmlTreeNode.Source.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
source += query.Length > 1 ? query[1].EnsureStartsWith('?') : "";
|
||||
|
||||
//TODO: Might need to add stuff to additional attributes
|
||||
|
||||
return new TreeNode(xmlTreeNode.NodeID, source)
|
||||
{
|
||||
HasChildren = xmlTreeNode.HasChildren,
|
||||
Icon = xmlTreeNode.Icon,
|
||||
Title = xmlTreeNode.Text
|
||||
};
|
||||
}
|
||||
|
||||
internal static TreeNodeCollection ConvertFromLegacy(XmlTree xmlTree, UrlHelper urlHelper)
|
||||
{
|
||||
//TODO: Once we get the editor URL stuff working we'll need to figure out how to convert
|
||||
@@ -19,24 +41,7 @@ namespace Umbraco.Web.Trees
|
||||
var collection = new TreeNodeCollection();
|
||||
foreach (var x in xmlTree.treeCollection)
|
||||
{
|
||||
// /umbraco/tree.aspx?rnd=d0d0ff11a1c347dabfaa0fc75effcc2a&id=1046&treeType=content&contextMenu=false&isDialog=false
|
||||
|
||||
//we need to convert the node source to our legacy tree controller
|
||||
var source = urlHelper.GetUmbracoApiService<LegacyTreeApiController>("GetNodes");
|
||||
//append the query strings
|
||||
var query = x.Source.IsNullOrWhiteSpace()
|
||||
? new string[] { }
|
||||
: x.Source.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
source += query.Length > 1 ? query[1].EnsureStartsWith('?') : "";
|
||||
|
||||
var node = new TreeNode(x.NodeID, source)
|
||||
{
|
||||
HasChildren = x.HasChildren,
|
||||
Icon = x.Icon,
|
||||
Title = x.Text
|
||||
};
|
||||
//TODO: Might need to add stuff to additional attributes
|
||||
collection.Add(node);
|
||||
collection.Add(ConvertFromLegacy(x, urlHelper));
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
34
src/Umbraco.Web/Trees/LegacyTreeParams.cs
Normal file
34
src/Umbraco.Web/Trees/LegacyTreeParams.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using umbraco.cms.presentation.Trees;
|
||||
|
||||
namespace Umbraco.Web.Trees
|
||||
{
|
||||
|
||||
//Temporary, but necessary until we refactor trees in general
|
||||
internal class LegacyTreeParams : ITreeService
|
||||
{
|
||||
public LegacyTreeParams()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public LegacyTreeParams(IEnumerable<KeyValuePair<string, string>> formCollection)
|
||||
{
|
||||
var p = TreeRequestParams.FromDictionary(formCollection.ToDictionary(x => x.Key, x => x.Value));
|
||||
NodeKey = p.NodeKey;
|
||||
StartNodeID = p.StartNodeID;
|
||||
ShowContextMenu = p.ShowContextMenu;
|
||||
IsDialog = p.IsDialog;
|
||||
DialogMode = p.DialogMode;
|
||||
FunctionToCall = p.FunctionToCall;
|
||||
}
|
||||
|
||||
public string NodeKey { get; set; }
|
||||
public int StartNodeID { get; set; }
|
||||
public bool ShowContextMenu { get; set; }
|
||||
public bool IsDialog { get; set; }
|
||||
public TreeDialogModes DialogMode { get; set; }
|
||||
public string FunctionToCall { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@ namespace Umbraco.Web.Trees
|
||||
return collection;
|
||||
}
|
||||
|
||||
protected override string RootNodeId
|
||||
{
|
||||
get { return (-1).ToString(CultureInfo.InvariantCulture); }
|
||||
}
|
||||
//protected override string RootNodeId
|
||||
//{
|
||||
// get { return (-1).ToString(CultureInfo.InvariantCulture); }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Formatting;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using umbraco.businesslogic;
|
||||
@@ -57,10 +59,10 @@ namespace Umbraco.Web.Trees
|
||||
/// </remarks>
|
||||
protected abstract TreeNodeCollection GetTreeData(string id, FormDataCollection queryStrings);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the root node for the tree
|
||||
/// </summary>
|
||||
protected abstract string RootNodeId { get; }
|
||||
///// <summary>
|
||||
///// Returns the root node for the tree
|
||||
///// </summary>
|
||||
//protected abstract string RootNodeId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name to display on the root node
|
||||
@@ -95,10 +97,14 @@ namespace Umbraco.Web.Trees
|
||||
/// <returns></returns>
|
||||
protected virtual TreeNode CreateRootNode(FormDataCollection queryStrings)
|
||||
{
|
||||
var getChildNodesUrl = Url.GetTreeUrl(GetType(), RootNodeId, queryStrings);
|
||||
var getChildNodesUrl = Url.GetTreeUrl(
|
||||
GetType(),
|
||||
Constants.System.Root.ToString(CultureInfo.InvariantCulture),
|
||||
queryStrings);
|
||||
|
||||
var isDialog = queryStrings.GetValue<bool>(TreeQueryStringParameters.DialogMode);
|
||||
//var node = new TreeNode(RootNodeId, BackOfficeRequestContext.RegisteredComponents.MenuItems, jsonUrl)
|
||||
var node = new TreeNode(RootNodeId, getChildNodesUrl)
|
||||
var node = new TreeNode(Constants.System.Root.ToString(CultureInfo.InvariantCulture), getChildNodesUrl)
|
||||
{
|
||||
HasChildren = true,
|
||||
|
||||
@@ -161,7 +167,7 @@ namespace Umbraco.Web.Trees
|
||||
protected bool AddRootNodeToCollection(string id, FormDataCollection queryStrings)
|
||||
{
|
||||
//if its the root model
|
||||
if (id == RootNodeId)
|
||||
if (id == Constants.System.Root.ToString(CultureInfo.InvariantCulture))
|
||||
{
|
||||
//get the root model
|
||||
var rootNode = CreateRootNode(queryStrings);
|
||||
|
||||
@@ -322,6 +322,7 @@
|
||||
<Compile Include="Trees\LegacyTreeApiController.cs" />
|
||||
<Compile Include="Trees\ISearchableTree.cs" />
|
||||
<Compile Include="Trees\LegacyTreeDataAdapter.cs" />
|
||||
<Compile Include="Trees\LegacyTreeParams.cs" />
|
||||
<Compile Include="Trees\SearchResultItem.cs" />
|
||||
<Compile Include="Trees\TreeApiController.cs" />
|
||||
<Compile Include="Trees\ApplicationTreeExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user