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

Commit cb284a7

Browse files
Switched to using content type aliases, rather than guids. Everything is guid tolerant though so it should all be self updating / fixing.
Added support for having multiple views for a doc type alias by trying the editor alias first
1 parent 76f80f5 commit cb284a7

File tree

7 files changed

+139
-73
lines changed

7 files changed

+139
-73
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@
265265
<PropertyGroup>
266266
<PostBuildEvent>IF %25ComputerName%25 == MBP13-PC-BC (
267267
IF NOT "$(SolutionDir)" == "*Undefined*" (
268-
xcopy /s /y "$(TargetPath)" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoCms.7.2.6\bin"
269-
xcopy /s /y "$(TargetDir)$(ProjectName).pdb" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoCms.7.2.6\bin"
270-
xcopy /s /y "$(ProjectDir)Web\UI\*.*" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoCms.7.2.6"
268+
xcopy /s /y "$(TargetPath)" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoUHangoutDemo\bin"
269+
xcopy /s /y "$(TargetDir)$(ProjectName).pdb" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoUHangoutDemo\bin"
270+
xcopy /s /y "$(ProjectDir)Web\UI\*.*" "C:\Users\Matt\Work\Sandbox\Umbraco\UmbracoUHangoutDemo"
271271
)
272272
)</PostBuildEvent>
273273
</PropertyGroup>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ public IEnumerable<object> GetContentTypes([System.Web.Http.ModelBinding.ModelBi
4040
}
4141

4242
[System.Web.Http.HttpGet]
43-
public object GetContentTypeIcon([System.Web.Http.ModelBinding.ModelBinder] Guid guid)
43+
public object GetContentTypeIcon([System.Web.Http.ModelBinding.ModelBinder] string contentTypeAlias)
4444
{
45-
var contentTypeAlias = Services.ContentTypeService.GetAliasByGuid(guid);
45+
Guid docTypeGuid;
46+
if (Guid.TryParse(contentTypeAlias, out docTypeGuid))
47+
contentTypeAlias = Services.ContentTypeService.GetAliasByGuid(docTypeGuid);
48+
4649
var contentType = Services.ContentTypeService.GetContentType(contentTypeAlias);
4750
return new
4851
{

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
using System.Web.Mvc;
33
using System.Web.Mvc.Html;
44
using Our.Umbraco.DocTypeGridEditor.Extensions;
5+
using Umbraco.Core;
56
using Umbraco.Core.Models;
67
using Umbraco.Web;
8+
using Content = System.Web.UI.WebControls.Content;
79

810
namespace Our.Umbraco.DocTypeGridEditor.Web.Extensions
911
{
1012
public static class HtmlHelperExtensions
1113
{
1214
public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
1315
IPublishedContent content,
16+
string editorAlias = "",
1417
string viewPath = "",
1518
string previewViewPath = "")
1619
{
@@ -25,12 +28,20 @@ public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
2528
if (!string.IsNullOrWhiteSpace(previewViewPath))
2629
previewViewPath = previewViewPath.TrimEnd('/') + "/";
2730

28-
var actionName = content.DocumentTypeAlias;
29-
3031
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
31-
if (umbracoHelper.SurfaceControllerExists(controllerName, actionName, true))
32+
if (!editorAlias.IsNullOrWhiteSpace() && umbracoHelper.SurfaceControllerExists(controllerName, editorAlias, true))
3233
{
33-
return helper.Action(actionName, controllerName, new
34+
return helper.Action(editorAlias, controllerName, new
35+
{
36+
dtgeModel = content,
37+
dtgeViewPath = viewPath,
38+
dtgePreviewViewPath = previewViewPath
39+
});
40+
}
41+
42+
if (umbracoHelper.SurfaceControllerExists(controllerName, content.DocumentTypeAlias, true))
43+
{
44+
return helper.Action(content.DocumentTypeAlias, controllerName, new
3445
{
3546
dtgeModel = content,
3647
dtgeViewPath = viewPath,
@@ -42,7 +53,13 @@ public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
4253
if (!string.IsNullOrWhiteSpace(previewViewPath)
4354
&& helper.ViewContext.RequestContext.HttpContext.Request.QueryString["dtgePreview"] == "1")
4455
{
45-
var fullPreviewViewPath = previewViewPath + content.DocumentTypeAlias + ".cshtml";
56+
var fullPreviewViewPath = previewViewPath + editorAlias + ".cshtml";
57+
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
58+
{
59+
return helper.Partial(fullPreviewViewPath, content);
60+
}
61+
62+
fullPreviewViewPath = previewViewPath + content.DocumentTypeAlias + ".cshtml";
4663
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
4764
{
4865
return helper.Partial(fullPreviewViewPath, content);
@@ -52,14 +69,25 @@ public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
5269
// Check for view path view
5370
if (!string.IsNullOrWhiteSpace(viewPath))
5471
{
55-
var fullViewPath = viewPath + content.DocumentTypeAlias + ".cshtml";
72+
var fullViewPath = viewPath + editorAlias + ".cshtml";
5673
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
5774
{
5875
return helper.Partial(fullViewPath, content);
5976
}
77+
78+
fullViewPath = viewPath + content.DocumentTypeAlias + ".cshtml";
79+
if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
80+
{
81+
return helper.Partial(fullViewPath, content);
82+
}
83+
}
84+
85+
// Resort to standard partial views
86+
if (ViewEngines.Engines.ViewExists(helper.ViewContext, editorAlias, true))
87+
{
88+
return helper.Partial(editorAlias, content);
6089
}
6190

62-
// Resort to standard partial view
6391
return helper.Partial(content.DocumentTypeAlias, content);
6492
}
6593
}

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

Lines changed: 68 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@
44
"$rootScope",
55
"$timeout",
66
"$routeParams",
7+
"editorState",
78
'assetsService',
89
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeDialogService",
910
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",
1011

11-
function ($scope, $rootScope, $timeout, $routeParams, assetsService, dtgeDialogService, dtgeResources) {
12+
function ($scope, $rootScope, $timeout, $routeParams, editorState, assetsService, dtgeDialogService, dtgeResources) {
1213

1314
$scope.title = "Click to insert item";
14-
$scope.icon = "icon-item-arrangement";
15+
$scope.icon = "icon-item-arrangement";
1516

16-
$scope.setValue = function (data) {
17+
$scope.setValue = function (data, callback) {
1718
$scope.control.value = data;
1819
if (!("id" in $scope.control.value) || $scope.control.value.id == "") {
1920
$scope.control.value.id = guid();
2021
}
2122
if ("name" in $scope.control.value.value && $scope.control.value.value.name) {
2223
$scope.title = $scope.control.value.value.name;
2324
}
24-
if ("docType" in $scope.control.value && $scope.control.value.docType) {
25-
dtgeResources.getContentTypeIcon($scope.control.value.docType).then(function (data2) {
25+
if ("dtgeContentTypeAlias" in $scope.control.value && $scope.control.value.dtgeContentTypeAlias) {
26+
dtgeResources.getContentTypeIcon($scope.control.value.dtgeContentTypeAlias).then(function (data2) {
2627
if (data2.icon) {
2728
$scope.icon = data2.icon;
2829
}
2930
});
3031
}
32+
if (callback)
33+
callback();
3134
};
3235

3336
$scope.setDocType = function () {
@@ -36,12 +39,12 @@
3639
allowedDocTypes: $scope.control.editor.config.allowedDocTypes || [],
3740
nameTemplate: $scope.control.editor.config.nameTemplate,
3841
dialogData: {
39-
docType: $scope.control.value.docType,
42+
docTypeAlias: $scope.control.value.dtgeContentTypeAlias,
4043
value: $scope.control.value.value
4144
},
4245
callback: function (data) {
4346
$scope.setValue({
44-
docType: data.docType,
47+
dtgeContentTypeAlias: data.docTypeAlias,
4548
value: data.value
4649
});
4750
$scope.setPreview($scope.control.value);
@@ -52,7 +55,7 @@
5255
$scope.setPreview = function (model) {
5356
if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview) {
5457
var nodeId = $routeParams.id;
55-
dtgeResources.getEditorMarkupForDocTypePartial(nodeId, model.id, model.docType, model.value, $scope.control.editor.config.viewPath, $scope.control.editor.config.previewViewPath)
58+
dtgeResources.getEditorMarkupForDocTypePartial(nodeId, model.id, $scope.control.editor.alias, model.dtgeContentTypeAlias, model.value, $scope.control.editor.config.viewPath, $scope.control.editor.config.previewViewPath)
5659
.success(function(htmlResult) {
5760
if (htmlResult.trim().length > 0) {
5861
$scope.preview = htmlResult;
@@ -61,11 +64,38 @@
6164
}
6265
};
6366

64-
$scope.setValue($scope.control.value || {
65-
id: guid(),
66-
docType: "",
67-
value: {}
68-
});
67+
function init() {
68+
$timeout(function () {
69+
if ($scope.control.$initializing) {
70+
$scope.setDocType();
71+
} else if ($scope.control.value) {
72+
$scope.setPreview($scope.control.value);
73+
}
74+
}, 200);
75+
}
76+
77+
if ($scope.control.value) {
78+
if (!$scope.control.value.dtgeContentTypeAlias && $scope.control.value.docType) {
79+
$scope.control.value.dtgeContentTypeAlias = $scope.control.value.docType;
80+
}
81+
if ($scope.control.value.docType) {
82+
delete $scope.control.value.docType;
83+
}
84+
if (isGuid($scope.control.value.dtgeContentTypeAlias)) {
85+
dtgeResources.getContentTypeAliasByGuid($scope.control.value.dtgeContentTypeAlias).then(function(data1) {
86+
$scope.control.value.dtgeContentTypeAlias = data1.alias;
87+
$scope.setValue($scope.control.value, init);
88+
});
89+
} else {
90+
$scope.setValue($scope.control.value, init);
91+
}
92+
} else {
93+
$scope.setValue({
94+
id: guid(),
95+
dtgeContentTypeAlias: "",
96+
value: {}
97+
}, init);
98+
}
6999

70100
// Load preview css / js files
71101
if ("enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview)
@@ -79,14 +109,6 @@
79109
}
80110
}
81111

82-
$timeout(function () {
83-
if ($scope.control.$initializing) {
84-
$scope.setDocType();
85-
} else if ($scope.control.value) {
86-
$scope.setPreview($scope.control.value);
87-
}
88-
}, 200);
89-
90112
function guid() {
91113
function s4() {
92114
return Math.floor((1 + Math.random()) * 0x10000)
@@ -97,6 +119,10 @@
97119
s4() + '-' + s4() + s4() + s4();
98120
}
99121

122+
function isGuid(input) {
123+
return new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", "i").test(input.toString());
124+
}
125+
100126
}
101127
]);
102128

@@ -122,7 +148,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
122148

123149
$scope.selectDocType = function () {
124150
$scope.dialogMode = "edit";
125-
$scope.dialogData.docType = $scope.selectedDocType.guid;
151+
$scope.dialogData.docTypeAlias = $scope.selectedDocType.alias;
126152
loadNode();
127153
};
128154

@@ -164,33 +190,30 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
164190
};
165191

166192
function loadNode() {
167-
dtgeResources.getContentAliasByGuid($scope.dialogData.docType).then(function (data1) {
168-
contentResource.getScaffold(-20, data1.alias).then(function (data) {
169-
// Remove the last tab
170-
data.tabs.pop();
171-
172-
// Merge current value
173-
if ($scope.dialogData.value) {
174-
for (var t = 0; t < data.tabs.length; t++) {
175-
var tab = data.tabs[t];
176-
for (var p = 0; p < tab.properties.length; p++) {
177-
var prop = tab.properties[p];
178-
if ($scope.dialogData.value[prop.alias]) {
179-
prop.value = $scope.dialogData.value[prop.alias];
180-
}
193+
contentResource.getScaffold(-20, $scope.dialogData.docTypeAlias).then(function (data) {
194+
// Remove the last tab
195+
data.tabs.pop();
196+
197+
// Merge current value
198+
if ($scope.dialogData.value) {
199+
for (var t = 0; t < data.tabs.length; t++) {
200+
var tab = data.tabs[t];
201+
for (var p = 0; p < tab.properties.length; p++) {
202+
var prop = tab.properties[p];
203+
console.log(prop.alias);
204+
if ($scope.dialogData.value[prop.alias]) {
205+
prop.value = $scope.dialogData.value[prop.alias];
181206
}
182207
}
183-
};
184-
185-
// Assign the model to scope
186-
$scope.nodeContext = $scope.node = data;
208+
}
209+
};
187210

188-
//editorState.set($scope.node);
189-
});
211+
// Assign the model to scope
212+
$scope.nodeContext = $scope.node = data;
190213
});
191-
};
214+
}
192215

193-
if ($scope.dialogData.docType) {
216+
if ($scope.dialogData.docTypeAlias) {
194217
$scope.dialogMode = "edit";
195218
loadNode();
196219
} else {
@@ -199,7 +222,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
199222
dtgeResources.getContentTypes($scope.dialogOptions.allowedDocTypes).then(function (docTypes) {
200223
$scope.docTypes = docTypes;
201224
if ($scope.docTypes.length == 1) {
202-
$scope.dialogData.docType = $scope.docTypes[0].guid;
225+
$scope.dialogData.docTypeAlias = $scope.docTypes[0].alias;
203226
$scope.dialogMode = "edit";
204227
loadNode();
205228
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
angular.module('umbraco.resources').factory('Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources',
22
function ($q, $http, umbRequestHelper) {
33
return {
4-
getContentAliasByGuid: function (guid) {
4+
getContentTypeAliasByGuid: function (guid) {
55
var url = "/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetContentTypeAliasByGuid?guid=" + guid;
66
return umbRequestHelper.resourcePromise(
77
$http.get(url),
@@ -20,8 +20,8 @@
2020
'Failed to retrieve content types'
2121
);
2222
},
23-
getContentTypeIcon: function (guid) {
24-
var url = "/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetContentTypeIcon?guid=" + guid;
23+
getContentTypeIcon: function (contentTypeAlias) {
24+
var url = "/umbraco/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetContentTypeIcon?contentTypeAlias=" + contentTypeAlias;
2525
return umbRequestHelper.resourcePromise(
2626
$http.get(url),
2727
'Failed to retrieve content type icon'
@@ -34,14 +34,15 @@
3434
'Failed to retrieve datatypes'
3535
);
3636
},
37-
getEditorMarkupForDocTypePartial: function (nodeId, id, docType, value, viewPath, previewViewPath) {
37+
getEditorMarkupForDocTypePartial: function (nodeId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath) {
3838
var url = "/" + nodeId +"?dtgePreview=1";
3939
return $http({
4040
method: 'POST',
4141
url: url,
4242
data: $.param({
4343
id: id,
44-
docType: docType,
44+
editorAlias: editorAlias,
45+
contentTypeAlias: contentTypeAlias,
4546
value: JSON.stringify(value),
4647
viewPath: viewPath,
4748
previewViewPath: previewViewPath
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
@using System.Web.Mvc
22
@using System.Web.Mvc.Html
3+
@using Microsoft.CSharp.RuntimeBinder
34
@using Our.Umbraco.DocTypeGridEditor.Helpers
45
@using Our.Umbraco.DocTypeGridEditor.Web.Extensions
56
@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
67
@if (Model.value != null)
78
{
89
string id = Model.value.id.ToString();
9-
string docType = Model.value.docType.ToString();
10+
string editorAlias = Model.editor.alias.ToString();
11+
string contentTypeAlias = "";
1012
string value = Model.value.value.ToString();
1113
string viewPath = Model.editor.config.viewPath.ToString();
12-
string previewViewPath = Model.editor.config.previewViewPath.ToString();
13-
14-
if(docType != "")
15-
{
16-
var content = DocTypeGridEditorHelper.ConvertValueToContent(id, docType, value);
14+
15+
try
16+
{
17+
contentTypeAlias = Model.value.dtgeContentTypeAlias.ToString();
18+
}
19+
catch (RuntimeBinderException)
20+
{
21+
contentTypeAlias = Model.value.docType.ToString();
22+
}
23+
24+
if (contentTypeAlias != "")
25+
{
26+
var content = DocTypeGridEditorHelper.ConvertValueToContent(id, contentTypeAlias, value);
1727

18-
@Html.RenderDocTypeGridEditorItem(content, viewPath)
28+
@Html.RenderDocTypeGridEditorItem(content, editorAlias, viewPath)
1929
}
2030
}

0 commit comments

Comments
 (0)