From dda247fea571a40530461b85d4a25db5edac8214 Mon Sep 17 00:00:00 2001 From: AndyButland Date: Sat, 26 Sep 2015 22:41:56 +0200 Subject: [PATCH 1/6] Implemented decimal property editor --- src/Umbraco.Core/Constants-PropertyEditors.cs | 5 ++ src/Umbraco.Core/CoreBootManager.cs | 1 + .../Models/DataTypeDatabaseType.cs | 4 +- src/Umbraco.Core/Models/PropertyType.cs | 3 + .../Models/Rdbms/PropertyDataDto.cs | 17 ++++-- .../Persistence/Factories/PropertyFactory.cs | 14 ++++- .../PropertyEditors/DecimalValidator.cs | 30 ++++++++++ .../PropertyEditors/PropertyValueEditor.cs | 10 ++++ .../ValueConverters/DecimalValueConverter.cs | 31 ++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 2 + .../src/views/prevalueeditors/decimal.html | 11 ++++ .../src/views/prevalueeditors/number.html | 2 +- .../propertyeditors/decimal/decimal.html | 9 +++ .../propertyeditors/integer/integer.html | 1 - .../PropertyEditors/DecimalPropertyEditor.cs | 57 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 16 files changed, 190 insertions(+), 8 deletions(-) create mode 100644 src/Umbraco.Core/PropertyEditors/DecimalValidator.cs create mode 100644 src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs create mode 100644 src/Umbraco.Web.UI.Client/src/views/prevalueeditors/decimal.html create mode 100644 src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html create mode 100644 src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs diff --git a/src/Umbraco.Core/Constants-PropertyEditors.cs b/src/Umbraco.Core/Constants-PropertyEditors.cs index a719e845b1..1a1eda2ae2 100644 --- a/src/Umbraco.Core/Constants-PropertyEditors.cs +++ b/src/Umbraco.Core/Constants-PropertyEditors.cs @@ -158,6 +158,11 @@ namespace Umbraco.Core /// public const string IntegerAlias = "Umbraco.Integer"; + /// + /// Alias for the Decimal datatype. + /// + public const string DecimalAlias = "Umbraco.Decimal"; + /// /// Alias for the listview datatype. /// diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index b4e3d06273..49829513bb 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -431,6 +431,7 @@ namespace Umbraco.Core new Lazy(() => typeof (DelimitedManifestValueValidator)), new Lazy(() => typeof (EmailValidator)), new Lazy(() => typeof (IntegerValidator)), + new Lazy(() => typeof (DecimalValidator)), }); //by default we'll use the db server registrar unless the developer has the legacy diff --git a/src/Umbraco.Core/Models/DataTypeDatabaseType.cs b/src/Umbraco.Core/Models/DataTypeDatabaseType.cs index e45cdd1a73..1db8ac65cb 100644 --- a/src/Umbraco.Core/Models/DataTypeDatabaseType.cs +++ b/src/Umbraco.Core/Models/DataTypeDatabaseType.cs @@ -21,6 +21,8 @@ namespace Umbraco.Core.Models [EnumMember] Integer, [EnumMember] - Date + Date, + [EnumMember] + Decimal } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index 239792bf08..69c714c85a 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -402,6 +402,9 @@ namespace Umbraco.Core.Models if (DataTypeDatabaseType == DataTypeDatabaseType.Integer && type == typeof(int)) return true; + if (DataTypeDatabaseType == DataTypeDatabaseType.Decimal && type == typeof(decimal)) + return true; + if (DataTypeDatabaseType == DataTypeDatabaseType.Date && type == typeof(DateTime)) return true; diff --git a/src/Umbraco.Core/Models/Rdbms/PropertyDataDto.cs b/src/Umbraco.Core/Models/Rdbms/PropertyDataDto.cs index 4e59f0275b..63e3104d12 100644 --- a/src/Umbraco.Core/Models/Rdbms/PropertyDataDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/PropertyDataDto.cs @@ -33,6 +33,10 @@ namespace Umbraco.Core.Models.Rdbms [NullSetting(NullSetting = NullSettings.Null)] public int? Integer { get; set; } + [Column("dataDecimal")] + [NullSetting(NullSetting = NullSettings.Null)] + public decimal? Decimal { get; set; } + [Column("dataDate")] [NullSetting(NullSetting = NullSettings.Null)] public DateTime? Date { get; set; } @@ -55,22 +59,27 @@ namespace Umbraco.Core.Models.Rdbms { get { - if(Integer.HasValue) + if (Integer.HasValue) { return Integer.Value; } + + if (Decimal.HasValue) + { + return Decimal.Value; + } - if(Date.HasValue) + if (Date.HasValue) { return Date.Value; } - if(string.IsNullOrEmpty(VarChar) == false) + if (string.IsNullOrEmpty(VarChar) == false) { return VarChar; } - if(string.IsNullOrEmpty(Text) == false) + if (string.IsNullOrEmpty(Text) == false) { return Text; } diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs index 4e3653bf9e..8d51b627ea 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs @@ -63,7 +63,9 @@ namespace Umbraco.Core.Persistence.Factories //Check if property has an Id and set it, so that it can be updated if it already exists if (property.HasIdentity) + { dto.Id = property.Id; + } if (property.DataTypeDatabaseType == DataTypeDatabaseType.Integer) { @@ -82,11 +84,21 @@ namespace Umbraco.Core.Persistence.Factories } } } + else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Decimal && property.Value != null) + { + decimal val; + if (decimal.TryParse(property.Value.ToString(), out val)) + { + dto.Decimal = val; + } + } else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Date && property.Value != null && string.IsNullOrWhiteSpace(property.Value.ToString()) == false) { DateTime date; - if(DateTime.TryParse(property.Value.ToString(), out date)) + if (DateTime.TryParse(property.Value.ToString(), out date)) + { dto.Date = date; + } } else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Ntext && property.Value != null) { diff --git a/src/Umbraco.Core/PropertyEditors/DecimalValidator.cs b/src/Umbraco.Core/PropertyEditors/DecimalValidator.cs new file mode 100644 index 0000000000..632821bc24 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/DecimalValidator.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Umbraco.Core.Models; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// A validator that validates that the value is a valid decimal + /// + [ValueValidator("Decimal")] + internal sealed class DecimalValidator : ManifestValueValidator, IPropertyValidator + { + public override IEnumerable Validate(object value, string config, PreValueCollection preValues, PropertyEditor editor) + { + if (value != null && value.ToString() != string.Empty) + { + var result = value.TryConvertTo(); + if (result.Success == false) + { + yield return new ValidationResult("The value " + value + " is not a valid decimal", new[] { "value" }); + } + } + } + + public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor) + { + return Validate(value, "", preValues, editor); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs index 8b00164059..3ddc557693 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs @@ -133,6 +133,8 @@ namespace Umbraco.Core.PropertyEditors case "INT": case "INTEGER": return DataTypeDatabaseType.Integer; + case "DECIMAL": + return DataTypeDatabaseType.Decimal; case "STRING": return DataTypeDatabaseType.Nvarchar; case "TEXT": @@ -202,6 +204,11 @@ namespace Umbraco.Core.PropertyEditors ? Attempt.Succeed((int)(long)result.Result) : result; + case DataTypeDatabaseType.Decimal: + //ensure these are nullable so we can return a null if required + valueType = typeof(decimal?); + break; + case DataTypeDatabaseType.Date: //ensure these are nullable so we can return a null if required valueType = typeof(DateTime?); @@ -283,6 +290,7 @@ namespace Umbraco.Core.PropertyEditors } return property.Value.ToString(); case DataTypeDatabaseType.Integer: + case DataTypeDatabaseType.Decimal: //we can just ToString() any of these types return property.Value.ToString(); case DataTypeDatabaseType.Date: @@ -325,6 +333,7 @@ namespace Umbraco.Core.PropertyEditors { case DataTypeDatabaseType.Date: case DataTypeDatabaseType.Integer: + case DataTypeDatabaseType.Decimal: return new XText(ConvertDbToString(property, propertyType, dataTypeService)); case DataTypeDatabaseType.Nvarchar: case DataTypeDatabaseType.Ntext: @@ -354,6 +363,7 @@ namespace Umbraco.Core.PropertyEditors property.Value.ToXmlString(); return property.Value.ToXmlString(); case DataTypeDatabaseType.Integer: + case DataTypeDatabaseType.Decimal: return property.Value.ToXmlString(property.Value.GetType()); case DataTypeDatabaseType.Date: //treat dates differently, output the format as xml format diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs new file mode 100644 index 0000000000..32fe356764 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs @@ -0,0 +1,31 @@ +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(decimal))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class DecimalValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Constants.PropertyEditors.DecimalAlias.Equals(propertyType.PropertyEditorAlias); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + if (source == null) return 0M; + + // in XML a decimal is a string + var sourceString = source as string; + if (sourceString != null) + { + decimal d; + return (decimal.TryParse(sourceString, out d)) ? d : 0M; + } + + // in the database an a decimal is an a decimal + // default value is zero + return (source is decimal) ? source : 0M; + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 15e00bcb8f..ae3ca88db1 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -456,7 +456,9 @@ + + diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/decimal.html b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/decimal.html new file mode 100644 index 0000000000..c4e4c95e39 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/decimal.html @@ -0,0 +1,11 @@ +
+ + + Not a number + {{propertyForm.requiredField.errorMsg}} + +
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/number.html b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/number.html index 6d7b8c4c78..e7490e2703 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/number.html +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/number.html @@ -3,7 +3,7 @@ type="number" ng-model="model.value" val-server="value" - fix-number /> + fix-number /> Not a number {{propertyForm.requiredField.errorMsg}} diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html new file mode 100644 index 0000000000..823a7b40ad --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html @@ -0,0 +1,9 @@ +
+ + + Not a number + {{propertyForm.requiredField.errorMsg}} +
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html index 251a6066d8..28a81b035f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html @@ -6,5 +6,4 @@ Not a number {{propertyForm.requiredField.errorMsg}} - \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs new file mode 100644 index 0000000000..f636e8cdb2 --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/DecimalPropertyEditor.cs @@ -0,0 +1,57 @@ +using Umbraco.Core; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Web.PropertyEditors +{ + [PropertyEditor(Constants.PropertyEditors.DecimalAlias, "Decimal", "decimal", "decimal", IsParameterEditor = true)] + public class DecimalPropertyEditor : PropertyEditor + { + /// + /// Overridden to ensure that the value is validated + /// + /// + protected override PropertyValueEditor CreateValueEditor() + { + var editor = base.CreateValueEditor(); + editor.Validators.Add(new DecimalValidator()); + return editor; + } + + protected override PreValueEditor CreatePreValueEditor() + { + return new DecimalPreValueEditor(); + } + + /// + /// A custom pre-value editor class to deal with the legacy way that the pre-value data is stored. + /// + internal class DecimalPreValueEditor : PreValueEditor + { + public DecimalPreValueEditor() + { + //create the fields + Fields.Add(new PreValueField(new DecimalValidator()) + { + Description = "Enter the minimum amount of number to be entered", + Key = "min", + View = "decimal", + Name = "Minimum" + }); + Fields.Add(new PreValueField(new DecimalValidator()) + { + Description = "Enter the intervals amount between each step of number to be entered", + Key = "step", + View = "decimal", + Name = "Step Size" + }); + Fields.Add(new PreValueField(new DecimalValidator()) + { + Description = "Enter the maximum amount of number to be entered", + Key = "max", + View = "decimal", + Name = "Maximum" + }); + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index f8744e58c2..07c378714b 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -307,6 +307,7 @@ + From b48b18ec8a3b5d58c8d7d8362c45d1bd90323162 Mon Sep 17 00:00:00 2001 From: AndyButland Date: Sat, 26 Sep 2015 22:46:47 +0200 Subject: [PATCH 2/6] Added migration for 7.4.0 for additional column required for decimal property editor --- .../AddDataDecimalColumn.cs | 29 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + 2 files changed, 30 insertions(+) create mode 100644 src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs new file mode 100644 index 0000000000..f238c1ac24 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs @@ -0,0 +1,29 @@ +using System.Linq; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Persistence.SqlSyntax; + +namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenFourZero +{ + [Migration("7.4.0", 1, GlobalSettings.UmbracoMigrationName)] + public class AddDataDecimalColumn : MigrationBase + { + public AddDataDecimalColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger) + : base(sqlSyntax, logger) + { + } + + public override void Up() + { + //Don't exeucte if the column is already there + var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToArray(); + + if (columns.Any(x => x.TableName.InvariantEquals("cmsPropertyData") && x.ColumnName.InvariantEquals("dataDecimal")) == false) + Create.Column("dataDecimal").OnTable("cmsPropertyData").AsDecimal(18, 9).Nullable(); + } + + public override void Down() + { + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index ae3ca88db1..a0999741ee 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -405,6 +405,7 @@ + From 09ec87c1c799ddbbb060fab6159efc770d667269 Mon Sep 17 00:00:00 2001 From: AndyButland Date: Sun, 27 Sep 2015 07:44:57 +0200 Subject: [PATCH 3/6] Added unit tests for decimal conversion in property editor value editors --- .../PropertyEditorValueEditorTests.cs | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 9ab275e5fb..7bf8f1dd30 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -5,12 +5,29 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; +using Umbraco.Core.ObjectResolution; +using Umbraco.Core.Strings; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.PropertyEditors { [TestFixture] public class PropertyEditorValueEditorTests { + [SetUp] + public virtual void TestSetup() + { + ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(SettingsForTests.GetDefault())); + Resolution.Freeze(); + } + + [TearDown] + public virtual void TestTearDown() + { + ResolverCollection.ResetAll(); + Resolution.Reset(); + } + [TestCase("{prop1: 'val1', prop2: 'val2'}", true)] [TestCase("{1,2,3,4}", false)] [TestCase("[1,2,3,4]", true)] @@ -46,6 +63,47 @@ namespace Umbraco.Tests.PropertyEditors Assert.AreEqual(expected, result.Result); } + // The following decimal tests have not been added as [TestCase]s + // as the decimal type cannot be used as an attribute parameter + [Test] + public void Value_Editor_Can_Convert_To_Decimal_Clr_Type() + { + var valueEditor = new PropertyValueEditor + { + ValueType = "DECIMAL" + }; + + var result = valueEditor.TryConvertValueToCrlType("12.34"); + Assert.IsTrue(result.Success); + Assert.AreEqual(12.34M, result.Result); + } + + [Test] + public void Value_Editor_Can_Convert_To_Decimal_Clr_Type_With_Other_Separator() + { + var valueEditor = new PropertyValueEditor + { + ValueType = "DECIMAL" + }; + + var result = valueEditor.TryConvertValueToCrlType("12,34"); + Assert.IsTrue(result.Success); + Assert.AreEqual(12.34M, result.Result); + } + + [Test] + public void Value_Editor_Can_Convert_To_Decimal_Clr_Type_With_Empty_String() + { + var valueEditor = new PropertyValueEditor + { + ValueType = "DECIMAL" + }; + + var result = valueEditor.TryConvertValueToCrlType(string.Empty); + Assert.IsTrue(result.Success); + Assert.IsNull(result.Result); + } + [Test] public void Value_Editor_Can_Convert_To_Date_Clr_Type() { @@ -78,6 +136,35 @@ namespace Umbraco.Tests.PropertyEditors Assert.AreEqual(expected, result); } + [Test] + public void Value_Editor_Can_Serialize_Decimal_Value() + { + var value = 12.34M; + var valueEditor = new PropertyValueEditor + { + ValueType = "DECIMAL" + }; + + var prop = new Property(1, Guid.NewGuid(), new PropertyType("test", DataTypeDatabaseType.Decimal), value); + + var result = valueEditor.ConvertDbToEditor(prop, prop.PropertyType, new Mock().Object); + Assert.AreEqual("12.34", result); + } + + [Test] + public void Value_Editor_Can_Serialize_Decimal_Value_With_Empty_String() + { + var valueEditor = new PropertyValueEditor + { + ValueType = "DECIMAL" + }; + + var prop = new Property(1, Guid.NewGuid(), new PropertyType("test", DataTypeDatabaseType.Decimal), string.Empty); + + var result = valueEditor.ConvertDbToEditor(prop, prop.PropertyType, new Mock().Object); + Assert.AreEqual(string.Empty, result); + } + [Test] public void Value_Editor_Can_Serialize_Date_Value() { From 7efa0bed46f0f4bf4f12962cb4a5d09b1ecab515 Mon Sep 17 00:00:00 2001 From: AndyButland Date: Mon, 12 Oct 2015 22:05:40 +0100 Subject: [PATCH 4/6] Added pattern to integer and decimal property editor views to support numeric keyboards on mobile --- .../src/views/propertyeditors/decimal/decimal.html | 11 +++++++---- .../src/views/propertyeditors/integer/integer.html | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html index 823a7b40ad..64730bbfb2 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html @@ -1,8 +1,11 @@ 
- + Not a number {{propertyForm.requiredField.errorMsg}} diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html index 28a81b035f..ff82be99b2 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/integer/integer.html @@ -1,8 +1,11 @@ 
- + Not a number {{propertyForm.requiredField.errorMsg}} From d92af31b0a718af72496e8e241250ba66f6e0ceb Mon Sep 17 00:00:00 2001 From: Claus Date: Wed, 14 Oct 2015 09:39:25 +0200 Subject: [PATCH 5/6] Fixes: U4-7246 Integer datatype PropertyEditor is missing ValueType definition --- src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs index e93f16d7e8..7e0ac8443f 100644 --- a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs @@ -3,7 +3,7 @@ using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { - [PropertyEditor(Constants.PropertyEditors.IntegerAlias, "Numeric", "integer", IsParameterEditor = true)] + [PropertyEditor(Constants.PropertyEditors.IntegerAlias, "Numeric", "integer", IsParameterEditor = true, ValueType = "integer")] public class IntegerPropertyEditor : PropertyEditor { /// From 327a00aaf4b6f12e8221631968965dcf1db05646 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 14 Oct 2015 12:07:50 +0200 Subject: [PATCH 6/6] Fixes issue with migrations running with a Decimal column: The logic would produce incorrect syntax. Fixed the default string column for sql server, made them all consistent. Moved ctor logic for shared sql syntax providers to the base class. Created formatted Decimal column definitions so that a custom precision/scale works. Set the migration to use the default precision/scale values. Removes the pattern validators because they don't do anything... due to the fix-number directive which has it's own issues but we won't solve those now. --- .../AddDataDecimalColumn.cs | 2 +- .../MicrosoftSqlSyntaxProviderBase.cs | 13 +++++++++++++ .../SqlSyntax/MySqlSyntaxProvider.cs | 9 ++------- .../SqlSyntax/SqlCeSyntaxProvider.cs | 14 +------------- .../SqlSyntax/SqlServerSyntaxProvider.cs | 14 +------------- .../SqlSyntax/SqlSyntaxProviderBase.cs | 19 ++++++++++++++++++- .../validation/valregex.directive.js | 2 +- .../propertyeditors/decimal/decimal.html | 1 - .../propertyeditors/integer/integer.html | 1 - 9 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs index f238c1ac24..442b92d2b5 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenFourZero/AddDataDecimalColumn.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenFourZer var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToArray(); if (columns.Any(x => x.TableName.InvariantEquals("cmsPropertyData") && x.ColumnName.InvariantEquals("dataDecimal")) == false) - Create.Column("dataDecimal").OnTable("cmsPropertyData").AsDecimal(18, 9).Nullable(); + Create.Column("dataDecimal").OnTable("cmsPropertyData").AsDecimal().Nullable(); } public override void Down() diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/MicrosoftSqlSyntaxProviderBase.cs b/src/Umbraco.Core/Persistence/SqlSyntax/MicrosoftSqlSyntaxProviderBase.cs index 84c6e6e824..a6d1d690ba 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/MicrosoftSqlSyntaxProviderBase.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/MicrosoftSqlSyntaxProviderBase.cs @@ -10,6 +10,19 @@ namespace Umbraco.Core.Persistence.SqlSyntax public abstract class MicrosoftSqlSyntaxProviderBase : SqlSyntaxProviderBase where TSyntax : ISqlSyntaxProvider { + protected MicrosoftSqlSyntaxProviderBase() + { + AutoIncrementDefinition = "IDENTITY(1,1)"; + GuidColumnDefinition = "UniqueIdentifier"; + RealColumnDefinition = "FLOAT"; + BoolColumnDefinition = "BIT"; + DecimalColumnDefinition = "DECIMAL(38,6)"; + TimeColumnDefinition = "TIME"; //SQLSERVER 2008+ + BlobColumnDefinition = "VARBINARY(MAX)"; + + InitColumnTypeMap(); + } + public override string RenameTable { get { return "sp_rename '{0}', '{1}'"; } } public override string AddColumn { get { return "ALTER TABLE {0} ADD {1}"; } } diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs index 1b96855a3d..b151f84c08 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs @@ -18,10 +18,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax public MySqlSyntaxProvider(ILogger logger) { _logger = logger; - DefaultStringLength = 255; - StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat; - StringColumnDefinition = string.Format(StringLengthColumnDefinitionFormat, DefaultStringLength); - + AutoIncrementDefinition = "AUTO_INCREMENT"; IntColumnDefinition = "int(11)"; BoolColumnDefinition = "tinyint(1)"; @@ -29,9 +26,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax TimeColumnDefinition = "time"; DecimalColumnDefinition = "decimal(38,6)"; GuidColumnDefinition = "char(36)"; - - InitColumnTypeMap(); - + DefaultValueFormat = "DEFAULT {0}"; } diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/SqlCeSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/SqlCeSyntaxProvider.cs index 4ac513a110..1c6e1bba52 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/SqlCeSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/SqlCeSyntaxProvider.cs @@ -15,19 +15,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax { public SqlCeSyntaxProvider() { - StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat; - StringColumnDefinition = string.Format(StringLengthColumnDefinitionFormat, DefaultStringLength); - - AutoIncrementDefinition = "IDENTITY(1,1)"; - StringColumnDefinition = "NVARCHAR(255)"; - GuidColumnDefinition = "UniqueIdentifier"; - RealColumnDefinition = "FLOAT"; - BoolColumnDefinition = "BIT"; - DecimalColumnDefinition = "DECIMAL(38,6)"; - TimeColumnDefinition = "TIME"; //SQLSERVER 2008+ - BlobColumnDefinition = "VARBINARY(MAX)"; - - InitColumnTypeMap(); + } public override bool SupportsClustered() diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs index 53198cdf5e..9cb0ce327d 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs @@ -13,19 +13,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax { public SqlServerSyntaxProvider() { - StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat; - StringColumnDefinition = string.Format(StringLengthColumnDefinitionFormat, DefaultStringLength); - - AutoIncrementDefinition = "IDENTITY(1,1)"; - StringColumnDefinition = "VARCHAR(8000)"; - GuidColumnDefinition = "UniqueIdentifier"; - RealColumnDefinition = "FLOAT"; - BoolColumnDefinition = "BIT"; - DecimalColumnDefinition = "DECIMAL(38,6)"; - TimeColumnDefinition = "TIME"; //SQLSERVER 2008+ - BlobColumnDefinition = "VARBINARY(MAX)"; - - InitColumnTypeMap(); + } /// diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs b/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs index 7c08e34a98..c2b81aa753 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs @@ -32,6 +32,13 @@ namespace Umbraco.Core.Persistence.SqlSyntax FormatPrimaryKey, FormatIdentity }; + + //defaults for all providers + StringLengthColumnDefinitionFormat = StringLengthUnicodeColumnDefinitionFormat; + StringColumnDefinition = string.Format(StringLengthColumnDefinitionFormat, DefaultStringLength); + DecimalColumnDefinition = string.Format(DecimalColumnDefinitionFormat, DefaultDecimalPrecision, DefaultDecimalScale); + + InitColumnTypeMap(); } public string GetWildcardPlaceholder() @@ -41,9 +48,12 @@ namespace Umbraco.Core.Persistence.SqlSyntax public string StringLengthNonUnicodeColumnDefinitionFormat = "VARCHAR({0})"; public string StringLengthUnicodeColumnDefinitionFormat = "NVARCHAR({0})"; + public string DecimalColumnDefinitionFormat = "DECIMAL({0},{1})"; public string DefaultValueFormat = "DEFAULT ({0})"; public int DefaultStringLength = 255; + public int DefaultDecimalPrecision = 20; + public int DefaultDecimalScale = 9; //Set by Constructor public string StringColumnDefinition; @@ -55,7 +65,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax public string GuidColumnDefinition = "GUID"; public string BoolColumnDefinition = "BOOL"; public string RealColumnDefinition = "DOUBLE"; - public string DecimalColumnDefinition = "DECIMAL"; + public string DecimalColumnDefinition; public string BlobColumnDefinition = "BLOB"; public string DateTimeColumnDefinition = "DATETIME"; public string TimeColumnDefinition = "DATETIME"; @@ -431,6 +441,13 @@ namespace Umbraco.Core.Persistence.SqlSyntax return string.Format(StringLengthColumnDefinitionFormat, valueOrDefault); } + if (type == typeof(decimal)) + { + var precision = column.Size != default(int) ? column.Size : DefaultDecimalPrecision; + var scale = column.Precision != default(int) ? column.Precision : DefaultDecimalScale; + return string.Format(DecimalColumnDefinitionFormat, precision, scale); + } + string definition = DbTypeMap.ColumnTypeMap.First(x => x.Key == type).Value; string dbTypeDefinition = column.Size != default(int) ? string.Format("{0}({1})", definition, column.Size) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/validation/valregex.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/validation/valregex.directive.js index 651c0a54c7..0f3372eecb 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/validation/valregex.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/validation/valregex.directive.js @@ -40,7 +40,7 @@ function valRegex() { var patternValidator = function (viewValue) { //NOTE: we don't validate on empty values, use required validator for that - if (!viewValue || regex.test(viewValue)) { + if (!viewValue || regex.test(viewValue.toString())) { // it is valid ctrl.$setValidity('valRegex', true); //assign a message to the validator diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html index 64730bbfb2..113148c3c6 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/decimal/decimal.html @@ -1,7 +1,6 @@