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

Commit 921efa2

Browse files
committed
Revert "Merge pull request #105 from kows/feature/preview-unpublished"
This reverts commit ad3b326, reversing changes made to 3b319a2.
1 parent ad3b326 commit 921efa2

File tree

12 files changed

+52
-277
lines changed

12 files changed

+52
-277
lines changed

src/Our.Umbraco.DocTypeGridEditor/Bootstrap.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Web.Mvc;
23
using Newtonsoft.Json;
4+
using Our.Umbraco.DocTypeGridEditor.Web.Attributes;
35
using Our.Umbraco.DocTypeGridEditor.Web.Mvc;
46
using Umbraco.Core;
57
using Umbraco.Core.Sync;
@@ -12,6 +14,8 @@ internal class Bootstrap : ApplicationEventHandler
1214
{
1315
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
1416
{
17+
GlobalFilters.Filters.Add(new DocTypeGridEditorPreviewAttribute());
18+
1519
if (DefaultDocTypeGridEditorSurfaceControllerResolver.HasCurrent == false)
1620
{
1721
DefaultDocTypeGridEditorSurfaceControllerResolver.Current = new DefaultDocTypeGridEditorSurfaceControllerResolver();

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

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

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

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

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@
7070
</Reference>
7171
<Reference Include="System" />
7272
<Reference Include="System.Core" />
73-
<Reference Include="System.Net.Http" />
74-
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
75-
<SpecificVersion>False</SpecificVersion>
76-
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
77-
<Private>False</Private>
78-
</Reference>
7973
<Reference Include="System.Web" />
8074
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8175
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
@@ -106,19 +100,16 @@
106100
<Compile Include="Models\DetachedPublishedContent.cs" />
107101
<Compile Include="Models\DetachedPublishedProperty.cs" />
108102
<Compile Include="Models\JsonDbRow.cs" />
109-
<Compile Include="Models\UnpublishedContent.cs" />
110-
<Compile Include="Models\UnpublishedProperty.cs" />
111103
<Compile Include="PackageActions\AddObjectToJsonArray.cs" />
112104
<Compile Include="Properties\AssemblyInfo.cs" />
113105
<Compile Include="Properties\VersionInfo.cs" />
106+
<Compile Include="Web\Attributes\DocTypeGridEditorPreviewAttribute.cs" />
114107
<Compile Include="Web\Controllers\DocTypeGridEditorApiController.cs" />
115108
<Compile Include="Extensions\ContentTypeServiceExtensions.cs" />
116109
<Compile Include="Web\Controllers\DocTypeGridEditorSurfaceController.cs" />
117110
<Compile Include="Web\Extensions\HtmlHelperExtensions.cs" />
118111
<Compile Include="Web\Helpers\SurfaceControllerHelper.cs" />
119-
<Compile Include="Web\Helpers\ViewHelper.cs" />
120112
<Compile Include="Web\Mvc\DefaultDocTypeGridEditorSurfaceControllerResolver.cs" />
121-
<Compile Include="Web\PreviewModel.cs" />
122113
</ItemGroup>
123114
<ItemGroup>
124115
<None Include="app.config" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Web;
2+
using System.Web.Mvc;
3+
4+
namespace Our.Umbraco.DocTypeGridEditor.Web.Attributes
5+
{
6+
internal class DocTypeGridEditorPreviewAttribute : ActionFilterAttribute
7+
{
8+
public override void OnResultExecuting(ResultExecutingContext filterContext)
9+
{
10+
if (HttpContext.Current.Request.QueryString["dtgePreview"] == "1"
11+
&& HttpContext.Current.Request.HttpMethod == "POST")
12+
{
13+
var viewResult = filterContext.Result as ViewResult;
14+
if (viewResult != null)
15+
{
16+
viewResult.ViewName =
17+
"~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml";
18+
}
19+
// NOTE: [LK:2016-11-16] If the preview result is a redirect, then cancel the request.
20+
// The issue here is that typically a redirect from a controller would be to a full-loading HTML page.
21+
// Meaning that a full bodied HTML page would be injected into a DTGE grid cell, causing havoc.
22+
// This is a temporary resolution until we implement a more robust DTGE previewer mechanism.
23+
else if (filterContext.Result is RedirectResult)
24+
{
25+
filterContext.Cancel = true;
26+
}
27+
}
28+
29+
base.OnResultExecuting(filterContext);
30+
}
31+
}
32+
}

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Net.Http;
5-
using System.Net.Http.Formatting;
6-
using System.Net.Http.Headers;
7-
using System.Net.Mime;
84
using System.Text.RegularExpressions;
95
using System.Web.Http;
106
using System.Web.Http.ModelBinding;
117
using Our.Umbraco.DocTypeGridEditor.Extensions;
12-
using Our.Umbraco.DocTypeGridEditor.Models;
138
using Umbraco.Core.Models;
149
using Umbraco.Core.PropertyEditors;
1510
using Umbraco.Web.Editors;
16-
using Umbraco.Web.Models;
1711
using Umbraco.Web.Mvc;
1812

1913
namespace Our.Umbraco.DocTypeGridEditor.Web.Controllers
@@ -92,43 +86,5 @@ public object GetDataTypePreValues(string dtdId)
9286
var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
9387
return propEditor.PreValueEditor.ConvertDbToEditor(propEditor.DefaultPreValues, preValue);
9488
}
95-
96-
[HttpPost]
97-
public HttpResponseMessage GetPreviewMarkup([FromBody] FormDataCollection item, [FromUri] int pageId)
98-
{
99-
var page = default(IPublishedContent);
100-
101-
// If the page is new, then the ID will be zero
102-
if (pageId > 0)
103-
{
104-
// Get page container node
105-
page = UmbracoContext.ContentCache.GetById(pageId);
106-
if (page == null)
107-
{
108-
// If unpublished, then fake PublishedContent (with IContent object)
109-
page = new UnpublishedContent(pageId, Services);
110-
}
111-
}
112-
113-
var culture = UmbracoContext.Application.Services.ContentService.GetById(pageId).GetCulture();
114-
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
115-
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
116-
117-
// Construct preview model
118-
var model = new PreviewModel { Page = page, Values = item };
119-
120-
// Render view
121-
var markup = Helpers.ViewHelper.RenderPartial("~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml", model);
122-
123-
// Return response
124-
var response = new HttpResponseMessage
125-
{
126-
Content = new StringContent(markup ?? string.Empty)
127-
};
128-
129-
response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);
130-
131-
return response;
132-
}
13389
}
13490
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Our.Umbraco.DocTypeGridEditor.Web.Mvc;
77
using Umbraco.Core;
88
using Umbraco.Core.Models;
9+
using Umbraco.Web;
910

1011
namespace Our.Umbraco.DocTypeGridEditor.Web.Extensions
1112
{

src/Our.Umbraco.DocTypeGridEditor/Web/Helpers/ViewHelper.cs

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

src/Our.Umbraco.DocTypeGridEditor/Web/PreviewModel.cs

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

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
dtgeResources.getEditorMarkupForDocTypePartial(editorState.current.id, model.id,
117117
$scope.control.editor.alias, model.dtgeContentTypeAlias, model.value,
118118
$scope.control.editor.config.viewPath,
119-
$scope.control.editor.config.previewViewPath)
119+
$scope.control.editor.config.previewViewPath,
120+
!!editorState.current.publishDate)
120121
.success(function (htmlResult) {
121122
if (htmlResult.trim().length > 0) {
122123
$scope.preview = htmlResult;

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.resources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
'Failed to retrieve datatypes'
3535
);
3636
},
37-
getEditorMarkupForDocTypePartial: function (pageId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath) {
38-
var url = umbRequestHelper.convertVirtualToAbsolutePath("~/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetPreviewMarkup?dtgePreview=1&pageId=" + pageId);
37+
getEditorMarkupForDocTypePartial: function (nodeId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath, published) {
38+
var url = umbRequestHelper.convertVirtualToAbsolutePath("~/" + (published ? nodeId : "") + "?dtgePreview=1" + (published ? "" : "&nodeId=" + nodeId));
3939
return $http({
4040
method: 'POST',
4141
url: url,

0 commit comments

Comments
 (0)