Show relations in edit view

This commit is contained in:
James Coxhead
2018-11-15 22:22:15 +00:00
parent 06d19f2735
commit 10f6f8df90
9 changed files with 108 additions and 38 deletions

View File

@@ -1,4 +1,4 @@
function RelationTypeEditController($scope, $routeParams, relationTypeResource, editorState, navigationService) {
function RelationTypeEditController($scope, $routeParams, relationTypeResource, editorState, navigationService, dateHelper, userService) {
var vm = this;
@@ -14,17 +14,29 @@ function RelationTypeEditController($scope, $routeParams, relationTypeResource,
relationTypeResource.getById($routeParams.id)
.then(function(data) {
vm.relation = data;
vm.relationType = data;
editorState.set(vm.relation);
editorState.set(vm.relationType);
navigationService.syncTree({ tree: "relationTypes", path: data.path, forceReload: true }).then(function (syncArgs) {
vm.page.menu.currentNode = syncArgs.node;
});
formatDates(vm.relationType.relations);
vm.page.loading = false;
});
}
function formatDates(relations) {
if(relations) {
userService.getCurrentUser().then(function (currentUser) {
angular.forEach(relations, function (relation) {
relation.timestampFormatted = dateHelper.getLocalDate(relation.createDate, currentUser.locale, 'LLL');
});
});
}
}
}
angular.module("umbraco").controller("Umbraco.Editors.RelationTypes.EditController", RelationTypeEditController);

View File

@@ -4,8 +4,8 @@
<form name="relationTypeForm" novalidate val-form-manager>
<umb-editor-view ng-if="!vm.page.loading">
<umb-editor-header
name="vm.relation.name"
alias="vm.relation.alias"
name="vm.relationType.name"
alias="vm.relationType.alias"
hide-description="true"
hide-icon="true">
</umb-editor-header>
@@ -15,8 +15,8 @@
<umb-box-content>
<!-- ID -->
<umb-control-group label="Id">
<div>{{vm.relation.id}}</div>
<small>{{vm.relation.key}}</small>
<div>{{vm.relationType.id}}</div>
<small>{{vm.relationType.key}}</small>
</umb-control-group>
<!-- Direction -->
@@ -24,12 +24,12 @@
<ul class="unstyled">
<li>
<label class="radio">
<input type="radio" name="relationType-direction" ng-model="vm.relation.isBidirectional" ng-value="false"> Parent to child
<input type="radio" name="relationType-direction" ng-model="vm.relationType.isBidirectional" ng-value="false"> Parent to child
</label>
</li>
<li>
<label class="radio">
<input type="radio" name="relationType-direction" ng-model="vm.relation.isBidirectional" ng-value="true"> Bidirectional
<input type="radio" name="relationType-direction" ng-model="vm.relationType.isBidirectional" ng-value="true"> Bidirectional
</label>
</li>
</ul>
@@ -37,23 +37,22 @@
<!-- Parent-->
<umb-control-group label="Parent">
<div>{{vm.relation.parentObjectTypeName}}</div>
<div>{{vm.relationType.parentObjectTypeName}}</div>
</umb-control-group>
<!-- Child -->
<umb-control-group label="Child">
<div>{{vm.relation.childObjectTypeName}}</div>
<div>{{vm.relationType.childObjectTypeName}}</div>
</umb-control-group>
<!-- Relation count -->
<umb-control-group label="Count">
<div>12</div>
<umb-control-group label="Count" ng-if="vm.relationType.relations.length > 0">
<div>{{vm.relationType.relations.length}}</div>
</umb-control-group>
<!-- Relations -->
<umb-control-group label="Relations">
<umb-control-group label="Relations" ng-if="vm.relationType.relations.length > 0">
<div>
<!-- TODO: Replace with umb-table directive -->
<table class="table">
<thead>
<th>Parent</th>
@@ -61,23 +60,11 @@
<th>Created</th>
<th>Comment</th>
</thead>
<tr>
<td>Something</td>
<td>Something else</td>
<td>2018-10-27 18:58</td>
<td>A comment here</td>
</tr>
<tr>
<td>Something</td>
<td>Something else</td>
<td>2018-10-27 18:58</td>
<td>A comment here</td>
</tr>
<tr>
<td>Something</td>
<td>Something else</td>
<td>2018-10-27 18:58</td>
<td>A comment here</td>
<tr ng-repeat="relation in vm.relationType.relations">
<td>{{relation.parentId}}</td>
<td>{{relation.childId}}</td>
<td>{{relation.timestampFormatted}}</td>
<td>{{relation.comment}}</td>
</tr>
</table>
</div>

View File

@@ -35,8 +35,13 @@ namespace Umbraco.Web.Editors
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var relations = Services.RelationService.GetByRelationTypeId(relationType.Id);
return Mapper.Map<IRelationType, RelationTypeDisplay>(relationType);
var display = Mapper.Map<IRelationType, RelationTypeDisplay>(relationType);
display.Relations = Mapper.Map<IEnumerable<IRelation>, IEnumerable<RelationDisplay>>(relations);
return display;
}
public void PostSave()

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
@@ -6,6 +7,7 @@ using System.Threading.Tasks;
namespace Umbraco.Web.Models.ContentEditing
{
[Obsolete("Use Umbraco.Web.Models.ContentEditing.RelationDisplay instead")]
[DataContract(Name = "relation", Namespace = "")]
public class Relation
{

View File

@@ -0,0 +1,52 @@
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "relation", Namespace = "")]
public class RelationDisplay
{
/// <summary>
/// Gets or sets the Parent Id of the Relation (Source).
/// </summary>
[DataMember(Name = "parentId")]
[ReadOnly(true)]
public int ParentId { get; set; }
/// <summary>
/// Gets or sets the Parent Name of the relation (Source).
/// </summary>
[DataMember(Name = "parentName")]
[ReadOnly(true)]
public string ParentName { get; set; }
/// <summary>
/// Gets or sets the Child Id of the Relation (Destination).
/// </summary>
[DataMember(Name = "childId")]
[ReadOnly(true)]
public int ChildId { get; set; }
/// <summary>
/// Gets or sets the Child Name of the relation (Destination).
/// </summary>
[DataMember(Name = "childName")]
[ReadOnly(true)]
public string ChildName { get; set; }
/// <summary>
/// Gets or sets the date when the Relation was created.
/// </summary>
[DataMember(Name = "createDate")]
[ReadOnly(true)]
public DateTime CreateDate { get; set; }
/// <summary>
/// Gets or sets a comment for the Relation.
/// </summary>
[DataMember(Name = "comment")]
[ReadOnly(true)]
public string Comment { get; set; }
}
}

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
@@ -40,5 +42,12 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "childObjectTypeName")]
[ReadOnly(true)]
public string ChildObjectTypeName { get; set; }
/// <summary>
/// Gets or sets the relations associated with this relation type.
/// </summary>
[DataMember(Name = "relations")]
[ReadOnly(true)]
public IEnumerable<RelationDisplay> Relations { get; set; }
}
}

View File

@@ -20,6 +20,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(x => x.AdditionalData, expression => expression.Ignore())
.ForMember(x => x.ChildObjectTypeName, expression => expression.Ignore())
.ForMember(x => x.ParentObjectTypeName, expression => expression.Ignore())
.ForMember(x => x.Relations, expression => expression.Ignore())
.ForMember(
x => x.Udi,
expression => expression.MapFrom(
@@ -34,6 +35,9 @@ namespace Umbraco.Web.Models.Mapping
dest.ChildObjectTypeName = ObjectTypes.GetUmbracoObjectType(src.ChildObjectType).GetFriendlyName();
});
// FROM IRelation to RelationDisplay
CreateMap<IRelation, RelationDisplay>();
//FROM IRelationType TO RelationType
CreateMap<IRelationType, RelationType>();

View File

@@ -24,10 +24,8 @@ namespace Umbraco.Web.Trees
if (id == Constants.System.Root.ToInvariantString())
{
//Create the normal create action
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias))
//Since we haven't implemented anything for relationtypes in angular, this needs to be converted to
//use the legacy format
.ConvertLegacyMenuItem(null, "initrelationTypes", queryStrings.GetValue<string>("application"));
menu.Items.Add<CreateChildEntity, ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias));
//refresh action
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);

View File

@@ -148,6 +148,7 @@
<Compile Include="Media\TypeDetector\SvgDetector.cs" />
<Compile Include="Media\TypeDetector\TIFFDetector.cs" />
<Compile Include="Media\UploadAutoFillProperties.cs" />
<Compile Include="Models\ContentEditing\RelationDisplay.cs" />
<Compile Include="Models\ContentEditing\RelationTypeDisplay.cs" />
<Compile Include="Models\ContentEditing\RollbackVersion.cs" />
<Compile Include="Models\ContentEditing\UnpublishContent.cs" />