From d0cd8ba3467845ef3bf48d60e22f7deb776a1480 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 8 Oct 2013 10:55:47 +1100 Subject: [PATCH] Moves GetPath to EntityController and entityResource since all entities can have a path not just content. --- .../src/common/resources/content.resource.js | 29 --------------- .../src/common/resources/entity.resource.js | 35 +++++++++++++++++-- .../common/dialogs/linkpicker.controller.js | 10 +++--- src/Umbraco.Web/Editors/ContentController.cs | 16 --------- src/Umbraco.Web/Editors/EntityController.cs | 22 ++++++++++-- 5 files changed, 58 insertions(+), 54 deletions(-) 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 feecdac18c..7cf9c61111 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 @@ -401,35 +401,6 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { 'Failed to retrieve url for id:' + id); }, - /** - * @ngdoc method - * @name umbraco.resources.contentResource#getPath - * @methodOf umbraco.resources.contentResource - * - * @description - * Returns a url, given a node ID - * - * ##usage - *
-         * contentResource.getPath(id)
-         *    .then(function(pathArray) {
-         *        alert('its here!');
-         *    });
-         * 
- * - * @param {Int} id Id of node to return the public url to - * @returns {Promise} resourcePromise object containing the url. - * - */ - getPath: function (id) { - return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentApiBaseUrl", - "GetPath",[{id: id}])), - 'Failed to retrieve path for id:' + id); - }, - /** * @ngdoc method * @name umbraco.resources.contentResource#getChildren diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js index 9aa0d39040..a23697344b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js @@ -35,6 +35,37 @@ function entityResource($q, $http, umbRequestHelper) { //the factory object returned return { + /** + * @ngdoc method + * @name umbraco.resources.entityResource#getPath + * @methodOf umbraco.resources.entityResource + * + * @description + * Returns a path, given a node ID and type + * + * ##usage + *
+         * entityResource.getPath(id)
+         *    .then(function(pathArray) {
+         *        alert('its here!');
+         *    });
+         * 
+ * + * @param {Int} id Id of node to return the public url to + * @param {string} type Object type name + * @returns {Promise} resourcePromise object containing the url. + * + */ + getPath: function (id, type) { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "entityApiBaseUrl", + "GetPath", + [{ id: id, type: type }])), + 'Failed to retrieve path for id:' + id); + }, + /** * @ngdoc method * @name umbraco.resources.entityResource#getById @@ -54,7 +85,7 @@ function entityResource($q, $http, umbRequestHelper) { * * * @param {Int} id id of entity to return - * @param {string} type optional Object type name + * @param {string} type Object type name * @returns {Promise} resourcePromise object containing the entity. * */ @@ -87,7 +118,7 @@ function entityResource($q, $http, umbRequestHelper) { * * * @param {Array} ids ids of entities to return as an array - * @param {string} type optional type name + * @param {string} type type name * @returns {Promise} resourcePromise object containing the entity array. * */ diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js index f02966e029..1e584740a0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js @@ -1,6 +1,6 @@ //used for the media picker dialog angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController", - function ($scope, eventsService, contentResource, $log) { + function ($scope, eventsService, entityResource, contentResource, $log) { var dialogOptions = $scope.$parent.dialogOptions; $scope.dialogTreeEventHandler = $({}); @@ -12,10 +12,10 @@ angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController", //if we a node ID, we fetch the current node to build the form data if($scope.target.id){ - if(!$scope.target.path){ - contentResource.getPath($scope.target.id).then(function(path){ - $scope.target.path = path; - }) + if(!$scope.target.path) { + entityResource.getPath($scope.target.id, "Document").then(function (path) { + $scope.target.path = path; + }); } contentResource.getNiceUrl($scope.target.id).then(function(url){ diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 9784b6027d..c23495b04f 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -120,22 +120,6 @@ namespace Umbraco.Web.Editors return url; } - /// - /// Gets the path for a given node ID - /// - /// - /// - public IEnumerable GetPath(int id) - { - var foundContent = GetEntityFromRequest(() => Services.ContentService.GetById(id)); - if (foundContent == null) - { - HandleContentNotFound(id); - } - - return foundContent.Path.Split(',').Select(x => int.Parse(x)); - } - /// /// Gets the children for the content id passed in /// diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 63782c4c55..a3e39692f3 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -48,7 +48,20 @@ namespace Umbraco.Web.Editors default: throw new NotSupportedException("The " + typeof(EntityController) + " currently does not support searching against object type " + type); } - } + } + + /// + /// Gets the path for a given node ID + /// + /// + /// + /// + public IEnumerable GetPath(int id, UmbracoEntityTypes type) + { + var foundContent = GetResultForId(id, type); + + return foundContent.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse); + } public EntityBasic GetById(int id, UmbracoEntityTypes type) { @@ -235,7 +248,12 @@ namespace Umbraco.Web.Editors var objectType = ConvertToObjectType(entityType); if (objectType.HasValue) { - return Mapper.Map(Services.EntityService.Get(id, objectType.Value)); + var found = Services.EntityService.Get(id, objectType.Value); + if (found == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + return Mapper.Map(found); } //now we need to convert the unknown ones switch (entityType)