Skip to content

Commit

Permalink
Merge pull request #57 from leekelleher/dev/v1.1.1
Browse files Browse the repository at this point in the history
Preparing v1.1.1 release
  • Loading branch information
leekelleher authored Dec 11, 2020
2 parents 5b50a5c + eb7afab commit 5cb8091
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 71 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,11 @@ public DataListValueConverter(ConfigurationEditorUtility utility)

public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
var defaultValueType = typeof(string);
TryGetPropertyTypeConfiguration(propertyType, out var hasMultipleValues, out var valueType, out _);

if (propertyType.DataType.Configuration is Dictionary<string, object> configuration &&
configuration.TryGetValue(DataListConfigurationEditor.DataSource, out var tmp1) &&
tmp1 is JArray array1 && array1.Count > 0 && array1[0] is JObject obj1 &&
configuration.TryGetValue(DataListConfigurationEditor.ListEditor, out var tmp2) &&
tmp2 is JArray array2 && array2.Count > 0 && array2[0] is JObject obj2)
{
var valueType = default(Type);
var hasMultipleValues = false;

// NOTE: Patches a breaking-change. I'd renamed `type` to become `key`. [LK:2020-04-03]
if (obj1.ContainsKey("key") == false && obj1.ContainsKey("type"))
{
obj1.Add("key", obj1["type"]);
obj1.Remove("type");
}

var source = _utility.GetConfigurationEditor<IDataListSourceValueConverter>(obj1.Value<string>("key"));
if (source != null)
{
var config = obj1["value"].ToObject<Dictionary<string, object>>();
valueType = source.GetValueType(config);
}

// NOTE: Patches a breaking-change. I'd renamed `type` to become `key`. [LK:2020-04-03]
if (obj2.ContainsKey("key") == false && obj2.ContainsKey("type"))
{
obj2.Add("key", obj2["type"]);
obj2.Remove("type");
}

var editor = _utility.GetConfigurationEditor<IDataListEditor>(obj2.Value<string>("key"));
if (editor != null)
{
var config = obj2["value"].ToObject<Dictionary<string, object>>();
hasMultipleValues = editor.HasMultipleValues(config);
}

return hasMultipleValues == true
? typeof(IEnumerable<>).MakeGenericType(valueType ?? defaultValueType)
: valueType ?? defaultValueType;
}

return defaultValueType;
return hasMultipleValues == true
? typeof(IEnumerable<>).MakeGenericType(valueType)
: valueType;
}

public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
Expand All @@ -91,28 +51,7 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub

public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
var converter = default(Func<Type, string, object>);
var valueType = typeof(string);

if (propertyType.DataType.Configuration is Dictionary<string, object> configuration &&
configuration.TryGetValue(DataListConfigurationEditor.DataSource, out var tmp1) &&
tmp1 is JArray array1 && array1.Count > 0 && array1[0] is JObject item1)
{
// NOTE: Patches a breaking-change. I'd renamed `type` to become `key`. [LK:2020-04-03]
if (item1.ContainsKey("key") == false && item1.ContainsKey("type"))
{
item1.Add("key", item1["type"]);
item1.Remove("type");
}

var source = _utility.GetConfigurationEditor<IDataListSourceValueConverter>(item1.Value<string>("key"));
if (source != null)
{
var config = item1["value"].ToObject<Dictionary<string, object>>();
valueType = source.GetValueType(config);
converter = source.ConvertValue;
}
}
TryGetPropertyTypeConfiguration(propertyType, out var hasMultipleValues, out var valueType, out var converter);

if (inter is string value)
{
Expand All @@ -123,7 +62,7 @@ public override object ConvertIntermediateToObject(IPublishedElement owner, IPub

if (inter is IEnumerable<string> items)
{
if (propertyType.ClrType.IsGenericType)
if (hasMultipleValues == true)
{
var objects = new List<object>();

Expand Down Expand Up @@ -161,11 +100,65 @@ public override object ConvertIntermediateToObject(IPublishedElement owner, IPub

return result;
}
else
{
// NOTE: When the `inter` is enumerable, but `hasMultipleValues` is false, take the first item value.
foreach (var item in items)
{
return converter != null
? converter(valueType, item)
: item;
}
}

// NOTE: This is the last resort. Comma-separated string.
return string.Join(",", items);
}

return base.ConvertIntermediateToObject(owner, propertyType, referenceCacheLevel, inter, preview);
}

private void TryGetPropertyTypeConfiguration(IPublishedPropertyType propertyType, out bool hasMultipleValues, out Type valueType, out Func<Type, string, object> converter)
{
hasMultipleValues = false;
valueType = typeof(string);
converter = default;

if (propertyType.DataType.Configuration is Dictionary<string, object> configuration &&
configuration.TryGetValue(DataListConfigurationEditor.DataSource, out var tmp1) &&
tmp1 is JArray array1 && array1.Count > 0 && array1[0] is JObject obj1 &&
configuration.TryGetValue(DataListConfigurationEditor.ListEditor, out var tmp2) &&
tmp2 is JArray array2 && array2.Count > 0 && array2[0] is JObject obj2)
{
// NOTE: Patches a breaking-change. I'd renamed `type` to become `key`. [LK:2020-04-03]
if (obj1.ContainsKey("key") == false && obj1.ContainsKey("type"))
{
obj1.Add("key", obj1["type"]);
obj1.Remove("type");
}

var source = _utility.GetConfigurationEditor<IDataListSourceValueConverter>(obj1.Value<string>("key"));
if (source != null)
{
var config = obj1["value"].ToObject<Dictionary<string, object>>();
valueType = source.GetValueType(config);
converter = source.ConvertValue;
}

// NOTE: Patches a breaking-change. I'd renamed `type` to become `key`. [LK:2020-04-03]
if (obj2.ContainsKey("key") == false && obj2.ContainsKey("type"))
{
obj2.Add("key", obj2["type"]);
obj2.Remove("type");
}

var editor = _utility.GetConfigurationEditor<IDataListEditor>(obj2.Value<string>("key"));
if (editor != null)
{
var config = obj2["value"].ToObject<Dictionary<string, object>>();
hasMultipleValues = editor.HasMultipleValues(config);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;

Expand Down Expand Up @@ -90,7 +91,7 @@ public sealed class ItemPickerDataListEditor : IDataListEditor

public bool HasMultipleValues(Dictionary<string, object> config)
{
return (config.TryGetValue(MaxItemsConfigurationField.MaxItems, out var tmp) && tmp.ToString() == "1") == false;
return config.TryGetValueAs(MaxItemsConfigurationField.MaxItems, out int maxItems) == true && maxItems != 1;
}

public OverlaySize OverlaySize => OverlaySize.Small;
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Community.Contentment/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;

[assembly: AssemblyVersion("1.1")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0-develop")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: AssemblyInformationalVersion("1.1.1-develop")]

0 comments on commit 5cb8091

Please sign in to comment.