Completes: U4-3155 Ensure new tree events are fired for legacy trees

This commit is contained in:
Shannon
2013-10-28 13:45:38 +11:00
parent e707506303
commit 3110b199c6
6 changed files with 164 additions and 118 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<trees>
<!--Content-->
<add initialize="true" sortOrder="0" alias="content" application="content" title="Content" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.ContentTreeController, umbraco" action="" />
<add initialize="false" sortOrder="0" alias="contentRecycleBin" application="content" title="Recycle Bin" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.cms.presentation.Trees.ContentRecycleBin, umbraco" action="" />
<add initialize="true" sortOrder="0" alias="content" application="content" title="Content" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.ContentTreeController, umbraco" />
<add initialize="false" sortOrder="0" alias="contentRecycleBin" application="content" title="Recycle Bin" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.cms.presentation.Trees.ContentRecycleBin, umbraco" />
<!--Media-->
<add initialize="true" sortOrder="0" alias="media" application="media" title="Media" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.MediaTreeController, umbraco" />
<add initialize="false" sortOrder="0" alias="mediaRecycleBin" application="media" title="Recycle Bin" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.cms.presentation.Trees.MediaRecycleBin, umbraco" />
@@ -12,7 +12,7 @@
<add application="settings" alias="templates" title="Templates" type="umbraco.loadTemplates, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="1" />
<add application="settings" alias="partialViews" title="Partial Views" silent="false" initialize="true" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.PartialViewsTree, umbraco" sortOrder="2" />
<add application="settings" alias="scripts" title="Scripts" type="umbraco.loadScripts, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="3" />
<add application="settings" alias="dictionary" title="Dictionary" type="umbraco.loadDictionary, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" action="openDictionary()" sortOrder="4" />
<add application="settings" alias="dictionary" title="Dictionary" type="umbraco.loadDictionary, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="4" />
<add application="settings" alias="languages" title="Languages" type="umbraco.loadLanguages, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="5" />
<add application="settings" alias="mediaTypes" title="Media Types" type="umbraco.loadMediaTypes, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="6" />
<add application="settings" alias="nodeTypes" title="Document Types" type="umbraco.loadNodeTypes, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="7" />
@@ -34,8 +34,8 @@
<add application="member" alias="memberGroup" title="Member Groups" type="umbraco.loadMemberGroups, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="1" />
<add application="member" alias="memberType" title="Member Types" type="umbraco.loadMemberTypes, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="2" />
<!--Translation-->
<add silent="false" initialize="true" sortOrder="1" alias="openTasks" application="translation" title="Tasks assigned to you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadOpenTasks, umbraco" action="" />
<add silent="false" initialize="true" sortOrder="2" alias="yourTasks" application="translation" title="Tasks created by you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadYourTasks, umbraco" action="" />
<add silent="false" initialize="true" sortOrder="1" alias="openTasks" application="translation" title="Tasks assigned to you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadOpenTasks, umbraco" />
<add silent="false" initialize="true" sortOrder="2" alias="yourTasks" application="translation" title="Tasks created by you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadYourTasks, umbraco" />
<!-- Custom -->
<!--<add application="myApplication" alias="myTree" title="Me Tree" type="MyNamespace.myTree, MyAssembly"
iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="10" />-->

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<trees>
<!--Content-->
<add initialize="true" sortOrder="0" alias="content" application="content" title="Content" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.ContentTreeController, umbraco" action="" />
<add initialize="false" sortOrder="0" alias="contentRecycleBin" application="content" title="Recycle Bin" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.cms.presentation.Trees.ContentRecycleBin, umbraco" action="" />
<add initialize="true" sortOrder="0" alias="content" application="content" title="Content" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.ContentTreeController, umbraco" />
<add initialize="false" sortOrder="0" alias="contentRecycleBin" application="content" title="Recycle Bin" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.cms.presentation.Trees.ContentRecycleBin, umbraco" />
<!--Media-->
<add initialize="true" sortOrder="0" alias="media" application="media" title="Media" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.MediaTreeController, umbraco" />
<add initialize="false" sortOrder="0" alias="mediaRecycleBin" application="media" title="Recycle Bin" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.cms.presentation.Trees.MediaRecycleBin, umbraco" />
@@ -12,7 +12,7 @@
<add application="settings" alias="templates" title="Templates" type="umbraco.loadTemplates, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="1" />
<add application="settings" alias="partialViews" title="Partial Views" silent="false" initialize="true" iconClosed="icon-folder" iconOpen="icon-folder" type="Umbraco.Web.Trees.PartialViewsTree, umbraco" sortOrder="2" />
<add application="settings" alias="scripts" title="Scripts" type="umbraco.loadScripts, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="3" />
<add application="settings" alias="dictionary" title="Dictionary" type="umbraco.loadDictionary, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" action="openDictionary()" sortOrder="4" />
<add application="settings" alias="dictionary" title="Dictionary" type="umbraco.loadDictionary, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="4" />
<add application="settings" alias="languages" title="Languages" type="umbraco.loadLanguages, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="5" />
<add application="settings" alias="mediaTypes" title="Media Types" type="umbraco.loadMediaTypes, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="6" />
<add application="settings" alias="nodeTypes" title="Document Types" type="umbraco.loadNodeTypes, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="7" />
@@ -34,8 +34,8 @@
<add application="member" alias="memberGroup" title="Member Groups" type="umbraco.loadMemberGroups, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="1" />
<add application="member" alias="memberType" title="Member Types" type="umbraco.loadMemberTypes, umbraco" iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="2" />
<!--Translation-->
<add silent="false" initialize="true" sortOrder="1" alias="openTasks" application="translation" title="Tasks assigned to you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadOpenTasks, umbraco" action="" />
<add silent="false" initialize="true" sortOrder="2" alias="yourTasks" application="translation" title="Tasks created by you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadYourTasks, umbraco" action="" />
<add silent="false" initialize="true" sortOrder="1" alias="openTasks" application="translation" title="Tasks assigned to you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadOpenTasks, umbraco" />
<add silent="false" initialize="true" sortOrder="2" alias="yourTasks" application="translation" title="Tasks created by you" iconClosed="icon-folder" iconOpen="icon-folder" type="umbraco.loadYourTasks, umbraco" />
<!-- Custom -->
<!--<add application="myApplication" alias="myTree" title="Me Tree" type="MyNamespace.myTree, MyAssembly"
iconClosed="icon-folder" iconOpen="icon-folder" sortOrder="10" />-->

View File

@@ -81,8 +81,12 @@ namespace Umbraco.Web.Trees
{
return Attempt<TreeNode>.Fail(xmlTreeNodeAttempt.Exception);
}
return Attempt.Succeed(
LegacyTreeDataConverter.ConvertFromLegacy(xmlTreeNodeAttempt.Result.NodeID, xmlTreeNodeAttempt.Result, urlHelper, currentSection, formCollection, isRoot: true));
var legacyController = new LegacyTreeController(xmlTreeNodeAttempt.Result, appTree.Alias, currentSection, urlHelper);
var newRoot = legacyController.GetRootNode(formCollection);
return Attempt.Succeed(newRoot);
}
internal static Attempt<XmlTreeNode> TryGetRootXmlNodeFromLegacyTree(this ApplicationTree appTree, FormDataCollection formCollection, UrlHelper urlHelper)
@@ -96,7 +100,10 @@ namespace Umbraco.Web.Trees
var bTree = treeDef.CreateInstance();
var treeParams = new LegacyTreeParams(formCollection);
bTree.SetTreeParameters(treeParams);
return Attempt.Succeed(bTree.RootNode);
var xmlRoot = bTree.RootNode;
return Attempt.Succeed(xmlRoot);
}
internal static Attempt<TreeDefinition> TryGetLegacyTreeDef(this ApplicationTree appTree)

View File

@@ -2,6 +2,7 @@
using System.Globalization;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web.Http.Routing;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
@@ -9,6 +10,7 @@ using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using Umbraco.Web.WebApi.Filters;
using umbraco.cms.presentation.Trees;
namespace Umbraco.Web.Trees
{
@@ -17,16 +19,40 @@ namespace Umbraco.Web.Trees
/// This is used to output JSON from legacy trees
/// </summary>
[PluginController("UmbracoTrees")]
public class LegacyTreeController : UmbracoAuthorizedApiController
//public class LegacyTreeController : UmbracoAuthorizedApiController
public class LegacyTreeController : TreeControllerBase
{
/// <summary>
/// Convert a legacy tree to a new tree result
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
[HttpQueryStringFilter("queryStrings")]
public TreeNodeCollection GetNodes(string id, FormDataCollection queryStrings)
private readonly XmlTreeNode _xmlTreeNode;
private readonly string _treeAlias;
private readonly string _currentSection;
private readonly string _rootDisplay;
public LegacyTreeController()
{
}
public LegacyTreeController(XmlTreeNode xmlTreeNode, string treeAlias, string currentSection, UrlHelper urlHelper)
{
_xmlTreeNode = xmlTreeNode;
_treeAlias = treeAlias;
_currentSection = currentSection;
_rootDisplay = xmlTreeNode.Text;
Url = urlHelper;
}
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
{
return LegacyTreeDataConverter.ConvertFromLegacy(
_xmlTreeNode.NodeID,
_xmlTreeNode,
Url,
_currentSection,
queryStrings,
isRoot: true);
}
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var tree = GetTree(queryStrings);
var attempt = tree.TryLoadFromLegacyTree(id, queryStrings, Url, tree.ApplicationAlias);
@@ -40,19 +66,8 @@ namespace Umbraco.Web.Trees
return attempt.Result;
}
/// <summary>
/// This will return the menu item collection for the tree node with the specified Id
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
/// <remarks>
/// Due to the nature of legacy trees this means that we need to lookup the parent node, render
/// the TreeNodeCollection and then find the node we're looking for and render it's menu.
/// </remarks>
[HttpQueryStringFilter("queryStrings")]
public MenuItemCollection GetMenu(string id, FormDataCollection queryStrings)
{
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
//get the parent id from the query strings
var parentId = queryStrings.GetRequiredString("parentId");
var tree = GetTree(queryStrings);
@@ -98,6 +113,16 @@ namespace Umbraco.Web.Trees
}
}
public override string RootNodeDisplayName
{
get { return _rootDisplay; }
}
public override string TreeAlias
{
get { return _treeAlias; }
}
private ApplicationTree GetTree(FormDataCollection queryStrings)
{
//need to ensure we have a tree type

View File

@@ -14,12 +14,11 @@ using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Trees
{
/// <summary>
/// The base controller for all tree requests
/// A base controller reference for non-attributed trees (un-registered). Developers should inherit from
/// TreeController.
/// </summary>
public abstract class TreeController : UmbracoAuthorizedApiController
public abstract class TreeControllerBase : UmbracoAuthorizedApiController
{
private readonly TreeAttribute _attribute;
/// <summary>
/// Remove the xml formatter... only support JSON!
/// </summary>
@@ -30,23 +29,6 @@ namespace Umbraco.Web.Trees
controllerContext.Configuration.Formatters.Remove(controllerContext.Configuration.Formatters.XmlFormatter);
}
protected TreeController()
{
//Locate the tree attribute
var treeAttributes = GetType()
.GetCustomAttributes(typeof(TreeAttribute), false)
.OfType<TreeAttribute>()
.ToArray();
if (treeAttributes.Any() == false)
{
throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute");
}
//assign the properties of this object to those of the metadata attribute
_attribute = treeAttributes.First();
}
/// <summary>
/// The method called to render the contents of the tree structure
/// </summary>
@@ -71,18 +53,12 @@ namespace Umbraco.Web.Trees
/// <summary>
/// The name to display on the root node
/// </summary>
public virtual string RootNodeDisplayName
{
get { return _attribute.Title; }
}
public abstract string RootNodeDisplayName { get; }
/// <summary>
/// Gets the current tree alias from the attribute assigned to it.
/// </summary>
public string TreeAlias
{
get { return _attribute.Alias; }
}
public abstract string TreeAlias { get; }
/// <summary>
/// Returns the root node for the tree
@@ -96,7 +72,7 @@ namespace Umbraco.Web.Trees
var node = CreateRootNode(queryStrings);
//add the tree alias to the root
node.AdditionalData.Add("treeAlias", TreeAlias);
node.AdditionalData["treeAlias"] = TreeAlias;
AddQueryStringsToAdditionalData(node, queryStrings);
@@ -207,6 +183,96 @@ namespace Umbraco.Web.Trees
}
}
/// <summary>
/// If the request is for a dialog mode tree
/// </summary>
/// <param name="queryStrings"></param>
/// <returns></returns>
protected bool IsDialog(FormDataCollection queryStrings)
{
return queryStrings.GetValue<bool>(TreeQueryStringParameters.DialogMode);
}
/// <summary>
/// An event that allows developers to modify the tree node collection that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public static event TypedEventHandler<TreeControllerBase, TreeNodesRenderingEventArgs> TreeNodesRendering;
private static void OnTreeNodesRendering(TreeControllerBase instance, TreeNodesRenderingEventArgs e)
{
var handler = TreeNodesRendering;
if (handler != null) handler(instance, e);
}
/// <summary>
/// An event that allows developer to modify the root tree node that is being rendered
/// </summary>
public static event TypedEventHandler<TreeControllerBase, TreeNodeRenderingEventArgs> RootNodeRendering;
private static void OnRootNodeRendering(TreeControllerBase instance, TreeNodeRenderingEventArgs e)
{
var handler = RootNodeRendering;
if (handler != null) handler(instance, e);
}
/// <summary>
/// An event that allows developers to modify the meun that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public static event TypedEventHandler<TreeControllerBase, MenuRenderingEventArgs> MenuRendering;
private static void OnMenuRendering(TreeControllerBase instance, MenuRenderingEventArgs e)
{
var handler = MenuRendering;
if (handler != null) handler(instance, e);
}
}
/// <summary>
/// The base controller for all tree requests
/// </summary>
public abstract class TreeController : TreeControllerBase
{
private readonly TreeAttribute _attribute;
protected TreeController()
{
//Locate the tree attribute
var treeAttributes = GetType()
.GetCustomAttributes(typeof(TreeAttribute), false)
.OfType<TreeAttribute>()
.ToArray();
if (treeAttributes.Any() == false)
{
throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute");
}
//assign the properties of this object to those of the metadata attribute
_attribute = treeAttributes.First();
}
/// <summary>
/// The name to display on the root node
/// </summary>
public override string RootNodeDisplayName
{
get { return _attribute.Title; }
}
/// <summary>
/// Gets the current tree alias from the attribute assigned to it.
/// </summary>
public override string TreeAlias
{
get { return _attribute.Alias; }
}
#region Create TreeNode methods
/// <summary>
@@ -295,59 +361,6 @@ namespace Umbraco.Web.Trees
#region Query String parameter helpers
/// <summary>
/// If the request is for a dialog mode tree
/// </summary>
/// <param name="queryStrings"></param>
/// <returns></returns>
protected bool IsDialog(FormDataCollection queryStrings)
{
return queryStrings.GetValue<bool>(TreeQueryStringParameters.DialogMode);
}
#endregion
#region Events
/// <summary>
/// An event that allows developers to modify the tree node collection that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public static event TypedEventHandler<TreeController, TreeNodesRenderingEventArgs> TreeNodesRendering;
private static void OnTreeNodesRendering(TreeController instance, TreeNodesRenderingEventArgs e)
{
var handler = TreeNodesRendering;
if (handler != null) handler(instance, e);
}
/// <summary>
/// An event that allows developer to modify the root tree node that is being rendered
/// </summary>
public static event TypedEventHandler<TreeController, TreeNodeRenderingEventArgs> RootNodeRendering;
private static void OnRootNodeRendering(TreeController instance, TreeNodeRenderingEventArgs e)
{
var handler = RootNodeRendering;
if (handler != null) handler(instance, e);
}
/// <summary>
/// An event that allows developers to modify the meun that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public static event TypedEventHandler<TreeController, MenuRenderingEventArgs> MenuRendering;
private static void OnMenuRendering(TreeController instance, MenuRenderingEventArgs e)
{
var handler = MenuRendering;
if (handler != null) handler(instance, e);
}
#endregion
}

View File

@@ -38,6 +38,7 @@ namespace umbraco
{
rootNode.NodeType = "init" + TreeAlias;
rootNode.NodeID = "init";
rootNode.Action = "javascript:openDictionary()";
}
protected override void CreateAllowedActions(ref List<IAction> actions)