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

Commit 09777c8

Browse files
committed
porting c# code. Still doesn't work, it just sends the current node as the content, not the DTGE content.
1 parent 1f80444 commit 09777c8

File tree

7 files changed

+60
-102
lines changed

7 files changed

+60
-102
lines changed

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

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@
1515

1616
namespace Our.Umbraco.DocTypeGridEditor.Helpers
1717
{
18-
public class DocTypeGridEditorHelper
18+
public static class DocTypeGridEditorHelper
1919
{
20-
private readonly IUmbracoContextAccessor _umbracoContext;
2120

22-
public DocTypeGridEditorHelper(IUmbracoContextAccessor umbracoContext)
23-
{
24-
_umbracoContext = umbracoContext;
25-
}
26-
27-
public IPublishedElement ConvertValueToContent(string id, string contentTypeAlias, string dataJson)
21+
public static IPublishedElement ConvertValueToContent(string id, string contentTypeAlias, string dataJson)
2822
{
2923
if (string.IsNullOrWhiteSpace(contentTypeAlias))
3024
return null;
3125

3226
if (dataJson == null)
3327
return null;
3428

35-
if (_umbracoContext == null)
29+
if (Current.UmbracoContext == null)
3630
return ConvertValue(id, contentTypeAlias, dataJson);
3731

38-
return (IPublishedContent)Current.AppCaches.RuntimeCache.GetCacheItem(
32+
return (IPublishedElement)Current.AppCaches.RuntimeCache.GetCacheItem(
3933
$"Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.ConvertValueToContent_{id}_{contentTypeAlias}",
4034
() =>
4135
{
@@ -45,8 +39,6 @@ public IPublishedElement ConvertValueToContent(string id, string contentTypeAlia
4539

4640
private static IPublishedElement ConvertValue(string id, string contentTypeAlias, string dataJson)
4741
{
48-
using (Current.ProfilingLogger.DebugDuration<DocTypeGridEditorHelper>(string.Format("ConvertValue ({0}, {1})", id, contentTypeAlias)))
49-
{
5042
var contentTypes = GetContentTypesByAlias(contentTypeAlias);
5143
var properties = new List<IPublishedProperty>();
5244

@@ -112,22 +104,13 @@ private static IPublishedElement ConvertValue(string id, string contentTypeAlias
112104
var containerNode = pcr != null && pcr.HasPublishedContent ? pcr.PublishedContent : null;
113105

114106
// Create the model based on our implementation of IPublishedContent
115-
116107
// TODO: FIXME!
117-
//var content = new DetachedPublishedContent(
118-
// nameObj?.ToString(),
119-
// contentTypes.PublishedContentType,
120-
// properties.ToArray(),
121-
// containerNode);
122-
123-
//if (PublishedContentModelFactoryResolver.HasCurrent && PublishedContentModelFactoryResolver.Current.HasValue)
124-
//{
125-
// // Let the current model factory create a typed model to wrap our model
126-
// content = PublishedContentModelFactoryResolver.Current.Factory.CreateModel(content);
127-
//}
128-
129-
return pcr.PublishedContent;
130-
}
108+
var content = new DetachedPublishedElement(
109+
key,
110+
contentTypes.PublishedContentType,
111+
properties.ToArray());
112+
113+
return content;
131114

132115
}
133116

src/Our.Umbraco.DocTypeGridEditor/Models/DetachedPublishedContent.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Umbraco.Core;
5+
using Umbraco.Core.Models.PublishedContent;
6+
7+
namespace Our.Umbraco.DocTypeGridEditor.Models
8+
{
9+
internal class DetachedPublishedElement : IPublishedElement
10+
{
11+
private readonly PublishedContentType _contentType;
12+
private readonly IEnumerable<IPublishedProperty> _properties;
13+
private readonly bool _isPreviewing;
14+
private readonly Guid _key;
15+
16+
17+
public DetachedPublishedElement(
18+
Guid key,
19+
PublishedContentType contentType,
20+
IEnumerable<IPublishedProperty> properties,
21+
bool isPreviewing = false)
22+
{
23+
_key = key;
24+
_contentType = contentType;
25+
_properties = properties;
26+
_isPreviewing = isPreviewing;
27+
}
28+
public PublishedContentType ContentType => _contentType;
29+
30+
public IPublishedProperty GetProperty(string alias) => _properties.FirstOrDefault(x => x.PropertyType.Alias.InvariantEquals(alias));
31+
32+
public Guid Key => _key;
33+
34+
public IEnumerable<IPublishedProperty> Properties => _properties;
35+
36+
public bool IsDraft => _isPreviewing;
37+
}
38+
}

src/Our.Umbraco.DocTypeGridEditor/Models/DetachedPublishedProperty.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Umbraco.Core.Models;
33
using Umbraco.Core.Models.PublishedContent;
4+
using PropertyEditors = Umbraco.Core.PropertyEditors;
45

56
namespace Our.Umbraco.DocTypeGridEditor.Models
67
{
@@ -25,9 +26,9 @@ public DetachedPublishedProperty(PublishedPropertyType propertyType, object valu
2526
_rawValue = value;
2627

2728
// TODO: FIXME!
28-
//_sourceValue = new Lazy<object>(() => _propertyType.ConvertDataToSource(_rawValue, _isPreview));
29-
//_objectValue = new Lazy<object>(() => _propertyType.ConvertSourceToObject(_sourceValue.Value, _isPreview));
30-
//_xpathValue = new Lazy<object>(() => _propertyType.ConvertSourceToXPath(_sourceValue.Value, _isPreview));
29+
_sourceValue = new Lazy<object>(() => _propertyType.ConvertSourceToInter(null, _rawValue, _isPreview));
30+
_objectValue = new Lazy<object>(() => _propertyType.ConvertInterToObject(null, PropertyEditors.PropertyCacheLevel.None, _sourceValue.Value, _isPreview));
31+
_xpathValue = new Lazy<object>(() => _propertyType.ConvertInterToXPath(null, PropertyEditors.PropertyCacheLevel.None, _sourceValue.Value, _isPreview));
3132
}
3233

3334
public string PropertyTypeAlias
@@ -60,22 +61,22 @@ public object XPathValue
6061

6162
bool IPublishedProperty.HasValue(string culture, string segment)
6263
{
63-
throw new NotImplementedException();
64+
return HasValue;
6465
}
6566

6667
public object GetSourceValue(string culture = null, string segment = null)
6768
{
68-
throw new NotImplementedException();
69+
return DataValue;
6970
}
7071

7172
public object GetValue(string culture = null, string segment = null)
7273
{
73-
throw new NotImplementedException();
74+
return Value;
7475
}
7576

7677
public object GetXPathValue(string culture = null, string segment = null)
7778
{
78-
throw new NotImplementedException();
79+
return XPathValue;
7980
}
8081

8182
public PublishedPropertyType PropertyType { get; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
<Compile Include="Extensions\JsonExtensions.cs" />
221221
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
222222
<Compile Include="Helpers\XmlHelper.cs" />
223-
<Compile Include="Models\DetachedPublishedContent.cs" />
223+
<Compile Include="Models\DetachedPublishedElement.cs" />
224224
<Compile Include="Models\DetachedPublishedProperty.cs" />
225225
<Compile Include="Models\JsonDbRow.cs" />
226226
<Compile Include="Models\UnpublishedContent.cs" />

src/Our.Umbraco.DocTypeGridEditor/Web/Controllers/DocTypeGridEditorApiController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
183183
}
184184

185185
// Get content node object
186-
var docTypeGridEditorHelper = new DocTypeGridEditorHelper(_umbracoContext);
187-
var content = docTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);
186+
var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);
188187

189188
// Construct preview model
190189
var model = new PreviewModel

src/Our.Umbraco.DocTypeGridEditor/Web/Extensions/HtmlHelperExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class HtmlHelperExtensions
1313
// TODO: Once we bump the major version number, we can remove this stub method.
1414
public static HtmlString RenderDocTypeGridEditorItem(
1515
this HtmlHelper helper,
16-
IPublishedContent content,
16+
IPublishedElement content,
1717
string editorAlias,
1818
string viewPath,
1919
string previewViewPath)
@@ -23,7 +23,7 @@ public static HtmlString RenderDocTypeGridEditorItem(
2323

2424
public static HtmlString RenderDocTypeGridEditorItem(
2525
this HtmlHelper helper,
26-
IPublishedContent content,
26+
IPublishedElement content,
2727
string editorAlias = "",
2828
string viewPath = "",
2929
string previewViewPath = "",

0 commit comments

Comments
 (0)