Adds new endpoint to DataTypeController to return the correct data and wires that up to angular
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Gets a content type.
|
||||
/// </summary>
|
||||
TItem Get(int id);
|
||||
new TItem Get(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content type.
|
||||
@@ -40,6 +40,7 @@ namespace Umbraco.Core.Services
|
||||
int Count();
|
||||
|
||||
IEnumerable<TItem> GetAll(params int[] ids);
|
||||
IEnumerable<TItem> GetAll(IEnumerable<Guid> ids);
|
||||
|
||||
IEnumerable<TItem> GetDescendants(int id, bool andSelf); // parent-child axis
|
||||
IEnumerable<TItem> GetComposedOf(int id); // composition axis
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
IReadOnlyDictionary<Udi, IEnumerable<string>> FindUsages(int id);
|
||||
IReadOnlyDictionary<Udi, IEnumerable<string>> GetReferences(int id);
|
||||
|
||||
Attempt<OperationResult<OperationResultType, EntityContainer>> CreateContainer(int parentId, string name, int userId = Constants.Security.SuperUserId);
|
||||
Attempt<OperationResult> SaveContainer(EntityContainer container, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
+2
-2
@@ -252,12 +252,12 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TItem> GetAll(params Guid[] ids)
|
||||
public IEnumerable<TItem> GetAll(IEnumerable<Guid> ids)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(ReadLockIds);
|
||||
return Repository.GetMany(ids);
|
||||
return Repository.GetMany(ids.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -466,7 +466,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<Udi, IEnumerable<string>> FindUsages(int id)
|
||||
public IReadOnlyDictionary<Udi, IEnumerable<string>> GetReferences(int id)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete:true))
|
||||
{
|
||||
|
||||
@@ -330,7 +330,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<Udi, IEnumerable<string>> FindUsages(int id)
|
||||
public IReadOnlyDictionary<Udi, IEnumerable<string>> GetReferences(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* <pre>
|
||||
* dataTypeResource.getRelation(1234)
|
||||
* .then(function(relations) {
|
||||
* alert('its gone!');
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @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);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+8
-8
@@ -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;
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -283,6 +283,59 @@ namespace Umbraco.Web.Editors
|
||||
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the references (usages) for the data type
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps the found content types and usages to the resulting model
|
||||
/// </summary>
|
||||
/// <param name="cts"></param>
|
||||
/// <param name="usages"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<DataTypeReferences.ContentTypeReferences> GetContentTypeUsages(
|
||||
IEnumerable<IContentTypeBase> cts,
|
||||
IReadOnlyDictionary<Guid, IEnumerable<string>> 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
|
||||
/// <summary>
|
||||
/// Gets the content json for all data types
|
||||
|
||||
@@ -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<ContentTypeReferences> DocumentTypes { get; set; } = Enumerable.Empty<ContentTypeReferences>();
|
||||
|
||||
[DataMember(Name = "mediaTypes")]
|
||||
public IEnumerable<ContentTypeReferences> MediaTypes { get; set; } = Enumerable.Empty<ContentTypeReferences>();
|
||||
|
||||
[DataMember(Name = "memberTypes")]
|
||||
public IEnumerable<ContentTypeReferences> MemberTypes { get; set; } = Enumerable.Empty<ContentTypeReferences>();
|
||||
|
||||
[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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,6 +212,7 @@
|
||||
<Compile Include="Media\UploadAutoFillProperties.cs" />
|
||||
<Compile Include="Migrations\PostMigrations\PublishedSnapshotRebuilder.cs" />
|
||||
<Compile Include="Models\AnchorsModel.cs" />
|
||||
<Compile Include="Models\ContentEditing\DataTypeReferences.cs" />
|
||||
<Compile Include="Models\ContentEditing\LinkDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\MacroDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\MacroParameterDisplay.cs" />
|
||||
|
||||
Reference in New Issue
Block a user