Adds GetCustomListView and GetByName to datatype service

This commit is contained in:
Per Ploug
2015-06-16 11:35:24 +02:00
parent 554dff5235
commit aed6819b6c
2 changed files with 82 additions and 2 deletions

View File

@@ -54,8 +54,8 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
* ##usage
* <pre>
* dataTypeResource.getById(1234)
* .then(function() {
* alert('its gone!');
* .then(function(datatype) {
* alert('its here!');
* });
* </pre>
*
@@ -74,6 +74,37 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
'Failed to retrieve data for data type id ' + id);
},
/**
* @ngdoc method
* @name umbraco.resources.dataTypeResource#getByName
* @methodOf umbraco.resources.dataTypeResource
*
* @description
* Gets a data type item with a given name
*
* ##usage
* <pre>
* dataTypeResource.getByName("upload")
* .then(function(datatype) {
* alert('its here!');
* });
* </pre>
*
* @param {String} name Name of data type to retrieve
* @returns {Promise} resourcePromise object.
*
*/
getByName: function (name) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"dataTypeApiBaseUrl",
"GetByName",
[{ name: name }])),
'Failed to retrieve data for data type with name: ' + name);
},
getAll: function () {
return umbRequestHelper.resourcePromise(
@@ -170,6 +201,39 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
'Failed to delete item ' + id);
},
/**
* @ngdoc method
* @name umbraco.resources.dataTypeResource#getCustomListView
* @methodOf umbraco.resources.dataTypeResource
*
* @description
* Returns a custom listview, given a content types alias
*
*
* ##usage
* <pre>
* dataTypeResource.getCustomListView("home")
* .then(function(listview) {
* });
* </pre>
*
* @returns {Promise} resourcePromise object containing the listview datatype.
*
*/
getCustomListView: function (contentTypeAlias) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"dataTypeApiBaseUrl",
"GetCustomListView",
{ contentTypeAlias: contentTypeAlias }
)),
'Failed to retrieve data for custom listview datatype');
},
/**
* @ngdoc method
* @name umbraco.resources.dataTypeResource#save

View File

@@ -140,6 +140,22 @@ namespace Umbraco.Web.Editors
return Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dt);
}
/// <summary>
/// Returns a custom listview, based on a content type alias, if found
/// </summary>
/// <param name="contentTypeAlias"></param>
/// <returns>a DataTypeDisplay</returns>
public DataTypeDisplay GetCustomListView(string contentTypeAlias)
{
var dt = Services.DataTypeService.GetDataTypeDefinitionByName(Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias);
if (dt == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dt);
}
/// <summary>
/// Returns the pre-values for the specified property editor
/// </summary>