Creates parameter editor manfests and resolver, updates the legacy macro editor to resolve items from here.

This commit is contained in:
Shannon
2013-09-19 15:33:47 +10:00
parent bbd5747177
commit ec3761baa0
10 changed files with 171 additions and 17 deletions

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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; }
}
}

View 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);
}
}
}

View File

@@ -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>

View 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);
}
}
}

View File

@@ -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" />