From d2fe3e7406127162a05de5c856f8135ac8c8ac07 Mon Sep 17 00:00:00 2001 From: Shannon Date: Sun, 4 Jun 2017 20:58:56 +0200 Subject: [PATCH] editing blueprints now working --- .../components/content/edit.controller.js | 13 +++-- .../src/common/resources/content.resource.js | 39 ++++++++++--- .../views/content/content.edit.controller.js | 4 +- .../src/views/content/edit.html | 5 +- .../contentblueprints/edit.controller.js | 6 +- .../src/views/contentblueprints/edit.html | 5 +- src/Umbraco.Web/Editors/ContentController.cs | 56 ++++++++++++++++--- 7 files changed, 102 insertions(+), 26 deletions(-) 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 2b14f46727..60dddff3a5 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 @@ -49,14 +49,14 @@ function syncTreeNode(content, path, initialLoad) { if (!scope.content.isChildOfListView) { - navigationService.syncTree({ tree: "content", path: path.split(","), forceReload: initialLoad !== true }).then(function (syncArgs) { + navigationService.syncTree({ tree: scope.treeAlias, path: path.split(","), forceReload: initialLoad !== true }).then(function (syncArgs) { scope.page.menu.currentNode = syncArgs.node; }); } else if (initialLoad === true) { //it's a child item, just sync the ui node to the parent - navigationService.syncTree({ tree: "content", path: path.substring(0, path.lastIndexOf(",")).split(","), forceReload: initialLoad !== true }); + navigationService.syncTree({ tree: scope.treeAlias, path: path.substring(0, path.lastIndexOf(",")).split(","), forceReload: initialLoad !== true }); //if this is a child of a list view and it's the initial load of the editor, we need to get the tree node // from the server so that we can load in the actions menu. @@ -134,7 +134,7 @@ scope.page.loading = true; //we are editing so get the content item from the server - contentResource.getById(scope.contentId) + scope.getMethod()(scope.contentId) .then(function (data) { scope.content = data; @@ -200,7 +200,7 @@ }; scope.save = function () { - return performSave({ saveMethod: contentResource.save, statusMessage: "Saving...", action: "save" }); + return performSave({ saveMethod: scope.saveMethod(), statusMessage: "Saving...", action: "save" }); }; scope.preview = function (content) { @@ -230,8 +230,11 @@ templateUrl: 'views/components/content/edit.html', scope: { contentId: "=", + treeAlias: "@", createOptions: "=?", - page: "=?" + page: "=?", + saveMethod: "&", + getMethod: "&" }, 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 8cc8db635d..3f3acbef88 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 @@ -26,11 +26,9 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { /** internal method process the saving of data and post processing the result */ - function saveContentItem(content, action, files) { + function saveContentItem(content, action, files, restApiUrl) { return umbRequestHelper.postSaveContent({ - restApiUrl: umbRequestHelper.getApiUrl( - "contentApiBaseUrl", - "PostSave"), + restApiUrl: restApiUrl, content: content, action: action, files: files, @@ -277,7 +275,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { "DeleteBlueprint", [{ id: id }])), 'Failed to delete blueprint ' + id); - }, + }, /** * @ngdoc method @@ -310,6 +308,16 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { 'Failed to retrieve data for content id ' + id); }, + getBlueprintById: function (id) { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "GetBlueprintById", + [{ id: id }])), + 'Failed to retrieve data for content id ' + id); + }, + /** * @ngdoc method * @name umbraco.resources.contentResource#getByIds @@ -574,9 +582,18 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { * */ save: function (content, isNew, files) { - return saveContentItem(content, "save" + (isNew ? "New" : ""), files); + var endpoint = umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "PostSave"); + return saveContentItem(content, "save" + (isNew ? "New" : ""), files, endpoint); }, + saveBlueprint: function (content, isNew, files) { + var endpoint = umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "PostSaveBlueprint"); + return saveContentItem(content, "save" + (isNew ? "New" : ""), files, endpoint); + }, /** * @ngdoc method @@ -607,7 +624,10 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { * */ publish: function (content, isNew, files) { - return saveContentItem(content, "publish" + (isNew ? "New" : ""), files); + var endpoint = umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "PostSave"); + return saveContentItem(content, "publish" + (isNew ? "New" : ""), files, endpoint); }, @@ -638,7 +658,10 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { * */ sendToPublish: function (content, isNew, files) { - return saveContentItem(content, "sendPublish" + (isNew ? "New" : ""), files); + var endpoint = umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "PostSave"); + return saveContentItem(content, "sendPublish" + (isNew ? "New" : ""), files, endpoint); }, /** 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 6c549d7a05..2c2183695f 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 @@ -6,9 +6,11 @@ * @description * The controller for the content editor */ -function ContentEditController($scope, $routeParams) { +function ContentEditController($scope, $routeParams, contentResource) { $scope.contentId = $routeParams.id; + $scope.saveMethod = contentResource.save; + $scope.getMethod = contentResource.getById; $scope.page = $routeParams.page; $scope.createOptions = null; if ($routeParams.create && $routeParams.doctype) { 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 c36c41eb32..bd764628b4 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/edit.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/edit.html @@ -1,6 +1,9 @@
+ page="page" + save-method="saveMethod" + get-method="getMethod" + tree-alias="content">
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 index 49d4d74562..8c98364295 100644 --- a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.controller.js @@ -6,8 +6,10 @@ * @description * The controller for the content editor */ -function ContentBlueprintEditController($scope, $routeParams) { +function ContentBlueprintEditController($scope, $routeParams, contentResource) { $scope.contentId = $routeParams.id; + $scope.saveMethod = contentResource.saveBlueprint; + $scope.getMethod = contentResource.getBlueprintById; } -angular.module("umbraco").controller("Umbraco.Editors.ContentBlueprint.EditController", ContentEditController); +angular.module("umbraco").controller("Umbraco.Editors.ContentBlueprint.EditController", ContentBlueprintEditController); 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 940d2acb3a..3ca4b6447e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.html +++ b/src/Umbraco.Web.UI.Client/src/views/contentblueprints/edit.html @@ -1,4 +1,7 @@
- +
diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 778258d931..9b0e0c2139 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -24,6 +24,7 @@ using Umbraco.Web.WebApi.Binders; using Umbraco.Web.WebApi.Filters; using umbraco.cms.businesslogic.web; using umbraco.presentation.preview; +using Umbraco.Core.Events; using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors @@ -104,6 +105,21 @@ namespace Umbraco.Web.Editors return display; } + public ContentItemDisplay GetBlueprintById(int id) + { + var foundContent = Services.ContentService.GetBlueprintById(id); + if (foundContent == null) + { + HandleContentNotFound(id); + } + + var content = Mapper.Map(foundContent); + + content.AllowedActions = new[] {'A'}; + + return content; + } + /// /// Gets the content json for the content id /// @@ -289,14 +305,14 @@ namespace Umbraco.Web.Editors 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()); @@ -305,6 +321,24 @@ namespace Umbraco.Web.Editors return Request.CreateResponse(HttpStatusCode.OK); } + /// + /// Saves content + /// + /// + [FileUploadCleanupFilter] + [ContentPostValidate] + public ContentItemDisplay PostSaveBlueprint( + [ModelBinder(typeof(ContentItemBinder))] ContentItemSave contentItem) + { + return PostSaveInternal(contentItem, + content => + { + Services.ContentService.SaveBlueprint(contentItem.PersistedContent, Security.CurrentUser.Id); + //we need to reuse the underlying logic so return the result that it wants + return Attempt.Succeed(new OperationStatus(OperationStatusType.Success, new EventMessages())); + }); + } + /// /// Saves content /// @@ -314,6 +348,12 @@ namespace Umbraco.Web.Editors public ContentItemDisplay PostSave( [ModelBinder(typeof(ContentItemBinder))] ContentItemSave contentItem) + { + return PostSaveInternal(contentItem, + content => Services.ContentService.WithResult().Save(contentItem.PersistedContent, Security.CurrentUser.Id)); + } + + private ContentItemDisplay PostSaveInternal(ContentItemSave contentItem, Func> saveMethod) { //If we've reached here it means: // * Our model has been bound @@ -361,7 +401,7 @@ namespace Umbraco.Web.Editors if (contentItem.Action == ContentSaveAction.Save || contentItem.Action == ContentSaveAction.SaveNew) { //save the item - var saveResult = Services.ContentService.WithResult().Save(contentItem.PersistedContent, Security.CurrentUser.Id); + var saveResult = saveMethod(contentItem.PersistedContent); wasCancelled = saveResult.Success == false && saveResult.Result.StatusType == OperationStatusType.FailedCancelledByEvent; } @@ -391,8 +431,8 @@ namespace Umbraco.Web.Editors if (wasCancelled == false) { display.AddSuccessNotification( - Services.TextService.Localize("speechBubbles/editContentSavedHeader"), - Services.TextService.Localize("speechBubbles/editContentSavedText")); + Services.TextService.Localize("speechBubbles/editContentSavedHeader"), + Services.TextService.Localize("speechBubbles/editContentSavedText")); } else { @@ -404,8 +444,8 @@ namespace Umbraco.Web.Editors if (wasCancelled == false) { display.AddSuccessNotification( - Services.TextService.Localize("speechBubbles/editContentSendToPublish"), - Services.TextService.Localize("speechBubbles/editContentSendToPublishText")); + Services.TextService.Localize("speechBubbles/editContentSendToPublish"), + Services.TextService.Localize("speechBubbles/editContentSendToPublishText")); } else { @@ -429,7 +469,7 @@ namespace Umbraco.Web.Editors } return display; - } + } /// /// Publishes a document with a given ID