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

Removed setting the InPreviewMode flag #127

Merged
merged 3 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/developers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

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

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

#### Rendering Alternative Preview Content

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.
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.

```
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@if (UmbracoContext.InPreviewMode)
@if (Request.QueryString["dtgePreview"] == "1")
{
// Render preview view
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
}

// Set DTGE's preview to be in "preview mode", (storing the original value in a temp variable for resetting it later).
var inPreviewMode = UmbracoContext.InPreviewMode;
UmbracoContext.InPreviewMode = true;

// Get content node object
var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);

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

// Restore the "preview mode" to its original value
UmbracoContext.InPreviewMode = inPreviewMode;

// Return response
var response = new HttpResponseMessage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
using Umbraco.Core;
using Umbraco.Core.Models;
Expand Down Expand Up @@ -29,7 +30,7 @@ public string PreviewViewPath

public bool IsPreview
{
get { return UmbracoContext.InPreviewMode; }
get { return ControllerContext.RouteData.Values.TryGetValue("dtgePreview", out object value) && Convert.ToBoolean(value); }
}

protected PartialViewResult CurrentPartialView(object model = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public static HtmlString RenderDocTypeGridEditorItem(
{
dtgeModel = content,
dtgeViewPath = viewPath,
dtgePreviewViewPath = previewViewPath
dtgePreviewViewPath = previewViewPath,
dtgePreview = isPreview
};

// Try looking for surface controller with action named after the editor alias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
);
},
getEditorMarkupForDocTypePartial: function (pageId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath, published) {
var url = umbRequestHelper.convertVirtualToAbsolutePath("~/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetPreviewMarkup?pageId=" + pageId);
var url = umbRequestHelper.convertVirtualToAbsolutePath("~/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetPreviewMarkup?dtgePreview=1&pageId=" + pageId);
return $http({
method: 'POST',
url: url,
Expand Down