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

Commit d9d11f2

Browse files
authored
Merge pull request #127 from umco/patch/preview-fixes-1
Removed setting the `InPreviewMode` flag
2 parents dd9ab08 + db0afd3 commit d9d11f2

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

docs/developers-guide.md

Lines changed: 5 additions & 5 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-
a. [System Requirements](#system-requirements)
7+
1. [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-
a. [Rendering Alternative Preview Content](#rendering-alternative-preview-content)
12-
b. [DocTypeGridEditorSurfaceController](#doctypegrideditorsurfacecontroller)
11+
1. [Rendering Alternative Preview Content](#rendering-alternative-preview-content)
12+
2. [DocTypeGridEditorSurfaceController](#doctypegrideditorsurfacecontroller)
1313
6. [Useful Links](#useful-links)
1414

1515
---
@@ -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, check `UmbracoContext.InPreviewMode` is set to true 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 querystring parameter `dtgePreview` being set to "1" to detect being in preview mode to provide an alternative view.
143143

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

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
136136
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
137137
}
138138

139-
// Set DTGE's preview to be in "preview mode", (storing the original value in a temp variable for resetting it later).
140-
var inPreviewMode = UmbracoContext.InPreviewMode;
141-
UmbracoContext.InPreviewMode = true;
142-
143139
// Get content node object
144140
var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);
145141

@@ -157,9 +153,6 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
157153
var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml";
158154
var markup = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext);
159155

160-
// Restore the "preview mode" to its original value
161-
UmbracoContext.InPreviewMode = inPreviewMode;
162-
163156
// Return response
164157
var response = new HttpResponseMessage
165158
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Web.Mvc;
1+
using System;
2+
using System.Web.Mvc;
23
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
34
using Umbraco.Core;
45
using Umbraco.Core.Models;
@@ -29,7 +30,7 @@ public string PreviewViewPath
2930

3031
public bool IsPreview
3132
{
32-
get { return UmbracoContext.InPreviewMode; }
33+
get { return ControllerContext.RouteData.Values.TryGetValue("dtgePreview", out object value) && Convert.ToBoolean(value); }
3334
}
3435

3536
protected PartialViewResult CurrentPartialView(object model = null)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public static HtmlString RenderDocTypeGridEditorItem(
4646
{
4747
dtgeModel = content,
4848
dtgeViewPath = viewPath,
49-
dtgePreviewViewPath = previewViewPath
49+
dtgePreviewViewPath = previewViewPath,
50+
dtgePreview = isPreview
5051
};
5152

5253
// Try looking for surface controller with action named after the editor alias

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
);
3636
},
3737
getEditorMarkupForDocTypePartial: function (pageId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath, published) {
38-
var url = umbRequestHelper.convertVirtualToAbsolutePath("~/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetPreviewMarkup?pageId=" + pageId);
38+
var url = umbRequestHelper.convertVirtualToAbsolutePath("~/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetPreviewMarkup?dtgePreview=1&pageId=" + pageId);
3939
return $http({
4040
method: 'POST',
4141
url: url,

0 commit comments

Comments
 (0)