diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index cd763f4e32..d2a2a780b7 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -32,13 +32,14 @@ namespace Umbraco.Core.Persistence.Repositories internal class ContentBlueprintRepository : ContentRepository { public ContentBlueprintRepository(IScopeUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider syntaxProvider, IContentTypeRepository contentTypeRepository, ITemplateRepository templateRepository, ITagRepository tagRepository, IContentSection contentSection) : base(work, cacheHelper, logger, syntaxProvider, contentTypeRepository, templateRepository, tagRepository, contentSection) - { + { } protected override Guid NodeObjectTypeId { get { return Constants.ObjectTypes.DocumentBlueprintGuid; } - } + } + } /// diff --git a/src/Umbraco.Core/Persistence/RepositoryFactory.cs b/src/Umbraco.Core/Persistence/RepositoryFactory.cs index 3b8a2be53a..114d3ee95f 100644 --- a/src/Umbraco.Core/Persistence/RepositoryFactory.cs +++ b/src/Umbraco.Core/Persistence/RepositoryFactory.cs @@ -156,8 +156,9 @@ namespace Umbraco.Core.Persistence CreateTemplateRepository(uow), CreateTagRepository(uow), _settings.Content) - { - EnsureUniqueNaming = _settings.Content.EnsureUniqueNaming + { + //duplicates are allowed + EnsureUniqueNaming = false }; } diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 97972c178f..4f0d101379 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -1153,6 +1153,15 @@ namespace Umbraco.Core.Services return ((IContentServiceOperations)this).SaveAndPublish(content, userId, raiseEvents); } + public IContent GetBlueprintById(int id) + { + using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) + { + var repository = RepositoryFactory.CreateContentBlueprintRepository(uow); + return repository.Get(id); + } + } + public void SaveBlueprint(IContent content, int userId = 0) { //always ensure the blueprint is at the root diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs index 5e949b0b89..b5416e750f 100644 --- a/src/Umbraco.Core/Services/IContentService.cs +++ b/src/Umbraco.Core/Services/IContentService.cs @@ -97,6 +97,7 @@ namespace Umbraco.Core.Services public interface IContentService : IContentServiceBase { IEnumerable GetBlueprintsForContentTypes(params int[] documentTypeIds); + IContent GetBlueprintById(int id); void SaveBlueprint(IContent content, int userId = 0); void DeleteBlueprint(IContent content, int userId = 0); IContent CreateContentFromBlueprint(IContent blueprint, string name, int userId = 0); diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index aa1a8b08b0..2b14f46727 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -230,7 +230,8 @@ templateUrl: 'views/components/content/edit.html', scope: { contentId: "=", - createOptions: "=" + createOptions: "=?", + page: "=?" }, link: link }; diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index 98816fe490..8cc8db635d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -269,6 +269,16 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { 'Failed to delete item ' + id); }, + deleteBlueprint: function (id) { + return umbRequestHelper.resourcePromise( + $http.post( + umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "DeleteBlueprint", + [{ id: id }])), + 'Failed to delete blueprint ' + id); + }, + /** * @ngdoc method * @name umbraco.resources.contentResource#getById diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js index aa87044530..6c549d7a05 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js @@ -9,6 +9,7 @@ function ContentEditController($scope, $routeParams) { $scope.contentId = $routeParams.id; + $scope.page = $routeParams.page; $scope.createOptions = null; if ($routeParams.create && $routeParams.doctype) { $scope.createOptions = { diff --git a/src/Umbraco.Web.UI.Client/src/views/content/edit.html b/src/Umbraco.Web.UI.Client/src/views/content/edit.html index 432d0ba19e..c36c41eb32 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/edit.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/edit.html @@ -1,5 +1,6 @@
+ content-id="contentId" + page="page">
diff --git a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/delete.controller.js b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/delete.controller.js index feae545a3e..cc5e4b32a9 100644 --- a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/delete.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/delete.controller.js @@ -6,14 +6,14 @@ * @description * The controller for deleting content blueprints */ -function ContentBlueprintDeleteController($scope, codefileResource, treeService, navigationService) { +function ContentBlueprintDeleteController($scope, contentResource, treeService, navigationService) { $scope.performDelete = function() { //mark it for deletion (used in the UI) $scope.currentNode.loading = true; - codefileResource.deleteByPath('partialViews', $scope.currentNode.id) + contentResource.deleteBlueprint($scope.currentNode.id) .then(function() { $scope.currentNode.loading = false; //get the root node before we remove it diff --git a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.controller.js new file mode 100644 index 0000000000..49d4d74562 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.controller.js @@ -0,0 +1,13 @@ +/** + * @ngdoc controller + * @name Umbraco.Editors.Content.EditController + * @function + * + * @description + * The controller for the content editor + */ +function ContentBlueprintEditController($scope, $routeParams) { + $scope.contentId = $routeParams.id; +} + +angular.module("umbraco").controller("Umbraco.Editors.ContentBlueprint.EditController", ContentEditController); diff --git a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.html b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.html index 04d4259e09..940d2acb3a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.html +++ b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.html @@ -1,3 +1,4 @@ -
- +
+ +
diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 39a4b850d3..778258d931 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -282,16 +282,27 @@ namespace Umbraco.Web.Editors /// The name of the blueprint /// [HttpPost] - public IHttpActionResult CreateBlueprintFromContent([FromUri]int contentId, [FromUri]string name) + public HttpResponseMessage CreateBlueprintFromContent([FromUri]int contentId, [FromUri]string name) { var content = Services.ContentService.GetById(contentId); - if (content == null) return NotFound(); + if (content == null) return Request.CreateResponse(HttpStatusCode.NotFound); + + var existing = Services.ContentService.GetBlueprintsForContentTypes(content.ContentTypeId); + if (existing.Any(x => x.Name == name)) + { + //not allowed + var notificationModel = new SimpleNotificationModel(); + notificationModel.AddSuccessNotification( + "Error", + "Another Blueprint with the same name already exists"); + return Request.CreateValidationErrorResponse(notificationModel); + } var blueprint = Services.ContentService.CreateContentFromBlueprint(content, name, Security.GetUserId()); Services.ContentService.SaveBlueprint(blueprint, Security.GetUserId()); - return Ok(); + return Request.CreateResponse(HttpStatusCode.OK); } /// @@ -453,6 +464,22 @@ namespace Umbraco.Web.Editors } + [HttpDelete] + [HttpPost] + public HttpResponseMessage DeleteBlueprint(int id) + { + var found = Services.ContentService.GetBlueprintById(id); + + if (found == null) + { + return HandleContentNotFound(id, false); + } + + Services.ContentService.DeleteBlueprint(found); + + return Request.CreateResponse(HttpStatusCode.OK); + } + /// /// Moves an item to the recycle bin, if it is already there then it will permanently delete it ///