Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dawoe committed Jan 16, 2024
2 parents 7554211 + 3630f72 commit aa56b2c
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 57 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions Utilities/SetupTestSite.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]" --password "1234567890"

dotnet new umbraco -n $ProjectName --development-database-type SQLite --version $CmsVersion --friendly-name "Admin" --email "[email protected]" --password "1234567890"

cd "$Destination\$ProjectName"

Expand All @@ -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")

Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions Utilities/Variables.ps1
Original file line number Diff line number Diff line change
@@ -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"
$UmbracoVersion = "13.0.0"
$StarterKitVersion = "13.0.0"
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: Visual Studio 2022

# Version format
version: 12.0.0.{build}
version: 13.0.0.{build}

branches:
only:
Expand Down Expand Up @@ -44,7 +44,7 @@ deploy:
- provider: NuGet
server:
api_key:
secure: sYcQ+cM92ahNwBrZW4//jqeMtDFxKy51Z0FThvNSIG97cbUkocK/RF4OXEVjf2Ii
secure: jGBXo3OViKTOrtG7HM8mNCdtBCuYipyMjW5DaNV08WkecP0iKJpmzwyZui/KTcYb
artifact: /.*\.nupkg/
on:
branch: master
Expand Down
30 changes: 2 additions & 28 deletions src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,19 @@

using Microsoft.AspNetCore.Html;
using Newtonsoft.Json;
using Umbraco.Cms.Core.Strings;

namespace Dawoe.OEmbedPickerPropertyEditor.Core.Models
{
/// <summary>
/// Represents a item picked in the editor.
/// </summary>
public class OEmbedItem
public class OEmbedItem : OEmbedItemBase
{
/// <summary>
/// Gets or sets the url.
/// </summary>
[JsonProperty(PropertyName = "url")]
public string Url { get; set; }

/// <summary>
/// Gets or sets the width.
/// </summary>
[JsonProperty(PropertyName = "width")]
public int Width { get; set; }

/// <summary>
/// Gets or sets the height.
/// </summary>
[JsonProperty(PropertyName = "height")]
public int Height { get; set; }

/// <summary>
/// Gets the embed code.
/// </summary>
[JsonIgnore]
public IHtmlContent EmbedCode => new HtmlString(this.Preview);

/// <summary>
/// Gets or sets the preview.
/// </summary>
[JsonProperty(PropertyName = "preview")]
internal string Preview { get; set; }

/// <inheritdoc />
public override string ToString() => this.Preview;
}
}
14 changes: 14 additions & 0 deletions src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// <copyright file="OEmbedItemApi.cs" company="Umbraco community">
// Copyright (c) Dave Woestenborghs and contributors. Licensed under the MIT License. See LICENSE in the project root for license information.
// </copyright>

using Newtonsoft.Json;

namespace Dawoe.OEmbedPickerPropertyEditor.Core.Models
{
internal class OEmbedItemApi : OEmbedItemBase
{
[JsonProperty(PropertyName = "embedCode")]
public string EmbedCode => this.Preview;
}
}
41 changes: 41 additions & 0 deletions src/Dawoe.OEmbedPickerPropertyEditor.Core/Models/OEmbedItemBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// <copyright file="OEmbedItemBase.cs" company="Umbraco community">
// Copyright (c) Dave Woestenborghs and contributors. Licensed under the MIT License. See LICENSE in the project root for license information.
// </copyright>

using Newtonsoft.Json;

namespace Dawoe.OEmbedPickerPropertyEditor.Core.Models
{
/// <summary>
/// Base class for OEmbed items.
/// </summary>
public abstract class OEmbedItemBase
{
/// <summary>
/// Gets or sets the url.
/// </summary>
[JsonProperty(PropertyName = "url")]
public string Url { get; set; }

/// <summary>
/// Gets or sets the width.
/// </summary>
[JsonProperty(PropertyName = "width")]
public int Width { get; set; }

/// <summary>
/// Gets or sets the height.
/// </summary>
[JsonProperty(PropertyName = "height")]
public int Height { get; set; }

/// <summary>
/// Gets or sets the preview.
/// </summary>
[JsonProperty(PropertyName = "preview")]
internal string Preview { get; set; }

/// <inheritdoc />
public override string ToString() => this.Preview;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,32 @@
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
{
/// <summary>
/// Represents a the property value converter for the OEmbed picker.
/// </summary>
public class OEmbedPickerValueConverter : PropertyValueConverterBase
public class OEmbedPickerValueConverter : PropertyValueConverterBase, IDeliveryApiPropertyValueConverter
{
/// <inheritdoc />
public override bool IsConverter(IPublishedPropertyType propertyType) =>
Constants.DataEditorAlias.Equals(propertyType.EditorAlias);

/// <inheritdoc />
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) =>
propertyType.DataType.ConfigurationAs<OEmbedPickerConfiguration>().AllowMultiple
this.IsMultipleDataType(propertyType.DataType)
? typeof(IEnumerable<OEmbedItem>)
: typeof(OEmbedItem);

/// <inheritdoc />
public override bool? IsValue(object value, PropertyValueLevel level) => value?.ToString() != "[]";

/// <inheritdoc/>
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Element;

/// <inheritdoc />
public override object ConvertSourceToIntermediate(
IPublishedElement owner,
Expand All @@ -47,22 +51,57 @@ public override object ConvertIntermediateToObject(
IPublishedPropertyType propertyType,
PropertyCacheLevel referenceCacheLevel,
object inter,
bool preview)
bool preview) =>
this.ConvertDataToIntermediate<OEmbedItem>(propertyType, inter);

/// <inheritdoc />
public PropertyCacheLevel GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType propertyType) =>
PropertyCacheLevel.Element;

/// <inheritdoc/>
public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType) =>
this.IsMultipleDataType(propertyType.DataType)
? typeof(IEnumerable<OEmbedItemApi>)
: typeof(OEmbedItemApi);

/// <inheritdoc/>
public object ConvertIntermediateToDeliveryApiObject(
IPublishedElement owner,
IPublishedPropertyType propertyType,
PropertyCacheLevel referenceCacheLevel,
object inter,
bool preview,
bool expanding) =>
this.ConvertDataToIntermediate<OEmbedItemApi>(propertyType, inter);

private bool IsMultipleDataType(PublishedDataType dataType)
{
var config = ConfigurationEditor.ConfigurationAs<OEmbedPickerConfiguration>(dataType.Configuration);

return config is not null && config.AllowMultiple;
}

private object FirstOrDefault(IList items) => items.Count == 0 ? null : items[0];

private object ConvertDataToIntermediate<T>(
IPublishedPropertyType propertyType,
object inter)
where T : OEmbedItemBase
{
var isMultiple = this.IsMultipleDataType(propertyType.DataType);

var sourceString = inter?.ToString();

if (string.IsNullOrWhiteSpace(sourceString))
{
return isMultiple ? Enumerable.Empty<OEmbedItem>() : null;
return isMultiple ? Enumerable.Empty<T>() : null;
}

if (sourceString.DetectIsJson())
{
try
{
var items = JsonConvert.DeserializeObject<List<OEmbedItem>>(sourceString);
var items = JsonConvert.DeserializeObject<List<T>>(sourceString);

return isMultiple ? items : this.FirstOrDefault(items);
}
Expand All @@ -71,15 +110,7 @@ public override object ConvertIntermediateToObject(
}
}

return isMultiple ? Enumerable.Empty<OEmbedItem>() : null;
return isMultiple ? Enumerable.Empty<T>() : null;
}

private bool IsMultipleDataType(PublishedDataType dataType)
{
var config = ConfigurationEditor.ConfigurationAs<OEmbedPickerConfiguration>(dataType.Configuration);
return config.AllowMultiple;
}

private object FirstOrDefault(IList items) => items.Count == 0 ? null : items[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// </copyright>

using System.Collections.Generic;
using System.Reflection;
using Umbraco.Cms.Core.Manifest;

namespace Dawoe.OEmbedPickerPropertyEditor.UI
Expand All @@ -17,6 +18,7 @@ public void Filter(List<PackageManifest> manifests) =>
manifests.Add(new()
{
PackageName = "Dawoe.OEmbedPickerPropertyEditor",
Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
Scripts = new[]
{
"/App_Plugins/Dawoe.OEmbedPickerPropertyEditor/scripts/editor.controller.js",
Expand Down
12 changes: 6 additions & 6 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project>

<PropertyGroup>
<TargetFrameworks>net7</TargetFrameworks>
<TargetFrameworks>net8</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Umbraco.Cms.Web.Website" Version="[12.0.0,13.0.0)" />
<PackageReference Include="Umbraco.Cms.Web.BackOffice" Version="[12.0.0,13.0.0)" />
<PackageReference Include="Umbraco.Cms.Web.Website" Version="[13.0.0,14.0.0)" />
<PackageReference Include="Umbraco.Cms.Web.BackOffice" Version="[13.0.0,14.0.0)" />
</ItemGroup>

<ItemGroup>
Expand All @@ -27,9 +27,9 @@
<RepositoryType>git</RepositoryType>
<Copyright>Copyright &amp;#169; Dave Woestenborghs and contributors.</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<AssemblyVersion>12.0.0</AssemblyVersion>
<VersionPrefix>12.0.0</VersionPrefix>
<InformationalVersion>12.0.0</InformationalVersion>
<AssemblyVersion>13.0.0</AssemblyVersion>
<VersionPrefix>13.0.0</VersionPrefix>
<InformationalVersion>13.0.0</InformationalVersion>
</PropertyGroup>


Expand Down
4 changes: 4 additions & 0 deletions umbraco-marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{
"Name": "Jan van Helvoort",
"Url": "https://github.com/janvanhelvoort"
},
{
"Name": "Asbjørn Riis-Knudsen",
"Url": "https://github.com/arknu"
}
]
},
Expand Down

0 comments on commit aa56b2c

Please sign in to comment.