diff --git a/zero.Core/Api/PagesApi.cs b/zero.Core/Api/PagesApi.cs
index cb44b008..52c7e49f 100644
--- a/zero.Core/Api/PagesApi.cs
+++ b/zero.Core/Api/PagesApi.cs
@@ -71,18 +71,6 @@ namespace zero.Core.Api
}
- ///
- public async Task> GetRevisions(string id, int pageNumber = 1, int pageSize = 30)
- {
- using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
- {
-
- List revisions = await session.Advanced.Revisions.GetForAsync(id, pageNumber - 1, pageSize);
- return new ListResult(revisions, revisions.Count, pageNumber, pageSize);
- }
- }
-
-
///
public async Task> Save(T model)
{
@@ -310,11 +298,6 @@ namespace zero.Core.Api
///
PageType GetPageType(string alias);
- ///
- /// Get revisions of a page (if activated in RavenDB configuration)
- ///
- Task> GetRevisions(string id, int pageNumber = 1, int pageSize = 30);
-
///
/// Creates or updates a page
///
diff --git a/zero.Core/Api/RevisionsApi.cs b/zero.Core/Api/RevisionsApi.cs
new file mode 100644
index 00000000..f0672fcb
--- /dev/null
+++ b/zero.Core/Api/RevisionsApi.cs
@@ -0,0 +1,77 @@
+using Newtonsoft.Json;
+using Raven.Client.Documents;
+using Raven.Client.Documents.Session;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using zero.Core.Entities;
+using zero.Core.Extensions;
+using zero.Core.Options;
+
+namespace zero.Core.Api
+{
+ public class RevisionsApi : IRevisionsApi
+ {
+ protected IZeroOptions Options { get; set; }
+
+ protected IDocumentStore Raven { get; set; }
+
+
+ public RevisionsApi(IZeroOptions options, IDocumentStore raven)
+ {
+ Options = options;
+ Raven = raven;
+ }
+
+
+ ///
+ /// Get revision list for an entity
+ ///
+ public async Task> GetPaged(string id, int pageNumber = 1, int pageSize = 30, bool includeContent = false) where T : IZeroEntity
+ {
+ using IAsyncDocumentSession session = Raven.OpenAsyncSession();
+
+ List items = await session.Advanced.Revisions.GetForAsync(id, pageNumber - 1, pageSize);
+ List revisions = new List();
+
+ string[] userIds = items.Select(x => x.LastModifiedById).Distinct().ToArray();
+ Dictionary users = await session.LoadAsync(userIds);
+
+ foreach (T item in items)
+ {
+ DateTime? date = session.Advanced.GetLastModifiedFor(item);
+
+ Revision revision = new Revision()
+ {
+ ChangeVector = session.Advanced.GetChangeVectorFor(item),
+ Date = date.HasValue ? new DateTimeOffset(date.Value) : item.CreatedDate,
+ Json = includeContent ? JsonConvert.SerializeObject(item) : null
+ };
+
+ if (!item.LastModifiedById.IsNullOrEmpty() && users.TryGetValue(item.LastModifiedById, out User user))
+ {
+ revision.User = new RevisionUser()
+ {
+ AvatarId = user.AvatarId,
+ Id = user.Id,
+ Name = user.Name
+ };
+ }
+
+ revisions.Add(revision);
+ }
+
+ return new ListResult(revisions, revisions.Count, pageNumber, pageSize);
+ }
+ }
+
+
+ public interface IRevisionsApi
+ {
+ ///
+ /// Get revision list (without content JSON) for an entity
+ ///
+ Task> GetPaged(string id, int pageNumber = 1, int pageSize = 30, bool includeContent = false) where T : IZeroEntity;
+ }
+}
diff --git a/zero.Core/Entities/Revision.cs b/zero.Core/Entities/Revision.cs
index 4b34b46e..884e2fc7 100644
--- a/zero.Core/Entities/Revision.cs
+++ b/zero.Core/Entities/Revision.cs
@@ -1,29 +1,24 @@
-//using System;
+using System;
-//namespace zero.Core.Entities
-//{
-// public class Revision : ZeroEntity, IRevision
-// {
-// ///
-// public string Content { get; set; }
-// }
+namespace zero.Core.Entities
+{
+ public class Revision
+ {
+ public RevisionUser User { get; set; }
+ public DateTimeOffset Date { get; set; }
-// public interface IRevision : IZeroEntity, IZeroDbConventions
-// {
-// ///
-// /// Id of the affected entity
-// ///
-// string EntityId { get; set; }
+ public string ChangeVector { get; set; }
-// ///
-// /// Id of the affected entity
-// ///
-// string EntityId { get; set; }
+ public string Json { get; set; }
+ }
-// ///
-// /// Contains the content as JSON
-// ///
-// string Content { get; set; }
-// }
-//}
+ public class RevisionUser
+ {
+ public string Id { get; set; }
+
+ public string Name { get; set; }
+
+ public string AvatarId { get; set; }
+ }
+}
diff --git a/zero.Core/Extensions/RavenDocumentSessionExtensions.cs b/zero.Core/Extensions/RavenDocumentSessionExtensions.cs
new file mode 100644
index 00000000..04b08ada
--- /dev/null
+++ b/zero.Core/Extensions/RavenDocumentSessionExtensions.cs
@@ -0,0 +1,49 @@
+using Raven.Client.Documents.Session;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using zero.Core.Entities;
+
+namespace zero.Core.Extensions
+{
+ public static class RavenDocumentSessionExtensions
+ {
+ ///
+ /// Get revision list (without content JSON) for an entity
+ ///
+ public static async Task> GetRevisions(this IAsyncDocumentSession session, string id, int pageNumber = 1, int pageSize = 30) where T : IZeroEntity
+ {
+ List items = await session.Advanced.Revisions.GetForAsync(id, pageNumber - 1, pageSize);
+ List revisions = new List();
+
+ string[] userIds = items.Select(x => x.LastModifiedById).Distinct().ToArray();
+ Dictionary users = await session.LoadAsync(userIds);
+
+ foreach (T item in items)
+ {
+ DateTime? date = session.Advanced.GetLastModifiedFor(item);
+
+ Revision revision = new Revision()
+ {
+ ChangeVector = session.Advanced.GetChangeVectorFor(item),
+ Date = date.HasValue ? new DateTimeOffset(date.Value) : item.CreatedDate
+ };
+
+ if (!item.LastModifiedById.IsNullOrEmpty() && users.TryGetValue(item.LastModifiedById, out User user))
+ {
+ revision.User = new RevisionUser()
+ {
+ AvatarId = user.AvatarId,
+ Id = user.Id,
+ Name = user.Name
+ };
+ }
+
+ revisions.Add(revision);
+ }
+
+ return new ListResult(revisions, revisions.Count, pageNumber, pageSize);
+ }
+ }
+}
diff --git a/zero.Core/Extensions/DocumentStoreExtensions.cs b/zero.Core/Extensions/RavenDocumentStoreExtensions.cs
similarity index 98%
rename from zero.Core/Extensions/DocumentStoreExtensions.cs
rename to zero.Core/Extensions/RavenDocumentStoreExtensions.cs
index 123576f6..4e0c2772 100644
--- a/zero.Core/Extensions/DocumentStoreExtensions.cs
+++ b/zero.Core/Extensions/RavenDocumentStoreExtensions.cs
@@ -12,7 +12,7 @@ using zero.Core.Utils;
namespace zero.Core.Extensions
{
- public static class DocumentStoreExtensions
+ public static class RavenDocumentStoreExtensions
{
///
/// Setup conventions for the document store
diff --git a/zero.Web.UI/App/components/date.vue b/zero.Web.UI/App/components/date.vue
index 2dc7664c..03f9879a 100644
--- a/zero.Web.UI/App/components/date.vue
+++ b/zero.Web.UI/App/components/date.vue
@@ -18,6 +18,10 @@
format: {
type: String,
default: null
+ },
+ split: {
+ type: Boolean,
+ default: false
}
},
@@ -47,10 +51,24 @@
return;
}
- this.output = Strings.date(this.value, this.format);
+ if (!this.split)
+ {
+ this.output = Strings.date(this.value, this.format);
+ }
+ else
+ {
+ this.output = Strings.date(this.value, 'short') + ' ' + Strings.date(this.value, 'time') + '';
+ }
}
}
}
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/zero.Web.UI/App/components/revisions.vue b/zero.Web.UI/App/components/revisions.vue
new file mode 100644
index 00000000..c343aedf
--- /dev/null
+++ b/zero.Web.UI/App/components/revisions.vue
@@ -0,0 +1,112 @@
+
+
+
+
updated
+
+
+
+ {{revision.user.name}}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/zero.Web.UI/App/pages/pages/page-info.vue b/zero.Web.UI/App/pages/pages/page-info.vue
index 1dc1626d..7420a481 100644
--- a/zero.Web.UI/App/pages/pages/page-info.vue
+++ b/zero.Web.UI/App/pages/pages/page-info.vue
@@ -1,7 +1,11 @@