diff --git a/README.md b/README.md index adaf65d..0bc1535 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,15 @@ When you only need the source url of the iframe in the embed code you can do the ## Changelog +### 13.0.0 + +- Support for Umbraco 12 + +### 12.1.0 + +- Fixes (#31) +- Better Delivery API support + ### 12.0.0 - Support for Umbraco 12 diff --git a/Utilities/SetupTestSite.ps1 b/Utilities/SetupTestSite.ps1 index 266133e..22f093f 100644 --- a/Utilities/SetupTestSite.ps1 +++ b/Utilities/SetupTestSite.ps1 @@ -16,11 +16,12 @@ Write-Host $CurrentDir Write-Host "Installing Umbraco templates" - dotnet new --install Umbraco.Templates + dotnet new -i Umbraco.Templates::$UmbracoVersion --force Write-Host "Creating Umbraco site" cd $Destination - dotnet new umbraco -n $ProjectName --development-database-type SQLite --version $CmsVersion --friendly-name "Test admin" --email "admin@example.com" --password "1234567890" + + dotnet new umbraco -n $ProjectName --development-database-type SQLite --version $CmsVersion --friendly-name "Admin" --email "admin@example.com" --password "1234567890" cd "$Destination\$ProjectName" @@ -34,7 +35,7 @@ $propertyGroup = Select-XML -Xml $xml -XPath '//PropertyGroup[1]' $newNode = $xml.CreateElement('RestoreAdditionalProjectSources') - $newNode.InnerText = '../Nuget' + $newNode.InnerText = '../nuget' $propertyGroup.Node.AppendChild($newNode) $xml.Save("$Destination\$ProjectName\$ProjectName.csproj") @@ -53,7 +54,7 @@ if (Test-Path -Path $TestSitePath) { Remove-Item -LiteralPath $TestSitePath -Force -Recurse } -New-Item -Path $RootDir -Name $TestSitesFolderName -ItemType "directory" +New-Item -Path $RootDir -Name "$TestSitesFolder\$TestProjectName" -ItemType "directory" Create-Test-Site $TestSitesFolder $TestProjectName $UmbracoVersion diff --git a/Utilities/Variables.ps1 b/Utilities/Variables.ps1 index cb57e61..0023582 100644 --- a/Utilities/Variables.ps1 +++ b/Utilities/Variables.ps1 @@ -1,9 +1,9 @@ $RootDir = Split-Path -Path $CurrentDir -Parent $TestSitesFolderName = "testsites" $TestSitesFolder = "$RootDir\$TestSitesFolderName" -$TestProjectName = "V12" +$TestProjectName = "V13" $PackageName = "Dawoe.OEmbedPickerPropertyEditor" $SolutionName = "Dawoe.OEmbedPickerPropertyEditor" $SourceDir = "$RootDir\src" -$UmbracoVersion = "12.0.0" -$StarterKitVersion = "11.0.0" \ No newline at end of file +$UmbracoVersion = "13.0.0" +$StarterKitVersion = "13.0.0" \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 6053989..4476e8a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ image: Visual Studio 2022 # Version format -version: 12.0.0.{build} +version: 13.0.0.{build} branches: only: @@ -44,7 +44,7 @@ deploy: - provider: NuGet server: api_key: - secure: sYcQ+cM92ahNwBrZW4//jqeMtDFxKy51Z0FThvNSIG97cbUkocK/RF4OXEVjf2Ii + secure: jGBXo3OViKTOrtG7HM8mNCdtBCuYipyMjW5DaNV08WkecP0iKJpmzwyZui/KTcYb artifact: /.*\.nupkg/ on: branch: master diff --git a/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItem.cs b/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItem.cs index 2fbf67c..c93ca25 100644 --- a/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItem.cs +++ b/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItem.cs @@ -4,45 +4,19 @@ using Microsoft.AspNetCore.Html; using Newtonsoft.Json; +using Umbraco.Cms.Core.Strings; namespace Dawoe.OEmbedPickerPropertyEditor.Core.Models { /// /// Represents a item picked in the editor. /// - public class OEmbedItem + public class OEmbedItem : OEmbedItemBase { - /// - /// Gets or sets the url. - /// - [JsonProperty(PropertyName = "url")] - public string Url { get; set; } - - /// - /// Gets or sets the width. - /// - [JsonProperty(PropertyName = "width")] - public int Width { get; set; } - - /// - /// Gets or sets the height. - /// - [JsonProperty(PropertyName = "height")] - public int Height { get; set; } - /// /// Gets the embed code. /// [JsonIgnore] public IHtmlContent EmbedCode => new HtmlString(this.Preview); - - /// - /// Gets or sets the preview. - /// - [JsonProperty(PropertyName = "preview")] - internal string Preview { get; set; } - - /// - public override string ToString() => this.Preview; } } diff --git a/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemApi.cs b/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemApi.cs new file mode 100644 index 0000000..ec06d2d --- /dev/null +++ b/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemApi.cs @@ -0,0 +1,14 @@ +// +// Copyright (c) Dave Woestenborghs and contributors. Licensed under the MIT License. See LICENSE in the project root for license information. +// + +using Newtonsoft.Json; + +namespace Dawoe.OEmbedPickerPropertyEditor.Core.Models +{ + internal class OEmbedItemApi : OEmbedItemBase + { + [JsonProperty(PropertyName = "embedCode")] + public string EmbedCode => this.Preview; + } +} diff --git a/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemBase.cs b/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemBase.cs new file mode 100644 index 0000000..b8886fc --- /dev/null +++ b/src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemBase.cs @@ -0,0 +1,41 @@ +// +// Copyright (c) Dave Woestenborghs and contributors. Licensed under the MIT License. See LICENSE in the project root for license information. +// + +using Newtonsoft.Json; + +namespace Dawoe.OEmbedPickerPropertyEditor.Core.Models +{ + /// + /// Base class for OEmbed items. + /// + public abstract class OEmbedItemBase + { + /// + /// Gets or sets the url. + /// + [JsonProperty(PropertyName = "url")] + public string Url { get; set; } + + /// + /// Gets or sets the width. + /// + [JsonProperty(PropertyName = "width")] + public int Width { get; set; } + + /// + /// Gets or sets the height. + /// + [JsonProperty(PropertyName = "height")] + public int Height { get; set; } + + /// + /// Gets or sets the preview. + /// + [JsonProperty(PropertyName = "preview")] + internal string Preview { get; set; } + + /// + public override string ToString() => this.Preview; + } +} diff --git a/src/Dawoe.OEmbedPickerPropertyEditor.Core/ValueConverters/OEmbedPickerValueConverter.cs b/src/Dawoe.OEmbedPickerPropertyEditor.Core/ValueConverters/OEmbedPickerValueConverter.cs index 4855248..48dc2ce 100644 --- a/src/Dawoe.OEmbedPickerPropertyEditor.Core/ValueConverters/OEmbedPickerValueConverter.cs +++ b/src/Dawoe.OEmbedPickerPropertyEditor.Core/ValueConverters/OEmbedPickerValueConverter.cs @@ -11,6 +11,7 @@ using Newtonsoft.Json; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.PropertyEditors.DeliveryApi; using Umbraco.Extensions; namespace Dawoe.OEmbedPickerPropertyEditor.Core.ValueConverters @@ -18,7 +19,7 @@ namespace Dawoe.OEmbedPickerPropertyEditor.Core.ValueConverters /// /// Represents a the property value converter for the OEmbed picker. /// - public class OEmbedPickerValueConverter : PropertyValueConverterBase + public class OEmbedPickerValueConverter : PropertyValueConverterBase, IDeliveryApiPropertyValueConverter { /// public override bool IsConverter(IPublishedPropertyType propertyType) => @@ -26,13 +27,16 @@ public override bool IsConverter(IPublishedPropertyType propertyType) => /// public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => - propertyType.DataType.ConfigurationAs().AllowMultiple + this.IsMultipleDataType(propertyType.DataType) ? typeof(IEnumerable) : typeof(OEmbedItem); /// public override bool? IsValue(object value, PropertyValueLevel level) => value?.ToString() != "[]"; + /// + public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Element; + /// public override object ConvertSourceToIntermediate( IPublishedElement owner, @@ -47,7 +51,42 @@ public override object ConvertIntermediateToObject( IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, - bool preview) + bool preview) => + this.ConvertDataToIntermediate(propertyType, inter); + + /// + public PropertyCacheLevel GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType propertyType) => + PropertyCacheLevel.Element; + + /// + public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType) => + this.IsMultipleDataType(propertyType.DataType) + ? typeof(IEnumerable) + : typeof(OEmbedItemApi); + + /// + public object ConvertIntermediateToDeliveryApiObject( + IPublishedElement owner, + IPublishedPropertyType propertyType, + PropertyCacheLevel referenceCacheLevel, + object inter, + bool preview, + bool expanding) => + this.ConvertDataToIntermediate(propertyType, inter); + + private bool IsMultipleDataType(PublishedDataType dataType) + { + var config = ConfigurationEditor.ConfigurationAs(dataType.Configuration); + + return config is not null && config.AllowMultiple; + } + + private object FirstOrDefault(IList items) => items.Count == 0 ? null : items[0]; + + private object ConvertDataToIntermediate( + IPublishedPropertyType propertyType, + object inter) + where T : OEmbedItemBase { var isMultiple = this.IsMultipleDataType(propertyType.DataType); @@ -55,14 +94,14 @@ public override object ConvertIntermediateToObject( if (string.IsNullOrWhiteSpace(sourceString)) { - return isMultiple ? Enumerable.Empty() : null; + return isMultiple ? Enumerable.Empty() : null; } if (sourceString.DetectIsJson()) { try { - var items = JsonConvert.DeserializeObject>(sourceString); + var items = JsonConvert.DeserializeObject>(sourceString); return isMultiple ? items : this.FirstOrDefault(items); } @@ -71,15 +110,7 @@ public override object ConvertIntermediateToObject( } } - return isMultiple ? Enumerable.Empty() : null; + return isMultiple ? Enumerable.Empty() : null; } - - private bool IsMultipleDataType(PublishedDataType dataType) - { - var config = ConfigurationEditor.ConfigurationAs(dataType.Configuration); - return config.AllowMultiple; - } - - private object FirstOrDefault(IList items) => items.Count == 0 ? null : items[0]; } } diff --git a/src/Dawoe.OEmbedPickerPropertyEditor.UI/PackageManifestFilter.cs b/src/Dawoe.OEmbedPickerPropertyEditor.UI/PackageManifestFilter.cs index 625c1e3..b1610e6 100644 --- a/src/Dawoe.OEmbedPickerPropertyEditor.UI/PackageManifestFilter.cs +++ b/src/Dawoe.OEmbedPickerPropertyEditor.UI/PackageManifestFilter.cs @@ -3,6 +3,7 @@ // using System.Collections.Generic; +using System.Reflection; using Umbraco.Cms.Core.Manifest; namespace Dawoe.OEmbedPickerPropertyEditor.UI @@ -17,6 +18,7 @@ public void Filter(List manifests) => manifests.Add(new() { PackageName = "Dawoe.OEmbedPickerPropertyEditor", + Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(), Scripts = new[] { "/App_Plugins/Dawoe.OEmbedPickerPropertyEditor/scripts/editor.controller.js", diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 14ec263..797f4e7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,12 +1,12 @@ - net7 + net8 - - + + @@ -27,9 +27,9 @@ git Copyright © Dave Woestenborghs and contributors. MIT - 12.0.0 - 12.0.0 - 12.0.0 + 13.0.0 + 13.0.0 + 13.0.0 diff --git a/umbraco-marketplace.json b/umbraco-marketplace.json index 90dfbcb..7ac1f9e 100644 --- a/umbraco-marketplace.json +++ b/umbraco-marketplace.json @@ -20,6 +20,10 @@ { "Name": "Jan van Helvoort", "Url": "https://github.com/janvanhelvoort" + }, + { + "Name": "Asbjørn Riis-Knudsen", + "Url": "https://github.com/arknu" } ] },