Added AMV editing UI

This commit is contained in:
Eduard Urbach 2018-04-14 23:51:18 +02:00
parent d19542b5aa
commit 42c72b6174
7 changed files with 82 additions and 5 deletions

7
mixins/AMV.pixy Normal file
View File

@ -0,0 +1,7 @@
component AMV(amv *arn.AMV, user *arn.User)
p= amv.Title.ByUser(user)
.amv.mountable
.video-container
video.video(controls="controls", controlsList="nodownload")
source(src="", type="video/webm")

View File

@ -1,8 +1,23 @@
package amv
import "github.com/aerogo/aero"
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Get a single AMV.
func Get(ctx *aero.Context) string {
return ctx.HTML("Coming soon™.")
id := ctx.Get("id")
amv, err := arn.GetAMV(id)
user := utils.GetUser(ctx)
if err != nil {
return ctx.Error(http.StatusNotFound, "AMV not found", err)
}
return ctx.HTML(components.AMVPage(amv, user))
}

View File

@ -1,2 +1,17 @@
component AMV(amv *arn.AMV, user *arn.User)
component AMVPage(amv *arn.AMV, user *arn.User)
AMVTabs(amv, user)
if amv.Title.String() == ""
h1 untitled
else
h1= amv.Title.ByUser(user)
component AMVTabs(amv *arn.AMV, user *arn.User)
.tabs
TabLike(strconv.Itoa(len(amv.Likes)), "heart", "amv", amv, user)
Tab("AMV", "video-camera", amv.Link())
if user != nil
Tab("Edit", "pencil", amv.Link() + "/edit")
Tab("History", "history", amv.Link() + "/history")

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

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

14
pages/amv/history.go Normal file
View File

@ -0,0 +1,14 @@
package amv
import (
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils/history"
)
// History of the edits.
var History = history.Handler(renderHistory, "AMV")
func renderHistory(obj interface{}, entries []*arn.EditLogEntry, user *arn.User) string {
return components.AMVTabs(obj.(*arn.AMV), user) + components.EditLog(entries, user)
}

View File

@ -145,6 +145,8 @@ func Configure(app *aero.Application) {
l.Page("/amvs", amvs.Latest)
l.Page("/amvs/best", amvs.Best)
l.Page("/amv/:id", amv.Get)
l.Page("/amv/:id/edit", amv.Edit)
l.Page("/amv/:id/history", amv.History)
// Quotes
l.Page("/quote/:id", quote.Get)

View File

@ -120,7 +120,7 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i
// Try to infer the ID type by the field name
if idType == "" {
switch field.Name {
case "AnimeID":
case "AnimeID", "MainAnimeID":
idType = "Anime"
case "CharacterID":