Creates parameter editor manfests and resolver, updates the legacy macro editor to resolve items from here.
This commit is contained in:
@@ -36,6 +36,27 @@ namespace Umbraco.Core.Manifest
|
||||
return editors;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all parameter editors found in the manfifests
|
||||
/// </summary>
|
||||
internal static IEnumerable<ParameterEditor> ParameterEditors
|
||||
{
|
||||
get
|
||||
{
|
||||
return (IEnumerable<ParameterEditor>)StaticCache.GetOrAdd(
|
||||
PropertyEditorsKey,
|
||||
s =>
|
||||
{
|
||||
var editors = new List<ParameterEditor>();
|
||||
foreach (var manifest in GetManifests())
|
||||
{
|
||||
editors.AddRange(ManifestParser.GetParameterEditors(manifest.ParameterEditors));
|
||||
}
|
||||
return editors;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -38,6 +38,18 @@ namespace Umbraco.Core.Manifest
|
||||
new PropertyEditorConverter(),
|
||||
new PreValueFieldConverter());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse the property editors from the json array
|
||||
/// </summary>
|
||||
/// <param name="jsonEditors"></param>
|
||||
/// <returns></returns>
|
||||
internal static IEnumerable<ParameterEditor> GetParameterEditors(JArray jsonEditors)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<IEnumerable<ParameterEditor>>(
|
||||
jsonEditors.ToString(),
|
||||
new ParameterEditorConverter());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all registered manifests
|
||||
@@ -143,11 +155,11 @@ namespace Umbraco.Core.Manifest
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var manifest = new PackageManifest()
|
||||
{
|
||||
JavaScriptInitialize = jConfig,
|
||||
PropertyEditors = propEditors.Any() ? (JArray)deserialized["propertyEditors"] : new JArray(),
|
||||
ParameterEditors = propEditors.Any() ? (JArray)deserialized["parameterEditors"] : new JArray()
|
||||
};
|
||||
result.Add(manifest);
|
||||
}
|
||||
|
||||
@@ -16,5 +16,10 @@ namespace Umbraco.Core.Manifest
|
||||
/// The json array of property editors
|
||||
/// </summary>
|
||||
public JArray PropertyEditors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The json array of parameter editors
|
||||
/// </summary>
|
||||
public JArray ParameterEditors { get; set; }
|
||||
}
|
||||
}
|
||||
31
src/Umbraco.Core/Manifest/ParameterEditorConverter.cs
Normal file
31
src/Umbraco.Core/Manifest/ParameterEditorConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Manifest
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to convert a parameter editor manifest to a property editor object
|
||||
/// </summary>
|
||||
internal class ParameterEditorConverter : JsonCreationConverter<ParameterEditor>
|
||||
{
|
||||
protected override ParameterEditor Create(Type objectType, JObject jObject)
|
||||
{
|
||||
return new ParameterEditor();
|
||||
}
|
||||
|
||||
protected override void Deserialize(JObject jObject, ParameterEditor target, JsonSerializer serializer)
|
||||
{
|
||||
//since it's a manifest editor, we need to create it's instance.
|
||||
//we need to specify the view value for the editor here otherwise we'll get an exception.
|
||||
target.ManifestDefinedParameterValueEditor = new ParameterValueEditor
|
||||
{
|
||||
View = jObject["view"].ToString()
|
||||
};
|
||||
|
||||
base.Deserialize(jObject, target, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
@@ -45,6 +46,18 @@ namespace Umbraco.Core.PropertyEditors
|
||||
[JsonProperty("name", Required = Required.Always)]
|
||||
public string Name { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allows a parameter editor to be re-used based on the configuration specified.
|
||||
/// </summary>
|
||||
[JsonProperty("config")]
|
||||
public virtual IDictionary<string, object> Configuration { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ParameterValueEditor ValueEditor
|
||||
{
|
||||
get { return CreateValueEditor(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a value editor instance
|
||||
/// </summary>
|
||||
|
||||
40
src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs
Normal file
40
src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// A resolver to resolve all parameter editors
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This resolver will contain any property editors defined in manifests as well!
|
||||
/// </remarks>
|
||||
internal class ParameterEditorResolver : LazyManyObjectsResolverBase<ParameterEditorResolver, ParameterEditor>
|
||||
{
|
||||
public ParameterEditorResolver(Func<IEnumerable<Type>> typeListProducerList)
|
||||
: base(typeListProducerList, ObjectLifetimeScope.Application)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the property editors
|
||||
/// </summary>
|
||||
public IEnumerable<ParameterEditor> ParameterEditors
|
||||
{
|
||||
get { return Values.Union(ManifestBuilder.ParameterEditors); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a property editor by alias
|
||||
/// </summary>
|
||||
/// <param name="alias"></param>
|
||||
/// <returns></returns>
|
||||
public ParameterEditor GetByAlias(string alias)
|
||||
{
|
||||
return ParameterEditors.SingleOrDefault(x => x.Alias == alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,6 +278,7 @@
|
||||
<Compile Include="Manifest\ManifestParser.cs" />
|
||||
<Compile Include="Manifest\ManifestValidatorConverter.cs" />
|
||||
<Compile Include="Manifest\PackageManifest.cs" />
|
||||
<Compile Include="Manifest\ParameterEditorConverter.cs" />
|
||||
<Compile Include="Manifest\PreValueFieldConverter.cs" />
|
||||
<Compile Include="Manifest\PropertyEditorConverter.cs" />
|
||||
<Compile Include="Media\MediaSubfolderCounter.cs" />
|
||||
@@ -716,6 +717,7 @@
|
||||
<Compile Include="PropertyEditors\ManifestPropertyValidator.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterEditor.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterEditorAttribute.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterEditorResolver.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\PreValueField.cs" />
|
||||
<Compile Include="PropertyEditors\PreValueFieldAttribute.cs" />
|
||||
|
||||
@@ -110,6 +110,36 @@ namespace Umbraco.Tests.Manifest
|
||||
Assert.AreEqual("some default pre val", parser.ElementAt(1).DefaultPreValues["key1"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_Parameter_Editors()
|
||||
{
|
||||
|
||||
var a = JsonConvert.DeserializeObject<JArray>(@"[
|
||||
{
|
||||
alias: 'parameter1',
|
||||
name: 'My Parameter',
|
||||
view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html'
|
||||
},
|
||||
{
|
||||
alias: 'parameter2',
|
||||
name: 'Another parameter',
|
||||
config: { key1: 'some config val' },
|
||||
view: '~/App_Plugins/MyPackage/PropertyEditors/CsvEditor.html'
|
||||
}
|
||||
]");
|
||||
var parser = ManifestParser.GetParameterEditors(a);
|
||||
|
||||
Assert.AreEqual(2, parser.Count());
|
||||
Assert.AreEqual("parameter1", parser.ElementAt(0).Alias);
|
||||
Assert.AreEqual("My Parameter", parser.ElementAt(0).Name);
|
||||
Assert.AreEqual("/App_Plugins/MyPackage/PropertyEditors/MyEditor.html", parser.ElementAt(0).ValueEditor.View);
|
||||
|
||||
Assert.AreEqual("parameter2", parser.ElementAt(1).Alias);
|
||||
Assert.AreEqual("Another parameter", parser.ElementAt(1).Name);
|
||||
Assert.IsTrue(parser.ElementAt(1).Configuration.ContainsKey("key1"));
|
||||
Assert.AreEqual("some config val", parser.ElementAt(1).Configuration["key1"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Merge_JArrays()
|
||||
{
|
||||
@@ -166,7 +196,6 @@ namespace Umbraco.Tests.Manifest
|
||||
Assert.AreEqual(5, obj1.Properties().Count());
|
||||
Assert.AreEqual("Value3", obj1.Properties().ElementAt(2).Value.Value<string>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestCase("C:\\Test", "C:\\Test\\MyFolder\\AnotherFolder", 2)]
|
||||
|
||||
@@ -1120,6 +1120,9 @@ namespace umbraco
|
||||
TraceInfo("umbracoMacro",
|
||||
"Xslt node adding search start (" + macroPropertyAlias + ",'" +
|
||||
macroPropertyValue + "')");
|
||||
|
||||
//TODO: WE need to fix this so that we give control of this stuff over to the actual parameter editors!
|
||||
|
||||
switch (macroPropertyType)
|
||||
{
|
||||
case "contentTree":
|
||||
@@ -1149,13 +1152,7 @@ namespace umbraco
|
||||
|
||||
macroXmlNode.AppendChild(currentNode);
|
||||
|
||||
break;
|
||||
|
||||
case "contentSubs": // disable that one, it does not work anyway...
|
||||
//x.LoadXml("<nodes/>");
|
||||
//x.FirstChild.AppendChild(x.ImportNode(umbracoXml.GetElementById(contentId), true));
|
||||
//macroXmlNode.InnerXml = TransformMacroXml(x, "macroGetSubs.xsl");
|
||||
break;
|
||||
break;
|
||||
|
||||
case "contentAll":
|
||||
macroXmlNode.AppendChild(macroXml.ImportNode(umbracoXml.DocumentElement, true));
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.IO;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.uicontrols;
|
||||
using umbraco.DataLayer;
|
||||
@@ -74,9 +76,7 @@ namespace umbraco.cms.presentation.developer
|
||||
}
|
||||
else
|
||||
{
|
||||
int macroID = Convert.ToInt32(Request.QueryString["macroID"]);
|
||||
|
||||
ClientTools
|
||||
ClientTools
|
||||
.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadMacros>().Tree.Alias)
|
||||
.SyncTree("-1,init," + m_macro.Id.ToString(), true); //true forces the reload
|
||||
|
||||
@@ -98,7 +98,6 @@ namespace umbraco.cms.presentation.developer
|
||||
HtmlInputHidden macroPropertyID = (HtmlInputHidden)item.FindControl("macroPropertyID");
|
||||
TextBox macroElementName = (TextBox)item.FindControl("macroPropertyName");
|
||||
TextBox macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
|
||||
CheckBox macroElementShow = (CheckBox)item.FindControl("macroPropertyHidden");
|
||||
DropDownList macroElementType = (DropDownList)item.FindControl("macroPropertyType");
|
||||
|
||||
MacroProperty mp = new MacroProperty(int.Parse(macroPropertyID.Value));
|
||||
@@ -247,11 +246,16 @@ namespace umbraco.cms.presentation.developer
|
||||
return test;
|
||||
}
|
||||
|
||||
[Obsolete("No longer used and will be removed in the future.")]
|
||||
public IRecordsReader GetMacroPropertyTypes()
|
||||
{
|
||||
// Load dataChildTypes
|
||||
return SqlHelper.ExecuteReader("select id, macroPropertyTypeAlias from cmsMacroPropertyType order by macroPropertyTypeAlias");
|
||||
}
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IEnumerable<ParameterEditor> GetMacroParameterEditors()
|
||||
{
|
||||
return ParameterEditorResolver.Current.ParameterEditors;
|
||||
}
|
||||
|
||||
public void macroPropertyCreate(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user