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

Commit 4964aaa

Browse files
skttlleekelleher
authored andcommitted
Adds support for blueprints
- an array of available blueprints is added to the output of GetContentTypes - new methods are added to the dialog controller, to handle blueprints. - blueprint scaffold is loaded using the contentResource
1 parent acfc3b4 commit 4964aaa

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,22 @@ public object GetContentTypeAliasByGuid([ModelBinder] Guid guid)
2727
[HttpGet]
2828
public IEnumerable<object> GetContentTypes([ModelBinder] string[] allowedContentTypes)
2929
{
30-
return Services.ContentTypeService.GetAllContentTypes()
30+
var contentTypes = Services.ContentTypeService.GetAllContentTypes()
3131
.Where(x => allowedContentTypes == null || allowedContentTypes.Length == 0 || allowedContentTypes.Any(y => Regex.IsMatch(x.Alias, y)))
3232
.OrderBy(x => x.Name)
33+
.ToList();
34+
var blueprints = Services.ContentService.GetBlueprintsForContentTypes(contentTypes.Select(x => x.Id).ToArray()).ToArray();
35+
36+
return contentTypes
3337
.Select(x => new
3438
{
3539
id = x.Id,
3640
guid = x.Key,
3741
name = x.Name,
3842
alias = x.Alias,
3943
description = x.Description,
40-
icon = x.Icon
44+
icon = x.Icon,
45+
blueprints = blueprints.Where(bp => bp.ContentTypeId == x.Id).ToDictionary(bp => bp.Id, bp => bp.Name)
4146
});
4247
}
4348

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
195195
"contentResource",
196196
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",
197197
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeGridEditorUtilityService",
198+
"blueprintConfig",
198199

199-
function ($scope, $interpolate, formHelper, contentResource, dtgeResources, dtgeUtilityService) {
200+
function ($scope, $interpolate, formHelper, contentResource, dtgeResources, dtgeUtilityService, blueprintConfig) {
200201

201202
$scope.docTypes = [];
202203
$scope.dialogMode = "selectDocType";
@@ -208,13 +209,41 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
208209
: undefined;
209210

210211
$scope.model.nameExp = nameExp;
211-
212-
$scope.selectDocType = function (alias) {
212+
213+
function createBlank() {
213214
$scope.dialogMode = "edit";
214-
$scope.model.dialogData.docTypeAlias = alias;
215215
loadNode();
216216
};
217217

218+
function createOrSelectBlueprintIfAny(docType) {
219+
220+
$scope.model.dialogData.docTypeAlias = docType.alias;
221+
var blueprintIds = _.keys(docType.blueprints || {});
222+
$scope.selectedDocType = docType;
223+
224+
if (blueprintIds.length) {
225+
if (blueprintConfig.skipSelect) {
226+
createFromBlueprint(blueprintIds[0]);
227+
} else {
228+
$scope.dialogMode = "selectBlueprint";
229+
}
230+
} else {
231+
createBlank();
232+
}
233+
};
234+
235+
function createFromBlueprint(blueprintId) {
236+
contentResource.getBlueprintScaffold(-20, blueprintId).then(function (data) {
237+
// Assign the model to scope
238+
$scope.nodeContext = $scope.model.node = data;
239+
$scope.dialogMode = "edit";
240+
});
241+
};
242+
243+
$scope.createBlank = createBlank;
244+
$scope.createOrSelectBlueprintIfAny = createOrSelectBlueprintIfAny;
245+
$scope.createFromBlueprint = createFromBlueprint;
246+
218247
function loadNode() {
219248
contentResource.getScaffold(-20, $scope.model.dialogData.docTypeAlias).then(function (data) {
220249

@@ -250,9 +279,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
250279
dtgeResources.getContentTypes($scope.model.allowedDocTypes).then(function (docTypes) {
251280
$scope.docTypes = docTypes;
252281
if ($scope.docTypes.length == 1) {
253-
$scope.model.dialogData.docTypeAlias = $scope.docTypes[0].alias;
254-
$scope.dialogMode = "edit";
255-
loadNode();
282+
createOrSelectBlueprintIfAny($scope.docTypes[0]);
256283
}
257284
});
258285
}

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.dialog.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<umb-control-group label="{{selectContentTypeLabel}}" ng-switch-when="selectDocType">
55
<ul class="umb-actions umb-actions-child">
66
<li data-element="action-create-{{docType.alias}}" ng-repeat="docType in docTypes | orderBy:'name':false">
7-
<a ng-click="selectDocType(docType.alias)">
7+
<a ng-click="createOrSelectBlueprintIfAny(docType)">
88
<i class="large {{docType.icon}}"></i>
99
<span class="menu-label">
1010
{{docType.name}}
@@ -17,6 +17,29 @@
1717
</ul>
1818
</umb-control-group>
1919

20+
<div ng-switch-when="selectBlueprint">
21+
<h5>Select a blueprint</h5>
22+
23+
<ul class="umb-actions umb-actions-child">
24+
<li ng-repeat="(key, value) in selectedDocType.blueprints | orderBy:'name':false">
25+
<a ng-click="createFromBlueprint(key)">
26+
<i class="large {{selectedDocType.icon}}"></i>
27+
<span class="menu-label">
28+
{{value}}
29+
</span>
30+
</a>
31+
</li>
32+
<li class="sep" ng-show="allowBlank">
33+
<a ng-click="createBlank()">
34+
<i class="large {{selectedDocType.icon}}"></i>
35+
<span class="menu-label">
36+
<localize key="blueprints_blankBlueprint">Blank</localize>
37+
</span>
38+
</a>
39+
</li>
40+
</ul>
41+
</div>
42+
2043
<div ng-switch-when="edit">
2144

2245
<fieldset ng-repeat="tab in model.node.tabs">

0 commit comments

Comments
 (0)