Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit a3ad8b5

Browse files
authored
Merge pull request #184 from skttl/develop
Preparing 1.2.0
2 parents 5770d9a + 449ab5b commit a3ad8b5

17 files changed

+372
-54
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A grid editor for Umbraco 8 that allows you to use Doc Types as a blue print for
1212

1313
### Installation
1414

15-
> *Note:* Doc Type Grid Editor has been developed against **Umbraco v8.1.0** and will support that version and above.
15+
> *Note:* Doc Type Grid Editor has been developed against **Umbraco v8.6.0** and will support that version and above.
1616
1717
Doc Type Grid Editor can be installed from either Our Umbraco package repository, or build manually from the source-code.
1818

@@ -60,8 +60,6 @@ Please be aware that not all property-editors will work within Doc Type Grid Edi
6060
* Tags
6161
* Upload
6262

63-
Another known issue is that validation of property-editors within the overlay do not always work. For editors that use client-side (HTML5) validation, this may appear to work, (e.g. text input require attribute is added), but server-side validation does not work.
64-
6563
---
6664

6765
## Contributing to this project

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: Visual Studio 2017
22

33
# version format
4-
version: 1.1.0.{build}
4+
version: 1.2.0.{build}
55

66
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
77
# 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.DocTypeGridEditor</ProjectName>
2020
<PackageName>Doc Type Grid Editor</PackageName>
21-
<MinUmbracoVersion>8.1.0</MinUmbracoVersion>
21+
<MinUmbracoVersion>8.6.0</MinUmbracoVersion>
2222
<Readme>Doc Type Grid Editor is an advanced grid editor for Umbraco 8</Readme>
2323
<AuthorName>Matt Brailsford, Lee Kelleher, Søren Kottal</AuthorName>
2424
<AuthorUrl>https://github.com/umco/umbraco-doc-type-grid-editor/graphs/contributors</AuthorUrl>

docs/developers-guide.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,47 @@ By inheriting from the `DocTypeGridEditorSurfaceController` base class, you'll a
207207

208208
---
209209

210+
### Value Processors
211+
Since Doc Type Grid Editor stores the data for each property as a JSON-blob, we're not processing the values in the same way as Umbraco-core before storing it. This also means that the values that comes back and are passed into a Property Value Converter might be in of a type/format that that Property Value Convert can't handle.
212+
213+
We've added something that we call "ValueProcessors" and these can be used to modify the raw property value before we send it to the property value converter. One example of where this is needed is the Tags-editor.
214+
215+
If you need to perform some processing of a value before it's sent to the property value converter you can add your own ValueProcessor.
216+
217+
```csharp
218+
public class UmbracoColorPickerValueProcessor : IDocTypeGridEditorValueProcessor
219+
{
220+
public bool IsProcessorFor(string propertyEditorAlias)
221+
=> propertyEditorAlias.Equals(Constants.PropertyEditors.Aliases.ColorPicker);
222+
223+
public object ProcessValue(object value)
224+
{
225+
// Do something with the value
226+
return value;
227+
}
228+
}
229+
```
230+
231+
Then register this during composition withing IUserComposer,
232+
```csharp
233+
public class MyCustomDocTypeGridEditorComposer : IUserComposer
234+
{
235+
public void Compose(Composition composition)
236+
{
237+
composition.DocTypeGridEditorValueProcessors()
238+
.Append<UmbracoColorPickerValueProcessor>();
239+
}
240+
}
241+
```
242+
243+
Dot Type Grid editor ships with a ValueProcessor for the Umbraco-Tags property.
244+
245+
**Note:** When using a Tag-editor inside a DTGE this would not create any relationship between the current node and that tag, if you need to tag a node you should use the Tags-editor as a property directly on the document type.
246+
247+
248+
249+
250+
210251
### Useful Links
211252

212253
* [Source Code](https://github.com/skttl/umbraco-doc-type-grid-editor)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Our.Umbraco.DocTypeGridEditor.Extensions;
2+
using Our.Umbraco.DocTypeGridEditor.ValueProcessing;
3+
using Umbraco.Core;
4+
using Umbraco.Core.Composing;
5+
6+
namespace Our.Umbraco.DocTypeGridEditor.Composing
7+
{
8+
/// <summary>
9+
/// Composes defaults for Doc Type Grid Editor
10+
/// </summary>
11+
public class DocTypeGridEditorComposer : IUserComposer
12+
{
13+
public void Compose(Composition composition)
14+
{
15+
composition.DocTypeGridEditorValueProcessors().Append<UmbracoTagsValueProcessor>();
16+
composition.DataValueReferenceFactories().Append<DocTypeGridEditorDataValueReference>();
17+
}
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Our.Umbraco.DocTypeGridEditor.ValueProcessing.Collections;
2+
using Umbraco.Core.Composing;
3+
4+
namespace Our.Umbraco.DocTypeGridEditor.Extensions
5+
{
6+
public static class CompositionExtensions
7+
{
8+
/// <summary>
9+
/// Used to modify the collection of Value Processors for Doc Type Grid Editor
10+
/// </summary>
11+
/// <param name="composition"></param>
12+
/// <returns></returns>
13+
public static DocTypeGridEditorValueProcessorsCollectionBuilder DocTypeGridEditorValueProcessors(this Composition composition)
14+
=> composition.WithCollectionBuilder<DocTypeGridEditorValueProcessorsCollectionBuilder>();
15+
}
16+
}

src/Our.Umbraco.DocTypeGridEditor/Helpers/DocTypeGridEditorHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Web.Mvc;
45
using Newtonsoft.Json;
56
using Newtonsoft.Json.Linq;
67
using Our.Umbraco.DocTypeGridEditor.Extensions;
78
using Our.Umbraco.DocTypeGridEditor.Models;
9+
using Our.Umbraco.DocTypeGridEditor.ValueProcessing;
10+
using Our.Umbraco.DocTypeGridEditor.ValueProcessing.Collections;
811
using Umbraco.Core;
912
using Umbraco.Core.Cache;
1013
using Umbraco.Web.Composing;
@@ -64,6 +67,14 @@ private static IPublishedElement ConvertValue(string id, string contentTypeAlias
6467

6568
var newValue = propEditor.GetValueEditor().FromEditor(contentPropData, jProp.Value);
6669

70+
// Performing "ValueProcessing" if any ValueProcessor is configured for this Property Editor-alias.
71+
var processorsCollection = Current.Factory.GetInstance<DocTypeGridEditorValueProcessorsCollection>();
72+
var processor = processorsCollection.FirstOrDefault(x => x.IsProcessorFor(propEditor.Alias));
73+
if (processor != null)
74+
{
75+
newValue = processor.ProcessValue(newValue);
76+
}
77+
6778
/* Now that we have the DB stored value, we actually need to then convert it into its
6879
* XML serialized state as expected by the published property by calling ConvertDbToString
6980
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Our.Umbraco.DocTypeGridEditor.Models
10+
{
11+
public class DocTypeGridEditorValue
12+
{
13+
[JsonProperty("value")]
14+
public JObject Value { get; set; }
15+
[JsonProperty("dtgeContentTypeAlias")]
16+
public string ContentTypeAlias { get; set; }
17+
[JsonProperty("id")]
18+
public Guid Id { get; set; }
19+
}
20+
}

src/Our.Umbraco.DocTypeGridEditor/Our.Umbraco.DocTypeGridEditor.csproj

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38+
<Reference Include="ClientDependency.Core, Version=1.9.9.0, Culture=neutral, processorArchitecture=MSIL">
39+
<HintPath>..\packages\ClientDependency.1.9.9\lib\net45\ClientDependency.Core.dll</HintPath>
40+
</Reference>
41+
<Reference Include="ClientDependency.Core.Mvc, Version=1.9.3.0, Culture=neutral, processorArchitecture=MSIL">
42+
<HintPath>..\packages\ClientDependency-Mvc5.1.9.3\lib\net45\ClientDependency.Core.Mvc.dll</HintPath>
43+
</Reference>
3844
<Reference Include="CSharpTest.Net.Collections, Version=14.906.1403.1082, Culture=neutral, PublicKeyToken=06aee00cce822474, processorArchitecture=MSIL">
3945
<HintPath>..\packages\CSharpTest.Net.Collections.14.906.1403.1082\lib\net40\CSharpTest.Net.Collections.dll</HintPath>
4046
</Reference>
41-
<Reference Include="Examine, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
42-
<HintPath>..\packages\Examine.1.0.0\lib\net452\Examine.dll</HintPath>
47+
<Reference Include="Examine, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Examine.1.0.2\lib\net452\Examine.dll</HintPath>
4349
</Reference>
4450
<Reference Include="HtmlAgilityPack, Version=1.8.14.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
4551
<HintPath>..\packages\HtmlAgilityPack.1.8.14\lib\Net45\HtmlAgilityPack.dll</HintPath>
@@ -206,21 +212,26 @@
206212
<Reference Include="System.Xml" />
207213
<Reference Include="System.Xml.Linq" />
208214
<Reference Include="Umbraco.Core, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
209-
<HintPath>..\packages\UmbracoCms.Core.8.1.0\lib\net472\Umbraco.Core.dll</HintPath>
215+
<HintPath>..\packages\UmbracoCms.Core.8.6.0\lib\net472\Umbraco.Core.dll</HintPath>
210216
</Reference>
211217
<Reference Include="Umbraco.Examine, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
212-
<HintPath>..\packages\UmbracoCms.Web.8.1.0\lib\net472\Umbraco.Examine.dll</HintPath>
218+
<HintPath>..\packages\UmbracoCms.Web.8.6.0\lib\net472\Umbraco.Examine.dll</HintPath>
219+
</Reference>
220+
<Reference Include="Umbraco.ModelsBuilder.Embedded, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
221+
<HintPath>..\packages\UmbracoCms.Web.8.6.0\lib\net472\Umbraco.ModelsBuilder.Embedded.dll</HintPath>
213222
</Reference>
214223
<Reference Include="Umbraco.Web, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
215-
<HintPath>..\packages\UmbracoCms.Web.8.1.0\lib\net472\Umbraco.Web.dll</HintPath>
224+
<HintPath>..\packages\UmbracoCms.Web.8.6.0\lib\net472\Umbraco.Web.dll</HintPath>
216225
</Reference>
217226
<Reference Include="Umbraco.Web.UI, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
218-
<HintPath>..\packages\UmbracoCms.Web.8.1.0\lib\net472\Umbraco.Web.UI.dll</HintPath>
227+
<HintPath>..\packages\UmbracoCms.Web.8.6.0\lib\net472\Umbraco.Web.UI.dll</HintPath>
219228
</Reference>
220229
</ItemGroup>
221230
<ItemGroup>
222231
<Compile Include="Bootstrap.cs" />
223232
<Compile Include="Composing\Current.cs" />
233+
<Compile Include="Models\DocTypeGridEditorValue.cs" />
234+
<Compile Include="ValueProcessing\DocTypeGridEditorDataValueReference.cs" />
224235
<Compile Include="Extensions\JsonExtensions.cs" />
225236
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
226237
<Compile Include="Helpers\XmlHelper.cs" />
@@ -231,6 +242,12 @@
231242
<Compile Include="Models\UnpublishedProperty.cs" />
232243
<Compile Include="Properties\AssemblyInfo.cs" />
233244
<Compile Include="Properties\VersionInfo.cs" />
245+
<Compile Include="Composing\DocTypeGridEditorComposer.cs" />
246+
<Compile Include="Extensions\CompositionExtensions.cs" />
247+
<Compile Include="ValueProcessing\Collections\DocTypeGridEditorValueProcessorsCollection.cs" />
248+
<Compile Include="ValueProcessing\Collections\DocTypeGridEditorValueProcessorsCollectionBuilder.cs" />
249+
<Compile Include="ValueProcessing\IDocTypeGridEditorValueProcessor.cs" />
250+
<Compile Include="ValueProcessing\UmbracoTagsValueProcessor.cs" />
234251
<Compile Include="Web\Controllers\DocTypeGridEditorApiController.cs" />
235252
<Compile Include="Extensions\ContentTypeServiceExtensions.cs" />
236253
<Compile Include="Web\Controllers\DocTypeGridEditorSurfaceController.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using Umbraco.Core.Composing;
3+
4+
namespace Our.Umbraco.DocTypeGridEditor.ValueProcessing.Collections
5+
{
6+
/// <summary>
7+
/// Collection to hold references to Value Processors to be used with Doc Type Grid Editor. <see cref="IDocTypeGridEditorValueProcessor"/>
8+
/// </summary>
9+
public class DocTypeGridEditorValueProcessorsCollection : BuilderCollectionBase<IDocTypeGridEditorValueProcessor>
10+
{
11+
public DocTypeGridEditorValueProcessorsCollection(IEnumerable<IDocTypeGridEditorValueProcessor> items) : base(items)
12+
{ }
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Umbraco.Core.Composing;
2+
3+
namespace Our.Umbraco.DocTypeGridEditor.ValueProcessing.Collections
4+
{
5+
/// <summary>
6+
/// Collection builder for Value Processors <see cref="IDocTypeGridEditorValueProcessor"/>
7+
/// </summary>
8+
public class DocTypeGridEditorValueProcessorsCollectionBuilder : OrderedCollectionBuilderBase<DocTypeGridEditorValueProcessorsCollectionBuilder, DocTypeGridEditorValueProcessorsCollection, IDocTypeGridEditorValueProcessor>
9+
{
10+
protected override DocTypeGridEditorValueProcessorsCollectionBuilder This => this;
11+
}
12+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Newtonsoft.Json;
2+
using Our.Umbraco.DocTypeGridEditor.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using Umbraco.Core;
7+
using Umbraco.Core.Composing;
8+
using Umbraco.Core.Models;
9+
using Umbraco.Core.Models.Editors;
10+
using Umbraco.Core.PropertyEditors;
11+
12+
namespace Our.Umbraco.DocTypeGridEditor.ValueProcessing
13+
{
14+
public class DocTypeGridEditorDataValueReference : IDataValueReferenceFactory, IDataValueReference
15+
{
16+
private readonly Lazy<Dictionary<string, IContentType>> _contentTypes;
17+
18+
public IDataValueReference GetDataValueReference() => this;
19+
20+
public bool IsForEditor(IDataEditor dataEditor) => dataEditor.Alias.InvariantEquals(Constants.PropertyEditors.Aliases.Grid);
21+
22+
23+
public DocTypeGridEditorDataValueReference()
24+
{
25+
_contentTypes = new Lazy<Dictionary<string, IContentType>>(() => Current.Services.ContentTypeService.GetAll().ToDictionary(c => c.Alias));
26+
}
27+
28+
public IEnumerable<UmbracoEntityReference> GetReferences(object value)
29+
{
30+
var result = new List<UmbracoEntityReference>();
31+
var _propertyEditors = Current.PropertyEditors;
32+
var rawJson = value == null ? string.Empty : value is string str ? str : value.ToString();
33+
DeserializeGridValue(rawJson, out var dtgeValues);
34+
35+
foreach (var control in dtgeValues)
36+
{
37+
if (_contentTypes.Value.TryGetValue(control.ContentTypeAlias, out var contentType))
38+
{
39+
var propertyTypes = contentType.CompositionPropertyTypes.ToDictionary(x => x.Alias, x => x);
40+
var properties = control.Value.Properties();
41+
42+
foreach (var property in properties)
43+
{
44+
if (propertyTypes.TryGetValue(property.Name, out var propertyType))
45+
{
46+
if (_propertyEditors.TryGet(propertyType.PropertyEditorAlias, out var propertyEditor))
47+
{
48+
if (propertyEditor.GetValueEditor() is IDataValueReference reference)
49+
{
50+
var propertyValue = property.Value.ToString();
51+
var refs = reference.GetReferences(propertyValue);
52+
result.AddRange(refs);
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
return result;
60+
61+
}
62+
63+
internal GridValue DeserializeGridValue(string rawJson, out IEnumerable<DocTypeGridEditorValue> dtgeValues)
64+
{
65+
var grid = JsonConvert.DeserializeObject<GridValue>(rawJson);
66+
67+
// Find all controls that uses DTGE editor
68+
var controls = grid.Sections.SelectMany(x => x.Rows.SelectMany(r => r.Areas).SelectMany(a => a.Controls)).ToArray();
69+
dtgeValues = controls.Where(x => x.Editor.Alias.ToLowerInvariant() == "doctype").Select(x => x.Value.ToObject<DocTypeGridEditorValue>());
70+
71+
return grid;
72+
}
73+
}
74+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Our.Umbraco.DocTypeGridEditor.ValueProcessing
2+
{
3+
/// <summary>
4+
/// Abstracts a ValueProcessor that is used to modify a property value before it's sent to a Property Value Converter
5+
/// These are useful when the data format stored for DTGE is different from what the PVC expects ie. like Umbraco.Tags
6+
/// </summary>
7+
public interface IDocTypeGridEditorValueProcessor
8+
{
9+
/// <summary>
10+
/// Returns if this processor can handle a certain property editor based on the property editors alias.
11+
/// </summary>
12+
/// <param name="propertyEditorAlias">Contains the alias of the property editor ie. "Umbraco.Tags" or "Umbraco.Picker".</param>
13+
/// <returns></returns>
14+
bool IsProcessorFor(string propertyEditorAlias);
15+
16+
/// <summary>
17+
/// Processes the value to de desired format/type. Most of the time this is to make sure that the object passed to the property value converters is
18+
/// of the correct type and in the correct format for the property value converter to handle.
19+
/// </summary>
20+
/// <param name="value"></param>
21+
/// <returns></returns>
22+
object ProcessValue(object value);
23+
}
24+
}

0 commit comments

Comments
 (0)