diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.restore.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.restore.controller.js index 0f492e74be..53b7701098 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.restore.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.restore.controller.js @@ -4,14 +4,29 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.RestoreController" var node = dialogOptions.currentNode; - relationResource.getByChildId(node.id, "relateParentDocumentOnDelete").then(function (data) { - $scope.relation = data[0]; + $scope.error = null; + $scope.success = false; - if ($scope.relation.ParentId == -1) { + relationResource.getByChildId(node.id, "relateParentDocumentOnDelete").then(function (data) { + + if (data.length == 0) { + $scope.success = false; + $scope.error = { + errorMsg: "Cannot automatically restore this item", + data: { + Message: "There is no 'restore' relation found for this node. Use the Move menu item to move it manually." + } + } + return; + } + + $scope.relation = data[0]; + + if ($scope.relation.parentId == -1) { $scope.target = { id: -1, name: "Root" }; } else { - contentResource.getById($scope.relation.ParentId).then(function (data) { + contentResource.getById($scope.relation.parentId).then(function (data) { $scope.target = data; }, function (err) { @@ -29,7 +44,7 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.RestoreController" // this code was copied from `content.move.controller.js` contentResource.move({ parentId: $scope.target.id, id: node.id }) .then(function (path) { - $scope.error = false; + $scope.success = true; //first we need to remove the node that launched the dialog diff --git a/src/Umbraco.Web.UI.Client/src/views/content/restore.html b/src/Umbraco.Web.UI.Client/src/views/content/restore.html index 4652e20402..c1901c4252 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/restore.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/restore.html @@ -1,26 +1,26 @@
-
+ -

+

Restore {{currentNode.name}} to under {{target.name}}?

-
+

{{error.errorMsg}}

{{error.data.Message}}

-
+

{{currentNode.name}} was moved underneath {{target.name}}

-
+
- \ No newline at end of file diff --git a/src/Umbraco.Web/Editors/RelationController.cs b/src/Umbraco.Web/Editors/RelationController.cs index 5457abbe9a..099d5b5c13 100644 --- a/src/Umbraco.Web/Editors/RelationController.cs +++ b/src/Umbraco.Web/Editors/RelationController.cs @@ -3,17 +3,19 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; +using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; +using Relation = Umbraco.Web.Models.ContentEditing.Relation; namespace Umbraco.Web.Editors { [PluginController("UmbracoApi")] [UmbracoApplicationAuthorizeAttribute(Constants.Applications.Content)] - public class RelationController : ContentControllerBase + public class RelationController : UmbracoAuthorizedJsonController { public RelationController() : this(UmbracoContext.Current) @@ -25,38 +27,40 @@ namespace Umbraco.Web.Editors { } - public IRelation GetById(int id) + public Relation GetById(int id) { - return Services.RelationService.GetById(id); + return Mapper.Map(Services.RelationService.GetById(id)); } - [EnsureUserPermissionForContent("childId")] - public IEnumerable GetByChildId(int childId, string relationTypeAlias = "") + //[EnsureUserPermissionForContent("childId")] + public IEnumerable GetByChildId(int childId, string relationTypeAlias = "") { - var relations = Services.RelationService.GetByChildId(childId); + var relations = Services.RelationService.GetByChildId(childId).ToArray(); - if (relations == null) + if (relations.Any() == false) { - throw new HttpResponseException(HttpStatusCode.NotFound); + return Enumerable.Empty(); } - if (!string.IsNullOrWhiteSpace(relationTypeAlias)) + if (string.IsNullOrWhiteSpace(relationTypeAlias) == false) { - return relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias)); + return + Mapper.Map, IEnumerable>( + relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias))); } - return relations; + return Mapper.Map, IEnumerable>(relations); } [HttpDelete] [HttpPost] public HttpResponseMessage DeleteById(int id) { - var foundRelation = GetObjectFromRequest(() => Services.RelationService.GetById(id)); + var foundRelation = Services.RelationService.GetById(id); if (foundRelation == null) { - return HandleContentNotFound(id, false); + return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No relation found with the specified id"); } Services.RelationService.Delete(foundRelation); diff --git a/src/Umbraco.Web/Models/ContentEditing/Relation.cs b/src/Umbraco.Web/Models/ContentEditing/Relation.cs new file mode 100644 index 0000000000..b166c67f55 --- /dev/null +++ b/src/Umbraco.Web/Models/ContentEditing/Relation.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Umbraco.Web.Models.ContentEditing +{ + [DataContract(Name = "relation", Namespace = "")] + public class Relation + { + + public Relation() + { + RelationType = new RelationType(); + } + + /// + /// Gets or sets the Parent Id of the Relation (Source) + /// + [DataMember(Name = "parentId")] + public int ParentId { get; set; } + + /// + /// Gets or sets the Child Id of the Relation (Destination) + /// + [DataMember(Name = "childId")] + public int ChildId { get; set; } + + /// + /// Gets or sets the for the Relation + /// + [DataMember(Name = "relationType", IsRequired = true)] + public RelationType RelationType { get; set; } + + /// + /// Gets or sets a comment for the Relation + /// + [DataMember(Name = "comment")] + public string Comment { get; set; } + + } +} diff --git a/src/Umbraco.Web/Models/ContentEditing/RelationType.cs b/src/Umbraco.Web/Models/ContentEditing/RelationType.cs new file mode 100644 index 0000000000..8c29343319 --- /dev/null +++ b/src/Umbraco.Web/Models/ContentEditing/RelationType.cs @@ -0,0 +1,42 @@ +using System; +using System.Runtime.Serialization; + +namespace Umbraco.Web.Models.ContentEditing +{ + [DataContract(Name = "relationType", Namespace = "")] + public class RelationType + { + + /// + /// Gets or sets the Name of the RelationType + /// + [DataMember(Name = "name", IsRequired = true)] + public string Name { get; set; } + + /// + /// Gets or sets the Alias of the RelationType + /// + [DataMember(Name = "alias", IsRequired = true)] + public string Alias { get; set; } + + /// + /// Gets or sets a boolean indicating whether the RelationType is Bidirectional (true) or Parent to Child (false) + /// + [DataMember(Name = "isBidirectional", IsRequired = true)] + public bool IsBidirectional { get; set; } + + /// + /// Gets or sets the Parents object type id + /// + /// Corresponds to the NodeObjectType in the umbracoNode table + [DataMember(Name = "parentObjectType", IsRequired = true)] + public Guid ParentObjectType { get; set; } + + /// + /// Gets or sets the Childs object type id + /// + /// Corresponds to the NodeObjectType in the umbracoNode table + [DataMember(Name = "childObjectType", IsRequired = true)] + public Guid ChildObjectType { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Models/Mapping/RelationModelMapper.cs b/src/Umbraco.Web/Models/Mapping/RelationModelMapper.cs new file mode 100644 index 0000000000..bc133abf96 --- /dev/null +++ b/src/Umbraco.Web/Models/Mapping/RelationModelMapper.cs @@ -0,0 +1,21 @@ +using AutoMapper; +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Mapping; +using Relation = Umbraco.Web.Models.ContentEditing.Relation; +using RelationType = Umbraco.Web.Models.ContentEditing.RelationType; + +namespace Umbraco.Web.Models.Mapping +{ + internal class RelationModelMapper : MapperConfiguration + { + public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext) + { + //FROM IRelationType TO RelationType + config.CreateMap(); + + //FROM IRelation TO Relation + config.CreateMap(); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 43e05789b8..c8a4cc61e7 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -268,8 +268,11 @@ + + +