Skip to content

Commit 086d084

Browse files
committed
Fixes issue #7, duplicate relations with bidirectional relation types.
1 parent f7fc3c5 commit 086d084

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

Umbraco.RelationEditor.Web/App_Plugins/RelationEditor/editrelations.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ <h4>{{resourceSet.Name}}</h4>
2121
<td style="width:5%;" class="direction"></td>
2222
<td style="width:15%;">{{relation.ChildId}}</td>
2323
<td style="width:70%;" title="{{relation.FullPath}}">{{relation.ChildName}}</td>
24-
<td style="width:10%;"><button class="btn btn-danger" ng-click="remove(relation)">Remove</button></td>
24+
<td style="width:10%;">
25+
<button class="btn btn-danger" ng-click="remove(relation)" ng-disabled="relation.Readonly"
26+
title="{{relation.RemoveTitle}}">
27+
Remove
28+
</button>
29+
</td>
2530
</tr>
2631
</tbody>
2732
<tfoot>

Umbraco.RelationEditor.Web/App_Plugins/RelationEditor/relationeditor.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@
104104

105105
var promise = relationsResources.getById($scope.currentNode.section, $scope.currentNode.nodeType, $scope.currentNode.id);
106106
promise.then(function (data) {
107+
$(data).each(function (i, type) {
108+
$(type.Sets).each(function (i2, set) {
109+
$(set.Relations).each(function(i3, relation) {
110+
relation.RemoveTitle = relation.Readonly ? "Must be removed from " + relation.ChildName : "Remove relation";
111+
});
112+
});
113+
});
107114
$scope.data = data;
108115
$scope.resourceSets = data.Sets;
109116
$scope.ready = true;

Umbraco.RelationEditor.Web/Web.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Umbraco web.config configuration documentation can be found here:
3636
http://our.umbraco.org/documentation/using-umbraco/config-files/#webconfig
3737
-->
38-
<add key="umbracoConfigurationStatus" value="7.1.3" />
38+
<add key="umbracoConfigurationStatus" value="7.1.2" />
3939
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd" />
4040
<add key="umbracoReservedPaths" value="~/umbraco,~/install/" />
4141
<add key="umbracoPath" value="~/umbraco" />

Umbraco.RelationEditor.Web/config/ClientDependency.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NOTES:
1010
* Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config
1111
* A new version will invalidate both client and server cache and create new persisted files
1212
-->
13-
<clientDependency version="240058734" fileDependencyExtensions=".js,.css" loggerType="Umbraco.Web.UI.CdfLogger, umbraco">
13+
<clientDependency version="652114428" fileDependencyExtensions=".js,.css" loggerType="Umbraco.Web.UI.CdfLogger, umbraco">
1414

1515
<!--
1616
This section is used for Web Forms only, the enableCompositeFiles="true" is optional and by default is set to true.

Umbraco.RelationEditor.Web/config/RelationEditor.config

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
<EnabledChildType Alias="Image" />
1414
</EnabledRelation>
1515
</ObjectType>
16-
<ObjectType Alias="page" Name="Document">
17-
<EnabledRelation Alias="documentRelation">
18-
<EnabledChildType Alias="page" />
19-
</EnabledRelation>
20-
<EnabledRelation Alias="docToDocType" />
21-
</ObjectType>
2216
<ObjectType Alias="page" Name="Document">
2317
<EnabledRelation Alias="documentRelation">
2418
<EnabledChildType Alias="page" />
@@ -31,4 +25,16 @@
3125
</EnabledRelation>
3226
<EnabledRelation Alias="docToDocType" />
3327
</ObjectType>
28+
<ObjectType Alias="page" Name="Document">
29+
<EnabledRelation Alias="documentRelation">
30+
<EnabledChildType Alias="page" />
31+
</EnabledRelation>
32+
<EnabledRelation Alias="docToDocType" />
33+
</ObjectType>
34+
<ObjectType Alias="post" Name="Document">
35+
<EnabledRelation Alias="documentRelation">
36+
<EnabledChildType Alias="page" />
37+
<EnabledChildType Alias="post" />
38+
</EnabledRelation>
39+
</ObjectType>
3440
</RelationEditor>

Umbraco.RelationEditor/Controllers/RelationsController.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ int parentId
8383
{
8484
int otherId;
8585
Guid relatedType;
86-
if (r.ParentId == parentId)
86+
var isParent = r.ParentId == parentId;
87+
if (isParent)
8788
{
8889
otherId = r.ChildId;
8990
relatedType = rt.ChildObjectType;
@@ -98,7 +99,8 @@ int parentId
9899
var fullPath = GetFullPath(relEntity);
99100
return new RelationDto
100101
{
101-
ChildId = otherId,
102+
Readonly = !isParent,
103+
ChildId = r.ChildId,
102104
FullPath = HttpContext.Current.Server.HtmlEncode(fullPath),
103105
ChildName = (configuration.BreadcrumbMode == BreadcrumbMode.ToolTip) ? otherName : HttpContext.Current.Server.HtmlDecode(fullPath),
104106
State = RelationStateEnum.Unmodified
@@ -134,7 +136,7 @@ public void SaveRelations(ContentRelationsDto contentRelations)
134136

135137
foreach (var relation in set.Relations)
136138
{
137-
if (relation.State == RelationStateEnum.Deleted)
139+
if (relation.State == RelationStateEnum.Deleted || relation.Readonly)
138140
continue;
139141

140142
var childEntity = entityService.Get(relation.ChildId, UmbracoObjectTypesExtensions.GetUmbracoObjectType(type.ChildObjectType));
@@ -234,6 +236,7 @@ public class RelationDto
234236
public string FullPath { get; set; }
235237
public RelationStateEnum State { get; set; }
236238
public bool Deleted { get; set; }
239+
public bool Readonly { get; set; }
237240

238241
public RelationDto()
239242
{

0 commit comments

Comments
 (0)