Merge pull request #2604 from umbraco/temp-U4-11276

Implements doc type collections | connects #73
This commit is contained in:
Robert
2018-06-26 23:58:35 -07:00
committed by GitHub
6 changed files with 177 additions and 5 deletions

View File

@@ -290,14 +290,22 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
'Failed to copy content');
},
createContainer: function(parentId, name) {
createContainer: function (parentId, name) {
return umbRequestHelper.resourcePromise(
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostCreateContainer", { parentId: parentId, name: name })),
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostCreateContainer", { parentId: parentId, name: name })),
'Failed to create a folder under parent id ' + parentId);
},
createCollection: function (parentId, collectionName, collectionItemName, collectionIcon, collectionItemIcon) {
return umbRequestHelper.resourcePromise(
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostCreateCollection", { parentId: parentId, collectionName: collectionName, collectionItemName: collectionItemName, collectionIcon: collectionIcon, collectionItemIcon: collectionItemIcon})),
'Failed to create collection under ' + parentId);
},
renameContainer: function(id, name) {
return umbRequestHelper.resourcePromise(

View File

@@ -6,12 +6,13 @@
* @description
* The controller for the doc type creation dialog
*/
function DocumentTypesCreateController($scope, $location, navigationService, contentTypeResource, formHelper, appState, notificationsService, localizationService) {
function DocumentTypesCreateController($scope, $location, navigationService, contentTypeResource, formHelper, appState, notificationsService, localizationService, iconHelper) {
$scope.model = {
allowCreateFolder: $scope.dialogOptions.currentNode.parentId === null || $scope.dialogOptions.currentNode.nodeType === "container",
folderName: "",
creatingFolder: false,
creatingDoctypeCollection: false
};
var disableTemplates = Umbraco.Sys.ServerVariables.features.disabledFeatures.disableTemplates;
@@ -24,6 +25,10 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
$scope.model.creatingFolder = true;
};
$scope.showCreateDocTypeCollection = function () {
$scope.model.creatingDoctypeCollection = true;
};
$scope.createContainer = function () {
if (formHelper.submitForm({ scope: $scope, formCtrl: this.createFolderForm, statusMessage: localizeCreateFolder })) {
@@ -61,6 +66,54 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
}
};
$scope.createCollection = function () {
if (formHelper.submitForm({ scope: $scope, formCtrl: this.createDoctypeCollectionForm, statusMessage: "Creating Doctype Collection..." })) {
// see if we can find matching icons
var collectionIcon = "icon-folders", collectionItemIcon = "icon-document";
iconHelper.getIcons().then(function (icons) {
for (var i = 0; i < icons.length; i++) {
// for matching we'll require a full match for collection, partial match for item
if (icons[i].substring(5) == $scope.model.collectionName.toLowerCase()) {
collectionIcon = icons[i];
} else if (icons[i].substring(5).indexOf($scope.model.collectionItemName.toLowerCase()) > -1) {
collectionItemIcon = icons[i];
}
}
contentTypeResource.createCollection(node.id, $scope.model.collectionName, $scope.model.collectionItemName, collectionIcon, collectionItemIcon).then(function (collectionData) {
navigationService.hideMenu();
$location.search('create', null);
$location.search('notemplate', null);
formHelper.resetForm({
scope: $scope
});
var section = appState.getSectionState("currentSection");
// redirect to the item id
$location.path("/settings/documenttypes/edit/" + collectionData.ItemId);
}, function (err) {
$scope.error = err;
//show any notifications
if (angular.isArray(err.data.notifications)) {
for (var i = 0; i < err.data.notifications.length; i++) {
notificationsService.showNotification(err.data.notifications[i]);
}
}
});
});
}
};
// Disabling logic for creating document type with template if disableTemplates is set to true
if (!disableTemplates) {
$scope.createDocType = function () {

View File

@@ -1,6 +1,6 @@
<div class="umbracoDialog umb-dialog-body with-footer" ng-controller="Umbraco.Editors.DocumentTypes.CreateController" ng-cloak>
<div class="umb-pane" ng-if="!model.creatingFolder">
<div class="umb-pane" ng-if="!model.creatingFolder && !model.creatingDoctypeCollection">
<h5><localize key="create_createUnder">Create an item under</localize> {{currentNode.name}}</h5>
<ul class="umb-actions umb-actions-child">
@@ -24,6 +24,17 @@
</span>
</a>
</li>
<li data-element="action-documentTypeCollection">
<a href="" ng-click="showCreateDocTypeCollection()">
<i class="large icon-thumbnail-list"></i>
<span class="menu-label">
Document Type Collection
<!-- <localize key="content_documentType_collection">Document Type Collection</localize>-->
</span>
</a>
</li>
<li data-element="action-folder" ng-if="model.allowCreateFolder">
<a href="" ng-click="showCreateFolder()">
<i class="large icon-folder"></i>
@@ -51,6 +62,33 @@
</form>
</div>
<div class="umb-pane" ng-if="model.creatingDoctypeCollection">
<small>
A Document Type collection is a fast way to create two Document Types in one task.
The Item Document Type will automatically be
allowed under the Parent Document Type.
</small>
<p>&nbsp;</p>
<form novalidate name="createDoctypeCollectionForm"
ng-submit="createCollection()"
val-form-manager>
<div ng-show="error">
<h5 class="text-error">{{error.errorMsg}}</h5>
<p class="text-error">{{error.data.message}}</p>
</div>
<umb-control-group label="Name of the Parent Document Type" hide-label="false">
<input type="text" name="collectionName" ng-model="model.collectionName" class="umb-textstring textstring input-block-level" umb-auto-focus required />
</umb-control-group>
<umb-control-group label="Name of the Item Document Type" hide-label="false">
<input type="text" name="collectionItemName" ng-model="model.collectionItemName" class="umb-textstring textstring input-block-level" required />
</umb-control-group>
<button type="submit" class="btn btn-primary"><localize key="general_create">Create</localize></button>
</form>
</div>
</div>
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar" ng-if="!model.creatingFolder">

View File

@@ -206,6 +206,64 @@ namespace Umbraco.Web.Editors
? Request.CreateResponse(HttpStatusCode.OK, result.Result) //return the id
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
public DocumentTypeCollectionDisplay PostCreateCollection(int parentId, string collectionName, string collectionItemName, string collectionIcon, string collectionItemIcon)
{
var storeInContainer = false;
var allowUnderDocType = -1;
// check if it's a folder
if (Services.ContentTypeService.GetContentType(parentId) == null)
{
storeInContainer = true;
} else
{
// if it's not a container, we'll change the parentid to the root,
// and use the parent id as the doc type the collection should be allowed under
allowUnderDocType = parentId;
parentId = -1;
}
// create item doctype
var itemDocType = new ContentType(parentId);
itemDocType.Name = collectionItemName;
itemDocType.Alias = collectionItemName.ToSafeAlias();
itemDocType.Icon = collectionItemIcon;
Services.ContentTypeService.Save(itemDocType);
// create collection doctype
var collectionDocType = new ContentType(parentId);
collectionDocType.Name = collectionName;
collectionDocType.Alias = collectionName.ToSafeAlias();
collectionDocType.Icon = collectionIcon;
collectionDocType.IsContainer = true;
collectionDocType.AllowedContentTypes = new List<ContentTypeSort>()
{
new ContentTypeSort(itemDocType.Id, 0)
};
Services.ContentTypeService.Save(collectionDocType);
// test if the parent id exist and then allow the collection underneath
if (storeInContainer == false && allowUnderDocType != -1)
{
var parentCt = Services.ContentTypeService.GetContentType(allowUnderDocType);
if (parentCt != null)
{
var allowedCts = parentCt.AllowedContentTypes.ToList();
allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
parentCt.AllowedContentTypes = allowedCts;
Services.ContentTypeService.Save(parentCt);
} else
{
}
}
return new DocumentTypeCollectionDisplay
{
CollectionId = collectionDocType.Id,
ItemId = itemDocType.Id
};
}
public DocumentTypeDisplay PostSave(DocumentTypeSave contentTypeSave)
{
@@ -369,4 +427,4 @@ namespace Umbraco.Web.Editors
doCopy: (type, i) => Services.ContentTypeService.CopyContentType(type, i));
}
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Umbraco.Web.Models.ContentEditing
{
public class DocumentTypeCollectionDisplay
{
public int CollectionId { get; set; }
public int ItemId { get; set; }
}
}

View File

@@ -342,6 +342,7 @@
<Compile Include="HealthCheck\Checks\Security\HstsCheck.cs" />
<Compile Include="Models\BackOfficeTourFilter.cs" />
<Compile Include="Models\ContentEditing\BackOfficePreview.cs" />
<Compile Include="Models\ContentEditing\DocumentTypeCollectionDisplay.cs" />
<Compile Include="Models\Mapping\AutoMapperExtensions.cs" />
<Compile Include="Models\Mapping\ContentTreeNodeUrlResolver.cs" />
<Compile Include="Models\Mapping\MemberTreeNodeUrlResolver.cs" />