Generic handler for object history

This commit is contained in:
2018-04-10 22:12:32 +02:00
parent 1d658a9e76
commit d0e518bedf
6 changed files with 50 additions and 95 deletions

View File

@ -1,29 +1,14 @@
package editanime
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)
anime, err := arn.GetAnime(id)
var History = history.Handler(renderHistory, "Anime", "AnimeCharacters", "AnimeRelations", "AnimeEpisodes")
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool {
return entry.ObjectID == id && (entry.ObjectType == "Anime" || entry.ObjectType == "AnimeCharacters" || entry.ObjectType == "AnimeRelations" || entry.ObjectType == "AnimeEpisodes")
})
arn.SortEditLogEntriesLatestFirst(entries)
return ctx.HTML(components.EditAnimeTabs(anime) + components.EditLog(entries, user))
func renderHistory(obj interface{}, entries []*arn.EditLogEntry, user *arn.User) string {
return components.EditAnimeTabs(obj.(*arn.Anime)) + components.EditLog(entries, user)
}