Added airing dates

This commit is contained in:
Eduard Urbach 2017-06-29 08:32:46 +02:00
parent b5266a3a17
commit f4c1800244
7 changed files with 77 additions and 20 deletions

View File

@ -2,7 +2,6 @@ package animelist
import ( import (
"net/http" "net/http"
"sort"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
@ -26,9 +25,7 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil) return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
} }
sort.Slice(animeList.Items, func(i, j int) bool { animeList.Sort()
return animeList.Items[i].FinalRating() > animeList.Items[j].FinalRating()
})
return ctx.HTML(components.AnimeList(animeList, user)) return ctx.HTML(components.AnimeList(animeList, user))
} }

View File

@ -3,6 +3,7 @@ component AnimeList(animeList *arn.AnimeList, user *arn.User)
thead thead
tr tr
th.anime-list-item-name Anime th.anime-list-item-name Anime
th.anime-list-item-airing-date Airing
th.anime-list-item-episodes Episodes th.anime-list-item-episodes Episodes
th.anime-list-item-rating Rating th.anime-list-item-rating Rating
if user != nil if user != nil
@ -12,6 +13,9 @@ component AnimeList(animeList *arn.AnimeList, user *arn.User)
tr.anime-list-item.mountable(title=item.Notes) tr.anime-list-item.mountable(title=item.Notes)
td.anime-list-item-name td.anime-list-item-name
a.ajax(href=item.Link(animeList.User().Nick))= item.Anime().Title.Canonical a.ajax(href=item.Link(animeList.User().Nick))= item.Anime().Title.Canonical
td.anime-list-item-airing-date
if item.Anime().UpcomingEpisode() != nil
span.utc-date(data-start-date=item.Anime().UpcomingEpisode().Episode.AiringDate.Start, data-end-date=item.Anime().UpcomingEpisode().Episode.AiringDate.End, data-episode-number=item.Anime().UpcomingEpisode().Episode.Number)
td.anime-list-item-episodes td.anime-list-item-episodes
.anime-list-item-episodes-watched= item.Episodes .anime-list-item-episodes-watched= item.Episodes
.anime-list-item-episodes-separator / .anime-list-item-episodes-separator /

View File

@ -51,6 +51,13 @@
.raw-icon .raw-icon
margin-bottom -4px margin-bottom -4px
.anime-list-item-airing-date
display none
> 700px
.anime-list-item-airing-date
display block
< 1100px < 1100px
.anime-list-item-rating .anime-list-item-rating
display none display none

View File

@ -2,7 +2,6 @@ package dashboard
import ( import (
"sort" "sort"
"time"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/aerogo/flow" "github.com/aerogo/flow"
@ -68,22 +67,19 @@ func dashboard(ctx *aero.Context) string {
} }
allAnimeInList := objects.([]*arn.Anime) allAnimeInList := objects.([]*arn.Anime)
now := time.Now().UTC().Format(time.RFC3339)
for _, anime := range allAnimeInList { for _, anime := range allAnimeInList {
if len(upcomingEpisodes) >= maxScheduleItems { if len(upcomingEpisodes) >= maxScheduleItems {
break break
} }
for _, episode := range anime.Episodes { futureEpisodes := anime.UpcomingEpisodes()
if episode.AiringDate.Start > now {
upcomingEpisodes = append(upcomingEpisodes, &arn.UpcomingEpisode{ if len(futureEpisodes) == 0 {
Anime: anime, continue
Episode: episode,
})
continue
}
} }
upcomingEpisodes = append(upcomingEpisodes, futureEpisodes...)
} }
sort.Slice(upcomingEpisodes, func(i, j int) bool { sort.Slice(upcomingEpisodes, func(i, j int) bool {

View File

@ -2,7 +2,6 @@ package embed
import ( import (
"net/http" "net/http"
"sort"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
@ -23,9 +22,7 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil) return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
} }
sort.Slice(animeList.Items, func(i, j int) bool { animeList.Sort()
return animeList.Items[i].FinalRating() > animeList.Items[j].FinalRating()
})
return utils.AllowEmbed(ctx, ctx.HTML(components.AnimeList(animeList, user))) return utils.AllowEmbed(ctx, ctx.HTML(components.AnimeList(animeList, user)))
} }

View File

@ -3,6 +3,23 @@ import { Diff } from "./Diff"
import { findAll, delay } from "./utils" import { findAll, delay } from "./utils"
import * as actions from "./actions" import * as actions from "./actions"
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
]
var dayNames = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
]
export class AnimeNotifier { export class AnimeNotifier {
app: Application app: Application
visibilityObserver: IntersectionObserver visibilityObserver: IntersectionObserver
@ -56,6 +73,38 @@ export class AnimeNotifier {
Promise.resolve().then(() => this.mountMountables()) Promise.resolve().then(() => this.mountMountables())
Promise.resolve().then(() => this.assignActions()) Promise.resolve().then(() => this.assignActions())
Promise.resolve().then(() => this.lazyLoadImages()) Promise.resolve().then(() => this.lazyLoadImages())
Promise.resolve().then(() => this.displayLocalDates())
}
displayLocalDates() {
const oneDay = 24 * 60 * 60 * 1000
const now = new Date()
for(let element of findAll("utc-date")) {
let startDate = new Date(element.dataset.startDate)
let endDate = new Date(element.dataset.endDate)
let h = startDate.getHours()
let m = startDate.getMinutes()
let startTime = (h <= 9 ? "0" + h : h) + ":" + (m <= 9 ? "0" + m : m)
h = endDate.getHours()
m = endDate.getMinutes()
let endTime = (h <= 9 ? "0" + h : h) + ":" + (m <= 9 ? "0" + m : m)
let dayDifference = Math.round(Math.abs((startDate.getTime() - now.getTime()) / oneDay))
let dayInfo = dayNames[startDate.getDay()] + ", " + monthNames[startDate.getMonth()] + " " + startDate.getDate()
if(dayDifference > 1) {
element.innerText = dayDifference + " day" + (dayDifference == 1 ? "" : "s")
} else if(dayDifference == 1) {
element.innerText = "Tomorrow"
} else {
element.innerText = "Today"
}
element.title = "Episode " + element.dataset.episodeNumber + " will be airing " + startTime + " - " + endTime + " your time"
}
} }
reloadContent() { reloadContent() {

View File

@ -1,3 +1,5 @@
remove-margin = 1.1rem
.embedded .embedded
// Put navigation to the bottom of the screen // Put navigation to the bottom of the screen
flex-direction column-reverse !important flex-direction column-reverse !important
@ -6,8 +8,13 @@
display inline-block display inline-block
.anime-list .anime-list
max-width 500px // max-width 500px
margin -1.1rem margin-left calc(remove-margin * -1)
margin-top calc(remove-margin * -1)
width calc(100% + remove-margin * 2)
td
padding 0.25rem 0.5rem
#navigation #navigation
font-size 0.9rem font-size 0.9rem