Added compact mode for the editor log

This commit is contained in:
Eduard Urbach 2020-02-10 17:46:26 +09:00
parent 79cba90a4a
commit 70849553ef
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 31 additions and 6 deletions

View File

@ -16,11 +16,12 @@ const (
entriesPerScroll = 40 entriesPerScroll = 40
) )
// Get edit log. // All edit log.
func Get(ctx aero.Context) error { func All(ctx aero.Context) error {
user := arn.GetUserFromContext(ctx) user := arn.GetUserFromContext(ctx)
index, _ := ctx.GetInt("index") index, _ := ctx.GetInt("index")
nick := ctx.Get("nick") nick := ctx.Get("nick")
compact := ctx.Query("compact") == "true"
if user == nil || (user.Role != "editor" && user.Role != "admin") { if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized") return ctx.Error(http.StatusUnauthorized, "Not authorized")
@ -43,6 +44,23 @@ func Get(ctx aero.Context) error {
// Sort by creation date // Sort by creation date
arn.SortEditLogEntriesLatestFirst(allEntries) 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 // Slice the part that we need
entries := allEntries[index:] entries := allEntries[index:]
maxLength := entriesFirstLoad maxLength := entriesFirstLoad

View File

@ -4,6 +4,13 @@ component EditLogPage(entries []*arn.EditLogEntry, nextIndex int, viewUser *arn.
else else
h1.mountable Editor log 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) EditLog(entries, user)
if nextIndex != -1 if nextIndex != -1

View File

@ -68,10 +68,10 @@ func Register(app *aero.Application) {
page.Get(app, "/editor/jobs", jobs.Overview) page.Get(app, "/editor/jobs", jobs.Overview)
// Log // Log
page.Get(app, "/log", editlog.Get) page.Get(app, "/log", editlog.All)
page.Get(app, "/log/from/:index", editlog.Get) page.Get(app, "/log/from/:index", editlog.All)
page.Get(app, "/user/:nick/log", editlog.Get) page.Get(app, "/user/:nick/log", editlog.All)
page.Get(app, "/user/:nick/log/from/:index", editlog.Get) page.Get(app, "/user/:nick/log/from/:index", editlog.All)
// Admin // Admin
page.Get(app, "/admin", admin.Get) page.Get(app, "/admin", admin.Get)