diff --git a/src/Umbraco.Web.UI.Client/src/common/mocks/resources/entity.mocks.js b/src/Umbraco.Web.UI.Client/src/common/mocks/resources/entity.mocks.js index 3efd57a3d3..e69aefd100 100644 --- a/src/Umbraco.Web.UI.Client/src/common/mocks/resources/entity.mocks.js +++ b/src/Umbraco.Web.UI.Client/src/common/mocks/resources/entity.mocks.js @@ -27,7 +27,7 @@ angular.module('umbraco.mocks'). $(ids).each(function(i, id){ var _id = parseInt(id, 10); - nodes.push(mocksUtils.getMockEntity(_id)); + nodes.push(mocksUtils.getMockEntity(_id)); }); return [200, nodes, null]; @@ -37,12 +37,20 @@ angular.module('umbraco.mocks'). return { register: function () { $httpBackend - .whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Entity/GetByIds')) + .whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Entity/GetEntitiesByIds')) .respond(returnEntitybyIds); $httpBackend - .whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Entity/GetById?')) + .whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Entity/GetEntityById?')) .respond(returnEntitybyId); + + $httpBackend + .whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Entity/GetDocumentsByIds')) + .respond(returnEntitybyIds); + + $httpBackend + .whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Entity/GetDocumentById?')) + .respond(returnEntitybyId); } }; }]); \ No newline at end of file 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 2c3be1949d..7ea411df02 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 @@ -7,6 +7,10 @@ * An entity is a basic **read-only** representation of an Umbraco node. It contains only the most * basic properties used to display the item in trees, lists and navigation. * + * ##What is the difference between get entity and get content? + * the entity only contains the basic node data, name, id and guid, whereas content + * nodes fetched through the entity service also contains additional meta data such + * as icon, document type, path and so on. **/ function entityResource($q, $http, umbRequestHelper) { @@ -15,7 +19,7 @@ function entityResource($q, $http, umbRequestHelper) { /** * @ngdoc method - * @name umbraco.resources.entityResource#getById + * @name umbraco.resources.entityResource#getEntityById * @methodOf umbraco.resources.entityResource * * @description @@ -23,7 +27,7 @@ function entityResource($q, $http, umbRequestHelper) { * * ##usage *
- * entityResource.getById(1234)
+ * entityResource.getEntityById(1234)
* .then(function(ent) {
* var myDoc = ent;
* alert('its here!');
@@ -34,19 +38,19 @@ function entityResource($q, $http, umbRequestHelper) {
* @returns {Promise} resourcePromise object containing the entity.
*
*/
- getById: function (id) {
+ getEntityById: function (id) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"entityApiBaseUrl",
- "GetById",
+ "GetEntityById",
[{ id: id }])),
'Failed to retreive entity data for id ' + id);
},
/**
* @ngdoc method
- * @name umbraco.resources.entityResource#getByIds
+ * @name umbraco.resources.entityResource#getEntitiesByIds
* @methodOf umbraco.resources.entityResource
*
* @description
@@ -54,7 +58,7 @@ function entityResource($q, $http, umbRequestHelper) {
*
* ##usage
*
- * entityResource.getByIds( [1234,2526,28262])
+ * entityResource.getEntitiesByIds( [1234,2526,28262])
* .then(function(contentArray) {
* var myDoc = contentArray;
* alert('they are here!');
@@ -65,7 +69,7 @@ function entityResource($q, $http, umbRequestHelper) {
* @returns {Promise} resourcePromise object containing the entity array.
*
*/
- getByIds: function (ids) {
+ getEntitiesByIds: function (ids) {
var idQuery = "";
_.each(ids, function(item) {
@@ -76,11 +80,146 @@ function entityResource($q, $http, umbRequestHelper) {
$http.get(
umbRequestHelper.getApiUrl(
"entityApiBaseUrl",
- "GetByIds",
+ "GetEntitiesByIds",
idQuery)),
'Failed to retreive entity data for ids ' + idQuery);
- }
+ },
+ /**
+ * @ngdoc method
+ * @name umbraco.resources.entityResource#getDocumentById
+ * @methodOf umbraco.resources.entityResource
+ *
+ * @description
+ * Gets a content entity with a given id
+ *
+ * ##usage
+ *
+ * entityResource.getDocumentById(1234)
+ * .then(function(ent) {
+ * var myDoc = ent;
+ * alert('its here!');
+ * });
+ *
+ *
+ * @param {Int} id id of document to return
+ * @returns {Promise} resourcePromise object containing the document.
+ *
+ */
+ getDocumentById: function (id) {
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "entityApiBaseUrl",
+ "GetDocumentById",
+ [{ id: id }])),
+ 'Failed to retreive entity data for id ' + id);
+ },
+
+ /**
+ * @ngdoc method
+ * @name umbraco.resources.entityResource#getDocumentsByIds
+ * @methodOf umbraco.resources.entityResource
+ *
+ * @description
+ * Gets an array of content entities, given a collection of ids
+ *
+ * ##usage
+ *
+ * entityResource.getDocumentsByIds( [1234,2526,28262])
+ * .then(function(contentArray) {
+ * var myDoc = contentArray;
+ * alert('they are here!');
+ * });
+ *
+ *
+ * @param {Array} ids ids of entities to return as an array
+ * @returns {Promise} resourcePromise object containing the entity array.
+ *
+ */
+ getDocumentsByIds: function (ids) {
+
+ var idQuery = "";
+ _.each(ids, function(item) {
+ idQuery += "ids=" + item + "&";
+ });
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "entityApiBaseUrl",
+ "GetDocumentsByIds",
+ idQuery)),
+ 'Failed to retreive document data for ids ' + idQuery);
+ },
+
+ /**
+ * @ngdoc method
+ * @name umbraco.resources.entityResource#getMediaById
+ * @methodOf umbraco.resources.entityResource
+ *
+ * @description
+ * Gets a media entity with a given id
+ *
+ * ##usage
+ *
+ * entityResource.getMediaById(1234)
+ * .then(function(ent) {
+ * var myDoc = ent;
+ * alert('its here!');
+ * });
+ *
+ *
+ * @param {Int} id id of media to return
+ * @returns {Promise} resourcePromise object containing the media.
+ *
+ */
+ getMediaById: function (id) {
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "entityApiBaseUrl",
+ "GetMediaById",
+ [{ id: id }])),
+ 'Failed to retreive media data for id ' + id);
+ },
+
+ /**
+ * @ngdoc method
+ * @name umbraco.resources.entityResource#getMediaByIds
+ * @methodOf umbraco.resources.entityResource
+ *
+ * @description
+ * Gets an array of media entities, given a collection of ids
+ *
+ * ##usage
+ *
+ * entityResource.getMediaByIds( [1234,2526,28262])
+ * .then(function(mediaArray) {
+ * var myDoc = contentArray;
+ * alert('they are here!');
+ * });
+ *
+ *
+ * @param {Array} ids ids of entities to return as an array
+ * @returns {Promise} resourcePromise object containing the entity array.
+ *
+ */
+ getMediaByIds: function (ids) {
+
+ var idQuery = "";
+ _.each(ids, function(item) {
+ idQuery += "ids=" + item + "&";
+ });
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "entityApiBaseUrl",
+ "GetMediaByIds",
+ idQuery)),
+ 'Failed to retreive media data for ids ' + idQuery);
+ }
};
}
diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs
index b88e563ca1..e19de69447 100644
--- a/src/Umbraco.Web/Editors/EntityController.cs
+++ b/src/Umbraco.Web/Editors/EntityController.cs
@@ -19,23 +19,71 @@ namespace Umbraco.Web.Editors
[PluginController("UmbracoApi")]
public class EntityController : UmbracoAuthorizedJsonController
{
- public EntityBasic GetById(int id)
+ public EntityBasic GetDocumentById(int id)
{
return Mapper.Map(Services.EntityService.Get(id, UmbracoObjectTypes.Document));
}
+ public IEnumerable GetDocumentChildren(int id)
+ {
+ return getChildren(id, UmbracoObjectTypes.Document);
+ }
+ public IEnumerable GetDocumentsByIds([FromUri]int[] ids)
+ {
+ return getEntitiesById(ids, UmbracoObjectTypes.Document);
+ }
- //TODO: This should probably be change to GetContentByIds since it will be different for media, etc...!
- //TODO: Because this is a publicly accessible API, we need to filter the results for what the currently logged in user
- // is actually allowed to access. We'll need to enhance the FilterAllowedOutgoingContent to acheive that.
+ public EntityBasic GetMediaById(int id)
+ {
+ return getEntityById(id, UmbracoObjectTypes.Media);
+ }
+ public IEnumerable GetMediaChildren(int id)
+ {
+ return getChildren(id, UmbracoObjectTypes.Media);
+ }
+ public IEnumerable GetMediaByIds([FromUri]int[] ids)
+ {
+ return getEntitiesById(ids, UmbracoObjectTypes.Media);
+ }
- public IEnumerable GetByIds([FromUri]int[] ids)
+
+
+ public EntityBasic GetEntityById(int id)
+ {
+ return Mapper.Map(Services.EntityService.Get(id));
+ }
+
+ public IEnumerable GetEntitiesByIds([FromUri]int[] ids)
{
if (ids == null) throw new ArgumentNullException("ids");
-
return ids.Select(id =>
- Mapper.Map(Services.EntityService.Get(id, UmbracoObjectTypes.Document)));
+ Mapper.Map(Services.EntityService.Get(id)));
+ }
+
+ private EntityBasic getEntityById(int id, UmbracoObjectTypes type)
+ {
+ return Mapper.Map(Services.EntityService.Get(id, type));
+ }
+
+ private IEnumerable getChildren(int id, UmbracoObjectTypes type)
+ {
+ return Services.EntityService.GetChildren(id, type)
+ .Select(child =>
+ Mapper.Map(child));
+ }
+
+ private IEnumerable getAncestors(int id, UmbracoObjectTypes type)
+ {
+ var ids = Services.EntityService.Get(id).Path.Split(',').Select(x => int.Parse(x));
+ return getEntitiesById(ids.ToArray(), type);
+ }
+
+ private IEnumerable getEntitiesById(int[] ids, UmbracoObjectTypes type)
+ {
+ if (ids == null) throw new ArgumentNullException("ids");
+ return ids.Select(id =>
+ Mapper.Map(Services.EntityService.Get(id, type)));
}
}
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index c89ad2db3d..e4847bf658 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -302,6 +302,7 @@
+