diff --git a/pages/company/company.pixy b/pages/company/company.pixy index 3d2f821e..8b10d67a 100644 --- a/pages/company/company.pixy +++ b/pages/company/company.pixy @@ -48,4 +48,5 @@ component CompanyAnime(label string, animes []*arn.Anime, user *arn.User) component CompanyTabs(company *arn.Company, user *arn.User) .tabs Tab("Company", "building", company.Link()) - Tab("Edit", "pencil", company.Link() + "/edit") \ No newline at end of file + Tab("Edit", "pencil", company.Link() + "/edit") + Tab("History", "history", company.Link() + "/history") \ No newline at end of file diff --git a/pages/company/history.go b/pages/company/history.go new file mode 100644 index 00000000..b2d9b14c --- /dev/null +++ b/pages/company/history.go @@ -0,0 +1,29 @@ +package company + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// History of the edits. +func History(ctx *aero.Context) string { + id := ctx.Get("id") + user := utils.GetUser(ctx) + company, err := arn.GetCompany(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Company not found", err) + } + + entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { + return entry.ObjectType == "Company" && entry.ObjectID == id + }) + + arn.SortEditLogEntriesLatestFirst(entries) + + return ctx.HTML(components.CompanyTabs(company, user) + components.EditLog(entries, user)) +} diff --git a/pages/editanime/editanime.pixy b/pages/editanime/editanime.pixy index e3083ad8..54050f82 100644 --- a/pages/editanime/editanime.pixy +++ b/pages/editanime/editanime.pixy @@ -7,4 +7,5 @@ component EditAnimeTabs(anime *arn.Anime) Tab("Edit", "pencil", anime.Link() + "/edit") Tab("Characters", "pencil", anime.Link() + "/edit/characters") Tab("Relations", "pencil", anime.Link() + "/edit/relations") - Tab("Episodes", "pencil", anime.Link() + "/edit/episodes") \ No newline at end of file + Tab("Episodes", "pencil", anime.Link() + "/edit/episodes") + Tab("History", "history", anime.Link() + "/edit/history") \ No newline at end of file diff --git a/pages/editanime/history.go b/pages/editanime/history.go new file mode 100644 index 00000000..f28a75ba --- /dev/null +++ b/pages/editanime/history.go @@ -0,0 +1,29 @@ +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" +) + +// History of the edits. +func History(ctx *aero.Context) string { + id := ctx.Get("id") + user := utils.GetUser(ctx) + anime, err := arn.GetAnime(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Anime not found", err) + } + + entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { + return entry.ObjectType == "Anime" && entry.ObjectID == id + }) + + arn.SortEditLogEntriesLatestFirst(entries) + + return ctx.HTML(components.EditAnimeTabs(anime) + components.EditLog(entries, user)) +} diff --git a/pages/editlog/editlog.go b/pages/editlog/editlog.go index 9576075d..2962903e 100644 --- a/pages/editlog/editlog.go +++ b/pages/editlog/editlog.go @@ -2,7 +2,6 @@ package editlog import ( "net/http" - "sort" "github.com/animenotifier/arn" @@ -25,13 +24,12 @@ func Get(ctx *aero.Context) string { entries := arn.AllEditLogEntries() // Sort by creation date - sort.Slice(entries, func(i, j int) bool { - return entries[i].Created > entries[j].Created - }) + arn.SortEditLogEntriesLatestFirst(entries) + // Limit results if len(entries) > maxEntries { entries = entries[:maxEntries] } - return ctx.HTML(components.EditLog(entries, user)) + return ctx.HTML(components.EditLogPage(entries, user)) } diff --git a/pages/editlog/editlog.pixy b/pages/editlog/editlog.pixy index 96f3537e..2c101f6c 100644 --- a/pages/editlog/editlog.pixy +++ b/pages/editlog/editlog.pixy @@ -1,6 +1,8 @@ -component EditLog(entries []*arn.EditLogEntry, user *arn.User) - h1 Editor log +component EditLogPage(entries []*arn.EditLogEntry, user *arn.User) + h1.mountable Editor log + EditLog(entries, user) +component EditLog(entries []*arn.EditLogEntry, user *arn.User) table.edit-log thead tr.mountable diff --git a/pages/index.go b/pages/index.go index 5983103b..7c6166c0 100644 --- a/pages/index.go +++ b/pages/index.go @@ -110,6 +110,7 @@ func Configure(app *aero.Application) { l.Page("/anime/:id/edit/characters", editanime.Characters) l.Page("/anime/:id/edit/relations", editanime.Relations) l.Page("/anime/:id/edit/episodes", editanime.Episodes) + l.Page("/anime/:id/edit/history", editanime.History) // Characters l.Page("/character/:id", character.Get) @@ -117,6 +118,7 @@ func Configure(app *aero.Application) { // Quotes l.Page("/quote/:id", quote.Get) l.Page("/quote/:id/edit", quote.Edit) + l.Page("/quote/:id/history", quote.History) l.Page("/quotes", quotes.Latest) l.Page("/quotes/from/:index", quotes.LatestFrom) l.Page("/quotes/best", quotes.Best) @@ -128,6 +130,7 @@ func Configure(app *aero.Application) { // Companies l.Page("/company/:id", company.Get) l.Page("/company/:id/edit", company.Edit) + l.Page("/company/:id/history", company.History) l.Page("/companies", companies.All) l.Page("/companies/popular", companies.Popular) @@ -148,6 +151,7 @@ func Configure(app *aero.Application) { l.Page("/soundtracks/tag/:tag/from/:index", soundtracks.FilterByTagFrom) l.Page("/soundtrack/:id", soundtrack.Get) l.Page("/soundtrack/:id/edit", soundtrack.Edit) + l.Page("/soundtrack/:id/history", soundtrack.History) // Groups l.Page("/groups", groups.Get) diff --git a/pages/quote/history.go b/pages/quote/history.go new file mode 100644 index 00000000..1cb51039 --- /dev/null +++ b/pages/quote/history.go @@ -0,0 +1,29 @@ +package quote + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// History of the edits. +func History(ctx *aero.Context) string { + id := ctx.Get("id") + user := utils.GetUser(ctx) + quote, err := arn.GetQuote(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Quote not found", err) + } + + entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { + return entry.ObjectType == "Quote" && entry.ObjectID == id + }) + + arn.SortEditLogEntriesLatestFirst(entries) + + return ctx.HTML(components.QuoteTabs(quote, user) + components.EditLog(entries, user)) +} diff --git a/pages/quote/quote.pixy b/pages/quote/quote.pixy index 66f893d1..17c70e50 100644 --- a/pages/quote/quote.pixy +++ b/pages/quote/quote.pixy @@ -53,6 +53,7 @@ component QuoteTabs(quote *arn.Quote, user *arn.User) TabLike(strconv.Itoa(len(quote.Likes)), "heart", "quote", quote, user) Tab("Quote", "quote-left", quote.Link()) Tab("Edit", "pencil", quote.Link() + "/edit") + Tab("History", "history", quote.Link() + "/history") component QuoteAnime(anime *arn.Anime, user *arn.User) a.quote-anime-list-item.ajax(href=anime.Link(), title=anime.Title.ByUser(user)) diff --git a/pages/soundtrack/history.go b/pages/soundtrack/history.go new file mode 100644 index 00000000..40213a1e --- /dev/null +++ b/pages/soundtrack/history.go @@ -0,0 +1,30 @@ +package soundtrack + +import ( + "net/http" + + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" +) + +// History of the edits. +func History(ctx *aero.Context) string { + id := ctx.Get("id") + user := utils.GetUser(ctx) + track, err := arn.GetSoundTrack(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Track not found", err) + } + + entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { + return entry.ObjectType == "SoundTrack" && entry.ObjectID == id + }) + + arn.SortEditLogEntriesLatestFirst(entries) + + return ctx.HTML(components.SoundTrackTabs(track, user) + components.EditLog(entries, user)) +} diff --git a/pages/soundtrack/soundtrack.pixy b/pages/soundtrack/soundtrack.pixy index f1f7178d..6db924ed 100644 --- a/pages/soundtrack/soundtrack.pixy +++ b/pages/soundtrack/soundtrack.pixy @@ -67,3 +67,4 @@ component SoundTrackTabs(track *arn.SoundTrack, user *arn.User) TabLike(strconv.Itoa(len(track.Likes)), "heart", "track", track, user) Tab("Soundtrack", "music", track.Link()) Tab("Edit", "pencil", track.Link() + "/edit") + Tab("History", "history", track.Link() + "/history") diff --git a/utils/editform/editform.go b/utils/editform/editform.go index d161dbab..7c9d1b03 100644 --- a/utils/editform/editform.go +++ b/utils/editform/editform.go @@ -26,7 +26,7 @@ func Render(obj interface{}, title string, user *arn.User) string { b.WriteString(`