From bb7d5b4bd2c684bf74e52567d27eb02c486f7825 Mon Sep 17 00:00:00 2001 From: Yannis Guedel Date: Wed, 23 Mar 2016 22:56:42 +0100 Subject: [PATCH] U4-8193 replaced loadMacros with MacrosTreeController --- src/Umbraco.Core/Constants-Applications.cs | 2 + .../config/trees.Release.config | 2 +- src/Umbraco.Web.UI/config/trees.config | 2 +- src/Umbraco.Web/Trees/MacrosTreeController.cs | 88 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 2 +- .../umbraco/Trees/loadMacros.cs | 66 -------------- .../developer/Macros/editMacro.aspx.cs | 4 +- 7 files changed, 95 insertions(+), 71 deletions(-) create mode 100644 src/Umbraco.Web/Trees/MacrosTreeController.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadMacros.cs diff --git a/src/Umbraco.Core/Constants-Applications.cs b/src/Umbraco.Core/Constants-Applications.cs index 38dc22c473..1c15083a81 100644 --- a/src/Umbraco.Core/Constants-Applications.cs +++ b/src/Umbraco.Core/Constants-Applications.cs @@ -106,6 +106,8 @@ public const string Xslt = "xslt"; public const string Languages = "languages"; + + public const string Macros = "macros"; /// /// alias for the user types tree. diff --git a/src/Umbraco.Web.UI/config/trees.Release.config b/src/Umbraco.Web.UI/config/trees.Release.config index 2825b5205e..bdf30ed8f3 100644 --- a/src/Umbraco.Web.UI/config/trees.Release.config +++ b/src/Umbraco.Web.UI/config/trees.Release.config @@ -20,7 +20,7 @@ - + diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index dece42a362..364ecfd4fd 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -17,7 +17,7 @@ - + diff --git a/src/Umbraco.Web/Trees/MacrosTreeController.cs b/src/Umbraco.Web/Trees/MacrosTreeController.cs new file mode 100644 index 0000000000..ce9d71fb75 --- /dev/null +++ b/src/Umbraco.Web/Trees/MacrosTreeController.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Net.Http.Formatting; +using System.Web.Http; +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Web.Models.Trees; +using Umbraco.Web.Mvc; +using Umbraco.Web.WebApi.Filters; +using umbraco; +using Umbraco.Core.Models.EntityBase; +using Umbraco.Core.Services; +using Umbraco.Web._Legacy.Actions; +using Constants = Umbraco.Core.Constants; + +namespace Umbraco.Web.Trees +{ + [UmbracoTreeAuthorize(Constants.Trees.Macros)] + [Tree(Constants.Applications.Developer, Constants.Trees.Macros, "Macros", sortOrder: 2)] + [PluginController("UmbracoTrees")] + [CoreTree] + public class MacrosTreeController : TreeController + { + protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) + { + var nodes = new TreeNodeCollection(); + + if (id == Constants.System.Root.ToInvariantString()) + { + foreach (var macro in Services.MacroService.GetAll()) + { + nodes.Add(CreateTreeNode( + macro.Id.ToString(), + id, + queryStrings, + macro.Name, + "icon-settings-alt", + false, + //TODO: Rebuild the macro editor in angular, then we dont need to have this at all (which is just a path to the legacy editor) + "/" + queryStrings.GetValue("application") + "/framed/" + + Uri.EscapeDataString("/umbraco/developer/macros/editMacro.aspx?macroID=" + macro.Id))); + } + } + + return nodes; + } + + protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) + { + var menu = new MenuItemCollection(); + + if (id == Constants.System.Root.ToInvariantString()) + { + //Create the normal create action + menu.Items.Add(Services.TextService.Localize("actions", ActionNew.Instance.Alias)) + //Since we haven't implemented anything for macros in angular, this needs to be converted to + //use the legacy format + .ConvertLegacyMenuItem(null, "initmacros", queryStrings.GetValue("application")); + + //refresh action + menu.Items.Add(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true); + + return menu; + } + + + var macro = Services.MacroService.GetById(int.Parse(id)); + if (macro == null) return new MenuItemCollection(); + + //add delete option for all languages + menu.Items.Add(Services.TextService.Localize("actions", ActionDelete.Instance.Alias)) + //Since we haven't implemented anything for languages in angular, this needs to be converted to + //use the legacy format + .ConvertLegacyMenuItem(new UmbracoEntity + { + Id = macro.Id, + Level = 1, + ParentId = -1, + Name = macro.Name + }, "macros", queryStrings.GetValue("application")); + + return menu; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 7dd0f6b41d..2f1dcef7ce 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -326,6 +326,7 @@ + @@ -1547,7 +1548,6 @@ - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadMacros.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadMacros.cs deleted file mode 100644 index 6a689878fa..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadMacros.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Text; - -using umbraco.DataLayer; -using umbraco.cms.presentation.Trees; -using Umbraco.Core; -using Umbraco.Web.Trees; - - -namespace umbraco -{ - /// - /// Handles loading of the cache application into the developer application tree - /// - [Tree(Constants.Applications.Developer, "macros", "Macros", sortOrder: 2)] - public class loadMacros : BaseTree - { - - public loadMacros(string application) : base(application) { } - - protected override void CreateRootNode(ref XmlTreeNode rootNode) - { - rootNode.NodeType = "init" + TreeAlias; - rootNode.NodeID = "init"; - } - - /// - /// Renders the JS. - /// - /// The javascript. - public override void RenderJS(ref StringBuilder Javascript) - { - Javascript.Append( - @" -function openMacro(id) { - UmbClientMgr.contentFrame('developer/macros/editMacro.aspx?macroID=' + id); -} -"); - } - - /// - /// This will call the normal Render method by passing the converted XmlTree to an XmlDocument. - /// TODO: need to update this render method to do everything that the obsolete render method does and remove the obsolete method - /// - /// - public override void Render(ref XmlTree tree) - { - foreach(var macros in ApplicationContext.Current.DatabaseContext.Database.Query("select id, macroName from cmsMacro order by macroName")) - { - XmlTreeNode xNode = XmlTreeNode.Create(this); - xNode.NodeID = macros.id.ToString(); - xNode.Text = macros.macroName; - xNode.Action = "javascript:openMacro(" + macros.id + ");"; - xNode.Icon = " icon-settings-alt"; - xNode.OpenIcon = "icon-settings-alt"; - OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); - if (xNode != null) - { - tree.Add(xNode); - } - OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); - } - } - - } -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs index 9e9d3b1522..08d28617e2 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs @@ -44,7 +44,7 @@ namespace umbraco.cms.presentation.developer if (IsPostBack == false) { ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) + .SetActiveTreeType(Constants.Trees.Macros) .SyncTree("-1,init," + _macro.Id, false); string tempMacroAssembly = _macro.ControlAssembly ?? ""; @@ -292,7 +292,7 @@ namespace umbraco.cms.presentation.developer Page.Validate(); ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) + .SetActiveTreeType(Constants.Trees.Macros) .SyncTree("-1,init," + _macro.Id.ToInvariantString(), true); //true forces the reload var tempMacroAssembly = macroAssembly.Text;