Added history tab to nearly all editable objects

This commit is contained in:
Eduard Urbach 2018-03-13 17:59:16 +01:00
parent b3257e78b6
commit 12de621214
12 changed files with 138 additions and 10 deletions

View File

@ -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")
Tab("Edit", "pencil", company.Link() + "/edit")
Tab("History", "history", company.Link() + "/history")

29
pages/company/history.go Normal file
View File

@ -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))
}

View File

@ -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")
Tab("Episodes", "pencil", anime.Link() + "/edit/episodes")
Tab("History", "history", anime.Link() + "/edit/history")

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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

View File

@ -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)

29
pages/quote/history.go Normal file
View File

@ -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))
}

View File

@ -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))

View File

@ -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))
}

View File

@ -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")

View File

@ -26,7 +26,7 @@ func Render(obj interface{}, title string, user *arn.User) string {
b.WriteString(`<div class="widget" data-api="` + endpoint + `">`)
// Title
b.WriteString(`<h1>`)
b.WriteString(`<h1 class="mountable">`)
b.WriteString(title)
b.WriteString(`</h1>`)
@ -84,6 +84,9 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i
return
}
b.WriteString("<div class='mountable'>")
defer b.WriteString("</div>")
fieldValue := reflect.Indirect(v.FieldByName(field.Name))
fieldType := field.Type.String()