Added more route tests
This commit is contained in:
119
pages/anime/editanime/editanime.go
Normal file
119
pages/anime/editanime/editanime.go
Normal file
@ -0,0 +1,119 @@
|
||||
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"
|
||||
"github.com/animenotifier/notify.moe/utils/editform"
|
||||
)
|
||||
|
||||
// Main anime edit page.
|
||||
func Main(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime", nil)
|
||||
}
|
||||
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(anime, "Edit anime", user))
|
||||
}
|
||||
|
||||
// Images anime images edit page.
|
||||
func Images(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime", nil)
|
||||
}
|
||||
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.EditAnimeImages(anime))
|
||||
}
|
||||
|
||||
// Characters anime characters edit page.
|
||||
func Characters(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
|
||||
}
|
||||
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
animeCharacters, err := arn.GetAnimeCharacters(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime characters not found", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(animeCharacters, "Edit anime characters", user))
|
||||
}
|
||||
|
||||
// Relations anime relations edit page.
|
||||
func Relations(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
|
||||
}
|
||||
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
animeRelations, err := arn.GetAnimeRelations(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime relations not found", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(animeRelations, "Edit anime relations", user))
|
||||
}
|
||||
|
||||
// Episodes anime episodes edit page.
|
||||
func Episodes(ctx *aero.Context) string {
|
||||
id := ctx.Get("id")
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
|
||||
}
|
||||
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
animeEpisodes, err := arn.GetAnimeEpisodes(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(animeEpisodes, "Edit anime episodes", user))
|
||||
}
|
12
pages/anime/editanime/editanime.pixy
Normal file
12
pages/anime/editanime/editanime.pixy
Normal file
@ -0,0 +1,12 @@
|
||||
component EditAnimeTabs(anime *arn.Anime)
|
||||
.tabs
|
||||
a.tab(href=anime.Link())
|
||||
Icon("tv")
|
||||
span Anime
|
||||
|
||||
Tab("Edit", "pencil", anime.Link() + "/edit")
|
||||
Tab("Images", "image", anime.Link() + "/edit/images")
|
||||
Tab("Characters", "users", anime.Link() + "/edit/characters")
|
||||
Tab("Relations", "exchange", anime.Link() + "/edit/relations")
|
||||
Tab("Episodes", "list-ol", anime.Link() + "/edit/episodes")
|
||||
Tab("History", "history", anime.Link() + "/edit/history")
|
14
pages/anime/editanime/history.go
Normal file
14
pages/anime/editanime/history.go
Normal file
@ -0,0 +1,14 @@
|
||||
package editanime
|
||||
|
||||
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, "Anime", "AnimeCharacters", "AnimeRelations", "AnimeEpisodes")
|
||||
|
||||
func renderHistory(obj interface{}, entries []*arn.EditLogEntry, user *arn.User) string {
|
||||
return components.EditAnimeTabs(obj.(*arn.Anime)) + components.EditLog(entries, user)
|
||||
}
|
15
pages/anime/editanime/images.pixy
Normal file
15
pages/anime/editanime/images.pixy
Normal file
@ -0,0 +1,15 @@
|
||||
component EditAnimeImages(anime *arn.Anime)
|
||||
EditAnimeTabs(anime)
|
||||
|
||||
.widget-form
|
||||
h1.mountable Edit anime images
|
||||
|
||||
.widget.mountable(data-api="/api/anime/" + anime.ID)
|
||||
h3.widget-title
|
||||
Icon("picture-o")
|
||||
span Image
|
||||
|
||||
InputFileUpload("anime-image-input", "File", "image", "/api/upload/anime/" + anime.ID + "/image")
|
||||
|
||||
.anime-image-container
|
||||
img.anime-image-input-preview.anime-cover-image.lazy(data-src=anime.ImageLink("large"), data-webp="true", data-color=anime.AverageColor(), alt="Anime image")
|
Reference in New Issue
Block a user