Improved editor logs
This commit is contained in:
parent
66bd51f603
commit
719c04f3d5
@ -6,30 +6,64 @@ import (
|
|||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
|
|
||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/utils/infinitescroll"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxEntries = 120
|
const (
|
||||||
|
entriesFirstLoad = 120
|
||||||
|
entriesPerScroll = 30
|
||||||
|
)
|
||||||
|
|
||||||
// Get edit log.
|
// Get edit log.
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
index, _ := ctx.GetInt("index")
|
||||||
|
nick := ctx.Get("nick")
|
||||||
|
|
||||||
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", nil)
|
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
entries := arn.AllEditLogEntries()
|
viewUser, err := arn.GetUserByNick(nick)
|
||||||
|
|
||||||
// Sort by creation date
|
if nick != "" && err != nil {
|
||||||
arn.SortEditLogEntriesLatestFirst(entries)
|
return ctx.Error(http.StatusNotFound, "User not found", err)
|
||||||
|
|
||||||
// Limit results
|
|
||||||
if len(entries) > maxEntries {
|
|
||||||
entries = entries[:maxEntries]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.EditLogPage(entries, user))
|
allEntries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool {
|
||||||
|
if viewUser != nil {
|
||||||
|
return entry.UserID == viewUser.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
// Sort by creation date
|
||||||
|
arn.SortEditLogEntriesLatestFirst(allEntries)
|
||||||
|
|
||||||
|
// Slice the part that we need
|
||||||
|
entries := allEntries[index:]
|
||||||
|
maxLength := entriesFirstLoad
|
||||||
|
|
||||||
|
if index > 0 {
|
||||||
|
maxLength = entriesPerScroll
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(entries) > maxLength {
|
||||||
|
entries = entries[:maxLength]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next index
|
||||||
|
nextIndex := infinitescroll.NextIndex(ctx, len(allEntries), maxLength, index)
|
||||||
|
|
||||||
|
// In case we're scrolling, send log entries only (without the page frame)
|
||||||
|
if index > 0 {
|
||||||
|
return ctx.HTML(components.EditLogScrollable(entries, user))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, send the full page
|
||||||
|
return ctx.HTML(components.EditLogPage(entries, nextIndex, viewUser, user))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
component EditLogPage(entries []*arn.EditLogEntry, user *arn.User)
|
component EditLogPage(entries []*arn.EditLogEntry, nextIndex int, viewUser *arn.User, user *arn.User)
|
||||||
h1.mountable Editor log
|
if viewUser != nil
|
||||||
|
h1.mountable= "Editor log: " + viewUser.Nick
|
||||||
|
else
|
||||||
|
h1.mountable Editor log
|
||||||
|
|
||||||
EditLog(entries, user)
|
EditLog(entries, user)
|
||||||
|
|
||||||
|
if nextIndex != -1
|
||||||
|
.buttons
|
||||||
|
LoadMore(nextIndex)
|
||||||
|
|
||||||
component EditLog(entries []*arn.EditLogEntry, user *arn.User)
|
component EditLog(entries []*arn.EditLogEntry, user *arn.User)
|
||||||
table.edit-log
|
table.edit-log
|
||||||
thead
|
thead
|
||||||
@ -13,48 +21,51 @@ component EditLog(entries []*arn.EditLogEntry, user *arn.User)
|
|||||||
th Old
|
th Old
|
||||||
th New
|
th New
|
||||||
th Date
|
th Date
|
||||||
tbody
|
tbody#load-more-target
|
||||||
each entry in entries
|
EditLogScrollable(entries, user)
|
||||||
tr.mountable
|
|
||||||
td
|
|
||||||
.edit-log-icon(title=entry.Action)
|
|
||||||
if entry.Action == "create"
|
|
||||||
.edit-log-create
|
|
||||||
RawIcon("plus")
|
|
||||||
else if entry.Action == "delete"
|
|
||||||
.edit-log-delete
|
|
||||||
RawIcon("minus")
|
|
||||||
else if entry.Action == "edit" || entry.Action == "arrayAppend" || entry.Action == "arrayRemove"
|
|
||||||
.edit-log-change
|
|
||||||
RawIcon("pencil")
|
|
||||||
|
|
||||||
if entry.Action == "arrayAppend"
|
component EditLogScrollable(entries []*arn.EditLogEntry, user *arn.User)
|
||||||
.edit-log-sub-icon.edit-log-add
|
each entry in entries
|
||||||
RawIcon("plus-square")
|
tr.mountable
|
||||||
else if entry.Action == "arrayRemove"
|
td
|
||||||
.edit-log-sub-icon.edit-log-remove
|
.edit-log-icon(title=entry.Action)
|
||||||
RawIcon("minus-square")
|
if entry.Action == "create"
|
||||||
else
|
.edit-log-create
|
||||||
if entry.OldValue == "" && entry.NewValue != ""
|
RawIcon("plus")
|
||||||
.edit-log-sub-icon.edit-log-add
|
else if entry.Action == "delete"
|
||||||
RawIcon("plus-circle")
|
.edit-log-delete
|
||||||
else if entry.OldValue != "" && entry.NewValue == ""
|
RawIcon("minus")
|
||||||
.edit-log-sub-icon.edit-log-remove
|
else if entry.Action == "edit" || entry.Action == "arrayAppend" || entry.Action == "arrayRemove"
|
||||||
RawIcon("minus-circle")
|
.edit-log-change
|
||||||
|
RawIcon("pencil")
|
||||||
|
|
||||||
td
|
if entry.Action == "arrayAppend"
|
||||||
.edit-log-user
|
.edit-log-sub-icon.edit-log-add
|
||||||
Avatar(entry.User())
|
RawIcon("plus-square")
|
||||||
td.edit-log-object
|
else if entry.Action == "arrayRemove"
|
||||||
if strings.HasPrefix(arn.GetObjectTitle(entry.ObjectType, entry.ObjectID), "<not found:")
|
.edit-log-sub-icon.edit-log-remove
|
||||||
span= arn.GetObjectTitle(entry.ObjectType, entry.ObjectID)
|
RawIcon("minus-square")
|
||||||
else
|
else
|
||||||
a(href="/" + strings.ToLower(entry.ObjectType) + "/" + entry.ObjectID, target="_blank")= arn.GetObjectTitle(entry.ObjectType, entry.ObjectID)
|
if entry.OldValue == "" && entry.NewValue != ""
|
||||||
td.edit-log-key
|
.edit-log-sub-icon.edit-log-add
|
||||||
span= entry.ObjectType
|
RawIcon("plus-circle")
|
||||||
|
else if entry.OldValue != "" && entry.NewValue == ""
|
||||||
|
.edit-log-sub-icon.edit-log-remove
|
||||||
|
RawIcon("minus-circle")
|
||||||
|
|
||||||
if entry.Key != ""
|
td
|
||||||
span= "." + entry.Key
|
.edit-log-user
|
||||||
td.edit-log-value(title=entry.OldValue)= entry.OldValue
|
Avatar(entry.User())
|
||||||
td.edit-log-value(title=entry.NewValue)= entry.NewValue
|
td.edit-log-object
|
||||||
td.edit-log-date.utc-date(data-date=entry.Created)
|
if strings.HasPrefix(arn.GetObjectTitle(entry.ObjectType, entry.ObjectID), "<not found:")
|
||||||
|
span= arn.GetObjectTitle(entry.ObjectType, entry.ObjectID)
|
||||||
|
else
|
||||||
|
a(href="/" + strings.ToLower(entry.ObjectType) + "/" + entry.ObjectID, target="_blank")= arn.GetObjectTitle(entry.ObjectType, entry.ObjectID)
|
||||||
|
td.edit-log-key
|
||||||
|
span= entry.ObjectType
|
||||||
|
|
||||||
|
if entry.Key != ""
|
||||||
|
span= "." + entry.Key
|
||||||
|
td.edit-log-value(title=entry.OldValue)= entry.OldValue
|
||||||
|
td.edit-log-value(title=entry.NewValue)= entry.NewValue
|
||||||
|
td.edit-log-date.utc-date(data-date=entry.Created)
|
@ -305,6 +305,9 @@ func Configure(app *aero.Application) {
|
|||||||
|
|
||||||
// Log
|
// Log
|
||||||
l.Page("/log", editlog.Get)
|
l.Page("/log", editlog.Get)
|
||||||
|
l.Page("/log/from/:index", editlog.Get)
|
||||||
|
l.Page("/user/:nick/log", editlog.Get)
|
||||||
|
l.Page("/user/:nick/log/from/:index", editlog.Get)
|
||||||
|
|
||||||
// Mixed
|
// Mixed
|
||||||
// l.Page("/database", database.Get)
|
// l.Page("/database", database.Get)
|
||||||
|
@ -126,3 +126,8 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string)
|
|||||||
Icon("archive")
|
Icon("archive")
|
||||||
span Recomms
|
span Recomms
|
||||||
|
|
||||||
|
if user != nil && (user.Role == "editor" || user.Role == "admin")
|
||||||
|
a.button.profile-action(href="/+" + viewUser.Nick + "/log")
|
||||||
|
Icon("edit")
|
||||||
|
span Log
|
||||||
|
|
@ -1,3 +1,5 @@
|
|||||||
|
import Diff from "./Diff"
|
||||||
|
|
||||||
export default class InfiniteScroller {
|
export default class InfiniteScroller {
|
||||||
container: HTMLElement
|
container: HTMLElement
|
||||||
threshold: number
|
threshold: number
|
||||||
@ -6,10 +8,21 @@ export default class InfiniteScroller {
|
|||||||
this.container = container
|
this.container = container
|
||||||
this.threshold = threshold
|
this.threshold = threshold
|
||||||
|
|
||||||
this.container.addEventListener("scroll", e => {
|
let check = () => {
|
||||||
if(this.container.scrollTop + this.container.clientHeight >= this.container.scrollHeight - threshold) {
|
if(this.container.scrollTop + this.container.clientHeight >= this.container.scrollHeight - threshold) {
|
||||||
this.loadMore()
|
this.loadMore()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.container.addEventListener("scroll", e => {
|
||||||
|
// Wait for mutations to finish before checking if we need infinite scroll to trigger.
|
||||||
|
if(Diff.mutations.mutations.length > 0) {
|
||||||
|
Diff.mutations.wait(() => check())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, check immediately.
|
||||||
|
check()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user