Added character editing UI

This commit is contained in:
Eduard Urbach 2018-04-10 21:25:45 +02:00
parent 68bc7c4c8e
commit 76831c469f
4 changed files with 66 additions and 2 deletions

View File

@ -1,9 +1,20 @@
component CharacterTabs(character *arn.Character, user *arn.User)
.tabs
Tab("Character", "user", character.Link())
Tab("Edit", "pencil", character.Link() + "/edit")
Tab("History", "history", character.Link() + "/history")
component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime, quotes []*arn.Quote, mainQuote *arn.Quote, user *arn.User)
.character-page
.character-left-column
.character-header
.character-image-container.mountable
img.character-image-fullsize(src=character.ImageLink("large"), alt=character.Name.Canonical)
.buttons
a.button(href=character.Link() + "/edit")
Icon("pencil")
span Edit character
.character-description-container
h1.character-name.mountable= character.Name.Canonical
@ -11,8 +22,6 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
.anime-alternative-title.mountable
if character.Name.Japanese != ""
Japanese(character.Name.Japanese)
else
Japanese("日本語の名前無し")
if mainQuote != nil
.character-quote

24
pages/character/edit.go Normal file
View File

@ -0,0 +1,24 @@
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/editform"
)
// Edit character.
func Edit(ctx *aero.Context) string {
id := ctx.Get("id")
character, err := arn.GetCharacter(id)
user := utils.GetUser(ctx)
if err != nil {
return ctx.Error(http.StatusNotFound, "Character not found", err)
}
return ctx.HTML(components.CharacterTabs(character, user) + editform.Render(character, "Edit character", user))
}

View File

@ -0,0 +1,29 @@
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"
)
// History of the edits.
func History(ctx *aero.Context) string {
id := ctx.Get("id")
user := utils.GetUser(ctx)
character, err := arn.GetCharacter(id)
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))
}

View File

@ -136,6 +136,8 @@ func Configure(app *aero.Application) {
// Characters
l.Page("/character/:id", character.Get)
l.Page("/character/:id/edit", character.Edit)
l.Page("/character/:id/history", character.History)
// Quotes
l.Page("/quote/:id", quote.Get)