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

Commit 5275b46

Browse files
authored
Merge pull request #112 from umco/develop
Preparing v0.6.0-beta release
2 parents e80d101 + 611c991 commit 5275b46

27 files changed

+544
-164
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ To clone it locally click the "Clone in Windows" button above or run the followi
4949

5050
For details on how to use the Doc Type Grid Editor package, please refer to our [Developers Guide](docs/developers-guide.md) documentation.
5151

52-
A PDF download is also available: [Doc Type Grid Editor - Developers Guide v1.0.pdf](docs/Doc-Type-Grid-Editor--Developers-Guide-v1.0.pdf)
53-
5452
---
5553

5654
## Known Issues
@@ -89,6 +87,7 @@ Have a question?
8987
### Special thanks
9088

9189
* Thanks to [Jeavon Leopold](https://github.com/Jeavon) for being a rockstar and adding AppVeyor & NuGet support.
90+
* Thanks to [Dave Woestenborghs](https://github.com/dawoe) for helping solve showstopper issues.
9291

9392

9493
## License

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
image: Visual Studio 2017
22

33
# version format
4-
version: 0.5.0.{build}
4+
version: 0.6.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
88
init:
9-
- set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=
9+
- set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
1010

1111
cache:
1212
- src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
Binary file not shown.
Binary file not shown.
Binary file not shown.

docs/developers-guide.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
1. [Introduction](#introduction)
66
2. [Getting Set Up](#getting-set-up)
7-
* [System Requirements](#system-requirements)
7+
a. [System Requirements](#system-requirements)
88
3. [Configuring The Doc Type Grid Editor](#configuring-the-doc-type-grid-editor)
99
4. [Hooking Up The Doc Type Grid Editor](#hooking-up-the-doc-type-grid-editor)
1010
5. [Rendering a Doc Type Grid Editor](#rendering-a-doc-type-grid-editor)
11-
* [Rendering Alternative Preview Content](#rendering-alternative-preview-content)
12-
* [DocTypeGridEditorSurfaceController](#doctypegrideditorsurfacecontroller)
11+
a. [Rendering Alternative Preview Content](#rendering-alternative-preview-content)
12+
b. [DocTypeGridEditorSurfaceController](#doctypegrideditorsurfacecontroller)
1313
6. [Useful Links](#useful-links)
1414

1515
---
@@ -82,7 +82,7 @@ The **Doc Type Grid Editor** supports 3 config options, all of which are optiona
8282

8383
| Member | Type | Description |
8484
|-----------------|----------|-------------|
85-
| AllowedDocTypes | String[] | An array of doc type aliases of which should be allowed to be selected in the grid editor. Strings can be REGEX patterns to allow matching groups of doc types in a single entry. e.g. "Widget$" will match all doc types with an alias ending in "Widget". |
85+
| AllowedDocTypes | String[] | An array of doc type aliases of which should be allowed to be selected in the grid editor. Strings can be REGEX patterns to allow matching groups of doc types in a single entry. e.g. "Widget$" will match all doc types with an alias ending in "Widget". However if a single doc type is matched, (aka **Single Doc Type Mode**), then dropdown selection stage (in the DTGE panel) will be skipped. |
8686
| EnablePreview | Boolean | Enables rendering a preview of the grid cell in the grid editor. |
8787
| ViewPath | String | Set's an alternative view path for where the **Doc Type Grid Editor** should look for views when rendering. Defaults to `~/Views/Partials/` |
8888

@@ -139,11 +139,11 @@ Because we treat your data as a standard `IPublishedContent` entity, that means
139139

140140
#### Rendering Alternative Preview Content
141141

142-
If your front end view is rather complex, you may decide that you want to feed the back office preview an alternative, less complex view. To do this, within your Razor view/partial, simply check for a querystring parameter `dtgePreview` being set to "1" to detect being in preview mode to provide an alternative view.
142+
If your front end view is rather complex, you may decide that you want to feed the back office preview an alternative, less complex view. To do this, within your Razor view/partial, check for a RouteData parameter `dtgePreview` being set to true to detect being in preview mode to provide an alternative view.
143143

144144
```
145145
@inherits Umbraco.Web.Mvc.UmbracoViewPage
146-
@if (Request.QueryString["dtgePreview"] == "1")
146+
@if (ViewContext.RouteData.Values["dtgePreview"])
147147
{
148148
// Render preview view
149149
}

src/Our.Umbraco.DocTypeGridEditor/Bootstrap.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
using System;
2-
using System.Web.Mvc;
32
using Newtonsoft.Json;
4-
using Our.Umbraco.DocTypeGridEditor.Web.Attributes;
53
using Our.Umbraco.DocTypeGridEditor.Web.Mvc;
64
using Umbraco.Core;
75
using Umbraco.Core.Sync;
86
using Umbraco.Web.Cache;
9-
using Umbraco.Web.Routing;
107

118
namespace Our.Umbraco.DocTypeGridEditor
129
{
1310
internal class Bootstrap : ApplicationEventHandler
1411
{
1512
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
1613
{
17-
GlobalFilters.Filters.Add(new DocTypeGridEditorPreviewAttribute());
18-
1914
if (DefaultDocTypeGridEditorSurfaceControllerResolver.HasCurrent == false)
2015
{
2116
DefaultDocTypeGridEditorSurfaceControllerResolver.Current = new DefaultDocTypeGridEditorSurfaceControllerResolver();
@@ -63,16 +58,6 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
6358
}
6459
}
6560
};
66-
67-
PublishedContentRequest.Prepared += (sender, e) =>
68-
{
69-
// Check if it's a dtgePreview request and is set to redirect.
70-
// If so reset the redirect url to an empty string to stop the redirect happening in preview mode.
71-
if (sender is PublishedContentRequest request && request.Uri.Query.InvariantContains("dtgePreview") && request.IsRedirect)
72-
{
73-
request.SetRedirect(string.Empty);
74-
}
75-
};
7661
}
7762
}
7863
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Umbraco.Core;
3+
using Umbraco.Core.Cache;
34
using Umbraco.Core.Services;
45

56
namespace Our.Umbraco.DocTypeGridEditor.Extensions
@@ -8,9 +9,11 @@ internal static class ContentTypeServiceExtensions
89
{
910
public static string GetAliasByGuid(this IContentTypeService contentTypeService, Guid id)
1011
{
11-
return (string)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
12+
return ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem<string>(
1213
string.Concat("Our.Umbraco.DocTypeGridEditor.Web.Extensions.ContentTypeServiceExtensions.GetAliasById_", id),
13-
() => ApplicationContext.Current.DatabaseContext.Database
14+
() => ApplicationContext.Current
15+
.DatabaseContext
16+
.Database
1417
.ExecuteScalar<string>("SELECT [cmsContentType].[alias] FROM [cmsContentType] INNER JOIN [umbracoNode] ON [cmsContentType].[nodeId] = [umbracoNode].[id] WHERE [umbracoNode].[uniqueID] = @0", id));
1518
}
1619
}

src/Our.Umbraco.DocTypeGridEditor/Extensions/ViewEnginesCollectionExtensions.cs

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ private static IEnumerable<JsonDbRow> GetPropertyDataRows(string docTypeAlias)
234234
public class ContentTypeContainer
235235
{
236236
public PublishedContentType PublishedContentType { get; set; }
237+
237238
public IContentType ContentType { get; set; }
238239
}
239240
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Umbraco.Core;
5+
using Umbraco.Core.Models;
6+
using Umbraco.Core.Models.PublishedContent;
7+
using Umbraco.Core.PropertyEditors;
8+
using Umbraco.Core.Services;
9+
using Umbraco.Web.Models;
10+
11+
namespace Our.Umbraco.DocTypeGridEditor.Models
12+
{
13+
internal class UnpublishedContent : PublishedContentWithKeyBase
14+
{
15+
private readonly IContent content;
16+
17+
private readonly Lazy<IEnumerable<IPublishedContent>> children;
18+
private readonly Lazy<PublishedContentType> contentType;
19+
private readonly Lazy<string> creatorName;
20+
private readonly Lazy<IPublishedContent> parent;
21+
private readonly Lazy<Dictionary<string, IPublishedProperty>> properties;
22+
private readonly Lazy<string> urlName;
23+
private readonly Lazy<string> writerName;
24+
25+
public UnpublishedContent(int id, ServiceContext serviceContext)
26+
: this(serviceContext.ContentService.GetById(id), serviceContext)
27+
{ }
28+
29+
public UnpublishedContent(IContent content, ServiceContext serviceContext)
30+
: base()
31+
{
32+
Mandate.ParameterNotNull(content, nameof(content));
33+
Mandate.ParameterNotNull(serviceContext, nameof(serviceContext));
34+
35+
var userService = new Lazy<IUserService>(() => serviceContext.UserService);
36+
37+
this.content = content;
38+
39+
this.children = new Lazy<IEnumerable<IPublishedContent>>(() => this.content.Children().Select(x => new UnpublishedContent(x, serviceContext)).ToList());
40+
this.contentType = new Lazy<PublishedContentType>(() => PublishedContentType.Get(this.ItemType, this.DocumentTypeAlias));
41+
this.creatorName = new Lazy<string>(() => this.content.GetCreatorProfile(userService.Value).Name);
42+
this.parent = new Lazy<IPublishedContent>(() => new UnpublishedContent(this.content.Parent(), serviceContext));
43+
this.properties = new Lazy<Dictionary<string, IPublishedProperty>>(() => MapProperties(PropertyEditorResolver.Current, serviceContext));
44+
this.urlName = new Lazy<string>(() => this.content.Name.ToUrlSegment());
45+
this.writerName = new Lazy<string>(() => this.content.GetWriterProfile(userService.Value).Name);
46+
}
47+
48+
public override Guid Key => this.content.Key;
49+
50+
public override PublishedItemType ItemType => PublishedItemType.Content;
51+
52+
public override int Id => this.content.Id;
53+
54+
public override int TemplateId => this.content.Template?.Id ?? default(int);
55+
56+
public override int SortOrder => this.content.SortOrder;
57+
58+
public override string Name => this.content.Name;
59+
60+
public override string UrlName => this.urlName.Value;
61+
62+
public override string DocumentTypeAlias => this.content.ContentType?.Alias;
63+
64+
public override int DocumentTypeId => this.content.ContentType?.Id ?? default(int);
65+
66+
public override string WriterName => this.writerName.Value;
67+
68+
public override string CreatorName => this.creatorName.Value;
69+
70+
public override int WriterId => this.content.WriterId;
71+
72+
public override int CreatorId => this.content.CreatorId;
73+
74+
public override string Path => this.content.Path;
75+
76+
public override DateTime CreateDate => this.content.CreateDate;
77+
78+
public override DateTime UpdateDate => this.content.UpdateDate;
79+
80+
public override Guid Version => this.content.Version;
81+
82+
public override int Level => this.content.Level;
83+
84+
public override bool IsDraft => true;
85+
86+
public override IPublishedContent Parent => this.parent.Value;
87+
88+
public override IEnumerable<IPublishedContent> Children => this.children.Value;
89+
90+
public override PublishedContentType ContentType => this.contentType.Value;
91+
92+
public override ICollection<IPublishedProperty> Properties => this.properties.Value.Values;
93+
94+
public override IPublishedProperty GetProperty(string alias)
95+
{
96+
return this.properties.Value.TryGetValue(alias, out IPublishedProperty property) ? property : null;
97+
}
98+
99+
private Dictionary<string, IPublishedProperty> MapProperties(PropertyEditorResolver resolver, ServiceContext services)
100+
{
101+
var contentType = this.contentType.Value;
102+
var properties = this.content.Properties;
103+
104+
var items = new Dictionary<string, IPublishedProperty>(StringComparer.InvariantCultureIgnoreCase);
105+
106+
foreach (var propertyType in contentType.PropertyTypes)
107+
{
108+
var property = properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyType.PropertyTypeAlias));
109+
var value = property?.Value;
110+
if (value != null)
111+
{
112+
var propertyEditor = resolver.GetByAlias(propertyType.PropertyEditorAlias);
113+
if (propertyEditor != null)
114+
{
115+
value = propertyEditor.ValueEditor.ConvertDbToString(property, property.PropertyType, services.DataTypeService);
116+
}
117+
}
118+
119+
items.Add(propertyType.PropertyTypeAlias, new UnpublishedProperty(propertyType, value));
120+
}
121+
122+
return items;
123+
}
124+
}
125+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using Umbraco.Core.Models;
3+
using Umbraco.Core.Models.PublishedContent;
4+
5+
namespace Our.Umbraco.DocTypeGridEditor.Models
6+
{
7+
internal class UnpublishedProperty : IPublishedProperty
8+
{
9+
private readonly PublishedPropertyType propertyType;
10+
private readonly object dataValue;
11+
private readonly Lazy<bool> hasValue;
12+
private readonly Lazy<object> sourceValue;
13+
private readonly Lazy<object> objectValue;
14+
private readonly Lazy<object> xpathValue;
15+
16+
public UnpublishedProperty(PublishedPropertyType propertyType, object value)
17+
{
18+
this.propertyType = propertyType;
19+
20+
this.dataValue = value;
21+
this.hasValue = new Lazy<bool>(() => value != null && value.ToString().Trim().Length > 0);
22+
23+
this.sourceValue = new Lazy<object>(() => this.propertyType.ConvertDataToSource(this.dataValue, true));
24+
this.objectValue = new Lazy<object>(() => this.propertyType.ConvertSourceToObject(this.sourceValue.Value, true));
25+
this.xpathValue = new Lazy<object>(() => this.propertyType.ConvertSourceToXPath(this.sourceValue.Value, true));
26+
}
27+
28+
public string PropertyTypeAlias => this.propertyType.PropertyTypeAlias;
29+
30+
public bool HasValue => this.hasValue.Value;
31+
32+
public object DataValue => this.dataValue;
33+
34+
public object Value => this.objectValue.Value;
35+
36+
public object XPathValue => this.xpathValue.Value;
37+
}
38+
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
</Reference>
7171
<Reference Include="System" />
7272
<Reference Include="System.Core" />
73+
<Reference Include="System.Net.Http" />
74+
<Reference Include="System.Runtime.Serialization" />
7375
<Reference Include="System.Web" />
7476
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7577
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
@@ -94,21 +96,24 @@
9496
<ItemGroup>
9597
<Compile Include="Bootstrap.cs" />
9698
<Compile Include="Extensions\JsonExtensions.cs" />
97-
<Compile Include="Extensions\ViewEnginesCollectionExtensions.cs" />
9899
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
99100
<Compile Include="Helpers\XmlHelper.cs" />
100101
<Compile Include="Models\DetachedPublishedContent.cs" />
101102
<Compile Include="Models\DetachedPublishedProperty.cs" />
102103
<Compile Include="Models\JsonDbRow.cs" />
104+
<Compile Include="Models\UnpublishedContent.cs" />
105+
<Compile Include="Models\UnpublishedProperty.cs" />
103106
<Compile Include="PackageActions\AddObjectToJsonArray.cs" />
104107
<Compile Include="Properties\AssemblyInfo.cs" />
105108
<Compile Include="Properties\VersionInfo.cs" />
106-
<Compile Include="Web\Attributes\DocTypeGridEditorPreviewAttribute.cs" />
107109
<Compile Include="Web\Controllers\DocTypeGridEditorApiController.cs" />
108110
<Compile Include="Extensions\ContentTypeServiceExtensions.cs" />
109111
<Compile Include="Web\Controllers\DocTypeGridEditorSurfaceController.cs" />
110112
<Compile Include="Web\Extensions\HtmlHelperExtensions.cs" />
111113
<Compile Include="Web\Helpers\SurfaceControllerHelper.cs" />
114+
<Compile Include="Web\Helpers\ViewHelper.cs" />
115+
<Compile Include="Web\Models\PreviewData.cs" />
116+
<Compile Include="Web\Models\PreviewModel.cs" />
112117
<Compile Include="Web\Mvc\DefaultDocTypeGridEditorSurfaceControllerResolver.cs" />
113118
</ItemGroup>
114119
<ItemGroup>
@@ -125,6 +130,9 @@
125130
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Js\doctypegrideditor.services.js" />
126131
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Js\doctypegrideditor.resources.js" />
127132
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Js\doctypegrideditor.controllers.js" />
133+
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Lang\da-DK.xml" />
134+
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Lang\en-GB.xml" />
135+
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Lang\en-US.xml" />
128136
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Views\doctypegrideditor.dialog.html" />
129137
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Views\doctypegrideditor.html" />
130138
</ItemGroup>

0 commit comments

Comments
 (0)