diff --git a/zero.Core/Collections/TreeCollectionBase.cs b/zero.Core/Collections/TreeCollectionBase.cs new file mode 100644 index 00000000..71c51691 --- /dev/null +++ b/zero.Core/Collections/TreeCollectionBase.cs @@ -0,0 +1,59 @@ +using FluentValidation; +using Raven.Client; +using Raven.Client.Documents; +using Raven.Client.Documents.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using zero.Core.Entities; +using zero.Core.Extensions; + +namespace zero.Core.Collections +{ + public abstract class TreeCollectionBase : CollectionBase, ITreeCollectionBase, IDisposable where T : IZeroEntity, ITreeEntity + { + public TreeCollectionBase(IZeroContext context, ICollectionInterceptorHandler interceptorHandler, IValidator validator = null) : base(context, interceptorHandler, validator) { } + + + ///// + //public async Task> GetHierarchy(string id) + //{ + // Categories_ByHierarchy.Result result = await Session.Query() + // .ProjectInto() + // .Include(x => x.Path.Select(p => p.Id)) + // .FirstOrDefaultAsync(x => x.Id == id); + + // if (result == null) + // { + // return new(); + // } + + // return (await Session.LoadAsync(result.Path.Select(x => x.Id))).Select(x => x.Value).ToList(); + //} + } + + + public interface ITreeCollectionBase : ICollectionBase where T : IZeroEntity, ITreeEntity + { + ///// + ///// Get the tree hierarchy path for this entity + ///// + //Task> GetHierarchy(string id); + + ///// + ///// Update sorting of entities on a specific level + ///// + //Task>> SaveSorting(string[] sortedIds); + + ///// + ///// Move an entity to a new parent + ///// + //Task> Move(string id, string parentId); + + ///// + ///// Copies an entity to a new location + ///// + //Task> Copy(string id, string destinationId, bool includeDescendants = false); + } +} diff --git a/zero.Core/Database/Indexes/TreeEntity_ByPath.cs b/zero.Core/Database/Indexes/TreeEntity_ByPath.cs new file mode 100644 index 00000000..3ef64fcd --- /dev/null +++ b/zero.Core/Database/Indexes/TreeEntity_ByPath.cs @@ -0,0 +1,58 @@ +//using Raven.Client.Documents.Indexes; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using zero.Core.Entities; + +//namespace zero.Core.Database.Indexes +//{ +// public class TreeEntity_ByPath : AbstractIndexCreationTask +// { +// public class Result : IZeroIdEntity, IZeroDbConventions +// { +// public string Id { get; set; } + +// public string Name { get; set; } + +// public List Path { get; set; } = new List(); + +// public List PathIds { get; set; } = new List(); +// } + + +// public class PathResult +// { +// public string Id { get; set; } + +// public string Name { get; set; } +// } + + +// public TreeEntity_ByPath() +// { +// Map = items => items.Select(item => new Result +// { +// Id = item.Id, +// Name = item.Name, +// Path = Recurse(item, x => LoadDocument(x.ParentId)) +// .Where(x => x != null && x.Id != null && x.Id != item.Id) +// .Reverse() +// .Select(current => new PathResult() +// { +// Id = current.Id, +// Name = current.Name +// }) +// .ToList(), +// PathIds = Recurse(item, x => LoadDocument(x.ParentId)) +// .Where(x => x != null && x.Id != null && x.Id != item.Id) +// .Reverse() +// .Select(current => current.Id) +// .ToList() +// }); + +// StoreAllFields(FieldStorage.Yes); +// Index("PathIds", FieldIndexing.Exact); +// //Index(x => x.ChannelId, FieldIndexing.Exact); +// } +// } +//} diff --git a/zero.Core/Entities/ITreeEntity.cs b/zero.Core/Entities/ITreeEntity.cs new file mode 100644 index 00000000..0ce9fc19 --- /dev/null +++ b/zero.Core/Entities/ITreeEntity.cs @@ -0,0 +1,10 @@ +namespace zero.Core.Entities +{ + public interface ITreeEntity : IZeroEntity + { + /// + /// Id of the parent entity + /// + string ParentId { get; set; } + } +} diff --git a/zero.Core/Entities/Pages/Page.cs b/zero.Core/Entities/Pages/Page.cs index d1d16e54..2414dfde 100644 --- a/zero.Core/Entities/Pages/Page.cs +++ b/zero.Core/Entities/Pages/Page.cs @@ -27,18 +27,13 @@ namespace zero.Core.Entities [Collection("Pages")] - public interface IPage : IZeroEntity, IZeroDbConventions + public interface IPage : IZeroEntity, IZeroDbConventions, ITreeEntity { /// /// Use this field (when filled out) instead of the alias for URL generation /// string UrlAlias { get; set; } - /// - /// Id of the parent page - /// - string ParentId { get; set; } - /// /// Alias of the used page type /// diff --git a/zero.Web.UI/App/navigation.vue b/zero.Web.UI/App/navigation.vue index 9c09a6d3..84626396 100644 --- a/zero.Web.UI/App/navigation.vue +++ b/zero.Web.UI/App/navigation.vue @@ -1,8 +1,8 @@