Anime relations patch

This commit is contained in:
Eduard Urbach 2018-03-09 16:27:40 +01:00
parent 49b887a201
commit 8aaa7898b3
5 changed files with 71 additions and 8 deletions

View File

@ -30,12 +30,12 @@ func main() {
}
}
func sync(data *kitsu.Anime) {
func sync(data *kitsu.Anime) *arn.Anime {
anime, err := arn.GetAnime(data.ID)
// This stops overwriting existing data
if err == nil || anime != nil {
return
if anime != nil {
return anime
}
if err != nil {
@ -153,6 +153,20 @@ func sync(data *kitsu.Anime) {
arn.DB.Set("AnimeEpisodes", anime.ID, episodes)
}
// Relations
relations, _ := arn.GetAnimeRelations(anime.ID)
if relations == nil {
relations := &arn.AnimeRelations{
AnimeID: anime.ID,
Items: []*arn.AnimeRelation{},
}
arn.DB.Set("AnimeRelations", anime.ID, relations)
}
// Log
fmt.Println(color.GreenString("✔"), anime.ID, anime.Title.Canonical)
return anime
}

View File

@ -75,3 +75,27 @@ func Relations(ctx *aero.Context) string {
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))
}

View File

@ -4,7 +4,7 @@ component EditAnimeTabs(anime *arn.Anime)
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")
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")

View File

@ -106,7 +106,7 @@ func Configure(app *aero.Application) {
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)
l.Page("/anime/:id/edit/episodes", editanime.Episodes)
// Characters
l.Page("/character/:id", character.Get)

View File

@ -0,0 +1,25 @@
package main
import (
"fmt"
"github.com/animenotifier/arn"
)
func main() {
defer arn.Node.Close()
for anime := range arn.StreamAnime() {
relations, _ := arn.GetAnimeRelations(anime.ID)
if relations == nil {
relations := &arn.AnimeRelations{
AnimeID: anime.ID,
Items: []*arn.AnimeRelation{},
}
arn.DB.Set("AnimeRelations", anime.ID, relations)
fmt.Println(anime.ID, anime.Title.Canonical)
}
}
}