From 90fe92da82f2dabe3d61d8aad6968777fd7d24ed Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 19 Sep 2013 20:17:12 +1000 Subject: [PATCH] Getting parameter editor architecture done: we can share with prop eds or create standalone in both c# and in manifest. --- src/Umbraco.Core/Manifest/ManifestBuilder.cs | 2 +- .../PropertyEditors/ParameterEditor.cs | 28 ++++++++++++++++++- .../ParameterEditorAttribute.cs | 1 + .../ParameterEditorResolver.cs | 28 ++++++++++++++----- .../PropertyEditors/ParameterValueEditor.cs | 20 ++++++------- .../PropertyEditors/PropertyEditor.cs | 21 +++++++++++++- .../PropertyEditorAttribute.cs | 1 + .../PropertyEditors/PropertyValueEditor.cs | 2 +- .../DropDownMultiplePropertyEditor.cs | 3 ++ src/Umbraco.Web/Umbraco.Web.csproj | 6 ++-- .../developer/Macros/editMacro.aspx.cs | 2 +- 11 files changed, 88 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Core/Manifest/ManifestBuilder.cs b/src/Umbraco.Core/Manifest/ManifestBuilder.cs index fe7d83304f..d880c4cc58 100644 --- a/src/Umbraco.Core/Manifest/ManifestBuilder.cs +++ b/src/Umbraco.Core/Manifest/ManifestBuilder.cs @@ -43,7 +43,7 @@ namespace Umbraco.Core.Manifest } /// - /// 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 /// internal static IEnumerable ParameterEditors { diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs index 0675b4894c..189fd59b8a 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditor.cs @@ -5,10 +5,30 @@ using Umbraco.Core.IO; namespace Umbraco.Core.PropertyEditors { + public interface IParameterEditor + { + /// + /// The id of the property editor + /// + string Alias { get; } + + /// + /// The name of the property editor + /// + string Name { get; } + + /// + /// Allows a parameter editor to be re-used based on the configuration specified. + /// + IDictionary Configuration { get; } + + IValueEditor ValueEditor { get; } + } + /// /// Basic definition of a macro parameter editor /// - 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; } + } + /// /// Creates a value editor instance /// diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs index 8a76e671b2..ab6fb559e4 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs @@ -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. /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class ParameterEditorAttribute : Attribute { public ParameterEditorAttribute(string alias, string name, string editorView) diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs index 212ffefe05..8d7c1a988f 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs @@ -10,21 +10,35 @@ namespace Umbraco.Core.PropertyEditors /// A resolver to resolve all parameter editors /// /// - /// 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. /// - internal class ParameterEditorResolver : LazyManyObjectsResolverBase + internal class ParameterEditorResolver : LazyManyObjectsResolverBase { public ParameterEditorResolver(Func> typeListProducerList) : base(typeListProducerList, ObjectLifetimeScope.Application) { } - + /// - /// Returns the property editors + /// Returns the parameter editors /// - public IEnumerable ParameterEditors + public IEnumerable 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); + } } /// @@ -32,7 +46,7 @@ namespace Umbraco.Core.PropertyEditors /// /// /// - public ParameterEditor GetByAlias(string alias) + public IParameterEditor GetByAlias(string alias) { return ParameterEditors.SingleOrDefault(x => x.Alias == alias); } diff --git a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs index f318b6e723..94ac544c73 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs @@ -2,13 +2,18 @@ namespace Umbraco.Core.PropertyEditors { + /// + /// An interface that is shared between parameter and property value editors to access their views + /// + public interface IValueEditor + { + string View { get; } + } + /// /// Represents the value editor for the parameter editor during macro parameter editing /// - /// - /// The Json serialization attributes are required for manifest property editors to work - /// - public class ParameterValueEditor + public class ParameterValueEditor : IValueEditor { /// /// default ctor @@ -27,13 +32,6 @@ namespace Umbraco.Core.PropertyEditors View = view; } - /// - /// 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 - /// - [JsonProperty("view", Required = Required.Always)] public string View { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs index d82337f364..611f180758 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core.PropertyEditors /// /// The Json serialization attributes are required for manifest property editors to work /// - 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 /// internal PreValueEditor ManifestDefinedPreValueEditor = null; + /// + /// Boolean flag determining if this can be used as a parameter editor + /// + [JsonProperty("isParameterEditor")] + public bool IsParameterEditor { get; internal set; } + /// /// The id of the property editor /// @@ -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 DefaultPreValues { get; set; } + [JsonIgnore] + IDictionary IParameterEditor.Configuration + { + get { return DefaultPreValues; } + } + /// /// Creates a value editor instance /// diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs index 642298ae97..50dfd1d062 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs @@ -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; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs index 4e8e3a63fd..6616fc612a 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.PropertyEditors /// /// The Json serialization attributes are required for manifest property editors to work /// - public class PropertyValueEditor + public class PropertyValueEditor : IValueEditor { /// /// assign defaults diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs index fc468a777b..02324f7d84 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs @@ -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. /// + [ParameterEditor("propertyTypePickerMultiple", "Name", "textbox")] + [ParameterEditor("contentTypeMultiple", "Name", "textbox")] + [ParameterEditor("tabPickerMultiple", "Name", "textbox")] [PropertyEditor(Constants.PropertyEditors.DropDownListMultipleAlias, "Dropdown list multiple", "dropdown")] public class DropDownMultiplePropertyEditor : DropDownMultipleWithKeysPropertyEditor { diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 2e09ff05c7..0815a400cb 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -308,6 +308,9 @@ + + + @@ -342,9 +345,6 @@ - - - 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 408859d4cf..788d9a26f2 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 @@ -261,7 +261,7 @@ namespace umbraco.cms.presentation.developer return null; } - protected IEnumerable GetMacroParameterEditors() + protected IEnumerable GetMacroParameterEditors() { return ParameterEditorResolver.Current.ParameterEditors; }