> GetReferences(int id)
{
throw new NotImplementedException();
}
diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js
index f20debc9c3..6400f7386f 100644
--- a/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js
+++ b/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js
@@ -45,108 +45,26 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
/**
* @ngdoc method
- * @name umbraco.resources.dataTypeResource#getRelations
+ * @name umbraco.resources.dataTypeResource#getReferences
* @methodOf umbraco.resources.dataTypeResource
*
* @description
* Retrieves relations of a given data type.
*
- * ##usage
- *
- * dataTypeResource.getRelation(1234)
- * .then(function(relations) {
- * alert('its gone!');
- * });
- *
- *
* @param {Int} id id of datatype to retrieve relations for
* @returns {Promise} resourcePromise object.
*
*/
- getRelations: function (id) {
-
- return $q((resolve, reject) => {
-
-
-var fakeData = {
- "documentTypes": [
- {
- "name": "Home",
- "alias": "home",
- "icon": "icon-home",
- "udi": "document-type://B6C7EFA7-1D03-46BF-B6D3-9187EF4CD176",
- "id": 1234,
- "properties": [
- {
- "alias": "bodyText",
- "name": "Body Text"
- },
- {
- "alias": "description",
- "name": "Description"
- }
- ]
- },
- {
- "name": "News",
- "alias": "news",
- "icon": "icon-newspaper",
- "udi": "document-type://FAB4F78E-530E-4F5D-959A-82441958460C",
- "id": 9876,
- "properties": [
- {
- "alias": "article",
- "name": "Article"
- }
- ]
- }
- ],
- "mediaTypes": [
- {
- "name": "Image",
- "alias": "image",
- "icon": "icon-umb-media",
- "udi": "media-type://488152AF-0C03-4F2D-9DE0-FDECC80212AD",
- "id": 9999,
- "properties": [
- {
- "alias": "altText",
- "name": "Alt Text"
- }
- ]
- }
- ],
- "memberTypes": [
- {
- "name": "Member",
- "alias": "member",
- "icon": "icon-people-alt-2",
- "udi": "member-type://93773B7C-2D83-4529-92D9-B9759220384C",
- "id": 7777,
- "properties": [
- {
- "alias": "bio",
- "name": "Bio"
- }
- ]
- }
- ]
-};
-
- resolve(fakeData);
- });
- /*
-
- TODO: get real data from server!
+ getReferences: function (id) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"dataTypeApiBaseUrl",
- "GetRelations",
- [{ id: id }])),
- "Failed to retrieve relations for data type of id " + id);
- */
+ "GetReferences",
+ { id: id })),
+ "Failed to retrieve usages for data type of id " + id);
+
},
/**
diff --git a/src/Umbraco.Web.UI.Client/src/views/datatypes/views/datatype.relations.controller.js b/src/Umbraco.Web.UI.Client/src/views/datatypes/views/datatype.relations.controller.js
index 83d6e4a379..db97053064 100644
--- a/src/Umbraco.Web.UI.Client/src/views/datatypes/views/datatype.relations.controller.js
+++ b/src/Umbraco.Web.UI.Client/src/views/datatypes/views/datatype.relations.controller.js
@@ -7,26 +7,26 @@
* The controller for the relations view of the datatype editor
*/
function DataTypeRelationsController($scope, $routeParams, dataTypeResource) {
-
+
var vm = this;
vm.relations = {};
vm.hasRelations = false;
-
+
vm.view = {};
vm.view.loading = true;
//we are editing so get the content item from the server
- dataTypeResource.getRelations($routeParams.id)
- .then(function(data) {
+ dataTypeResource.getReferences($routeParams.id)
+ .then(function (data) {
- vm.view.loading = false;
- vm.relations = data;
+ vm.view.loading = false;
+ vm.relations = data;
- vm.hasRelations = vm.relations.documentTypes.length > 0 || vm.relations.mediaTypes.length > 0 || vm.relations.memberTypes.length > 0;
+ vm.hasRelations = vm.relations.documentTypes.length > 0 || vm.relations.mediaTypes.length > 0 || vm.relations.memberTypes.length > 0;
- });
+ });
diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs
index 30c4162252..ca261b3043 100644
--- a/src/Umbraco.Web/Editors/DataTypeController.cs
+++ b/src/Umbraco.Web/Editors/DataTypeController.cs
@@ -283,6 +283,59 @@ namespace Umbraco.Web.Editors
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
+ ///
+ /// Returns the references (usages) for the data type
+ ///
+ ///
+ ///
+ public DataTypeReferences GetReferences(int id)
+ {
+ var result = new DataTypeReferences();
+ var usages = Services.DataTypeService.GetReferences(id);
+
+ foreach(var groupOfEntityType in usages.GroupBy(x => x.Key.EntityType))
+ {
+ //get all the GUIDs for the content types to find
+ var guidsAndPropertyAliases = groupOfEntityType.ToDictionary(i => ((GuidUdi)i.Key).Guid, i => i.Value);
+
+ if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.DocumentType))
+ result.DocumentTypes = GetContentTypeUsages(Services.ContentTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases);
+ else if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.MediaType))
+ result.MediaTypes = GetContentTypeUsages(Services.MediaTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases);
+ else if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.MemberType))
+ result.MemberTypes = GetContentTypeUsages(Services.MemberTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases);
+ }
+
+ return result;
+ }
+
+ ///
+ /// Maps the found content types and usages to the resulting model
+ ///
+ ///
+ ///
+ ///
+ private IEnumerable GetContentTypeUsages(
+ IEnumerable cts,
+ IReadOnlyDictionary> usages)
+ {
+ return cts.Select(x => new DataTypeReferences.ContentTypeReferences
+ {
+ Key = x.Key,
+ Alias = x.Alias,
+ Icon = x.Icon,
+ Name = x.Name,
+ Udi = new GuidUdi(ObjectTypes.GetUdiType(UmbracoObjectTypes.DocumentType), x.Key),
+ //only select matching properties
+ Properties = x.PropertyTypes.Where(p => usages[x.Key].InvariantContains(p.Alias))
+ .Select(p => new DataTypeReferences.ContentTypeReferences.PropertyTypeReferences
+ {
+ Alias = p.Alias,
+ Name = p.Name
+ })
+ });
+ }
+
#region ReadOnly actions to return basic data - allow access for: content ,media, members, settings, developer
///
/// Gets the content json for all data types
diff --git a/src/Umbraco.Web/Models/ContentEditing/DataTypeReferences.cs b/src/Umbraco.Web/Models/ContentEditing/DataTypeReferences.cs
new file mode 100644
index 0000000000..dd042660a2
--- /dev/null
+++ b/src/Umbraco.Web/Models/ContentEditing/DataTypeReferences.cs
@@ -0,0 +1,36 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+
+namespace Umbraco.Web.Models.ContentEditing
+{
+ [DataContract(Name = "dataTypeUsages", Namespace = "")]
+ public class DataTypeReferences
+ {
+ [DataMember(Name = "documentTypes")]
+ public IEnumerable DocumentTypes { get; set; } = Enumerable.Empty();
+
+ [DataMember(Name = "mediaTypes")]
+ public IEnumerable MediaTypes { get; set; } = Enumerable.Empty();
+
+ [DataMember(Name = "memberTypes")]
+ public IEnumerable MemberTypes { get; set; } = Enumerable.Empty();
+
+ [DataContract(Name = "contentType", Namespace = "")]
+ public class ContentTypeReferences : EntityBasic
+ {
+ [DataMember(Name = "properties")]
+ public object Properties { get; set; }
+
+ [DataContract(Name = "property", Namespace = "")]
+ public class PropertyTypeReferences
+ {
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+
+ [DataMember(Name = "alias")]
+ public string Alias { get; set; }
+ }
+ }
+ }
+}
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index a0ce64943a..f908fc7c30 100755
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -212,6 +212,7 @@
+