First attempt at getting legacy tree dialog to work with new trees. Just saving this revision since I might need to reference the code later but am going to revert since this doesn't seem like the way to go.

This commit is contained in:
Shannon
2013-09-04 12:01:41 +10:00
parent 91de4ebd42
commit f6ea604101
7 changed files with 106 additions and 39 deletions

View File

@@ -77,7 +77,7 @@ namespace Umbraco.Web.Trees
private TreeNode GetRootForMultipleAppTree(ApplicationTree configTree, FormDataCollection queryStrings)
{
if (configTree == null) throw new ArgumentNullException("configTree");
var byControllerAttempt = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext, Request);
var byControllerAttempt = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext);
if (byControllerAttempt.Success)
{
return byControllerAttempt.Result;
@@ -103,10 +103,10 @@ namespace Umbraco.Web.Trees
{
var rootId = Constants.System.Root.ToString(CultureInfo.InvariantCulture);
if (configTree == null) throw new ArgumentNullException("configTree");
var byControllerAttempt = configTree.TryLoadFromControllerTree(id, queryStrings, ControllerContext, Request);
var byControllerAttempt = configTree.TryLoadFromControllerTree(id, queryStrings, ControllerContext);
if (byControllerAttempt.Success)
{
var rootNode = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext, Request);
var rootNode = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext);
if (rootNode.Success == false)
{
//This should really never happen if we've successfully got the children above.

View File

@@ -22,7 +22,7 @@ namespace Umbraco.Web.Trees
internal static class ApplicationTreeExtensions
{
private static Attempt<Type> TryGetControllerTree(this ApplicationTree appTree)
internal static Attempt<Type> TryGetControllerTree(this ApplicationTree appTree)
{
//get reference to all TreeApiControllers
var controllerTrees = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers
@@ -38,7 +38,7 @@ namespace Umbraco.Web.Trees
return new Attempt<Type>(true, foundControllerTree);
}
internal static Attempt<TreeNode> TryGetRootNodeFromControllerTree(this ApplicationTree appTree, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request)
internal static Attempt<TreeNode> TryGetRootNodeFromControllerTree(this ApplicationTree appTree, FormDataCollection formCollection, HttpControllerContext controllerContext)
{
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
if (foundControllerTreeAttempt.Success == false)
@@ -49,7 +49,7 @@ namespace Umbraco.Web.Trees
//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;
instance.Request = controllerContext.Request;
//return the root
var node = instance.GetRootNode(formCollection);
return node == null
@@ -57,7 +57,7 @@ namespace Umbraco.Web.Trees
: new Attempt<TreeNode>(true, node);
}
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request)
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext)
{
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
if (foundControllerTreeAttempt.Success == false)
@@ -69,7 +69,7 @@ namespace Umbraco.Web.Trees
//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;
instance.Request = controllerContext.Request;
//return it's data
return new Attempt<TreeNodeCollection>(true, instance.GetNodes(id, formCollection));
}
@@ -99,7 +99,7 @@ namespace Umbraco.Web.Trees
return new Attempt<XmlTreeNode>(true, bTree.RootNode);
}
private static Attempt<TreeDefinition> TryGetLegacyTreeDef(this ApplicationTree appTree)
internal static Attempt<TreeDefinition> TryGetLegacyTreeDef(this ApplicationTree appTree)
{
//This is how the legacy trees worked....
var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias);

View File

@@ -20,6 +20,7 @@ namespace Umbraco.Web.Trees
/// </summary>
internal class LegacyTreeDataConverter
{
/// <summary>
/// Gets the menu item collection from a legacy tree node based on it's parent node's child collection
/// </summary>

View File

@@ -798,6 +798,7 @@
<Compile Include="WebApi\UmbracoAuthorizeAttribute.cs" />
<Compile Include="WebApi\UmbracoAuthorizedApiController.cs" />
<Compile Include="WebApi\Filters\ValidationFilterAttribute.cs" />
<Compile Include="WebApi\WebApiHelper.cs" />
<Compile Include="WebBootManager.cs" />
<Compile Include="Routing\LegacyRequestInitializer.cs" />
<Compile Include="Mvc\ControllerExtensions.cs" />

View File

@@ -1,4 +1,5 @@
using System.Web.Http.Controllers;
using System.Runtime.Remoting.Contexts;
using System.Web.Http.Controllers;
namespace Umbraco.Web.WebApi
{

View File

@@ -0,0 +1,31 @@
using System;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
namespace Umbraco.Web.WebApi
{
internal static class WebApiHelper
{
/// <summary>
/// A helper method to create a WebAPI HttpControllerContext which can be used to execute a controller manually
/// </summary>
/// <param name="method"></param>
/// <param name="uri"></param>
/// <param name="httpContext"></param>
/// <returns></returns>
internal static HttpControllerContext CreateContext(HttpMethod method, Uri uri, HttpContextBase httpContext)
{
var config = new HttpConfiguration(GlobalConfiguration.Configuration.Routes);
IHttpRouteData route = new HttpRouteData(new HttpRoute());
var req = new HttpRequestMessage(method, uri);
req.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
req.Properties[HttpPropertyKeys.HttpRouteDataKey] = route;
req.Properties["MS_HttpContext"] = httpContext;
return new HttpControllerContext(config, route, req);
}
}
}

View File

@@ -1,7 +1,16 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Services;
using Umbraco.Web.WebApi;
using Umbraco.Web.WebServices;
using umbraco.presentation.umbraco.controls;
using umbraco.cms.presentation.Trees;
@@ -11,29 +20,30 @@ using System.EnterpriseServices;
using System.IO;
using System.Web.UI;
using umbraco.controls.Tree;
using Umbraco.Web.Trees;
namespace umbraco.presentation.webservices
{
/// <summary>
/// Client side ajax utlities for the tree
/// </summary>
[ScriptService]
[WebService]
/// <summary>
/// Client side ajax utlities for the tree
/// </summary>
[ScriptService]
[WebService]
public class TreeClientService : UmbracoAuthorizedWebService
{
{
/// <summary>
/// Returns a key/value object with: json, app, js as the keys
/// </summary>
/// <returns></returns>
[WebMethod]
/// <summary>
/// Returns a key/value object with: json, app, js as the keys
/// </summary>
/// <returns></returns>
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Dictionary<string, string> GetInitAppTreeData(string app, string treeType, bool showContextMenu, bool isDialog, TreeDialogModes dialogMode, string functionToCall, string nodeKey)
{
AuthorizeRequest(app, true);
public Dictionary<string, string> GetInitAppTreeData(string app, string treeType, bool showContextMenu, bool isDialog, TreeDialogModes dialogMode, string functionToCall, string nodeKey)
{
AuthorizeRequest(app, true);
var treeCtl = new TreeControl()
{
var treeCtl = new TreeControl()
{
ShowContextMenu = showContextMenu,
IsDialog = isDialog,
DialogMode = dialogMode,
@@ -42,9 +52,9 @@ namespace umbraco.presentation.webservices
NodeKey = string.IsNullOrEmpty(nodeKey) ? "" : nodeKey,
StartNodeID = -1, //TODO: set this based on parameters!
FunctionToCall = string.IsNullOrEmpty(functionToCall) ? "" : functionToCall
};
};
var returnVal = new Dictionary<string, string>();
var returnVal = new Dictionary<string, string>();
if (string.IsNullOrEmpty(treeType))
{
@@ -54,7 +64,30 @@ namespace umbraco.presentation.webservices
}
else
{
//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 context = WebApiHelper.CreateContext(new HttpMethod("GET"), Context.Request.Url, new HttpContextWrapper(Context));
var rootAttempt = appTree.TryGetRootNodeFromControllerTree(
new FormDataCollection(new Dictionary<string, string> {{"app", app}}),
context);
if (rootAttempt.Success)
{
}
}
var legacyAttempt = appTree.TryGetLegacyTreeDef();
//get the tree that we need to render
var tree = TreeDefinitionCollection.Instance.FindTree(treeType).CreateInstance();
tree.ShowContextMenu = showContextMenu;
@@ -68,21 +101,21 @@ namespace umbraco.presentation.webservices
//now render it's start node
var xTree = new XmlTree();
xTree.Add(tree.RootNode);
returnVal.Add("json", xTree.ToString());
returnVal.Add("json", xTree.ToString());
}
returnVal.Add("app", app);
returnVal.Add("js", treeCtl.JSCurrApp);
returnVal.Add("js", treeCtl.JSCurrApp);
return returnVal;
}
return returnVal;
}
[Obsolete("Use the AuthorizeRequest methods on the base class UmbracoAuthorizedWebService instead")]
public static void Authorize()
{
if (!BasePages.BasePage.ValidateUserContextID(BasePages.BasePage.umbracoUserContextID))
throw new Exception("Client authorization failed. User is not logged in");
}
public static void Authorize()
{
if (!BasePages.BasePage.ValidateUserContextID(BasePages.BasePage.umbracoUserContextID))
throw new Exception("Client authorization failed. User is not logged in");
}
}
}
}