From 70849553efd553f519ccb1a3f9cc28821d6624c6 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 10 Feb 2020 17:46:26 +0900 Subject: [PATCH] Added compact mode for the editor log --- pages/editlog/editlog.go | 22 ++++++++++++++++++++-- pages/editlog/editlog.pixy | 7 +++++++ pages/index/staffroutes/staffroutes.go | 8 ++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pages/editlog/editlog.go b/pages/editlog/editlog.go index df5c538e..77139487 100644 --- a/pages/editlog/editlog.go +++ b/pages/editlog/editlog.go @@ -16,11 +16,12 @@ const ( entriesPerScroll = 40 ) -// Get edit log. -func Get(ctx aero.Context) error { +// All edit log. +func All(ctx aero.Context) error { user := arn.GetUserFromContext(ctx) index, _ := ctx.GetInt("index") nick := ctx.Get("nick") + compact := ctx.Query("compact") == "true" if user == nil || (user.Role != "editor" && user.Role != "admin") { return ctx.Error(http.StatusUnauthorized, "Not authorized") @@ -43,6 +44,23 @@ func Get(ctx aero.Context) error { // Sort by creation date arn.SortEditLogEntriesLatestFirst(allEntries) + // Show only one entry for a single object in compact mode + if compact { + filteredEntries := make([]*arn.EditLogEntry, 0, len(allEntries)) + lastObjectID := "" + + for _, entry := range allEntries { + if lastObjectID == entry.ObjectID { + continue + } + + filteredEntries = append(filteredEntries, entry) + lastObjectID = entry.ObjectID + } + + allEntries = filteredEntries + } + // Slice the part that we need entries := allEntries[index:] maxLength := entriesFirstLoad diff --git a/pages/editlog/editlog.pixy b/pages/editlog/editlog.pixy index 52c54fb0..c02a0f9c 100644 --- a/pages/editlog/editlog.pixy +++ b/pages/editlog/editlog.pixy @@ -4,6 +4,13 @@ component EditLogPage(entries []*arn.EditLogEntry, nextIndex int, viewUser *arn. else h1.mountable Editor log + .corner-buttons + a.button(href="/log", title="Full list") + RawIcon("list") + + a.button(href="/log?compact=true", title="Compact list") + RawIcon("list-alt") + EditLog(entries, user) if nextIndex != -1 diff --git a/pages/index/staffroutes/staffroutes.go b/pages/index/staffroutes/staffroutes.go index eae945e8..1cd5fe9c 100644 --- a/pages/index/staffroutes/staffroutes.go +++ b/pages/index/staffroutes/staffroutes.go @@ -68,10 +68,10 @@ func Register(app *aero.Application) { page.Get(app, "/editor/jobs", jobs.Overview) // Log - page.Get(app, "/log", editlog.Get) - page.Get(app, "/log/from/:index", editlog.Get) - page.Get(app, "/user/:nick/log", editlog.Get) - page.Get(app, "/user/:nick/log/from/:index", editlog.Get) + page.Get(app, "/log", editlog.All) + page.Get(app, "/log/from/:index", editlog.All) + page.Get(app, "/user/:nick/log", editlog.All) + page.Get(app, "/user/:nick/log/from/:index", editlog.All) // Admin page.Get(app, "/admin", admin.Get)