Skip to content
This repository was archived by the owner on Jun 18, 2018. It is now read-only.

Commit 217553d

Browse files
authored
Merge pull request #139 from umco/develop
Preparing for v0.5.0 release
2 parents c38c11a + f4f9069 commit 217553d

23 files changed

+393
-363
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A nested content property editor for Umbraco 7 that allows you to use Doc Types
1313

1414
### Installation
1515

16-
> *Note:* Nested Content has been developed against **Umbraco v7.1.4** and will support that version and above.
16+
> *Note:* Nested Content has been developed against **Umbraco v7.1.5** and will support that version and above.
1717
1818
Nested Content can be installed from either Our Umbraco or NuGet package repositories, or build manually from the source-code:
1919

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# version format
2-
version: 0.4.0.{build}
2+
version: 0.5.0.{build}
33

44
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
55
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta

build/package.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PropertyGroup>
1919
<ProjectName>Our.Umbraco.NestedContent</ProjectName>
2020
<PackageName>Nested Content</PackageName>
21-
<MinUmbracoVersion>7.1.4</MinUmbracoVersion>
21+
<MinUmbracoVersion>7.1.5</MinUmbracoVersion>
2222
<Readme>Nested Content is a list editing property editor for Umbraco 7.1+</Readme>
2323
<AuthorName>Matt Brailsford, Lee Kelleher</AuthorName>
2424
<AuthorUrl>https://github.com/umco/umbraco-nested-content/graphs/contributors</AuthorUrl>
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
using Umbraco.Core;
2-
using Umbraco.Core.Events;
3-
using Umbraco.Core.Models;
4-
using Umbraco.Core.Services;
1+
using System;
2+
using Newtonsoft.Json;
3+
using Our.Umbraco.NestedContent.Helpers;
4+
using Umbraco.Core;
5+
using Umbraco.Core.Cache;
6+
using Umbraco.Core.Sync;
7+
using Umbraco.Web.Cache;
58

69
namespace Our.Umbraco.NestedContent
710
{
811
public class Bootstrap : ApplicationEventHandler
912
{
1013
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
1114
{
12-
DataTypeService.Saved += ExpireCache;
15+
CacheRefresherBase<DataTypeCacheRefresher>.CacheUpdated += DataTypeCacheRefresher_Updated;
1316
}
1417

15-
private void ExpireCache(IDataTypeService sender, SaveEventArgs<IDataTypeDefinition> e)
18+
private void DataTypeCacheRefresher_Updated(DataTypeCacheRefresher sender, CacheRefresherEventArgs e)
1619
{
17-
foreach (var dataType in e.SavedEntities)
20+
if (e.MessageType == MessageType.RefreshByJson)
1821
{
19-
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(
20-
string.Concat("Our.Umbraco.NestedContent.GetPreValuesCollectionByDataTypeId_", dataType.Id));
22+
var payload = JsonConvert.DeserializeObject<JsonPayload[]>((string)e.MessageObject);
23+
if (payload != null)
24+
{
25+
foreach (var item in payload)
26+
{
27+
NestedContentHelper.ClearCache(item.Id);
28+
}
29+
}
2130
}
2231
}
32+
33+
private class JsonPayload
34+
{
35+
public Guid UniqueId { get; set; }
36+
public int Id { get; set; }
37+
}
2338
}
2439
}

src/Our.Umbraco.NestedContent/Converters/NestedContentValueConverter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
namespace Our.Umbraco.NestedContent.Converters
1010
{
11-
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
12-
[PropertyValueType(typeof(IEnumerable<IPublishedContent>))]
13-
public class NestedContentValueConverter : PropertyValueConverterBase
11+
public class NestedContentValueConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
1412
{
1513
public override bool IsConverter(PublishedPropertyType propertyType)
1614
{
@@ -30,5 +28,15 @@ public override object ConvertDataToSource(PublishedPropertyType propertyType, o
3028

3129
return null;
3230
}
31+
32+
public virtual Type GetPropertyValueType(PublishedPropertyType propertyType)
33+
{
34+
return typeof (IEnumerable<IPublishedContent>);
35+
}
36+
37+
public virtual PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType, PropertyCacheValue cacheValue)
38+
{
39+
return PropertyCacheLevel.Content;
40+
}
3341
}
3442
}

src/Our.Umbraco.NestedContent/Converters/SingleNestedContentValueConverter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
namespace Our.Umbraco.NestedContent.Converters
99
{
10-
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
11-
[PropertyValueType(typeof(IPublishedContent))]
12-
public class SingleNestedContentValueConverter : PropertyValueConverterBase
10+
public class SingleNestedContentValueConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
1311
{
1412
public override bool IsConverter(PublishedPropertyType propertyType)
1513
{
@@ -29,5 +27,15 @@ public override object ConvertDataToSource(PublishedPropertyType propertyType, o
2927

3028
return null;
3129
}
30+
31+
public virtual Type GetPropertyValueType(PublishedPropertyType propertyType)
32+
{
33+
return typeof(IPublishedContent);
34+
}
35+
36+
public virtual PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType, PropertyCacheValue cacheValue)
37+
{
38+
return PropertyCacheLevel.Content;
39+
}
3240
}
3341
}

src/Our.Umbraco.NestedContent/Extensions/ContentTypeServiceExtensions.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using Newtonsoft.Json.Linq;
3+
4+
namespace Our.Umbraco.NestedContent.Extensions
5+
{
6+
internal static class JsonExtensions
7+
{
8+
public static void Rename(this JToken token, string newName)
9+
{
10+
var parent = token.Parent;
11+
12+
if (parent == null)
13+
throw new InvalidOperationException("The parent is missing.");
14+
15+
var newToken = new JProperty(newName, token);
16+
parent.Replace(newToken);
17+
}
18+
}
19+
}

src/Our.Umbraco.NestedContent/Extensions/PreValueCollectionExtensions.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Our.Umbraco.NestedContent/Extensions/PublishedPropertyTypeExtensions.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static bool IsSingleNestedContentProperty(this PublishedPropertyType publ
2727
}
2828

2929
var preValueCollection = NestedContentHelper.GetPreValuesCollectionByDataTypeId(publishedProperty.DataTypeId);
30-
var preValueDictionary = preValueCollection.AsPreValueDictionary();
30+
var preValueDictionary = preValueCollection.PreValuesAsDictionary.ToDictionary(x => x.Key, x => x.Value.Value);
3131

3232
int minItems, maxItems;
3333
return preValueDictionary.ContainsKey("minItems") &&
@@ -46,7 +46,7 @@ public static object ConvertPropertyToNestedContent(this PublishedPropertyType p
4646
var processedValue = new List<IPublishedContent>();
4747

4848
var preValueCollection = NestedContentHelper.GetPreValuesCollectionByDataTypeId(propertyType.DataTypeId);
49-
var preValueDictionary = preValueCollection.AsPreValueDictionary();
49+
var preValueDictionary = preValueCollection.PreValuesAsDictionary.ToDictionary(x => x.Key, x => x.Value.Value);
5050

5151
for (var i = 0; i < rawValue.Count; i++)
5252
{
@@ -90,16 +90,26 @@ public static object ConvertPropertyToNestedContent(this PublishedPropertyType p
9090
}
9191

9292
// Get the current request node we are embedded in
93-
var pcr = UmbracoContext.Current.PublishedContentRequest;
93+
var pcr = UmbracoContext.Current == null ? null : UmbracoContext.Current.PublishedContentRequest;
9494
var containerNode = pcr != null && pcr.HasPublishedContent ? pcr.PublishedContent : null;
9595

96-
processedValue.Add(new DetachedPublishedContent(
96+
// Create the model based on our implementation of IPublishedContent
97+
IPublishedContent content = new DetachedPublishedContent(
9798
nameObj == null ? null : nameObj.ToString(),
9899
publishedContentType,
99100
properties.ToArray(),
100101
containerNode,
101102
i,
102-
preview));
103+
preview);
104+
105+
if (PublishedContentModelFactoryResolver.HasCurrent && PublishedContentModelFactoryResolver.Current.HasValue)
106+
{
107+
// Let the current model factory create a typed model to wrap our model
108+
content = PublishedContentModelFactoryResolver.Current.Factory.CreateModel(content);
109+
}
110+
111+
// Add the (typed) model as a result
112+
processedValue.Add(content);
103113
}
104114

105115
if (propertyType.IsSingleNestedContentProperty())

0 commit comments

Comments
 (0)