Added history tab to nearly all editable objects
This commit is contained in:
parent
b3257e78b6
commit
12de621214
@ -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
29
pages/company/history.go
Normal 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))
|
||||
}
|
@ -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")
|
29
pages/editanime/history.go
Normal file
29
pages/editanime/history.go
Normal 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))
|
||||
}
|
@ -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))
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
29
pages/quote/history.go
Normal 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))
|
||||
}
|
@ -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))
|
||||
|
30
pages/soundtrack/history.go
Normal file
30
pages/soundtrack/history.go
Normal 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))
|
||||
}
|
@ -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")
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user