Got the legacy refresh action working (should work for all trees)

This commit is contained in:
Shannon
2013-08-05 18:27:05 +10:00
parent 4b7345bfbd
commit 4b996ac693
8 changed files with 140 additions and 11 deletions

View File

@@ -10,7 +10,11 @@ namespace Umbraco.Web.Trees.Menu
/// These types of menu items are rare but they do exist. Things like refresh node simply execute
/// JS and don't launch a dialog.
///
/// Each action menu item describes what angular service that it's method exists in and what the method name is
/// Each action menu item describes what angular service that it's method exists in and what the method name is.
///
/// An action menu item must describe the angular service name for which it's method exists. It may also define what the
/// method name is that will be called in this service but if one is not specified then we will assume the method name is the
/// same as the Type name of the current action menu class.
/// </remarks>
public abstract class ActionMenuItem : MenuItem
{
@@ -24,7 +28,15 @@ namespace Umbraco.Web.Trees.Menu
}
//add the current type to the metadata
AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, attribute.MethodName));
if (attribute.MethodName.IsNullOrWhiteSpace())
{
//if no method name is supplied we will assume that the menu action is the type name of the current menu class
AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, this.GetType().Name));
}
else
{
AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, attribute.MethodName));
}
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using Umbraco.Core;
namespace Umbraco.Web.Trees.Menu
{
@@ -8,12 +9,30 @@ namespace Umbraco.Web.Trees.Menu
[AttributeUsage(AttributeTargets.Class)]
public sealed class ActionMenuItemAttribute : Attribute
{
/// <summary>
/// This constructor defines both the angular service and method name to use
/// </summary>
/// <param name="serviceName"></param>
/// <param name="methodName"></param>
public ActionMenuItemAttribute(string serviceName, string methodName)
{
Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName");
Mandate.ParameterNotNullOrEmpty(methodName, "methodName");
MethodName = methodName;
ServiceName = serviceName;
}
/// <summary>
/// This constructor will assume that the method name equals the type name of the action menu class
/// </summary>
/// <param name="serviceName"></param>
public ActionMenuItemAttribute(string serviceName)
{
Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName");
MethodName = "";
ServiceName = serviceName;
}
public string MethodName { get; private set; }
public string ServiceName { get; private set; }
}

View File

@@ -1,7 +1,9 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core;
using umbraco.BusinessLogic.Actions;
using umbraco.interfaces;
namespace Umbraco.Web.Trees.Menu
@@ -28,6 +30,9 @@ namespace Umbraco.Web.Trees.Menu
internal MenuItem AddMenuItem(IAction action)
{
var item = new MenuItem(action);
DetectLegacyActionMenu(action.GetType(), item);
_menuItems.Add(item);
return item;
}
@@ -105,6 +110,8 @@ namespace Umbraco.Web.Trees.Menu
}
}
DetectLegacyActionMenu(typeof (T), menuItem);
//TODO: Once we implement 'real' menu items, not just IActions we can implement this since
// people may need to pass specific data to their menu items
@@ -134,6 +141,32 @@ namespace Umbraco.Web.Trees.Menu
return null;
}
/// <summary>
/// Checks if the IAction type passed in is attributed with LegacyActionMenuItemAttribute and if so
/// ensures that the correct action metadata is added.
/// </summary>
/// <param name="actionType"></param>
/// <param name="menuItem"></param>
private void DetectLegacyActionMenu(Type actionType, MenuItem menuItem)
{
//This checks for legacy IActions that have the LegacyActionMenuItemAttribute which is a legacy hack
// to make old IAction actions work in v7 by mapping to the JS used by the new menu items
var attribute = actionType.GetCustomAttribute<LegacyActionMenuItemAttribute>(false);
if (attribute != null)
{
//add the current type to the metadata
if (attribute.MethodName.IsNullOrWhiteSpace())
{
//if no method name is supplied we will assume that the menu action is the type name of the current menu class
menuItem.AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, this.GetType().Name));
}
else
{
menuItem.AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, attribute.MethodName));
}
}
}
public IEnumerator<MenuItem> GetEnumerator()
{
return _menuItems.GetEnumerator();

View File

@@ -3,7 +3,7 @@
/// <summary>
/// Represents the refresh node menu item
/// </summary>
[ActionMenuItem("umbracoMenuActions", "refresh")]
[ActionMenuItem("umbracoMenuActions")]
public sealed class RefreshNodeMenuItem : ActionMenuItem
{
}