Generic handler for object history
This commit is contained in:
@ -1,29 +1,14 @@
|
||||
package character
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
"github.com/animenotifier/notify.moe/utils/history"
|
||||
)
|
||||
|
||||
// History of the edits.
|
||||
func History(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
user := utils.GetUser(ctx)
|
||||
character, err := arn.GetCharacter(id)
|
||||
var History = history.Handler(renderHistory, "Character")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Character not found", err)
|
||||
}
|
||||
|
||||
entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool {
|
||||
return entry.ObjectType == "Character" && entry.ObjectID == id
|
||||
})
|
||||
|
||||
arn.SortEditLogEntriesLatestFirst(entries)
|
||||
|
||||
return ctx.HTML(components.CharacterTabs(character, user) + components.EditLog(entries, user))
|
||||
func renderHistory(obj interface{}, entries []*arn.EditLogEntry, user *arn.User) string {
|
||||
return components.CharacterTabs(obj.(*arn.Character), user) + components.EditLog(entries, user)
|
||||
}
|
||||
|
Reference in New Issue
Block a user