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

Commit 67ece28

Browse files
committed
enables blueprints, config setting for choosing between grid/list when selecting doctype, makes dialog header responsive to dialogMode
1 parent 3c759d6 commit 67ece28

File tree

4 files changed

+128
-51
lines changed

4 files changed

+128
-51
lines changed

docs/developers-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ The **Doc Type Grid Editor** supports 3 config options, all of which are optiona
8989
| EnablePreview | Boolean | Enables rendering a preview of the grid cell in the grid editor. |
9090
| LargeDialog | Boolean | Makes the editing dialog larger. Especially useful for grid editors with complex property editors. |
9191
| ViewPath | String | Set's an alternative view path for where the **Doc Type Grid Editor** should look for views when rendering. Defaults to `~/Views/Partials/` |
92+
| ShowDocTypeSelectAsGrid | Boolean | Makes the content type selection dialog render a grid, in stead of the default list with descriptions |
9293

9394
---
9495

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,28 @@ public IEnumerable<object> GetContentTypes([ModelBinder] string[] allowedContent
5959
{
6060
var allContentTypes = Current.Services.ContentTypeService.GetAll().ToList();
6161
var contentTypes = allContentTypes
62+
.Where(x => x.IsElement)
6263
.Where(x => allowedContentTypes == null || allowedContentTypes.Length == 0 || allowedContentTypes.Any(y => Regex.IsMatch(x.Alias, y)))
6364
.OrderBy(x => x.Name)
65+
.ToList();
66+
67+
var blueprints = Current.Services.ContentService.GetBlueprintsForContentTypes(contentTypes.Select(x => x.Id).ToArray()).ToArray();
68+
69+
return contentTypes
6470
.Select(x => new
6571
{
6672
id = x.Id,
6773
guid = x.Key,
6874
name = x.Name,
6975
alias = x.Alias,
7076
description = x.Description,
71-
icon = x.Icon
77+
icon = x.Icon,
78+
blueprints = blueprints.Where(bp => bp.ContentTypeId == x.Id).Select(bp => new
79+
{
80+
id = bp.Id,
81+
name = bp.Name
82+
})
7283
});
73-
74-
//foreach (var contentType in allContentTypes)
75-
//{
76-
// var firstGroup = contentType.PropertyGroups.FirstOrDefault();
77-
// if(firstGroup != null)
78-
// foreach (var prop in firstGroup.PropertyTypes)
79-
// {
80-
// var test = GetDataTypePreValues(prop.DataTypeId.ToString());
81-
// }
82-
83-
//}
84-
85-
return contentTypes;
8684
}
8785

8886
[HttpGet]

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

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@
1111

1212
function ($scope, $timeout, editorState, assetsService, dtgeResources, umbRequestHelper, localizationService, editorService) {
1313

14-
const defaultTitle = "Click to insert item",
15-
defaultSelectContentTypeLabel = "Choose a Content Type",
16-
defaultOverlayTitle = "Edit item";
17-
18-
$scope.title = defaultTitle;
19-
$scope.selectContentTypeLabel = defaultSelectContentTypeLabel;
20-
21-
var overlayTitle = defaultOverlayTitle;
22-
2314
var overlayOptions = {
2415
view: umbRequestHelper.convertVirtualToAbsolutePath(
2516
"~/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.dialog.html"),
26-
model: {}
17+
model: {},
18+
titles: {
19+
insertItem: "Click to insert item",
20+
editItem: "Edit item",
21+
selectContentType: "Choose a Content Type",
22+
selectBlueprint: "Choose a Content Template"
23+
},
24+
title: "Edit item",
25+
submitButtonlabelKey: "bulk_done"
2726
};
2827

2928
$scope.icon = "icon-item-arrangement";
3029

3130
// localize strings
32-
localizationService.localizeMany(["docTypeGridEditor_insertItem", "docTypeGridEditor_editItem", "docTypeGridEditor_selectContentType"]).then(function (data) {
33-
if ($scope.title === defaultTitle) $scope.title = data[0];
34-
if (overlayTitle === defaultOverlayTitle) overlayTitle = data[1];
35-
if ($scope.selectContentTypeLabel === defaultSelectContentTypeLabel) $scope.selectContentTypeLabel = data[2];
31+
localizationService.localizeMany(["docTypeGridEditor_insertItem", "docTypeGridEditor_editItem", "docTypeGridEditor_selectContentType", "blueprints_selectBlueprint"]).then(function (data) {
32+
overlayOptions.titles.insertItem = data[0];
33+
overlayOptions.titles.editItem = data[1];
34+
overlayOptions.titles.selectContentType = data[2];
35+
overlayOptions.titles.selectBlueprint = data[3];
3636
});
3737

3838
$scope.setValue = function (data, callback) {
@@ -56,10 +56,9 @@
5656

5757
$scope.setDocType = function () {
5858

59-
overlayOptions.title = overlayTitle;
60-
overlayOptions.submitButtonLabelKey = "bulk_done";
6159
overlayOptions.editorName = $scope.control.editor.name;
6260
overlayOptions.allowedDocTypes = $scope.control.editor.config.allowedDocTypes || [];
61+
overlayOptions.showDocTypeSelectAsGrid = $scope.control.editor.config.showDocTypeSelectAsGrid === true;
6362
overlayOptions.nameTemplate = $scope.control.editor.config.nameTemplate;
6463
overlayOptions.size = $scope.control.editor.config.largeDialog ? null : "small";
6564

@@ -202,13 +201,16 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
202201
"contentResource",
203202
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",
204203
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeGridEditorUtilityService",
204+
"blueprintConfig",
205205

206-
function ($scope, $interpolate, formHelper, contentResource, dtgeResources, dtgeUtilityService) {
206+
function ($scope, $interpolate, formHelper, contentResource, dtgeResources, dtgeUtilityService, blueprintConfig) {
207207

208208
var vm = this;
209209
vm.submit = submit;
210210
vm.close = close;
211211
vm.loading = true;
212+
vm.blueprintConfig = blueprintConfig;
213+
212214
function submit() {
213215
if ($scope.model.submit) {
214216
$scope.$broadcast('formSubmitting', { scope: $scope });
@@ -232,12 +234,42 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
232234

233235
$scope.model.nameExp = nameExp;
234236

235-
$scope.selectDocType = function (alias) {
237+
function createBlank() {
236238
$scope.dialogMode = "edit";
237-
$scope.model.dialogData.docTypeAlias = alias;
238239
loadNode();
239240
};
240241

242+
function createOrSelectBlueprintIfAny(docType) {
243+
244+
$scope.model.dialogData.docTypeAlias = docType.alias;
245+
var blueprintIds = _.keys(docType.blueprints || {});
246+
$scope.selectedDocType = docType;
247+
248+
if (blueprintIds.length) {
249+
if (blueprintConfig.skipSelect) {
250+
createFromBlueprint(blueprintIds[0]);
251+
} else {
252+
$scope.dialogMode = "selectBlueprint";
253+
}
254+
} else {
255+
createBlank();
256+
}
257+
};
258+
259+
function createFromBlueprint(blueprintId) {
260+
contentResource.getBlueprintScaffold(-20, blueprintId).then(function (data) {
261+
// Assign the model to scope
262+
$scope.nodeContext = $scope.model.node = data;
263+
$scope.dialogMode = "edit";
264+
vm.content = $scope.nodeContext.variants[0];
265+
vm.loading = false;
266+
});
267+
};
268+
269+
$scope.createBlank = createBlank;
270+
$scope.createOrSelectBlueprintIfAny = createOrSelectBlueprintIfAny;
271+
$scope.createFromBlueprint = createFromBlueprint;
272+
241273
function loadNode() {
242274
vm.loading = true;
243275
contentResource.getScaffold(-20, $scope.model.dialogData.docTypeAlias).then(function (data) {
@@ -274,9 +306,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
274306
dtgeResources.getContentTypes($scope.model.allowedDocTypes).then(function (docTypes) {
275307
$scope.docTypes = docTypes;
276308
if ($scope.docTypes.length == 1) {
277-
$scope.model.dialogData.docTypeAlias = $scope.docTypes[0].alias;
278-
$scope.dialogMode = "edit";
279-
loadNode();
309+
createOrSelectBlueprintIfAny($scope.docTypes[0]);
280310
}
281311
else {
282312
vm.loading = false;

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

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<div class="dtge-dialog" ng-controller="Our.Umbraco.DocTypeGridEditor.Dialogs.DocTypeGridEditorDialog as vm">
2-
2+
33
<umb-editor-view>
4-
<umb-editor-header name="model.title"
4+
<umb-editor-header name="dialogMode == 'selectDocType' ? model.titles.selectContentType : dialogMode == 'selectBlueprint' ? model.titles.selectBlueprint : dialogMode == 'edit' ? model.titles.editItem : model.titles.insertItem"
55
name-locked="true"
66
hide-alias="true"
77
hide-icon="true"
88
hide-description="true">
99
</umb-editor-header>
10-
<umb-editor-container ng-if="!vm.loading && dialogMode == 'edit'">
11-
<ng-form val-form-manager>
12-
<umb-tabbed-content content="vm.content"></umb-tabbed-content>
13-
</ng-form>
14-
</umb-editor-container>
15-
<umb-editor-container ng-if="!vm.loading && dialogMode == 'selectDocType'">
16-
<umb-box>
17-
<umb-box-content>
18-
<div class="form-search" ng-hide="model.filter === false" style="margin-bottom: 15px;">
10+
<umb-editor-container ng-if="!vm.loading">
11+
12+
<div ng-switch="dialogMode">
13+
<div ng-switch-when="selectDocType">
14+
15+
<p class="abstract" ng-if="docTypes && docTypes.length === 0">
16+
<localize key="create_noDocumentTypes" />
17+
</p>
18+
19+
<div class="form-search" ng-hide="docTypes.length < 0 && model.filter === false" style="margin-bottom: 15px;">
1920
<i class="icon-search"></i>
2021
<input type="text"
2122
ng-model="searchTerm"
@@ -26,9 +27,25 @@
2627
no-dirty-check />
2728
</div>
2829

29-
<ul class="umb-card-grid -three-in-row">
30+
<ul class="umb-actions umb-actions-child" ng-if="docTypes.length > 0 && !model.showDocTypeSelectAsGrid">
31+
32+
<li class="umb-action" ng-repeat="docType in docTypes | orderBy:'name' | filter:searchTerm">
33+
<a class="umb-action-link" ng-click="createOrSelectBlueprintIfAny(docType)">
34+
<i class="large icon {{docType.icon}}"></i>
35+
<span class="menu-label">
36+
{{docType.name}}
37+
<small>
38+
{{docType.description}}
39+
</small>
40+
</span>
41+
</a>
42+
</li>
43+
44+
</ul>
45+
46+
<ul class="umb-card-grid -three-in-row" ng-if="docTypes.length > 0 && model.showDocTypeSelectAsGrid">
3047
<li ng-repeat="docType in docTypes | orderBy:'name' | filter:searchTerm"
31-
ng-click="selectDocType(docType.alias)">
48+
ng-click="createOrSelectBlueprintIfAny(docType)">
3249
<a class="umb-card-grid-item" href="" title="{{ docType.name }}">
3350
<span>
3451
<i class="{{ docType.icon }}"></i>
@@ -37,9 +54,40 @@
3754
</a>
3855
</li>
3956
</ul>
40-
</umb-box-content>
41-
</umb-box>
57+
</div>
58+
59+
60+
<div ng-switch-when="selectBlueprint">
61+
62+
<ul class="umb-actions umb-actions-child">
63+
64+
<li class="umb-action" ng-repeat="blueprint in selectedDocType.blueprints | orderBy:'name':false">
65+
<a class="umb-action-link" ng-click="createFromBlueprint(blueprint.id)">
66+
<i class="large icon {{selectedDocType.icon}}"></i>
67+
<span class="menu-label">
68+
{{blueprint.name}}
69+
</span>
70+
</a>
71+
</li>
72+
73+
<li class="umb-action sep" ng-show="vm.blueprintConfig.allowBlank">
74+
<a class="umb-action-link" ng-click="createBlank()">
75+
<i class="large icon {{selectedDocType.icon}}"></i>
76+
<span class="menu-label">
77+
<localize key="blueprints_blankBlueprint">Blank</localize>
78+
</span>
79+
</a>
80+
</li>
81+
82+
</ul>
83+
</div>
84+
<ng-form val-form-manager ng-switch-when="edit">
85+
<umb-tabbed-content content="vm.content"></umb-tabbed-content>
86+
</ng-form>
87+
</div>
88+
4289
</umb-editor-container>
90+
4391
<umb-editor-footer>
4492
<umb-editor-footer-content-right>
4593
<umb-button type="button"

0 commit comments

Comments
 (0)