Getting parameter editor architecture done: we can share with prop eds or create standalone in both c# and in manifest.

This commit is contained in:
Shannon
2013-09-19 20:17:12 +10:00
parent f62546a308
commit 90fe92da82
11 changed files with 88 additions and 26 deletions

View File

@@ -43,7 +43,7 @@ namespace Umbraco.Core.Manifest
}
/// <summary>
/// Returns all parameter editors found in the manfifests
/// Returns all parameter editors found in the manfifests and all property editors that are flagged to be parameter editors
/// </summary>
internal static IEnumerable<ParameterEditor> ParameterEditors
{

View File

@@ -5,10 +5,30 @@ using Umbraco.Core.IO;
namespace Umbraco.Core.PropertyEditors
{
public interface IParameterEditor
{
/// <summary>
/// The id of the property editor
/// </summary>
string Alias { get; }
/// <summary>
/// The name of the property editor
/// </summary>
string Name { get; }
/// <summary>
/// Allows a parameter editor to be re-used based on the configuration specified.
/// </summary>
IDictionary<string, object> Configuration { get; }
IValueEditor ValueEditor { get; }
}
/// <summary>
/// Basic definition of a macro parameter editor
/// </summary>
public class ParameterEditor
public class ParameterEditor : IParameterEditor
{
private readonly ParameterEditorAttribute _attribute;
@@ -58,6 +78,12 @@ namespace Umbraco.Core.PropertyEditors
get { return CreateValueEditor(); }
}
[JsonIgnore]
IValueEditor IParameterEditor.ValueEditor
{
get { return ValueEditor; }
}
/// <summary>
/// Creates a value editor instance
/// </summary>

View File

@@ -6,6 +6,7 @@ namespace Umbraco.Core.PropertyEditors
/// An attribute used to define all of the basic properties of a parameter editor
/// on the server side.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public sealed class ParameterEditorAttribute : Attribute
{
public ParameterEditorAttribute(string alias, string name, string editorView)

View File

@@ -10,21 +10,35 @@ namespace Umbraco.Core.PropertyEditors
/// A resolver to resolve all parameter editors
/// </summary>
/// <remarks>
/// This resolver will contain any property editors defined in manifests as well!
/// This resolver will contain any parameter editors defined in manifests as well as any property editors defined in manifests
/// that have the IsParameterEditorFlag = true and any PropertyEditors found in c# that have this flag as well.
/// </remarks>
internal class ParameterEditorResolver : LazyManyObjectsResolverBase<ParameterEditorResolver, ParameterEditor>
internal class ParameterEditorResolver : LazyManyObjectsResolverBase<ParameterEditorResolver, IParameterEditor>
{
public ParameterEditorResolver(Func<IEnumerable<Type>> typeListProducerList)
: base(typeListProducerList, ObjectLifetimeScope.Application)
{
}
/// <summary>
/// Returns the property editors
/// Returns the parameter editors
/// </summary>
public IEnumerable<ParameterEditor> ParameterEditors
public IEnumerable<IParameterEditor> ParameterEditors
{
get { return Values.Union(ManifestBuilder.ParameterEditors); }
get
{
//This will by default include all property editors and parameter editors but we need to filter this
//list to ensure that none of the property editors that do not have the IsParameterEditor flag set to true
//are filtered.
var filtered = Values.Select(x => x as PropertyEditor)
.WhereNotNull()
.Where(x => x.IsParameterEditor == false)
.ToArray();
//now we need to get all manifest property editors in here that are parameter editors!~
return Values.Except(filtered).Union(ManifestBuilder.ParameterEditors);
}
}
/// <summary>
@@ -32,7 +46,7 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
/// <param name="alias"></param>
/// <returns></returns>
public ParameterEditor GetByAlias(string alias)
public IParameterEditor GetByAlias(string alias)
{
return ParameterEditors.SingleOrDefault(x => x.Alias == alias);
}

View File

@@ -2,13 +2,18 @@
namespace Umbraco.Core.PropertyEditors
{
/// <summary>
/// An interface that is shared between parameter and property value editors to access their views
/// </summary>
public interface IValueEditor
{
string View { get; }
}
/// <summary>
/// Represents the value editor for the parameter editor during macro parameter editing
/// </summary>
/// <remarks>
/// The Json serialization attributes are required for manifest property editors to work
/// </remarks>
public class ParameterValueEditor
public class ParameterValueEditor : IValueEditor
{
/// <summary>
/// default ctor
@@ -27,13 +32,6 @@ namespace Umbraco.Core.PropertyEditors
View = view;
}
/// <summary>
/// Defines the view to use for the editor, this can be one of 3 things:
/// * the full virtual path or
/// * the relative path to the current Umbraco folder
/// * a simple view name which will map to the views/propertyeditors/{view}/{view}.html
/// </summary>
[JsonProperty("view", Required = Required.Always)]
public string View { get; set; }
}
}

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Core.PropertyEditors
/// <remarks>
/// The Json serialization attributes are required for manifest property editors to work
/// </remarks>
public class PropertyEditor
public class PropertyEditor : IParameterEditor
{
private readonly PropertyEditorAttribute _attribute;
@@ -29,6 +29,7 @@ namespace Umbraco.Core.PropertyEditors
//set the id/name from the attribute
Alias = _attribute.Alias;
Name = _attribute.Name;
IsParameterEditor = _attribute.IsParameterEditor;
}
}
@@ -44,6 +45,12 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
internal PreValueEditor ManifestDefinedPreValueEditor = null;
/// <summary>
/// Boolean flag determining if this can be used as a parameter editor
/// </summary>
[JsonProperty("isParameterEditor")]
public bool IsParameterEditor { get; internal set; }
/// <summary>
/// The id of the property editor
/// </summary>
@@ -62,6 +69,12 @@ namespace Umbraco.Core.PropertyEditors
get { return CreateValueEditor(); }
}
[JsonIgnore]
IValueEditor IParameterEditor.ValueEditor
{
get { return ValueEditor; }
}
[JsonProperty("prevalues")]
public PreValueEditor PreValueEditor
{
@@ -71,6 +84,12 @@ namespace Umbraco.Core.PropertyEditors
[JsonProperty("defaultConfig")]
public virtual IDictionary<string, object> DefaultPreValues { get; set; }
[JsonIgnore]
IDictionary<string, object> IParameterEditor.Configuration
{
get { return DefaultPreValues; }
}
/// <summary>
/// Creates a value editor instance
/// </summary>

View File

@@ -51,5 +51,6 @@ namespace Umbraco.Core.PropertyEditors
public string Name { get; private set; }
public string EditorView { get; private set; }
public string ValueType { get; set; }
public bool IsParameterEditor { get; set; }
}
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Core.PropertyEditors
/// <remarks>
/// The Json serialization attributes are required for manifest property editors to work
/// </remarks>
public class PropertyValueEditor
public class PropertyValueEditor : IValueEditor
{
/// <summary>
/// assign defaults

View File

@@ -12,6 +12,9 @@ namespace Umbraco.Web.PropertyEditors
/// Due to maintaining backwards compatibility this data type stores the value as a string which is a comma separated value of the
/// ids of the individual items so we have logic in here to deal with that.
/// </remarks>
[ParameterEditor("propertyTypePickerMultiple", "Name", "textbox")]
[ParameterEditor("contentTypeMultiple", "Name", "textbox")]
[ParameterEditor("tabPickerMultiple", "Name", "textbox")]
[PropertyEditor(Constants.PropertyEditors.DropDownListMultipleAlias, "Dropdown list multiple", "dropdown")]
public class DropDownMultiplePropertyEditor : DropDownMultipleWithKeysPropertyEditor
{

View File

@@ -308,6 +308,9 @@
<Compile Include="Models\ContentEditing\UmbracoEntityTypes.cs" />
<Compile Include="Models\Mapping\MacroModelMapper.cs" />
<Compile Include="PropertyEditors\ColorListPreValueEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TextAreaParameterEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TextParameterEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TrueFalseParameterEditor.cs" />
<Compile Include="PropertyEditors\RteEmbedController.cs" />
<Compile Include="Editors\EntityController.cs" />
<Compile Include="Editors\MediaPostValidateAttribute.cs" />
@@ -342,9 +345,6 @@
<Compile Include="PropertyEditors\PublishValuesMultipleValueEditor.cs" />
<Compile Include="PropertyEditors\DropDownMultipleWithKeysPropertyEditor.cs" />
<Compile Include="PropertyEditors\RadioButtonsPropertyEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TextAreaParameterEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TextParameterEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TrueFalseParameterEditor.cs" />
<Compile Include="PropertyEditors\UserPickerPropertyEditor.cs" />
<Compile Include="PropertyEditors\ValueListPreValueEditor.cs" />
<Compile Include="PropertyEditors\DropDownPropertyEditor.cs" />

View File

@@ -261,7 +261,7 @@ namespace umbraco.cms.presentation.developer
return null;
}
protected IEnumerable<ParameterEditor> GetMacroParameterEditors()
protected IEnumerable<IParameterEditor> GetMacroParameterEditors()
{
return ParameterEditorResolver.Current.ParameterEditors;
}