From 5357d669cfeb700c2fd722f44b1245e37da033c2 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 4 Dec 2017 21:07:13 +0100 Subject: [PATCH] Started working on episode pages --- pages/anime/anime.pixy | 2 +- pages/anime/episode.scarlet | 19 ++++++++-------- pages/anime/episodes.go | 2 +- pages/anime/episodes.pixy | 15 ++++++------- pages/episode/episode.go | 43 +++++++++++++++++++++++++++++++++++++ pages/episode/episode.pixy | 9 ++++++++ pages/index.go | 2 ++ 7 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 pages/episode/episode.go create mode 100644 pages/episode/episode.pixy diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 0d544ed1..9bffe83b 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -28,7 +28,7 @@ component AnimeMainColumn(anime *arn.Anime, tracks []*arn.SoundTrack, episodes [ AnimeCharacters(anime) AnimeRelations(anime, user) AnimeTracks(anime, tracks) - AnimeEpisodes(episodes, user) + AnimeEpisodes(anime, episodes, user) component AnimeSideColumn(anime *arn.Anime, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, user *arn.User) AnimeTrailer(anime) diff --git a/pages/anime/episode.scarlet b/pages/anime/episode.scarlet index f721843f..e1a46218 100644 --- a/pages/anime/episode.scarlet +++ b/pages/anime/episode.scarlet @@ -4,18 +4,21 @@ > 700px .episodes horizontal-wrap + justify-content space-around .episode - ui-element vertical - button-hover flex 0 - flex-basis 150px + flex-basis 200px margin 0.5rem padding 0.5rem + overflow hidden + border-radius ui-element-border-radius + color text-color - // :hover - // background-color table-row-hover-background + :hover + color text-color + background-color reverse-light-hover-color .episode-number display flex @@ -33,13 +36,9 @@ .episode-airing-date-start display flex justify-content center - font-size 0.8rem + font-size 0.7rem opacity 0.6 -< 800px - .episode-airing-date-start - display none - < 320px .episode-actions display none \ No newline at end of file diff --git a/pages/anime/episodes.go b/pages/anime/episodes.go index d4da8e38..4ca5ede6 100644 --- a/pages/anime/episodes.go +++ b/pages/anime/episodes.go @@ -21,5 +21,5 @@ func Episodes(ctx *aero.Context) string { return ctx.Error(http.StatusNotFound, "Anime not found", err) } - return ctx.HTML(components.AnimeEpisodes(anime.Episodes().Items, user)) + return ctx.HTML(components.AnimeEpisodes(anime, anime.Episodes().Items, user)) } diff --git a/pages/anime/episodes.pixy b/pages/anime/episodes.pixy index 7b38658a..09c9924c 100644 --- a/pages/anime/episodes.pixy +++ b/pages/anime/episodes.pixy @@ -1,24 +1,23 @@ -component AnimeEpisodes(episodes []*arn.AnimeEpisode, user *arn.User) +component AnimeEpisodes(anime *arn.Anime, episodes []*arn.AnimeEpisode, user *arn.User) if len(episodes) > 0 .anime-section.mountable h3.anime-section-name Episodes .episodes each episode in episodes - .episode.mountable(data-mountable-type="episode") + a.episode.ajax.mountable(href=anime.Link() + "/episode/" + strconv.Itoa(episode.Number), data-mountable-type="episode") .episode-number if episode.Number != -1 span= episode.Number - .episode-title= episode.Title.Japanese - //- if episode.Title.Japanese != "" - //- Japanese(episode.Title.Japanese) - //- else - //- span - + .episode-title + if episode.Title.Japanese != "" + span= episode.Title.Japanese + else + span - if validator.IsValidDate(episode.AiringDate.Start) .episode-airing-date-start.utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman() - //- table.episodes //- tbody //- each episode in episodes diff --git a/pages/episode/episode.go b/pages/episode/episode.go new file mode 100644 index 00000000..afb6094c --- /dev/null +++ b/pages/episode/episode.go @@ -0,0 +1,43 @@ +package episode + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Get renders the anime episode. +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + id := ctx.Get("id") + episodeNumber, err := ctx.GetInt("episode-number") + + if err != nil { + return ctx.Error(http.StatusBadRequest, "Episode is not a number", err) + } + + // Get anime + anime, err := arn.GetAnime(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Anime not found", err) + } + + // Get anime episodes + animeEpisodes, err := arn.GetAnimeEpisodes(id) + + if err != nil { + return ctx.Error(http.StatusNotFound, "Anime episodes not found", err) + } + + episode := animeEpisodes.Find(episodeNumber) + + if episode == nil { + return ctx.Error(http.StatusNotFound, "Anime episode not found", nil) + } + + return ctx.HTML(components.AnimeEpisode(anime, episode, user)) +} diff --git a/pages/episode/episode.pixy b/pages/episode/episode.pixy new file mode 100644 index 00000000..50cf7737 --- /dev/null +++ b/pages/episode/episode.pixy @@ -0,0 +1,9 @@ +component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, user *arn.User) + h1= episode.Title.Japanese + p + a.ajax(href=anime.Link(), title=anime.Title.ByUser(user)) + img(src=anime.Image("medium"), alt=anime.Title.ByUser(user)) + + if validator.IsValidDate(episode.AiringDate.Start) + .utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman() + \ No newline at end of file diff --git a/pages/index.go b/pages/index.go index 4a8c8372..5f8130b9 100644 --- a/pages/index.go +++ b/pages/index.go @@ -21,6 +21,7 @@ import ( "github.com/animenotifier/notify.moe/pages/editanime" "github.com/animenotifier/notify.moe/pages/editor" "github.com/animenotifier/notify.moe/pages/embed" + "github.com/animenotifier/notify.moe/pages/episode" "github.com/animenotifier/notify.moe/pages/explore" "github.com/animenotifier/notify.moe/pages/forum" "github.com/animenotifier/notify.moe/pages/genre" @@ -95,6 +96,7 @@ func Configure(app *aero.Application) { 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) // Characters l.Page("/character/:id", character.Get)