Gets macro editor working with new db changes and using new MacroService data layer

This commit is contained in:
Shannon
2013-09-19 17:34:57 +10:00
parent ec3761baa0
commit c0a303b328
25 changed files with 368 additions and 239 deletions
+2 -2
View File
@@ -257,9 +257,9 @@ namespace Umbraco.Core
/// </summary>
protected virtual void InitializeResolvers()
{
//setup custom resolvers... this is only temporary until we move into the umbraco core
PropertyEditorResolver.Current = new PropertyEditorResolver(() => PluginManager.Current.ResolvePropertyEditors());
ParameterEditorResolver.Current = new ParameterEditorResolver(() => PluginManager.Current.ResolveParameterEditors());
//setup the validators resolver with our predefined validators
ValidatorsResolver.Current = new ValidatorsResolver(new[]
{
+9 -2
View File
@@ -31,7 +31,11 @@ namespace Umbraco.Core.Manifest
var editors = new List<PropertyEditor>();
foreach (var manifest in GetManifests())
{
editors.AddRange(ManifestParser.GetPropertyEditors(manifest.PropertyEditors));
if (manifest.PropertyEditors != null)
{
editors.AddRange(ManifestParser.GetPropertyEditors(manifest.PropertyEditors));
}
}
return editors;
});
@@ -52,7 +56,10 @@ namespace Umbraco.Core.Manifest
var editors = new List<ParameterEditor>();
foreach (var manifest in GetManifests())
{
editors.AddRange(ManifestParser.GetParameterEditors(manifest.ParameterEditors));
if (manifest.ParameterEditors != null)
{
editors.AddRange(ManifestParser.GetParameterEditors(manifest.ParameterEditors));
}
}
return editors;
});
+6 -6
View File
@@ -7,7 +7,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// Defines a Macro
/// </summary>
internal interface IMacro : IAggregateRoot
public interface IMacro : IAggregateRoot
{
/// <summary>
/// Gets or sets the alias of the Macro
@@ -84,10 +84,10 @@ namespace Umbraco.Core.Models
[DataMember]
MacroPropertyCollection Properties { get; }
/// <summary>
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
/// </summary>
/// <returns><see cref="MacroTypes"/></returns>
MacroTypes MacroType();
///// <summary>
///// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
///// </summary>
///// <returns><see cref="MacroTypes"/></returns>
//MacroTypes MacroType();
}
}
+4 -1
View File
@@ -6,8 +6,11 @@ namespace Umbraco.Core.Models
/// <summary>
/// Defines a Property for a Macro
/// </summary>
internal interface IMacroProperty : IValueObject
public interface IMacroProperty : IValueObject
{
[DataMember]
int Id { get; set; }
/// <summary>
/// Gets or sets the Alias of the Property
/// </summary>
+1 -28
View File
@@ -379,33 +379,6 @@ namespace Umbraco.Core.Models
get { return _properties; }
}
/// <summary>
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
/// </summary>
/// <returns><see cref="MacroTypes"/></returns>
public MacroTypes MacroType()
{
if (string.IsNullOrEmpty(XsltPath) == false)
return MacroTypes.Xslt;
if (string.IsNullOrEmpty(ScriptPath) == false)
{
//we need to check if the file path saved is a virtual path starting with ~/Views/MacroPartials, if so then this is
//a partial view macro, not a script macro
//we also check if the file exists in ~/App_Plugins/[Packagename]/Views/MacroPartials, if so then it is also a partial view.
return (ScriptPath.InvariantStartsWith(SystemDirectories.MvcViews + "/MacroPartials/")
|| (Regex.IsMatch(ScriptPath, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled | RegexOptions.IgnoreCase)))
? MacroTypes.PartialView
: MacroTypes.Script;
}
if (string.IsNullOrEmpty(ControlType) == false && ControlType.InvariantContains(".ascx"))
return MacroTypes.UserControl;
if (string.IsNullOrEmpty(ControlType) == false && string.IsNullOrEmpty(ControlAssembly) == false)
return MacroTypes.CustomControl;
return MacroTypes.Unknown;
}
}
}
+43
View File
@@ -17,6 +17,13 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Ctor for creating a new property
/// </summary>
/// <param name="alias"></param>
/// <param name="name"></param>
/// <param name="sortOrder"></param>
/// <param name="editorAlias"></param>
public MacroProperty(string @alias, string name, int sortOrder, string editorAlias)
{
_alias = alias;
@@ -25,16 +32,52 @@ namespace Umbraco.Core.Models
_editorAlias = editorAlias;
}
/// <summary>
/// Ctor for creating an existing property
/// </summary>
/// <param name="id"></param>
/// <param name="alias"></param>
/// <param name="name"></param>
/// <param name="sortOrder"></param>
/// <param name="editorAlias"></param>
internal MacroProperty(int id, string @alias, string name, int sortOrder, string editorAlias)
{
_id = id;
_alias = alias;
_name = name;
_sortOrder = sortOrder;
_editorAlias = editorAlias;
}
private string _alias;
private string _name;
private int _sortOrder;
private int _id;
private string _editorAlias;
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Alias);
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Name);
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, int>(x => x.SortOrder);
private static readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo<Entity, int>(x => x.Id);
private static readonly PropertyInfo PropertyTypeSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.EditorAlias);
/// <summary>
/// Gets or sets the Alias of the Property
/// </summary>
[DataMember]
public int Id
{
get { return _id; }
set
{
SetPropertyValueAndDetectChanges(o =>
{
_id = value;
return _alias;
}, _alias, IdSelector);
}
}
/// <summary>
/// Gets or sets the Alias of the Property
/// </summary>
@@ -8,7 +8,7 @@ namespace Umbraco.Core.Models
/// <summary>
/// A macro's property collection
/// </summary>
internal class MacroPropertyCollection : ObservableDictionary<string, IMacroProperty>
public class MacroPropertyCollection : ObservableDictionary<string, IMacroProperty>
{
public MacroPropertyCollection()
: base(property => property.Alias)
+1 -1
View File
@@ -16,7 +16,7 @@ namespace Umbraco.Core
/// </remarks>
/// <typeparam name="TValue">The type of elements contained in the BindableCollection</typeparam>
/// <typeparam name="TKey">The type of the indexing key</typeparam>
internal class ObservableDictionary<TKey, TValue> : ObservableCollection<TValue>
public class ObservableDictionary<TKey, TValue> : ObservableCollection<TValue>
{
protected Dictionary<TKey, int> Indecies = new Dictionary<TKey, int>();
protected Func<TValue, TKey> KeySelector;
@@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Factories
var model = new Macro(dto.Id, dto.UseInEditor, dto.RefreshRate, dto.Alias, dto.Name, dto.ScriptType, dto.ScriptAssembly, dto.Xslt, dto.CacheByPage, dto.CachePersonalized, dto.DontRender, dto.Python);
foreach (var p in dto.MacroPropertyDtos)
{
model.Properties.Add(new MacroProperty(p.Alias, p.Name, p.SortOrder, null));
model.Properties.Add(new MacroProperty(p.Id, p.Alias, p.Name, p.SortOrder, p.EditorAlias));
}
//on initial construction we don't want to have dirty properties tracked
@@ -60,7 +60,8 @@ namespace Umbraco.Core.Persistence.Factories
Name = p.Name,
Macro = entity.Id,
SortOrder = (byte)p.SortOrder,
EditorAlias = p.EditorAlias
EditorAlias = p.EditorAlias,
Id = p.Id
};
list.Add(text);
+10
View File
@@ -432,6 +432,16 @@ namespace Umbraco.Core
//return all proeprty editor types found except for the base property editor type
return ResolveTypes<PropertyEditor>()
.Except(new[] {typeof (PropertyEditor)});
}
/// <summary>
/// Returns all found parameter editors
/// </summary>
internal IEnumerable<Type> ResolveParameterEditors()
{
//return all paramter editor types found except for the base property editor type
return ResolveTypes<ParameterEditor>()
.Except(new[] { typeof(ParameterEditor) });
}
/// <summary>
@@ -2,6 +2,12 @@
namespace Umbraco.Core.PropertyEditors
{
[ParameterEditor("text", "Text", "textbox")]
public class TextParameterEditor : ParameterEditor
{
}
/// <summary>
/// Represents the value editor for the parameter editor during macro parameter editing
/// </summary>
@@ -8,6 +8,7 @@ namespace Umbraco.Core.Services
/// </summary>
internal interface IMacroService : IService
{
/// <summary>
/// Gets an <see cref="IMacro"/> object by its alias
/// </summary>
+30
View File
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Umbraco.Core.Auditing;
using Umbraco.Core.Events;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Querying;
@@ -35,6 +37,34 @@ namespace Umbraco.Core.Services
_repositoryFactory = repositoryFactory;
}
/// <summary>
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
/// </summary>
/// <returns><see cref="MacroTypes"/></returns>
internal static MacroTypes GetMacroType(IMacro macro)
{
if (string.IsNullOrEmpty(macro.XsltPath) == false)
return MacroTypes.Xslt;
if (string.IsNullOrEmpty(macro.ScriptPath) == false)
{
//we need to check if the file path saved is a virtual path starting with ~/Views/MacroPartials, if so then this is
//a partial view macro, not a script macro
//we also check if the file exists in ~/App_Plugins/[Packagename]/Views/MacroPartials, if so then it is also a partial view.
return (macro.ScriptPath.InvariantStartsWith(SystemDirectories.MvcViews + "/MacroPartials/")
|| (Regex.IsMatch(macro.ScriptPath, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled | RegexOptions.IgnoreCase)))
? MacroTypes.PartialView
: MacroTypes.Script;
}
if (string.IsNullOrEmpty(macro.ControlType) == false && macro.ControlType.InvariantContains(".ascx"))
return MacroTypes.UserControl;
if (string.IsNullOrEmpty(macro.ControlType) == false && string.IsNullOrEmpty(macro.ControlAssembly) == false)
return MacroTypes.CustomControl;
return MacroTypes.Unknown;
}
/// <summary>
/// Gets an <see cref="IMacro"/> object by its alias
@@ -63,6 +63,91 @@ namespace Umbraco.Tests.Services
Assert.AreEqual(3, result.Count());
}
[Test]
public void Can_Create()
{
// Arrange
var macroService = ServiceContext.MacroService;
// Act
var macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
macroService.Save(macro);
//assert
Assert.IsTrue(macro.HasIdentity);
Assert.Greater(macro.Id, 0);
var result = macroService.GetById(macro.Id);
Assert.AreEqual("test", result.Alias);
Assert.AreEqual("Test", result.Name);
Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.ScriptPath);
Assert.AreEqual(1234, result.CacheDuration);
}
[Test]
public void Can_Delete()
{
// Arrange
var macroService = ServiceContext.MacroService;
var macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
macroService.Save(macro);
// Act
macroService.Delete(macro);
//assert
var result = macroService.GetById(macro.Id);
Assert.IsNull(result);
}
[Test]
public void Can_Update()
{
// Arrange
var macroService = ServiceContext.MacroService;
IMacro macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
macroService.Save(macro);
// Act
macro.Name = "New name";
macro.Alias = "NewAlias";
macroService.Save(macro);
macro = macroService.GetById(macro.Id);
//assert
Assert.AreEqual("New name", macro.Name);
Assert.AreEqual("NewAlias", macro.Alias);
}
[Test]
public void Can_Update_Property()
{
// Arrange
var macroService = ServiceContext.MacroService;
IMacro macro = new Macro("test", "Test", scriptPath: "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah"));
macroService.Save(macro);
// Act
macro.Properties.First().Alias = "new Alias";
macro.Properties.First().Name = "new Name";
macro.Properties.First().SortOrder = 1;
macro.Properties.First().EditorAlias = "new";
macroService.Save(macro);
macro = macroService.GetById(macro.Id);
//assert
Assert.AreEqual(1, macro.Properties.Count());
Assert.AreEqual("new Alias", macro.Properties.First().Alias);
Assert.AreEqual("new Name", macro.Properties.First().Name);
Assert.AreEqual(1, macro.Properties.First().SortOrder);
Assert.AreEqual("new", macro.Properties.First().EditorAlias);
}
//[Test]
//public void Can_Get_Many_By_Alias()
//{
@@ -8,7 +8,7 @@ using System.Web;
using System.Web.UI.WebControls;
using Umbraco.Core.IO;
using Umbraco.Core;
using umbraco.cms.businesslogic.macro;
using Umbraco.Core.Models;
namespace Umbraco.Web.UI.Umbraco.Developer.Macros
{
@@ -29,16 +29,16 @@ namespace Umbraco.Web.UI.Umbraco.Developer.Macros
/// <param name="macro"> </param>
/// <param name="macroAssemblyValue"></param>
/// <param name="macroTypeValue"></param>
protected override void PopulateFieldsOnLoad(Macro macro, string macroAssemblyValue, string macroTypeValue)
protected override void PopulateFieldsOnLoad(IMacro macro, string macroAssemblyValue, string macroTypeValue)
{
base.PopulateFieldsOnLoad(macro, macroAssemblyValue, macroTypeValue);
//check if the ScriptingFile property contains the MacroPartials path
if (macro.ScriptingFile.IsNullOrWhiteSpace() == false &&
(macro.ScriptingFile.StartsWith(SystemDirectories.MvcViews + "/MacroPartials/")
|| (Regex.IsMatch(macro.ScriptingFile, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled))))
if (macro.ScriptPath.IsNullOrWhiteSpace() == false &&
(macro.ScriptPath.StartsWith(SystemDirectories.MvcViews + "/MacroPartials/")
|| (Regex.IsMatch(macro.ScriptPath, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled))))
{
macroPython.Text = "";
SelectedPartialView.Text = macro.ScriptingFile;
SelectedPartialView.Text = macro.ScriptPath;
}
}
@@ -50,12 +50,12 @@ namespace Umbraco.Web.UI.Umbraco.Developer.Macros
/// <param name="macroCachePeriod"></param>
/// <param name="macroAssemblyValue"></param>
/// <param name="macroTypeValue"></param>
protected override void SetMacroValuesFromPostBack(Macro macro, int macroCachePeriod, string macroAssemblyValue, string macroTypeValue)
protected override void SetMacroValuesFromPostBack(IMacro macro, int macroCachePeriod, string macroAssemblyValue, string macroTypeValue)
{
base.SetMacroValuesFromPostBack(macro, macroCachePeriod, macroAssemblyValue, macroTypeValue);
if (!SelectedPartialView.Text.IsNullOrWhiteSpace())
{
macro.ScriptingFile = SelectedPartialView.Text;
macro.ScriptPath = SelectedPartialView.Text;
}
}
@@ -112,13 +112,13 @@
<thead>
<tr>
<th>
<%=umbraco.ui.Text("general", "alias",this.getUser())%>
<%=umbraco.ui.Text("general", "alias",UmbracoUser)%>
</th>
<th>
<%=umbraco.ui.Text("general", "name",this.getUser())%>
<%=umbraco.ui.Text("general", "name",UmbracoUser)%>
</th>
<th>
<%=umbraco.ui.Text("general", "type",this.getUser())%>
<%=umbraco.ui.Text("general", "type",UmbracoUser)%>
</th>
<th></th>
</tr>
@@ -128,18 +128,18 @@
<ItemTemplate>
<tr>
<td>
<input type="hidden" id="macroPropertyID" runat="server" value='<%#DataBinder.Eval(Container.DataItem, "id")%>'
<input type="hidden" id="macroPropertyID" runat="server" value='<%#Eval("Id")%>'
name="macroPropertyID" />
<asp:TextBox runat="server" ID="macroPropertyAlias" Text='<%#DataBinder.Eval(Container.DataItem, "Alias")%>' />
<asp:TextBox runat="server" ID="macroPropertyAlias" Text='<%#Eval("Alias")%>' />
</td>
<td>
<asp:TextBox runat="server" ID="macroPropertyName" Text='<%#DataBinder.Eval(Container.DataItem, "Name")%>' />
<asp:TextBox runat="server" ID="macroPropertyName" Text='<%#Eval("Name")%>' />
</td>
<td>
<asp:DropDownList OnPreRender="AddChooseList" runat="server" ID="macroPropertyType"
DataTextFormatString="" DataTextField='Name' DataValueField="Alias"
DataSource='<%# GetMacroParameterEditors()%>'
SelectedValue='<%# Eval("Alias") %>'>
SelectedValue='<%# Eval("EditorAlias") %>'>
</asp:DropDownList>
</td>
<td>
@@ -157,7 +157,9 @@
</td>
<td>
<asp:DropDownList OnPreRender="AddChooseList" runat="server" ID="macroPropertyTypeNew"
DataTextField="macroPropertyTypeAlias" DataValueField="id" DataSource='<%# GetMacroPropertyTypes()%>'>
DataTextField="Name"
DataValueField="Alias"
DataSource='<%# GetMacroParameterEditors()%>'>
</asp:DropDownList>
</td>
<td>
@@ -6,10 +6,11 @@ using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using umbraco.cms.businesslogic.macro;
using System.Reflection;
using System.Collections;
using umbraco.IO;
namespace umbraco.controls
{
[DefaultProperty("Text")]
@@ -114,11 +115,11 @@ namespace umbraco.controls
loadMacro();
addParameterControls();
AddParameterControls();
}
private void addParameterControls()
private void AddParameterControls()
{
Controls.Add(new LiteralControl("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"));
foreach (MacroProperty mp in m_macro.Properties)
@@ -131,7 +132,7 @@ namespace umbraco.controls
Assembly assembly = Assembly.LoadFrom( IOHelper.MapPath(SystemDirectories.Bin + "/" + macroAssembly + ".dll"));
Type type = assembly.GetType(macroAssembly + "." + macroType);
interfaces.IMacroGuiRendering typeInstance = Activator.CreateInstance(type) as interfaces.IMacroGuiRendering;
var typeInstance = Activator.CreateInstance(type) as interfaces.IMacroGuiRendering;
if (typeInstance != null)
{
((Control) typeInstance).ID = mp.Alias;
@@ -5,13 +5,15 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using umbraco.BasePages;
using umbraco.uicontrols;
using umbraco.DataLayer;
using umbraco.cms.presentation.Trees;
using umbraco.cms.businesslogic.macro;
using System.Linq;
namespace umbraco.cms.presentation.developer
{
@@ -27,37 +29,38 @@ namespace umbraco.cms.presentation.developer
protected PlaceHolder buttons;
protected Table macroElements;
protected Macro m_macro;
public TabPage InfoTabPage;
public TabPage Parameters;
private IMacro _macro;
protected void Page_Load(object sender, EventArgs e)
{
m_macro = new Macro(Convert.ToInt32(Request.QueryString["macroID"]));
_macro = Services.MacroService.GetById(Convert.ToInt32(Request.QueryString["macroID"]));
if (!IsPostBack)
{
ClientTools
.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadMacros>().Tree.Alias)
.SyncTree("-1,init," + m_macro.Id.ToString(), false);
.SyncTree("-1,init," + _macro.Id.ToString(), false);
string tempMacroAssembly = m_macro.Assembly ?? "";
string tempMacroType = m_macro.Type ?? "";
string tempMacroAssembly = _macro.ControlAssembly ?? "";
string tempMacroType = _macro.ControlType ?? "";
PopulateFieldsOnLoad(m_macro, tempMacroAssembly, tempMacroType);
PopulateFieldsOnLoad(_macro, tempMacroAssembly, tempMacroType);
// Check for assemblyBrowser
if (tempMacroType.IndexOf(".ascx") > 0)
assemblyBrowserUserControl.Controls.Add(
new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('" + IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/developer/macros/assemblyBrowser.aspx?fileName=" + macroUserControl.Text +
"&macroID=" + m_macro.Id.ToString() +
"&macroID=" + _macro.Id.ToInvariantString() +
"', 'Browse Properties', true, 475,500); return false;\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
else if (tempMacroType != string.Empty && tempMacroAssembly != string.Empty)
assemblyBrowser.Controls.Add(
new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('" + IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/developer/macros/assemblyBrowser.aspx?fileName=" + macroAssembly.Text +
"&macroID=" + m_macro.Id.ToString() + "&type=" + macroType.Text +
"&macroID=" + _macro.Id.ToInvariantString() + "&type=" + macroType.Text +
"', 'Browse Properties', true, 475,500); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
// Load elements from macro
@@ -78,41 +81,41 @@ namespace umbraco.cms.presentation.developer
{
ClientTools
.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadMacros>().Tree.Alias)
.SyncTree("-1,init," + m_macro.Id.ToString(), true); //true forces the reload
.SyncTree("-1,init," + _macro.Id.ToInvariantString(), true); //true forces the reload
string tempMacroAssembly = macroAssembly.Text;
string tempMacroType = macroType.Text;
string tempCachePeriod = cachePeriod.Text;
var tempMacroAssembly = macroAssembly.Text;
var tempMacroType = macroType.Text;
var tempCachePeriod = cachePeriod.Text;
if (tempCachePeriod == string.Empty)
tempCachePeriod = "0";
if (tempMacroAssembly == string.Empty && macroUserControl.Text != string.Empty)
tempMacroType = macroUserControl.Text;
SetMacroValuesFromPostBack(m_macro, Convert.ToInt32(tempCachePeriod), tempMacroAssembly, tempMacroType);
m_macro.Save();
SetMacroValuesFromPostBack(_macro, Convert.ToInt32(tempCachePeriod), tempMacroAssembly, tempMacroType);
// Save elements
var sort = 0;
foreach (RepeaterItem item in macroProperties.Items)
{
HtmlInputHidden macroPropertyID = (HtmlInputHidden)item.FindControl("macroPropertyID");
TextBox macroElementName = (TextBox)item.FindControl("macroPropertyName");
TextBox macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
DropDownList macroElementType = (DropDownList)item.FindControl("macroPropertyType");
MacroProperty mp = new MacroProperty(int.Parse(macroPropertyID.Value));
mp.Type = new MacroPropertyType(int.Parse(macroElementType.SelectedValue));
mp.Alias = macroElementAlias.Text;
mp.Name = macroElementName.Text;
mp.Save();
var macroPropertyId = (HtmlInputHidden)item.FindControl("macroPropertyID");
var macroElementName = (TextBox)item.FindControl("macroPropertyName");
var macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
var macroElementType = (DropDownList)item.FindControl("macroPropertyType");
var prop = _macro.Properties[int.Parse(macroPropertyId.Value)];
prop.Alias = macroElementAlias.Text.Trim();
prop.Name = macroElementName.Text.Trim();
prop.EditorAlias = macroElementType.SelectedValue;
prop.SortOrder = sort;
sort++;
}
Services.MacroService.Save(_macro);
ClientTools.ShowSpeechBubble(speechBubbleIcon.save, "Macro saved", "");
// Check for assemblyBrowser
if (tempMacroType.IndexOf(".ascx") > 0)
if (tempMacroType.IndexOf(".ascx", StringComparison.Ordinal) > 0)
assemblyBrowserUserControl.Controls.Add(
new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('developer/macros/assemblyBrowser.aspx?fileName=" + macroUserControl.Text +
"&macroID=" + Request.QueryString["macroID"] +
@@ -131,17 +134,17 @@ namespace umbraco.cms.presentation.developer
/// <param name="macro"></param>
/// <param name="macroAssemblyValue"></param>
/// <param name="macroTypeValue"></param>
protected virtual void PopulateFieldsOnLoad(Macro macro, string macroAssemblyValue, string macroTypeValue)
protected virtual void PopulateFieldsOnLoad(IMacro macro, string macroAssemblyValue, string macroTypeValue)
{
macroName.Text = macro.Name;
macroAlias.Text = macro.Alias;
macroXslt.Text = macro.Xslt;
macroPython.Text = macro.ScriptingFile;
cachePeriod.Text = macro.RefreshRate.ToString();
macroRenderContent.Checked = macro.RenderContent;
macroXslt.Text = macro.XsltPath;
macroPython.Text = macro.ScriptPath;
cachePeriod.Text = macro.CacheDuration.ToInvariantString();
macroRenderContent.Checked = macro.DontRender == false;
macroEditor.Checked = macro.UseInEditor;
cacheByPage.Checked = macro.CacheByPage;
cachePersonalized.Checked = macro.CachePersonalized;
cachePersonalized.Checked = macro.CacheByMember;
// Populate either user control or custom control
if (macroTypeValue != string.Empty && macroAssemblyValue != string.Empty)
@@ -158,54 +161,54 @@ namespace umbraco.cms.presentation.developer
/// <summary>
/// Sets the values on the Macro object from the values posted back before saving the macro
/// </summary>
protected virtual void SetMacroValuesFromPostBack(Macro macro, int macroCachePeriod, string macroAssemblyValue, string macroTypeValue)
protected virtual void SetMacroValuesFromPostBack(IMacro macro, int macroCachePeriod, string macroAssemblyValue, string macroTypeValue)
{
macro.UseInEditor = macroEditor.Checked;
macro.RenderContent = macroRenderContent.Checked;
macro.DontRender = macroRenderContent.Checked == false;
macro.CacheByPage = cacheByPage.Checked;
macro.CachePersonalized = cachePersonalized.Checked;
macro.RefreshRate = macroCachePeriod;
macro.CacheByMember = cachePersonalized.Checked;
macro.CacheDuration = macroCachePeriod;
macro.Alias = macroAlias.Text;
macro.Name = macroName.Text;
macro.Assembly = macroAssemblyValue;
macro.Type = macroTypeValue;
macro.Xslt = macroXslt.Text;
macro.ScriptingFile = macroPython.Text;
macro.ControlAssembly = macroAssemblyValue;
macro.ControlType = macroTypeValue;
macro.XsltPath = macroXslt.Text;
macro.ScriptPath = macroPython.Text;
}
private void GetXsltFilesFromDir(string orgPath, string path, ArrayList files)
private static void GetXsltFilesFromDir(string orgPath, string path, ArrayList files)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
var dirInfo = new DirectoryInfo(path);
// Populate subdirectories
DirectoryInfo[] dirInfos = dirInfo.GetDirectories();
foreach (DirectoryInfo dir in dirInfos)
var dirInfos = dirInfo.GetDirectories();
foreach (var dir in dirInfos)
GetXsltFilesFromDir(orgPath, path + "/" + dir.Name, files);
FileInfo[] fileInfo = dirInfo.GetFiles("*.xsl*");
var fileInfo = dirInfo.GetFiles("*.xsl*");
foreach (FileInfo file in fileInfo)
foreach (var file in fileInfo)
files.Add((path.Replace(orgPath, string.Empty).Trim('/') + "/" + file.Name).Trim('/'));
}
private void PopulateXsltFiles()
{
ArrayList xslts = new ArrayList();
string xsltDir = IOHelper.MapPath(SystemDirectories.Xslt + "/");
var xslts = new ArrayList();
var xsltDir = IOHelper.MapPath(SystemDirectories.Xslt + "/");
GetXsltFilesFromDir(xsltDir, xsltDir, xslts);
xsltFiles.DataSource = xslts;
xsltFiles.DataBind();
xsltFiles.Items.Insert(0, new ListItem("Browse xslt files on server...", string.Empty));
}
private void GetPythonFilesFromDir(string orgPath, string path, ArrayList files)
private static void GetPythonFilesFromDir(string orgPath, string path, ArrayList files)
{
var dirInfo = new DirectoryInfo(path);
if (!dirInfo.Exists)
return;
FileInfo[] fileInfo = dirInfo.GetFiles("*.*");
foreach (FileInfo file in fileInfo)
var fileInfo = dirInfo.GetFiles("*.*");
foreach (var file in fileInfo)
files.Add(path.Replace(orgPath, string.Empty) + file.Name);
// Populate subdirectories
@@ -216,8 +219,8 @@ namespace umbraco.cms.presentation.developer
private void PopulatePythonFiles()
{
ArrayList pythons = new ArrayList();
string pythonDir = IOHelper.MapPath(SystemDirectories.MacroScripts + "/");
var pythons = new ArrayList();
var pythonDir = IOHelper.MapPath(SystemDirectories.MacroScripts + "/");
GetPythonFilesFromDir(pythonDir, pythonDir, pythons);
pythonFiles.DataSource = pythons;
pythonFiles.DataBind();
@@ -234,7 +237,7 @@ namespace umbraco.cms.presentation.developer
public void macroPropertyBind()
{
macroProperties.DataSource = m_macro.Properties;
macroProperties.DataSource = _macro.Properties;
macroProperties.DataBind();
}
@@ -259,65 +262,54 @@ namespace umbraco.cms.presentation.developer
public void macroPropertyCreate(object sender, EventArgs e)
{
TextBox macroPropertyAliasNew = (TextBox)((Control)sender).Parent.FindControl("macroPropertyAliasNew");
TextBox macroPropertyNameNew = (TextBox)((Control)sender).Parent.FindControl("macroPropertyNameNew");
DropDownList macroPropertyTypeNew = (DropDownList)((Control)sender).Parent.FindControl("macroPropertyTypeNew");
bool _goAhead = true;
if (macroPropertyAliasNew.Text !=
ui.Text("general", "new", this.getUser()) + " " + ui.Text("general", "alias", this.getUser()))
var macroPropertyAliasNew = (TextBox)((Control)sender).Parent.FindControl("macroPropertyAliasNew");
var macroPropertyNameNew = (TextBox)((Control)sender).Parent.FindControl("macroPropertyNameNew");
var macroPropertyTypeNew = (DropDownList)((Control)sender).Parent.FindControl("macroPropertyTypeNew");
var goAhead = true;
if (macroPropertyAliasNew.Text != ui.Text("general", "new", UmbracoUser) + " " + ui.Text("general", "alias", UmbracoUser))
{
if (_macro.Properties.ContainsKey(macroPropertyAliasNew.Text.Trim()))
{
//don't continue
return;
}
_macro.Properties.Add(new MacroProperty(
macroPropertyAliasNew.Text.Trim(),
macroPropertyNameNew.Text.Trim(),
_macro.Properties.Any() ? _macro.Properties.Max(x => x.SortOrder) + 1 : 0,
macroPropertyTypeNew.SelectedValue));
foreach (cms.businesslogic.macro.MacroProperty mp in m_macro.Properties)
{
if (mp.Alias == macroPropertyAliasNew.Text)
{
_goAhead = false;
break;
Services.MacroService.Save(_macro);
}
}
if (_goAhead)
{
MacroProperty mp = new MacroProperty();
mp.Macro = m_macro;
mp.Public = true;
mp.Type = new MacroPropertyType(int.Parse(macroPropertyTypeNew.SelectedValue));
mp.Alias = macroPropertyAliasNew.Text;
mp.Name = macroPropertyNameNew.Text;
mp.Save();
m_macro.RefreshProperties();
macroPropertyBind();
}
macroPropertyBind();
}
}
public bool macroIsVisible(object IsChecked)
public bool macroIsVisible(object isChecked)
{
if (Convert.ToBoolean(IsChecked))
if (Convert.ToBoolean(isChecked))
return true;
else
return false;
}
public void AddChooseList(Object Sender, EventArgs e)
public void AddChooseList(Object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList dropDown = (DropDownList)Sender;
var dropDown = (DropDownList)sender;
dropDown.Items.Insert(0, new ListItem("Choose...", string.Empty));
}
}
private void PopulateUserControls(string path)
{
DirectoryInfo di = new DirectoryInfo(path);
var di = new DirectoryInfo(path);
string rootDir = IOHelper.MapPath(SystemDirectories.UserControls);
foreach (FileInfo uc in di.GetFiles("*.ascx"))
foreach (var uc in di.GetFiles("*.ascx"))
{
userControlList.Items.Add(
new ListItem(SystemDirectories.UserControls +
@@ -328,19 +320,12 @@ namespace umbraco.cms.presentation.developer
*/
}
foreach (DirectoryInfo dir in di.GetDirectories())
foreach (var dir in di.GetDirectories())
PopulateUserControls(dir.FullName);
}
#region Web Form Designer generated code
protected override void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
// Tab setup
InfoTabPage = TabView1.NewTabPage("Macro Properties");
InfoTabPage.Controls.Add(Pane1);
@@ -358,16 +343,6 @@ namespace umbraco.cms.presentation.developer
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
/// <summary>
/// TabView1 control.
/// </summary>
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Web.Services;
using System.Xml;
using Umbraco.Core;
@@ -35,7 +36,7 @@ namespace umbraco.webservices
foreach (var m in cms.businesslogic.macro.Macro.GetAll())
{
var mXml = xmlDoc.CreateElement("macro");
mXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "id", m.Id.ToString()));
mXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "id", m.Id.ToString(CultureInfo.InvariantCulture)));
mXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", m.Alias));
mXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", m.Name));
macros.AppendChild(mXml);
@@ -54,8 +55,8 @@ namespace umbraco.webservices
var xmlDoc = new XmlDocument();
var macro = xmlDoc.CreateElement("macro");
var m = new cms.businesslogic.macro.Macro(Id);
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "id", m.Id.ToString()));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "refreshRate", m.RefreshRate.ToString()));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "id", m.Id.ToString(CultureInfo.InvariantCulture)));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "refreshRate", m.RefreshRate.ToString(CultureInfo.InvariantCulture)));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "useInEditor", m.UseInEditor.ToString()));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", m.Alias));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", m.Name));
@@ -68,7 +69,7 @@ namespace umbraco.webservices
var pXml = xmlDoc.CreateElement("property");
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", mp.Alias));
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", mp.Name));
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "public", mp.Public.ToString()));
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "public", true.ToString()));
properties.AppendChild(pXml);
}
macro.AppendChild(properties);
@@ -26,6 +26,7 @@ namespace umbraco.cms.businesslogic.macro
/// A macro can have a variety of properties which are used to transfer userinput to either the usercontrol/custom control or the xsl
///
/// </summary>
[Obsolete("This is no longer used, use the IMacroService and related models instead")]
public class Macro
{
@@ -1,36 +0,0 @@
using System;
namespace umbraco.cms.businesslogic.macro
{
/// <summary>
/// Not implemented
/// </summary>
[AttributeUsage(AttributeTargets.Class |
AttributeTargets.Constructor |
AttributeTargets.Field |
AttributeTargets.Method |
AttributeTargets.Property,
AllowMultiple = true)]
public class MacroComment : System.Attribute
{
private string _comment;
/// <summary>
/// Not implemented
/// </summary>
public string Comment
{
set {_comment = value;}
get {return _comment;}
}
/// <summary>
/// Not implemented
/// </summary>
/// <param name="Comment">Not implemented</param>
public MacroComment(string Comment)
{
_comment = Comment;
}
}
}
@@ -3,6 +3,7 @@ using System.Data;
using System.Xml;
using System.Runtime.CompilerServices;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using umbraco.DataLayer;
using umbraco.BusinessLogic;
using System.Collections.Generic;
@@ -18,6 +19,7 @@ namespace umbraco.cms.businesslogic.macro
/// A MacroProperty uses it's MacroPropertyType to define which underlaying component should be used when
/// rendering the MacroProperty editor aswell as which datatype its containing.
/// </summary>
[Obsolete("This is no longer used, use the IMacroService and related models instead")]
public class MacroProperty
{
protected static ISqlHelper SqlHelper
@@ -75,11 +77,38 @@ namespace umbraco.cms.businesslogic.macro
/// <value>The macro.</value>
public Macro Macro { get; set; }
private MacroPropertyType _type;
/// <summary>
/// The basetype which defines which component is used in the UI for editing content
/// </summary>
[Obsolete("This no longer does anything and will be removed in future versions")]
public MacroPropertyType Type { get; set; }
[Obsolete("This is no longer used and will be removed in future versions")]
public MacroPropertyType Type
{
get
{
if (_type == null)
{
//we'll try to create one based on the resolved new parameter editors
var found = ParameterEditorResolver.Current.GetByAlias(ParameterEditorAlias);
if (found == null)
{
return null;
}
var type = new MacroPropertyType
{
Alias = ParameterEditorAlias,
Id = 0,
Assembly = found.GetType().Namespace,
BaseType = found.GetType().Name,
Type = "String"
};
_type = type;
}
return _type;
}
set { _type = Type; }
}
/// <summary>
/// The macro parameter editor alias used to render the editor
@@ -118,8 +147,7 @@ namespace umbraco.cms.businesslogic.macro
{
if (Id == 0)
{
MacroProperty mp =
MakeNew(Macro, Public, Alias, Name, Type);
MacroProperty mp = MakeNew(Macro, Alias, Name, ParameterEditorAlias);
Id = mp.Id;
}
@@ -26,28 +26,33 @@ namespace umbraco.cms.businesslogic.macro
/// <summary>
/// Identifier
/// </summary>
public int Id { get; private set; }
public int Id { get; internal set; }
/// <summary>
/// The alias of the MacroPropertyType
/// </summary>
public string Alias { get; private set; }
public string Alias { get; internal set; }
/// <summary>
/// The assembly (without the .dll extension) used to retrieve the component at runtime
/// </summary>
public string Assembly { get; private set; }
public string Assembly { get; internal set; }
/// <summary>
/// The MacroPropertyType
/// </summary>
public string Type { get; private set; }
public string Type { get; internal set; }
/// <summary>
/// The IMacroGuiRendering component (namespace.namespace.Classname)
/// </summary>
public string BaseType { get; private set; }
public string BaseType { get; internal set; }
internal MacroPropertyType()
{
}
/// <summary>
/// Constructor
/// </summary>
-3
View File
@@ -338,9 +338,6 @@
<Compile Include="businesslogic\macro\Macro.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="businesslogic\macro\MacroComment.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="businesslogic\macro\MacroProperty.cs">
<SubType>Code</SubType>
</Compile>
@@ -199,23 +199,19 @@ namespace umbraco.editorControls.macrocontainer
}
foreach (MacroProperty macroProperty in formMacro.Properties)
{
//Only add properties that people may see.
if (macroProperty.Public)
var prop = new PersistableMacroProperty();
prop.Alias = macroProperty.Alias;
prop.Name = macroProperty.Name;
prop.AssemblyName = macroProperty.Type.Assembly;
prop.TypeName = macroProperty.Type.Type;
//Assign value if specified
if (DataValues[macroProperty.Alias.ToLower()] != null)
{
PersistableMacroProperty prop = new PersistableMacroProperty();
prop.Alias = macroProperty.Alias;
prop.Name = macroProperty.Name;
prop.AssemblyName = macroProperty.Type.Assembly;
prop.TypeName = macroProperty.Type.Type;
//Assign value if specified
if (DataValues[macroProperty.Alias.ToLower()] != null)
{
prop.Value = DataValues[macroProperty.Alias.ToLower()].ToString();
}
props.Add(prop);
prop.Value = DataValues[macroProperty.Alias.ToLower()].ToString();
}
props.Add(prop);
}
}
}