From 10f6f8df909810a42bcec3bb7b207f3a9867f95b Mon Sep 17 00:00:00 2001 From: James Coxhead Date: Thu, 15 Nov 2018 22:22:15 +0000 Subject: [PATCH] Show relations in edit view --- .../views/relationtypes/edit.controller.js | 18 +++++-- .../src/views/relationtypes/edit.html | 45 ++++++---------- .../Editors/RelationTypeController.cs | 7 ++- .../Models/ContentEditing/Relation.cs | 4 +- .../Models/ContentEditing/RelationDisplay.cs | 52 +++++++++++++++++++ .../ContentEditing/RelationTypeDisplay.cs | 9 ++++ .../Models/Mapping/RelationMapperProfile.cs | 4 ++ .../Trees/RelationTypeTreeController.cs | 6 +-- src/Umbraco.Web/Umbraco.Web.csproj | 1 + 9 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 src/Umbraco.Web/Models/ContentEditing/RelationDisplay.cs diff --git a/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.controller.js index 37eb1ea6d9..290117850c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.controller.js @@ -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); diff --git a/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.html b/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.html index 3f88c914f4..c822c90a15 100644 --- a/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.html +++ b/src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.html @@ -4,8 +4,8 @@
@@ -15,8 +15,8 @@ -
{{vm.relation.id}}
- {{vm.relation.key}} +
{{vm.relationType.id}}
+ {{vm.relationType.key}}
@@ -24,12 +24,12 @@
@@ -37,23 +37,22 @@ -
{{vm.relation.parentObjectTypeName}}
+
{{vm.relationType.parentObjectTypeName}}
-
{{vm.relation.childObjectTypeName}}
+
{{vm.relationType.childObjectTypeName}}
- -
12
+ +
{{vm.relationType.relations.length}}
- +
- @@ -61,23 +60,11 @@ - - - - - - - - - - - - - - - - - + + + + +
ParentCreated Comment
SomethingSomething else2018-10-27 18:58A comment here
SomethingSomething else2018-10-27 18:58A comment here
SomethingSomething else2018-10-27 18:58A comment here
{{relation.parentId}}{{relation.childId}}{{relation.timestampFormatted}}{{relation.comment}}
diff --git a/src/Umbraco.Web/Editors/RelationTypeController.cs b/src/Umbraco.Web/Editors/RelationTypeController.cs index 2b9242ef31..552f3601e9 100644 --- a/src/Umbraco.Web/Editors/RelationTypeController.cs +++ b/src/Umbraco.Web/Editors/RelationTypeController.cs @@ -35,8 +35,13 @@ namespace Umbraco.Web.Editors { throw new HttpResponseException(HttpStatusCode.NotFound); } + + var relations = Services.RelationService.GetByRelationTypeId(relationType.Id); - return Mapper.Map(relationType); + var display = Mapper.Map(relationType); + display.Relations = Mapper.Map, IEnumerable>(relations); + + return display; } public void PostSave() diff --git a/src/Umbraco.Web/Models/ContentEditing/Relation.cs b/src/Umbraco.Web/Models/ContentEditing/Relation.cs index b166c67f55..2b012dc750 100644 --- a/src/Umbraco.Web/Models/ContentEditing/Relation.cs +++ b/src/Umbraco.Web/Models/ContentEditing/Relation.cs @@ -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 { diff --git a/src/Umbraco.Web/Models/ContentEditing/RelationDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/RelationDisplay.cs new file mode 100644 index 0000000000..24ebabc615 --- /dev/null +++ b/src/Umbraco.Web/Models/ContentEditing/RelationDisplay.cs @@ -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 + { + /// + /// Gets or sets the Parent Id of the Relation (Source). + /// + [DataMember(Name = "parentId")] + [ReadOnly(true)] + public int ParentId { get; set; } + + /// + /// Gets or sets the Parent Name of the relation (Source). + /// + [DataMember(Name = "parentName")] + [ReadOnly(true)] + public string ParentName { get; set; } + + /// + /// Gets or sets the Child Id of the Relation (Destination). + /// + [DataMember(Name = "childId")] + [ReadOnly(true)] + public int ChildId { get; set; } + + /// + /// Gets or sets the Child Name of the relation (Destination). + /// + [DataMember(Name = "childName")] + [ReadOnly(true)] + public string ChildName { get; set; } + + /// + /// Gets or sets the date when the Relation was created. + /// + [DataMember(Name = "createDate")] + [ReadOnly(true)] + public DateTime CreateDate { get; set; } + + /// + /// Gets or sets a comment for the Relation. + /// + [DataMember(Name = "comment")] + [ReadOnly(true)] + public string Comment { get; set; } + } +} diff --git a/src/Umbraco.Web/Models/ContentEditing/RelationTypeDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/RelationTypeDisplay.cs index 3861e0938d..4873d2288d 100644 --- a/src/Umbraco.Web/Models/ContentEditing/RelationTypeDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/RelationTypeDisplay.cs @@ -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; } + + /// + /// Gets or sets the relations associated with this relation type. + /// + [DataMember(Name = "relations")] + [ReadOnly(true)] + public IEnumerable Relations { get; set; } } } diff --git a/src/Umbraco.Web/Models/Mapping/RelationMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/RelationMapperProfile.cs index 95f4fab054..e56fd2ad3b 100644 --- a/src/Umbraco.Web/Models/Mapping/RelationMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/RelationMapperProfile.cs @@ -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(); + //FROM IRelationType TO RelationType CreateMap(); diff --git a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs index 884b6c5f54..5dbe18a690 100644 --- a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs @@ -24,10 +24,8 @@ namespace Umbraco.Web.Trees if (id == Constants.System.Root.ToInvariantString()) { //Create the normal create action - menu.Items.Add(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("application")); + menu.Items.Add(Services.TextService.Localize("actions", ActionNew.Instance.Alias)); + //refresh action menu.Items.Add(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 7e51974bc9..76ea0d92cf 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -148,6 +148,7 @@ +