diff --git a/pages/editanime/editanime.go b/pages/editanime/editanime.go index 682b9eec..d44cc37a 100644 --- a/pages/editanime/editanime.go +++ b/pages/editanime/editanime.go @@ -5,17 +5,18 @@ import ( "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" ) -// Get anime edit page. -func Get(ctx *aero.Context) string { +// 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.StatusBadRequest, "Not logged in or not auhorized to edit this anime", nil) + return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime", nil) } anime, err := arn.GetAnime(id) @@ -24,5 +25,53 @@ func Get(ctx *aero.Context) string { return ctx.Error(http.StatusNotFound, "Anime not found", err) } - return ctx.HTML(editform.Render(anime, "Edit anime", user)) + return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(anime, "Edit anime", user)) +} + +// 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)) } diff --git a/pages/editanime/editanime.pixy b/pages/editanime/editanime.pixy index 2ad96b86..5edc8b4b 100644 --- a/pages/editanime/editanime.pixy +++ b/pages/editanime/editanime.pixy @@ -1,17 +1,10 @@ -component EditAnime(anime *arn.Anime) - h1= anime.Title.Canonical - - .widget-form.mountable - .widget(data-api="/api/anime/" + anime.ID) - h3.widget-title Mappings - InputText("Virtual:ShoboiID", anime.GetMapping("shoboi/anime"), "Shoboi TID", "TID on cal.syoboi.jp") - InputText("Virtual:AniListID", anime.GetMapping("anilist/anime"), "AniList ID", "ID on anilist.co") - - .buttons - a.button.ajax(href="/anime/" + anime.ID) - Icon("arrow-left") - span View anime - - a.button(href="/api/anime/" + anime.ID, target="_blank") - Icon("search-plus") - span JSON API \ No newline at end of file +component EditAnimeTabs(anime *arn.Anime) + .tabs + a.tab.ajax(href=anime.Link()) + Icon("tv") + span Anime + + Tab("Edit anime", "pencil", anime.Link() + "/edit") + Tab("Edit characters", "pencil", anime.Link() + "/edit/characters") + Tab("Edit relations", "pencil", anime.Link() + "/edit/relations") + //- Tab("Edit episodes", "pencil", anime.Link() + "/edit/episodes") \ No newline at end of file diff --git a/pages/index.go b/pages/index.go index c2f5c4db..606dee15 100644 --- a/pages/index.go +++ b/pages/index.go @@ -100,9 +100,14 @@ func Configure(app *aero.Application) { l.Page("/anime/:id/episodes", anime.Episodes) l.Page("/anime/:id/characters", anime.Characters) l.Page("/anime/:id/tracks", anime.Tracks) - l.Page("/anime/:id/edit", editanime.Get) l.Page("/anime/:id/episode/:episode-number", episode.Get) + // Edit anime + l.Page("/anime/:id/edit", editanime.Main) + l.Page("/anime/:id/edit/characters", editanime.Characters) + l.Page("/anime/:id/edit/relations", editanime.Relations) + // l.Page("/anime/:id/edit/episodes", editanime.Episodes) + // Characters l.Page("/character/:id", character.Get)