Converted usage of property editor value type strings to constants

This commit is contained in:
AndyButland
2016-05-08 22:05:23 +02:00
parent f79a1f1a71
commit 7858521c8b
27 changed files with 71 additions and 45 deletions

View File

@@ -19,7 +19,7 @@ namespace Umbraco.Core.PropertyEditors
EditorView = editorView;
//defaults
ValueType = "string";
ValueType = PropertyEditorValueTypes.StringType;
Icon = Constants.Icons.PropertyEditor;
Group = "common";
}
@@ -33,7 +33,7 @@ namespace Umbraco.Core.PropertyEditors
Name = name;
//defaults
ValueType = "string";
ValueType = PropertyEditorValueTypes.StringType;
Icon = Constants.Icons.PropertyEditor;
Group = "common";
}

View File

@@ -0,0 +1,25 @@
namespace Umbraco.Core.PropertyEditors
{
public static class PropertyEditorValueTypes
{
public const string DateType = "DATE";
public const string DateTimeType = "DATETIME";
public const string DecimalType = "DECIMAL";
public const string IntegerType = "INT";
public const string IntegerTypeAlternative = "INTEGER";
public const string JsonType = "JSON";
public const string TextType = "TEXT";
public const string TimeType = "TIME";
public const string StringType = "STRING";
public const string XmlType = "XML";
}
}

View File

@@ -25,7 +25,7 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
public PropertyValueEditor()
{
ValueType = "string";
ValueType = PropertyEditorValueTypes.StringType;
//set a default for validators
Validators = new List<IPropertyValidator>();
}
@@ -238,7 +238,7 @@ namespace Umbraco.Core.PropertyEditors
public virtual object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue)
{
//if it's json but it's empty json, then return null
if (ValueType.InvariantEquals("JSON") && editorValue.Value != null && editorValue.Value.ToString().DetectIsEmptyJson())
if (ValueType.InvariantEquals(PropertyEditorValueTypes.JsonType) && editorValue.Value != null && editorValue.Value.ToString().DetectIsEmptyJson())
{
return null;
}

View File

@@ -22,7 +22,7 @@ namespace Umbraco.Core.PropertyEditors
{
var asString = value.ToString();
if (editor.ValueEditor.ValueType.InvariantEquals("JSON"))
if (editor.ValueEditor.ValueType.InvariantEquals(PropertyEditorValueTypes.JsonType))
{
if (asString.DetectIsEmptyJson())
{

View File

@@ -26,7 +26,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
{
var propertyEditor = PropertyEditorResolver.Current.GetByAlias(propertyType.PropertyEditorAlias);
if (propertyEditor == null) return false;
return propertyEditor.ValueEditor.ValueType.InvariantEquals("json");
return propertyEditor.ValueEditor.ValueType.InvariantEquals(PropertyEditorValueTypes.JsonType);
}
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)

View File

@@ -476,6 +476,7 @@
<Compile Include="Persistence\Repositories\TaskRepository.cs" />
<Compile Include="Persistence\Repositories\TaskTypeRepository.cs" />
<Compile Include="PropertyEditors\DecimalValidator.cs" />
<Compile Include="PropertyEditors\PropertyEditorValueTypes.cs" />
<Compile Include="PropertyEditors\ValueConverters\GridValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\DecimalValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\LabelValueConverter.cs" />

View File

@@ -41,8 +41,8 @@ namespace Umbraco.Tests.PropertyEditors
var valueEditor = new PropertyValueEditor
{
ValueType = "STRING"
};
ValueType = PropertyEditorValueTypes.StringType
};
var result = valueEditor.ConvertDbToEditor(prop, prop.PropertyType, new Mock<IDataTypeService>().Object);
Assert.AreEqual(isOk, !(result is string));
@@ -73,7 +73,7 @@ namespace Umbraco.Tests.PropertyEditors
{
var valueEditor = new PropertyValueEditor
{
ValueType = "DECIMAL"
ValueType = PropertyEditorValueTypes.DecimalType
};
var result = valueEditor.TryConvertValueToCrlType("12.34");
@@ -86,7 +86,7 @@ namespace Umbraco.Tests.PropertyEditors
{
var valueEditor = new PropertyValueEditor
{
ValueType = "DECIMAL"
ValueType = PropertyEditorValueTypes.DecimalType
};
var result = valueEditor.TryConvertValueToCrlType("12,34");
@@ -99,7 +99,7 @@ namespace Umbraco.Tests.PropertyEditors
{
var valueEditor = new PropertyValueEditor
{
ValueType = "DECIMAL"
ValueType = PropertyEditorValueTypes.DecimalType
};
var result = valueEditor.TryConvertValueToCrlType(string.Empty);
@@ -112,20 +112,20 @@ namespace Umbraco.Tests.PropertyEditors
{
var valueEditor = new PropertyValueEditor
{
ValueType = "DATE"
};
ValueType = PropertyEditorValueTypes.DateType
};
var result = valueEditor.TryConvertValueToCrlType("2010-02-05");
Assert.IsTrue(result.Success);
Assert.AreEqual(new DateTime(2010, 2, 5), result.Result);
}
[TestCase("STRING", "hello", "hello")]
[TestCase("TEXT", "hello", "hello")]
[TestCase("INT", 123, "123")]
[TestCase("INTEGER", 123, "123")]
[TestCase("INTEGER", "", "")] //test empty string for int
[TestCase("DATETIME", "", "")] //test empty string for date
[TestCase(PropertyEditorValueTypes.StringType, "hello", "hello")]
[TestCase(PropertyEditorValueTypes.TextType, "hello", "hello")]
[TestCase(PropertyEditorValueTypes.IntegerType, 123, "123")]
[TestCase(PropertyEditorValueTypes.IntegerTypeAlternative, 123, "123")]
[TestCase(PropertyEditorValueTypes.IntegerType, "", "")] //test empty string for int
[TestCase(PropertyEditorValueTypes.DateTimeType, "", "")] //test empty string for date
public void Value_Editor_Can_Serialize_Value(string valueType, object val, string expected)
{
var prop = new Property(1, Guid.NewGuid(), new PropertyType("test", DataTypeDatabaseType.Nvarchar), val);
@@ -145,8 +145,8 @@ namespace Umbraco.Tests.PropertyEditors
var value = 12.34M;
var valueEditor = new PropertyValueEditor
{
ValueType = "DECIMAL"
};
ValueType = PropertyEditorValueTypes.DecimalType
};
var prop = new Property(1, Guid.NewGuid(), new PropertyType("test", DataTypeDatabaseType.Decimal), value);
@@ -159,8 +159,8 @@ namespace Umbraco.Tests.PropertyEditors
{
var valueEditor = new PropertyValueEditor
{
ValueType = "DECIMAL"
};
ValueType = PropertyEditorValueTypes.DecimalType
};
var prop = new Property(1, Guid.NewGuid(), new PropertyType("test", DataTypeDatabaseType.Decimal), string.Empty);
@@ -174,8 +174,8 @@ namespace Umbraco.Tests.PropertyEditors
var now = DateTime.Now;
var valueEditor = new PropertyValueEditor
{
ValueType = "DATE"
};
ValueType = PropertyEditorValueTypes.DateType
};
var prop = new Property(1, Guid.NewGuid(), new PropertyType("test", DataTypeDatabaseType.Date), now);

View File

@@ -4,7 +4,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.ContentPickerAlias, "Content Picker", "INT", "contentpicker", IsParameterEditor = true, Group = "Pickers")]
[PropertyEditor(Constants.PropertyEditors.ContentPickerAlias, "Content Picker", PropertyEditorValueTypes.IntegerType, "contentpicker", IsParameterEditor = true, Group = "Pickers")]
public class ContentPickerPropertyEditor : PropertyEditor
{

View File

@@ -9,7 +9,7 @@ using Umbraco.Core.Services;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.DateAlias, "Date", "DATE", "datepicker", Icon="icon-calendar")]
[PropertyEditor(Constants.PropertyEditors.DateAlias, "Date", PropertyEditorValueTypes.DateType, "datepicker", Icon="icon-calendar")]
public class DatePropertyEditor : PropertyEditor
{
public DatePropertyEditor()

View File

@@ -5,7 +5,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.DateTimeAlias, "Date/Time", "datepicker", ValueType = "DATETIME", Icon="icon-time")]
[PropertyEditor(Constants.PropertyEditors.DateTimeAlias, "Date/Time", "datepicker", ValueType = PropertyEditorValueTypes.DateTimeType, Icon="icon-time")]
public class DateTimePropertyEditor : PropertyEditor
{
public DateTimePropertyEditor()

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.DecimalAlias, "Decimal", "decimal", "decimal", IsParameterEditor = true)]
[PropertyEditor(Constants.PropertyEditors.DecimalAlias, "Decimal", PropertyEditorValueTypes.DecimalType, "decimal", IsParameterEditor = true)]
public class DecimalPropertyEditor : PropertyEditor
{
/// <summary>

View File

@@ -16,7 +16,7 @@ namespace Umbraco.Web.PropertyEditors
/// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the string value is published
/// in cache and not the int ID.
/// </remarks>
[PropertyEditor(Constants.PropertyEditors.DropDownListAlias, "Dropdown list", "dropdown", ValueType = "STRING", Group = "lists", Icon = "icon-indent")]
[PropertyEditor(Constants.PropertyEditors.DropDownListAlias, "Dropdown list", "dropdown", ValueType = PropertyEditorValueTypes.StringType, Group = "lists", Icon = "icon-indent")]
public class DropDownPropertyEditor : DropDownWithKeysPropertyEditor
{
/// <summary>

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Web.PropertyEditors
/// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the INT ID value is published
/// in cache and not the string value.
/// </remarks>
[PropertyEditor(Constants.PropertyEditors.DropdownlistPublishingKeysAlias, "Dropdown list, publishing keys", "dropdown", ValueType = "INT", Group = "lists", Icon = "icon-indent")]
[PropertyEditor(Constants.PropertyEditors.DropdownlistPublishingKeysAlias, "Dropdown list, publishing keys", "dropdown", ValueType = PropertyEditorValueTypes.IntegerType, Group = "lists", Icon = "icon-indent")]
public class DropDownWithKeysPropertyEditor : PropertyEditor
{

View File

@@ -9,7 +9,7 @@ using Umbraco.Core.Services;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Core.Constants.PropertyEditors.GridAlias, "Grid layout", "grid", HideLabel = true, IsParameterEditor = false, ValueType = "JSON", Group="rich content", Icon="icon-layout")]
[PropertyEditor(Core.Constants.PropertyEditors.GridAlias, "Grid layout", "grid", HideLabel = true, IsParameterEditor = false, ValueType = PropertyEditorValueTypes.JsonType, Group="rich content", Icon="icon-layout")]
public class GridPropertyEditor : PropertyEditor
{
/// <summary>

View File

@@ -15,7 +15,7 @@ using Umbraco.Core.Services;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.ImageCropperAlias, "Image Cropper", "imagecropper", ValueType = "JSON", HideLabel = false, Group="media", Icon="icon-crop")]
[PropertyEditor(Constants.PropertyEditors.ImageCropperAlias, "Image Cropper", "imagecropper", ValueType = PropertyEditorValueTypes.JsonType, HideLabel = false, Group="media", Icon="icon-crop")]
public class ImageCropperPropertyEditor : PropertyEditor
{

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.IntegerAlias, "Numeric", "integer", IsParameterEditor = true, ValueType = "integer")]
[PropertyEditor(Constants.PropertyEditors.IntegerAlias, "Numeric", "integer", IsParameterEditor = true, ValueType = PropertyEditorValueTypes.IntegerTypeAlternative)]
public class IntegerPropertyEditor : PropertyEditor
{
/// <summary>

View File

@@ -9,7 +9,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer", ValueType = "TEXT", Group="rich content", Icon="icon-settings-alt")]
[PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer", ValueType = PropertyEditorValueTypes.TextType, Group="rich content", Icon="icon-settings-alt")]
public class MacroContainerPropertyEditor : PropertyEditor
{
/// <summary>

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.MarkdownEditorAlias, "Markdown editor", "markdowneditor", ValueType = "TEXT", Icon="icon-code", Group="rich content")]
[PropertyEditor(Constants.PropertyEditors.MarkdownEditorAlias, "Markdown editor", "markdowneditor", ValueType = PropertyEditorValueTypes.TextType, Icon="icon-code", Group="rich content")]
public class MarkdownPropertyEditor : PropertyEditor
{
protected override PreValueEditor CreatePreValueEditor()

View File

@@ -9,7 +9,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.MediaPickerAlias, "Legacy Media Picker", "INT", "mediapicker", Group="media", Icon="icon-picture")]
[PropertyEditor(Constants.PropertyEditors.MediaPickerAlias, "Legacy Media Picker", PropertyEditorValueTypes.IntegerType, "mediapicker", Group="media", Icon="icon-picture")]
public class MediaPickerPropertyEditor : PropertyEditor
{
public MediaPickerPropertyEditor()

View File

@@ -8,7 +8,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.MemberPickerAlias, "Member Picker", "INT", "memberpicker", Group = "People", Icon = "icon-user")]
[PropertyEditor(Constants.PropertyEditors.MemberPickerAlias, "Member Picker", PropertyEditorValueTypes.IntegerType, "memberpicker", Group = "People", Icon = "icon-user")]
public class MemberPickerPropertyEditor : PropertyEditor
{
}

View File

@@ -14,7 +14,7 @@ using Umbraco.Core.Services;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.MultipleTextstringAlias, "Repeatable textstrings", "multipletextbox", ValueType = "TEXT", Icon="icon-ordered-list", Group="lists")]
[PropertyEditor(Constants.PropertyEditors.MultipleTextstringAlias, "Repeatable textstrings", "multipletextbox", ValueType = PropertyEditorValueTypes.TextType, Icon="icon-ordered-list", Group="lists")]
public class MultipleTextStringPropertyEditor : PropertyEditor
{
protected override PropertyValueEditor CreateValueEditor()

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Web.PropertyEditors
/// as INT and we have logic in here to ensure it is formatted correctly including ensuring that the INT ID value is published
/// in cache and not the string value.
/// </remarks>
[PropertyEditor(Constants.PropertyEditors.RadioButtonListAlias, "Radio button list", "radiobuttons", ValueType = "INT", Group="lists", Icon="icon-target")]
[PropertyEditor(Constants.PropertyEditors.RadioButtonListAlias, "Radio button list", "radiobuttons", ValueType = PropertyEditorValueTypes.IntegerType, Group="lists", Icon="icon-target")]
public class RadioButtonsPropertyEditor : DropDownWithKeysPropertyEditor
{

View File

@@ -8,7 +8,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.RelatedLinksAlias, "Related links", "relatedlinks", ValueType ="JSON", Icon="icon-thumbnail-list", Group="pickers")]
[PropertyEditor(Constants.PropertyEditors.RelatedLinksAlias, "Related links", "relatedlinks", ValueType = PropertyEditorValueTypes.JsonType, Icon="icon-thumbnail-list", Group="pickers")]
public class RelatedLinksPropertyEditor : PropertyEditor
{
protected override PreValueEditor CreatePreValueEditor()

View File

@@ -7,7 +7,7 @@ using Umbraco.Core.Services;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.TinyMCEAlias, "Rich Text Editor", "rte", ValueType = "TEXT", HideLabel = false, Group="Rich Content", Icon="icon-browser-window")]
[PropertyEditor(Constants.PropertyEditors.TinyMCEAlias, "Rich Text Editor", "rte", ValueType = PropertyEditorValueTypes.TextType, HideLabel = false, Group="Rich Content", Icon="icon-browser-window")]
public class RichTextPropertyEditor : PropertyEditor
{
/// <summary>

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.TextboxMultipleAlias, "Textarea", "textarea", IsParameterEditor = true, ValueType = "TEXT", Icon="icon-application-window-alt")]
[PropertyEditor(Constants.PropertyEditors.TextboxMultipleAlias, "Textarea", "textarea", IsParameterEditor = true, ValueType = PropertyEditorValueTypes.TextType, Icon="icon-application-window-alt")]
public class TextAreaPropertyEditor : PropertyEditor
{
}

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.TrueFalseAlias, "True/False", "INT", "boolean", IsParameterEditor = true, Group = "Common", Icon="icon-checkbox")]
[PropertyEditor(Constants.PropertyEditors.TrueFalseAlias, "True/False", PropertyEditorValueTypes.IntegerType, "boolean", IsParameterEditor = true, Group = "Common", Icon="icon-checkbox")]
public class TrueFalsePropertyEditor : PropertyEditor
{
protected override PreValueEditor CreatePreValueEditor()

View File

@@ -6,7 +6,7 @@ using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{
[PropertyEditor(Constants.PropertyEditors.UserPickerAlias, "User picker", "INT", "entitypicker", Group="People", Icon="icon-user")]
[PropertyEditor(Constants.PropertyEditors.UserPickerAlias, "User picker", PropertyEditorValueTypes.IntegerType, "entitypicker", Group="People", Icon="icon-user")]
public class UserPickerPropertyEditor : PropertyEditor
{
private IDictionary<string, object> _defaultPreValues;