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

Commit 84d389f

Browse files
Merge branch 'preview-view-path' into develop
2 parents d7be8a5 + 8991d2c commit 84d389f

File tree

10 files changed

+135
-59
lines changed

10 files changed

+135
-59
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Web.Mvc;
2+
using Umbraco.Core.Logging;
3+
4+
namespace Our.Umbraco.DocTypeGridEditor.Extensions
5+
{
6+
internal static class ViewEnginesCollectionExtensions
7+
{
8+
public static bool ViewExists(this ViewEngineCollection viewEngines,
9+
ControllerContext controllerContext,
10+
string viewName, bool isPartial = false)
11+
{
12+
var result = !isPartial
13+
? viewEngines.FindView(controllerContext, viewName, null)
14+
: viewEngines.FindPartialView(controllerContext, viewName);
15+
if (result.View != null)
16+
return true;
17+
18+
LogHelper.Warn<Bootstrap>("No view file found with the name " + viewName);
19+
return false;
20+
}
21+
}
22+
}

Src/Our.Umbraco.DocTypeGridEditor/Our.Umbraco.DocTypeGridEditor.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
</ItemGroup>
191191
<ItemGroup>
192192
<Compile Include="Bootstrap.cs" />
193+
<Compile Include="Extensions\ViewEnginesCollectionExtensions.cs" />
193194
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
194195
<Compile Include="Helpers\XmlHelper.cs" />
195196
<Compile Include="Models\DetachedPublishedContent.cs" />
@@ -230,9 +231,9 @@
230231
<PropertyGroup>
231232
<PostBuildEvent>IF %25ComputerName%25 == MBP13-PC-BC (
232233
IF NOT "$(SolutionDir)" == "*Undefined*" (
233-
xcopy /s /y "$(TargetPath)" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoCms.7.2.2\bin"
234-
xcopy /s /y "$(TargetDir)$(ProjectName).pdb" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoCms.7.2.2\bin"
235-
xcopy /s /y "$(ProjectDir)Web\UI\*.*" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoCms.7.2.2"
234+
xcopy /s /y "$(TargetPath)" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoUHangoutDemo\bin"
235+
xcopy /s /y "$(TargetDir)$(ProjectName).pdb" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoUHangoutDemo\bin"
236+
xcopy /s /y "$(ProjectDir)Web\UI\*.*" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoUHangoutDemo"
236237
)
237238
)</PostBuildEvent>
238239
</PropertyGroup>
Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Web.Mvc;
2-
using Umbraco.Core.Logging;
2+
using Our.Umbraco.DocTypeGridEditor.Extensions;
33
using Umbraco.Core.Models;
44
using Umbraco.Web.Mvc;
55

@@ -21,16 +21,36 @@ public string ViewPath
2121
get { return ControllerContext.RouteData.Values["dtgeViewPath"] as string ?? string.Empty; }
2222
}
2323

24+
public string PreviewViewPath
25+
{
26+
get { return ControllerContext.RouteData.Values["dtgePreviewViewPath"] as string ?? string.Empty; }
27+
}
28+
29+
public bool IsPreview
30+
{
31+
get { return Request.QueryString["dtgePreview"] == "1"; }
32+
}
33+
2434
protected ActionResult CurrentPartialView(object model = null)
2535
{
2636
if (model == null)
2737
model = Model;
2838

2939
var viewName = ControllerContext.RouteData.Values["action"].ToString();
30-
var viewPath = GetFullViewPath(viewName);
3140

32-
if (ViewExists(viewPath, true))
33-
return base.PartialView(viewPath, model);
41+
if (IsPreview && !string.IsNullOrWhiteSpace(PreviewViewPath))
42+
{
43+
var previewViewPath = GetFullViewPath(viewName, PreviewViewPath);
44+
if (ViewEngines.Engines.ViewExists(ControllerContext, previewViewPath, true))
45+
return base.PartialView(previewViewPath, model);
46+
}
47+
48+
if (!string.IsNullOrWhiteSpace(ViewPath))
49+
{
50+
var viewPath = GetFullViewPath(viewName, ViewPath);
51+
if (ViewEngines.Engines.ViewExists(ControllerContext, viewPath, true))
52+
return base.PartialView(viewPath, model);
53+
}
3454

3555
return HttpNotFound();
3656
}
@@ -42,31 +62,33 @@ protected ActionResult CurrentPartialView(object model = null)
4262

4363
protected override PartialViewResult PartialView(string viewName, object model)
4464
{
45-
var viewPath = GetFullViewPath(viewName);
46-
return base.PartialView(viewPath, model);
65+
if (IsPreview && !string.IsNullOrWhiteSpace(PreviewViewPath))
66+
{
67+
var previewViewPath = GetFullViewPath(viewName, PreviewViewPath);
68+
if (ViewEngines.Engines.ViewExists(ControllerContext, previewViewPath, true))
69+
return base.PartialView(previewViewPath, model);
70+
}
71+
72+
if (!string.IsNullOrWhiteSpace(ViewPath))
73+
{
74+
var viewPath = GetFullViewPath(viewName, ViewPath);
75+
if (ViewEngines.Engines.ViewExists(ControllerContext, viewPath, true))
76+
return base.PartialView(viewPath, model);
77+
}
78+
79+
return base.PartialView(viewName, model);
4780
}
4881

49-
protected string GetFullViewPath(string viewName)
82+
protected string GetFullViewPath(string viewName, string baseViewPath)
5083
{
5184
if (viewName.StartsWith("~") || viewName.StartsWith("/")
52-
|| viewName.StartsWith(".") || string.IsNullOrWhiteSpace(ViewPath))
85+
|| viewName.StartsWith(".") || string.IsNullOrWhiteSpace(baseViewPath))
5386
{
5487
return viewName;
5588
}
5689

57-
return ViewPath.TrimEnd('/') + "/" + viewName + ".cshtml";
58-
}
59-
60-
protected bool ViewExists(string viewName, bool isPartial = false)
61-
{
62-
var result = !isPartial
63-
? ViewEngines.Engines.FindView(ControllerContext, viewName, null)
64-
: ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
65-
if (result.View != null)
66-
return true;
67-
68-
LogHelper.Warn<DocTypeGridEditorSurfaceController>("No view file found with the name " + viewName);
69-
return false;
90+
return baseViewPath.TrimEnd('/') + "/" + viewName + ".cshtml";
7091
}
92+
7193
}
7294
}

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

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,65 @@
11
using System.Web;
22
using System.Web.Mvc;
33
using System.Web.Mvc.Html;
4-
using Our.Umbraco.DocTypeGridEditor.Helpers;
4+
using Our.Umbraco.DocTypeGridEditor.Extensions;
55
using Umbraco.Core.Models;
66
using Umbraco.Web;
77

88
namespace Our.Umbraco.DocTypeGridEditor.Web.Extensions
99
{
1010
public static class HtmlHelperExtensions
1111
{
12-
public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
13-
string id,
14-
string docType,
15-
string value,
16-
string viewPath = "",
17-
string actionName = "",
18-
object model = null)
19-
{
20-
var content = DocTypeGridEditorHelper.ConvertValueToContent(id, docType, value);
21-
return helper.RenderDocTypeGridEditorItem(content, viewPath, actionName, model);
22-
}
23-
2412
public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
2513
IPublishedContent content,
2614
string viewPath = "",
27-
string actionName = "",
28-
object model = null)
29-
{
30-
31-
if (content == null)
15+
string previewViewPath = "")
16+
{
17+
if (content == null)
3218
return new HtmlString(string.Empty);
3319

34-
var controllerName = content.DocumentTypeAlias + "Surface";
20+
var controllerName = content.DocumentTypeAlias + "Surface";
3521

36-
if (!string.IsNullOrWhiteSpace(viewPath))
22+
if (!string.IsNullOrWhiteSpace(viewPath))
3723
viewPath = viewPath.TrimEnd('/') + "/";
3824

39-
if (string.IsNullOrWhiteSpace(actionName))
40-
actionName = content.DocumentTypeAlias;
25+
if (!string.IsNullOrWhiteSpace(previewViewPath))
26+
previewViewPath = previewViewPath.TrimEnd('/') + "/";
27+
28+
var actionName = content.DocumentTypeAlias;
4129

4230
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
4331
if (umbracoHelper.SurfaceControllerExists(controllerName, actionName, true))
4432
{
4533
return helper.Action(actionName, controllerName, new
4634
{
47-
dtgeModel = model ?? content,
48-
dtgeViewPath = viewPath
35+
dtgeModel = content,
36+
dtgeViewPath = viewPath,
37+
dtgePreviewViewPath = previewViewPath
4938
});
5039
}
5140

41+
// Check for preview view
42+
if (!string.IsNullOrWhiteSpace(previewViewPath)
43+
&& helper.ViewContext.RequestContext.HttpContext.Request.QueryString["dtgePreview"] == "1")
44+
{
45+
var fullPreviewViewPath = previewViewPath + content.DocumentTypeAlias + ".cshtml";
46+
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
47+
{
48+
return helper.Partial(fullPreviewViewPath, content);
49+
}
50+
}
51+
52+
// Check for view path view
5253
if (!string.IsNullOrWhiteSpace(viewPath))
53-
return helper.Partial(viewPath + content.DocumentTypeAlias + ".cshtml", content);
54+
{
55+
var fullViewPath = viewPath + content.DocumentTypeAlias + ".cshtml";
56+
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
57+
{
58+
return helper.Partial(fullViewPath, content);
59+
}
60+
}
5461

62+
// Resort to standard partial view
5563
return helper.Partial(content.DocumentTypeAlias, content);
5664
}
5765
}

Src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Config/grid.editors.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"config": {
88
"allowedDocTypes": [],
99
"enablePreview": true,
10-
"viewPath": "/Views/Partials/"
10+
"viewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/",
11+
"previewViewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/Previews/",
12+
"previewCssFilePath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/Previews/Css/dtge.css",
13+
"previewJsFilePath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/Previews/Js/dtge.js"
1114
}
1215
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"$rootScope",
55
"$timeout",
66
"$routeParams",
7+
'assetsService',
78
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeDialogService",
89
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",
910

10-
function ($scope, $rootScope, $timeout, $routeParams, dtgeDialogService, dtgeResources) {
11+
function ($scope, $rootScope, $timeout, $routeParams, assetsService, dtgeDialogService, dtgeResources) {
1112

1213
$scope.title = "Click to insert item";
1314
$scope.icon = "icon-item-arrangement";
@@ -49,7 +50,7 @@
4950
$scope.setPreview = function (model) {
5051
if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview) {
5152
var nodeId = $routeParams.id;
52-
dtgeResources.getEditorMarkupForDocTypePartial(nodeId, model.id, model.docType, model.value, $scope.control.editor.config.viewPath)
53+
dtgeResources.getEditorMarkupForDocTypePartial(nodeId, model.id, model.docType, model.value, $scope.control.editor.config.viewPath, $scope.control.editor.config.previewViewPath)
5354
.success(function(htmlResult) {
5455
if (htmlResult.trim().length > 0) {
5556
$scope.preview = htmlResult;
@@ -64,6 +65,18 @@
6465
value: {}
6566
});
6667

68+
// Load preview css / js files
69+
if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview)
70+
{
71+
if ("previewCssFilePath" in $scope.control.editor.config && $scope.control.editor.config.previewCssFilePath) {
72+
assetsService.loadCss($scope.control.editor.config.previewCssFilePath, $scope);
73+
};
74+
75+
if ("previewJsFilePath" in $scope.control.editor.config && $scope.control.editor.config.previewJsFilePath) {
76+
assetsService.loadJs($scope.control.editor.config.previewJsFilePath, $scope);
77+
}
78+
}
79+
6780
$timeout(function () {
6881
if ($scope.control.$initializing) {
6982
$scope.setDocType();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'Failed to retrieve datatypes'
3535
);
3636
},
37-
getEditorMarkupForDocTypePartial: function (nodeId, id, docType, value, viewPath) {
37+
getEditorMarkupForDocTypePartial: function (nodeId, id, docType, value, viewPath, previewViewPath) {
3838
var url = "/" + nodeId +"?dtgePreview=1";
3939
return $http({
4040
method: 'POST',
@@ -43,7 +43,8 @@
4343
id: id,
4444
docType: docType,
4545
value: JSON.stringify(value),
46-
viewPath: viewPath
46+
viewPath: viewPath,
47+
previewViewPath: previewViewPath
4748
}),
4849
headers: {
4950
'Content-Type': 'application/x-www-form-urlencoded'
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using System.Web.Mvc.Html
1+
@using System.Web.Mvc
2+
@using System.Web.Mvc.Html
23
@using Our.Umbraco.DocTypeGridEditor.Helpers
34
@using Our.Umbraco.DocTypeGridEditor.Web.Extensions
45
@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
@@ -8,8 +9,9 @@
89
string docType = Model.value.docType.ToString();
910
string value = Model.value.value.ToString();
1011
string viewPath = Model.editor.config.viewPath.ToString();
12+
string previewViewPath = Model.editor.config.previewViewPath.ToString();
1113

1214
var content = DocTypeGridEditorHelper.ConvertValueToContent(id, docType, value);
13-
14-
@Html.RenderDocTypeGridEditorItem(content, viewPath)
15+
16+
@Html.RenderDocTypeGridEditorItem(content, viewPath, previewViewPath)
1517
}

Src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
var docType = Request.Form["docType"];
99
var value = Request.Unvalidated.Form["value"];
1010
var viewPath = Request.Form["viewPath"];
11+
var previewViewPath = Request.Form["previewViewPath"];
12+
1113
var content = DocTypeGridEditorHelper.ConvertValueToContent(id, docType, value);
1214

13-
@Html.RenderDocTypeGridEditorItem(content, viewPath)
15+
@Html.RenderDocTypeGridEditorItem(content, viewPath, previewViewPath)
1416
}

Src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div ng-controller="Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor">
22

3-
<div class="usky-editor-placeholder" ng-click="setDocType()">
3+
<div class="usky-editor-placeholder dtge-editor-placeholder"
4+
ng-click="setDocType()"
5+
ng-class="{ 'dtge-editor-placeholder--preview' : preview }">
46
<div ng-if="!preview">
57
<i class="icon {{icon}}"></i>
68
<div class="help-text">{{title}}</div>

0 commit comments

Comments
 (0)