Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix so that a RelationLabels shows child relations as well as parent … #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@

namespace nuPickers.Shared.RelationDataSource
namespace nuPickers.Shared.RelationDataSource
{
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using umbraco.cms.businesslogic.relation;
using Umbraco.Core.Models;
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
using nuPickers.Shared.Editor;
using umbraco;
using CustomLabel;

[PluginController("nuPickers")]
public class RelationDataSourceApiController : UmbracoAuthorizedJsonController
{
public IEnumerable<object> GetRelationTypes()
{
return RelationType.GetAll()
.OrderBy(x => x.Name)
.Select(x => new
{
key = x.Alias,
label = x.Name,
biDirectional = x.Dual
});
var relationService = this.ApplicationContext.Services.RelationService;

return relationService.GetAllRelationTypes()
.OrderBy(x => x.Name)
.Select(x => new {
key = x.Alias,
label = x.Name,
biDirectional = x.IsBidirectional
});
}

[HttpPost]
Expand All @@ -33,19 +32,39 @@ public IEnumerable<EditorDataItem> GetEditorDataItems([FromUri] int currentId, [

var relationService = this.ApplicationContext.Services.RelationService;

IEnumerable<EditorDataItem> editorDataItems = relationService.GetEntitiesFromRelations(
relationService.GetByRelationTypeAlias((string)data.config.dataSource.relationType)
.Where(r => r.ParentId == contextId))
.Select(x => new EditorDataItem()
{
Key = x.Item2.Id.ToString(),
Label = x.Item2.Name.ToString()
})
.ToList();
var relation = relationService.GetByRelationTypeAlias((string) data.config.dataSource.relationType).FirstOrDefault();
if (relation != null)
{
var realtionType = relation.RelationType;

IEnumerable<IRelation> editorUmbracoEntities;

if (realtionType.IsBidirectional)
{
editorUmbracoEntities = relationService.GetByRelationTypeAlias((string) data.config.dataSource.relationType)
.Where(r => r.ParentId == contextId || r.ChildId == contextId);
}
else
{
editorUmbracoEntities = relationService.GetByRelationTypeAlias((string)data.config.dataSource.relationType)
.Where(r => r.ParentId == contextId);
}

IEnumerable<EditorDataItem> editorDataItems = relationService.GetEntitiesFromRelations(editorUmbracoEntities)
.Select(x => new EditorDataItem()
{
Key = x.Item2.Id.ToString(),
Label = x.Item2.Name.ToString()
})
.ToList();

CustomLabel customLabel = new CustomLabel((string)data.config.customLabel, contextId, propertyAlias);

return customLabel.ProcessEditorDataItems(editorDataItems);
}

CustomLabel customLabel = new CustomLabel((string)data.config.customLabel, contextId, propertyAlias);
return null;

return customLabel.ProcessEditorDataItems(editorDataItems);
}
}
}