-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
811 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
uSync.Core/DataTypes/DataTypeSerializers/ColourPickerMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Strings; | ||
|
||
using uSync.Core.Extensions; | ||
|
||
using static Umbraco.Cms.Core.PropertyEditors.ColorPickerConfiguration; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
||
internal class ColourPickerMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(ColourPickerMigratingConfigSerializer); | ||
public string[] Editors => [Constants.PropertyEditors.Aliases.ColorPicker]; | ||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
{ | ||
if (configuration.TryGetValue("items", out var items) is false || items is null) | ||
return configuration; | ||
|
||
if (items is JsonElement element == false) return configuration; | ||
if (element.ValueKind != JsonValueKind.Array) return configuration; | ||
|
||
var convertedItems = new List<ColorPickerItem>(); | ||
|
||
var array = element.EnumerateArray().Select(x => x); | ||
|
||
foreach(var item in element.EnumerateArray()) | ||
{ | ||
if (item.ValueKind != JsonValueKind.Object) continue; | ||
var obj = JsonSerializer.Deserialize<JsonObject>(item.ToString()); | ||
if (obj == null) continue; | ||
|
||
var valueJson = obj.GetPropertyAsString("value"); | ||
if (string.IsNullOrEmpty(valueJson)) continue; | ||
|
||
if (valueJson.TryDeserialize<JsonObject>(out var itemValues) is false || itemValues is null) | ||
return configuration; | ||
|
||
convertedItems.Add(new ColorPickerItem | ||
{ | ||
Label = itemValues.GetPropertyAsString("label"), | ||
Value = itemValues.GetPropertyAsString("value") | ||
}); | ||
} | ||
|
||
configuration.Remove("items"); | ||
configuration.Add("items", convertedItems); | ||
|
||
return configuration; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
uSync.Core/DataTypes/DataTypeSerializers/DataListMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Text.Json; | ||
|
||
using Umbraco.Cms.Core; | ||
|
||
using uSync.Core.Extensions; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
||
internal class DataListMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(DataListMigratingConfigSerializer); | ||
public string[] Editors => [ | ||
Constants.PropertyEditors.Aliases.CheckBoxList, | ||
Constants.PropertyEditors.Aliases.DropDownListFlexible, | ||
Constants.PropertyEditors.Aliases.RadioButtonList | ||
]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
{ | ||
if (configuration.TryGetValue("items", out var items) is false || items is null) | ||
return configuration; | ||
|
||
if (items is JsonElement element == false) return configuration; | ||
if (element.ValueKind != JsonValueKind.Array) return configuration; | ||
|
||
if (element.ToString().TryDeserialize<List<IdValuePair>>(out var values) is false || values is null) | ||
return configuration; | ||
|
||
var convertedItems = new List<string>(); | ||
|
||
foreach(var item in values.OrderBy(x => x.Id)) | ||
{ | ||
if (item?.Value is null) continue; | ||
convertedItems.Add(item.Value); | ||
} | ||
|
||
configuration["items"] = convertedItems; | ||
|
||
return configuration; | ||
} | ||
private class IdValuePair | ||
{ | ||
public int? Id { get; set; } | ||
public string? Value { get; set; } | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
uSync.Core/DataTypes/DataTypeSerializers/FileUploadMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
using Umbraco.Cms.Core; | ||
|
||
using uSync.Core.Extensions; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
internal class FileUploadMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(FileUploadMigratingConfigSerializer); | ||
|
||
public string[] Editors => [Constants.PropertyEditors.Aliases.UploadField]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
{ | ||
if (configuration.TryGetValue("fileExtensions", out var items) is false || items is null) | ||
return configuration; | ||
|
||
if (items is JsonElement element == false) return configuration; | ||
if (element.ValueKind != JsonValueKind.Array) return configuration; | ||
|
||
if (element.ToString().TryDeserialize<List<IdValuePair>>(out var values) is false || values is null) | ||
return configuration; | ||
|
||
var convertedItems = new List<string>(); | ||
|
||
foreach(var item in values.OrderBy(x => x.Id)) | ||
{ | ||
if (item.Value is null) continue; | ||
convertedItems.Add(item.Value); | ||
} | ||
|
||
configuration["fileExtensions"] = convertedItems; | ||
return configuration; | ||
} | ||
|
||
private class IdValuePair | ||
{ | ||
public int? Id { get; set; } | ||
public string? Value { get; set; } | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
uSync.Core/DataTypes/DataTypeSerializers/LabelMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Umbraco.Cms.Core; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
||
internal class LabelMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(LabelMigratingConfigSerializer); | ||
public string[] Editors => [Constants.PropertyEditors.Aliases.Label]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
=> MigratePropertyNames(configuration, new() | ||
{ | ||
{ "ValueType", "umbracoDataValueType" } | ||
}); | ||
} |
15 changes: 15 additions & 0 deletions
15
uSync.Core/DataTypes/DataTypeSerializers/MarkdownMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Umbraco.Cms.Core; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
internal class MarkdownMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(MarkdownMigratingConfigSerializer); | ||
|
||
public string[] Editors => [ Constants.PropertyEditors.Aliases.MarkdownEditor ]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
=> MigratePropertyNames(configuration, new() | ||
{ | ||
{ "displayLivePreview", "preview" } | ||
}); | ||
} |
17 changes: 17 additions & 0 deletions
17
uSync.Core/DataTypes/DataTypeSerializers/MultipleTextMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Umbraco.Cms.Core; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
||
internal class MultipleTextMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(MultipleTextMigratingConfigSerializer); | ||
|
||
public string[] Editors => [Constants.PropertyEditors.Aliases.MultipleTextstring]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
=> MigratePropertyNames(configuration, new() | ||
{ | ||
{ "maximum", "max" }, | ||
{ "minimum", "min" } | ||
}); | ||
} |
21 changes: 21 additions & 0 deletions
21
uSync.Core/DataTypes/DataTypeSerializers/SliderMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using NPoco.Linq; | ||
|
||
using Umbraco.Cms.Core; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
||
internal class SliderMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(SliderMigratingConfigSerializer); | ||
public string[] Editors => [Constants.PropertyEditors.Aliases.Slider]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
=> MigratePropertyNames(configuration, new() | ||
{ | ||
{ "initialValue", "initVal1" }, | ||
{ "initialValue2", "initVal2" }, | ||
{ "maximumValue", "maxVal" }, | ||
{ "minimumValue", "minVal" }, | ||
{ "stepIncrements", "step" } | ||
}); | ||
} |
41 changes: 41 additions & 0 deletions
41
uSync.Core/DataTypes/DataTypeSerializers/TagMigratingConfigSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Text.Json; | ||
|
||
using Umbraco.Cms.Core; | ||
|
||
using uSync.Core.Extensions; | ||
|
||
namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
||
internal class TagMigratingConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
{ | ||
public string Name => nameof(TagMigratingConfigSerializer); | ||
|
||
public string[] Editors => [Constants.PropertyEditors.Aliases.Tags]; | ||
|
||
public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
{ | ||
if (configuration.TryGetValue("StorageType", out var storageType) is false | ||
|| storageType == null) | ||
{ | ||
return configuration; | ||
} | ||
|
||
if (configuration.ContainsKey("delimiter")) | ||
configuration.Remove("delimiter"); | ||
|
||
if (storageType is JsonElement element == false) return configuration; | ||
if (element.ValueKind != JsonValueKind.Number) return configuration; | ||
var storageNumber = element.GetValueAs<int>(); | ||
|
||
var typeString = storageNumber == 0 ? "csv" : "Json"; | ||
// if storage type is a number. | ||
configuration.Remove("StorageType"); | ||
|
||
configuration.Add("storageType", new string[] { typeString }); | ||
|
||
return configuration; | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.