Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgraded to latest version of Umbraco + fixed issue with null check o… #2

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions source/nuPickers/Shared/CustomLabel/CustomLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Linq;
using System.Web;
using nuPickers.Shared.Editor;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.Composing;

namespace nuPickers.Shared.CustomLabel
Expand All @@ -23,14 +25,20 @@ internal class CustomLabel

private string PropertyAlias { get; set; }



private readonly IUmbracoComponentRenderer _componentRenderer;

/// <summary>
///
/// </summary>
/// <param name="macroAlias">alias of Macro to execute</param>
/// <param name="contextId">node, media or member id</param>
/// <param name="propertyAlias">property alias</param>
internal CustomLabel(string macroAlias, int contextId, string propertyAlias)
internal CustomLabel(string macroAlias, int contextId, string propertyAlias, IUmbracoComponentRenderer componentRenderer)
{
_componentRenderer = componentRenderer;

MacroAlias = macroAlias;
ContextId = contextId;
PropertyAlias = propertyAlias;
Expand All @@ -52,6 +60,7 @@ internal CustomLabel(string macroAlias, int contextId, string propertyAlias)
if (contextNode != null)
{
HttpContext.Current.Items["pageID"] = contextNode.Id;
ContextId = contextNode.Id;
HasMacroContext = true;
}
}
Expand Down Expand Up @@ -118,7 +127,7 @@ private string ProcessMacro(string key, string label, string keys, int counter,
/// <param name="properties"></param>
private string RenderToString(Macro macro, Dictionary<string, object> properties)
{
return Current.UmbracoHelper.RenderMacro(macro.Alias, properties).ToHtmlString();
return _componentRenderer.RenderMacro(ContextId, macro.Alias, properties).ToHtmlString();
}
}
}
17 changes: 14 additions & 3 deletions source/nuPickers/Shared/Editor/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ namespace nuPickers.Shared.Editor
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web;

internal static class Editor
{

public static IFactory Factory
=> Umbraco.Core.Composing.Current.Factory;

public static IUmbracoComponentRenderer UmbracoComponentRenderer
=> Factory.GetInstance<IUmbracoComponentRenderer>();



/// <summary>
/// Get a collection of all the (key/label) items for a picker (with optional typeahead)
/// </summary>
Expand All @@ -39,7 +50,7 @@ internal static IEnumerable<EditorDataItem> GetEditorDataItems(

if (!string.IsNullOrWhiteSpace(customLabelMacro))
{
editorDataItems = new CustomLabel(customLabelMacro, currentId, propertyAlias).ProcessEditorDataItems(editorDataItems);
editorDataItems = new CustomLabel(customLabelMacro, currentId, propertyAlias, UmbracoComponentRenderer).ProcessEditorDataItems(editorDataItems);
}

// if the datasource didn't handle the typeahead text, then it needs to be done here (post custom label processing ?)
Expand Down Expand Up @@ -78,7 +89,7 @@ internal static IEnumerable<EditorDataItem> GetEditorDataItems(

if (!string.IsNullOrWhiteSpace(customLabelMacro))
{
editorDataItems = new CustomLabel(customLabelMacro, currentId, propertyAlias).ProcessEditorDataItems(editorDataItems);
editorDataItems = new CustomLabel(customLabelMacro, currentId, propertyAlias, UmbracoComponentRenderer).ProcessEditorDataItems(editorDataItems);
}

// ensure sort order matches order of keys supplied
Expand Down Expand Up @@ -122,7 +133,7 @@ internal static IEnumerable<EditorDataItem> GetEditorDataItems(

if (!string.IsNullOrWhiteSpace(customLabelMacro))
{
editorDataItems = new CustomLabel(customLabelMacro, currentId, propertyAlias).ProcessEditorDataItems(editorDataItems);
editorDataItems = new CustomLabel(customLabelMacro, currentId, propertyAlias, UmbracoComponentRenderer).ProcessEditorDataItems(editorDataItems);
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/nuPickers/Shared/RelationMapping/RelationMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ internal static void UpdateRelationMapping(int contextId, string propertyAlias,
}

// check current context is of the correct object type (as according to the relation type)
if (Current.Services.EntityService.GetObjectType(contextId) == ObjectTypes.GetUmbracoObjectType(relationType.ChildObjectType))
if (Current.Services.EntityService.GetObjectType(contextId) == ObjectTypes.GetUmbracoObjectType(relationType.ChildObjectType.Value))
{
// for each picked item
foreach (int pickedId in pickedIds)
{
// check picked item context if of the correct object type (as according to the relation type)
if (Current.Services.EntityService.GetObjectType(pickedId) == ObjectTypes.GetUmbracoObjectType(relationType.ParentObjectType))
if (Current.Services.EntityService.GetObjectType(pickedId) == ObjectTypes.GetUmbracoObjectType(relationType.ParentObjectType.Value))
{
// if relation doesn't already exist (new picked item)
if (!relations.Exists(x => x.ParentId == pickedId))
Expand Down
38 changes: 17 additions & 21 deletions source/nuPickers/nuPickers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@
<Reference Include="AutoMapper.Net4">
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll</HintPath>
</Reference>
<Reference Include="ClientDependency.Core, Version=1.9.7.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\ClientDependency.1.9.7\lib\net45\ClientDependency.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="ClientDependency.Core, Version=1.9.9.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ClientDependency.1.9.9\lib\net45\ClientDependency.Core.dll</HintPath>
</Reference>
<Reference Include="ClientDependency.Core.Mvc, Version=1.8.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\ClientDependency-Mvc5.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll</HintPath>
<Private>True</Private>
<Reference Include="ClientDependency.Core.Mvc, Version=1.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ClientDependency-Mvc5.1.9.3\lib\net45\ClientDependency.Core.Mvc.dll</HintPath>
</Reference>
<Reference Include="CookComputing.XmlRpcV2">
<HintPath>..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll</HintPath>
Expand All @@ -53,9 +51,8 @@
<HintPath>..\packages\CSharpTest.Net.Collections.14.906.1403.1082\lib\net40\CSharpTest.Net.Collections.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Examine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Examine.1.0.0\lib\net452\Examine.dll</HintPath>
<Private>True</Private>
<Reference Include="Examine, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Examine.1.0.2\lib\net452\Examine.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.8.14.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a">
<HintPath>..\packages\HtmlAgilityPack.1.8.14\lib\Net45\HtmlAgilityPack.dll</HintPath>
Expand Down Expand Up @@ -290,21 +287,20 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Umbraco.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UmbracoCms.Core.8.1.1\lib\net472\Umbraco.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="Umbraco.Core, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.8.6.1\lib\net472\Umbraco.Core.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Examine, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UmbracoCms.Web.8.1.1\lib\net472\Umbraco.Examine.dll</HintPath>
<Private>True</Private>
<Reference Include="Umbraco.Examine, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Web.8.6.1\lib\net472\Umbraco.Examine.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UmbracoCms.Web.8.1.1\lib\net472\Umbraco.Web.dll</HintPath>
<Private>True</Private>
<Reference Include="Umbraco.ModelsBuilder.Embedded, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Web.8.6.1\lib\net472\Umbraco.ModelsBuilder.Embedded.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Web.UI, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UmbracoCms.Web.8.1.1\lib\net472\Umbraco.Web.UI.dll</HintPath>
<Private>True</Private>
<Reference Include="Umbraco.Web, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Web.8.6.1\lib\net472\Umbraco.Web.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Web.UI, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Web.8.6.1\lib\net472\Umbraco.Web.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions source/nuPickers/packages.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.0.0" targetFramework="net45" />
<package id="ClientDependency" version="1.9.7" targetFramework="net472" />
<package id="ClientDependency" version="1.9.9" targetFramework="net472" />
<package id="ClientDependency-Mvc" version="1.8.0.0" targetFramework="net45" />
<package id="ClientDependency-Mvc5" version="1.8.0.0" targetFramework="net472" />
<package id="ClientDependency-Mvc5" version="1.9.3" targetFramework="net472" />
<package id="CSharpTest.Net.Collections" version="14.906.1403.1082" targetFramework="net472" />
<package id="Examine" version="1.0.0" targetFramework="net472" />
<package id="Examine" version="1.0.2" targetFramework="net472" />
<package id="HtmlAgilityPack" version="1.8.14" targetFramework="net472" />
<package id="ImageProcessor" version="2.7.0.100" targetFramework="net472" />
<package id="ImageProcessor.Web" version="3.3.1.0" targetFramework="net45" />
Expand Down Expand Up @@ -57,7 +57,7 @@
<package id="System.Threading.Tasks.Dataflow" version="4.9.0" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
<package id="Umbraco.SqlServerCE" version="4.0.0.1" targetFramework="net472" />
<package id="UmbracoCms.Core" version="8.1.1" targetFramework="net472" />
<package id="UmbracoCms.Web" version="8.1.1" targetFramework="net472" />
<package id="UmbracoCms.Core" version="8.6.1" targetFramework="net472" />
<package id="UmbracoCms.Web" version="8.6.1" targetFramework="net472" />
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
</packages>