From c3c863174ae0e005b6828aadf7c73bfea1418b7e Mon Sep 17 00:00:00 2001 From: leekelleher Date: Mon, 5 Mar 2018 10:56:29 +0000 Subject: [PATCH 1/7] Bumped version number (to v1.1.1) for any hotfixes --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5c7592f..1a88947 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ image: Visual Studio 2017 # version format -version: 1.1.0.{build} +version: 1.1.1.{build} # UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha # example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta From 9ea76bf93c8d874928f84642ac6ced9a0d7cd9e0 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 5 Apr 2018 10:00:06 +0100 Subject: [PATCH 2/7] Renamed the property-editor directive to "umb-property-editor" As this is the preferred directive name within Umbraco core: https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Web.UI.Client/src/common/directives/components/property/umbpropertyeditor.directive.js#L40 --- .../UI/App_Plugins/InnerContent/views/innercontent.dialog.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Our.Umbraco.InnerContent/Web/UI/App_Plugins/InnerContent/views/innercontent.dialog.html b/src/Our.Umbraco.InnerContent/Web/UI/App_Plugins/InnerContent/views/innercontent.dialog.html index 3e2dd49..439518f 100644 --- a/src/Our.Umbraco.InnerContent/Web/UI/App_Plugins/InnerContent/views/innercontent.dialog.html +++ b/src/Our.Umbraco.InnerContent/Web/UI/App_Plugins/InnerContent/views/innercontent.dialog.html @@ -7,7 +7,7 @@ - + From 2da83ede48f69b413884e8b5f1cd0f67d3905df1 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 5 Apr 2018 10:22:49 +0100 Subject: [PATCH 3/7] ConfigureForDisplay - removed the extra Dictionary allocation The prevalues are already a Dictionary; https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Core/Models/PreValueCollection.cs#L60 --- .../InnerContentPropertyValueEditorWrapper.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Our.Umbraco.InnerContent/PropertyEditors/InnerContentPropertyValueEditorWrapper.cs b/src/Our.Umbraco.InnerContent/PropertyEditors/InnerContentPropertyValueEditorWrapper.cs index 56bf6e4..185a92f 100644 --- a/src/Our.Umbraco.InnerContent/PropertyEditors/InnerContentPropertyValueEditorWrapper.cs +++ b/src/Our.Umbraco.InnerContent/PropertyEditors/InnerContentPropertyValueEditorWrapper.cs @@ -22,10 +22,9 @@ public override void ConfigureForDisplay(PreValueCollection preValues) { base.ConfigureForDisplay(preValues); - var asDictionary = preValues.PreValuesAsDictionary.ToDictionary(x => x.Key, x => x.Value.Value); - if (asDictionary.ContainsKey("hideLabel")) + if (preValues.PreValuesAsDictionary.ContainsKey("hideLabel")) { - var boolAttempt = asDictionary["hideLabel"].TryConvertTo(); + var boolAttempt = preValues.PreValuesAsDictionary["hideLabel"].Value.TryConvertTo(); if (boolAttempt.Success) { HideLabel = boolAttempt.Result; From f4480b7c8af54b10ce2d95fe489fb2ef8789b31b Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 5 Apr 2018 10:08:02 +0100 Subject: [PATCH 4/7] Removed unused parameters from the internal "Recursive" methods --- .../SimpleInnerContentPropertyValueEditor.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs index 20087da..1d032ab 100644 --- a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs +++ b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs @@ -29,7 +29,7 @@ public override string ConvertDbToString(Property property, PropertyType propert return string.Empty; // Process value - ConvertDbToStringRecursive(value, property, propertyType, dataTypeService); + ConvertDbToStringRecursive(value, dataTypeService); // Update the value on the property property.Value = JsonConvert.SerializeObject(value); @@ -38,13 +38,13 @@ public override string ConvertDbToString(Property property, PropertyType propert return base.ConvertDbToString(property, propertyType, dataTypeService); } - protected void ConvertDbToStringRecursive(JToken token, Property property, PropertyType propertyType, IDataTypeService dataTypeService) + protected void ConvertDbToStringRecursive(JToken token, IDataTypeService dataTypeService) { if (token is JArray jArr) { foreach (var item in jArr) { - ConvertDbToStringRecursive(item, property, propertyType, dataTypeService); + ConvertDbToStringRecursive(item, dataTypeService); } } @@ -60,7 +60,7 @@ protected void ConvertDbToStringRecursive(JToken token, Property property, Prope { if (kvp.Value is JArray || kvp.Value is JObject) { - ConvertDbToStringRecursive(kvp.Value, property, propertyType, dataTypeService); + ConvertDbToStringRecursive(kvp.Value, dataTypeService); } } } @@ -82,7 +82,7 @@ public override object ConvertDbToEditor(Property property, PropertyType propert return string.Empty; // Process value - ConvertDbToEditorRecursive(value, property, propertyType, dataTypeService); + ConvertDbToEditorRecursive(value, dataTypeService); // Update the value on the property property.Value = JsonConvert.SerializeObject(value); @@ -91,13 +91,13 @@ public override object ConvertDbToEditor(Property property, PropertyType propert return base.ConvertDbToEditor(property, propertyType, dataTypeService); } - protected void ConvertDbToEditorRecursive(JToken token, Property property, PropertyType propertyType, IDataTypeService dataTypeService) + protected void ConvertDbToEditorRecursive(JToken token, IDataTypeService dataTypeService) { if (token is JArray jArr) { foreach (var item in jArr) { - ConvertDbToEditorRecursive(item, property, propertyType, dataTypeService); + ConvertDbToEditorRecursive(item, dataTypeService); } } @@ -113,7 +113,7 @@ protected void ConvertDbToEditorRecursive(JToken token, Property property, Prope { if (kvp.Value is JArray || kvp.Value is JObject) { - ConvertDbToEditorRecursive(kvp.Value, property, propertyType, dataTypeService); + ConvertDbToEditorRecursive(kvp.Value, dataTypeService); } } } @@ -131,19 +131,19 @@ public override object ConvertEditorToDb(ContentPropertyData editorValue, object return null; // Process value - ConvertEditorToDbRecursive(value, editorValue, currentValue); + ConvertEditorToDbRecursive(value, currentValue); // Return value return JsonConvert.SerializeObject(value); } - protected void ConvertEditorToDbRecursive(JToken token, ContentPropertyData editorValue, object currentValue) + protected void ConvertEditorToDbRecursive(JToken token, object currentValue) { if (token is JArray jArr) { foreach (var item in jArr) { - ConvertEditorToDbRecursive(item, editorValue, currentValue); + ConvertEditorToDbRecursive(item, currentValue); } } @@ -159,7 +159,7 @@ protected void ConvertEditorToDbRecursive(JToken token, ContentPropertyData edit { if (kvp.Value is JArray || kvp.Value is JObject) { - ConvertEditorToDbRecursive(kvp.Value, editorValue, currentValue); + ConvertEditorToDbRecursive(kvp.Value, currentValue); } } } From c8e66216bbe74b31584ecd8d56209bd2ee281085 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 5 Apr 2018 10:14:06 +0100 Subject: [PATCH 5/7] ConvertDbToString We were updating the `property.Value` reference, which was having adverse effects on the editor value. In the majority of cases this wasn't an issue, but it did mean that any prevalue-ID-based editors (e.g. dropdown list) had problems. I've removed the call to the base method, we don't need it - here's what it does... https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs#L367 It attempts to convert the value to an XML-safe string, which is ultimately `ToString()` (if not null): https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Core/ObjectExtensions.cs#L544 --- .../SimpleInnerContentPropertyValueEditor.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs index 1d032ab..a9fc5a8 100644 --- a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs +++ b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs @@ -31,11 +31,8 @@ public override string ConvertDbToString(Property property, PropertyType propert // Process value ConvertDbToStringRecursive(value, dataTypeService); - // Update the value on the property - property.Value = JsonConvert.SerializeObject(value); - - // Pass the call down - return base.ConvertDbToString(property, propertyType, dataTypeService); + // Return the serialized value + return JsonConvert.SerializeObject(value); } protected void ConvertDbToStringRecursive(JToken token, IDataTypeService dataTypeService) From 94189d9bd8abbad1e3fa5e73bbd3cf78f74c0b08 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 5 Apr 2018 10:17:53 +0100 Subject: [PATCH 6/7] ConvertDbToEditor Same as last commit, (for ConvertDbToString), we were updating the `property.Value` reference when we shouldn't be. We should be returning the converted value, not updating the original reference value itself. I've removed the call to the base method, we don't need it - it attempts to deserialize the JSON string that we've literally just serialized... https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Core/PropertyEditors/PropertyValueEditor.cs#L283 So we can pass the `JObject` value back ourselves for Angular to handle directly. --- .../SimpleInnerContentPropertyValueEditor.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs index a9fc5a8..8340d2e 100644 --- a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs +++ b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs @@ -81,11 +81,8 @@ public override object ConvertDbToEditor(Property property, PropertyType propert // Process value ConvertDbToEditorRecursive(value, dataTypeService); - // Update the value on the property - property.Value = JsonConvert.SerializeObject(value); - - // Pass the call down - return base.ConvertDbToEditor(property, propertyType, dataTypeService); + // Return the JObject, Angular can handle it directly + return value; } protected void ConvertDbToEditorRecursive(JToken token, IDataTypeService dataTypeService) From 3e85de883d6576779926d7ddc3636c86a12642ae Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 5 Apr 2018 10:19:52 +0100 Subject: [PATCH 7/7] ConvertEditorToDb A little tidy-up of this method. We were calling `ToString()` twice, also we were returning nulls when an empty string is suffice (since we're ultimately wanting to return a `string` value). --- .../SimpleInnerContentPropertyValueEditor.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs index 8340d2e..5414779 100644 --- a/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs +++ b/src/Our.Umbraco.InnerContent/PropertyEditors/SimpleInnerContentPropertyValueEditor.cs @@ -117,12 +117,16 @@ protected void ConvertDbToEditorRecursive(JToken token, IDataTypeService dataTyp public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue) { // Convert / validate value - if (editorValue.Value == null || string.IsNullOrWhiteSpace(editorValue.Value.ToString())) - return null; + if (editorValue.Value == null) + return string.Empty; + + var dbValue = editorValue.Value.ToString(); + if (string.IsNullOrWhiteSpace(dbValue)) + return string.Empty; - var value = JsonConvert.DeserializeObject(editorValue.Value.ToString()); + var value = JsonConvert.DeserializeObject(dbValue); if (value == null || (value is JArray && ((JArray)value).Count == 0)) - return null; + return string.Empty; // Process value ConvertEditorToDbRecursive(value, currentValue);