Added genre overview

This commit is contained in:
Eduard Urbach 2017-11-30 03:21:37 +01:00
parent d290e2d505
commit f358ffbf7c
3 changed files with 36 additions and 7 deletions

View File

@ -16,10 +16,11 @@ component Sidebar(user *arn.User)
SidebarButton("Forum", "/forum", "comment") SidebarButton("Forum", "/forum", "comment")
SidebarButton("Explore", "/explore", "th") SidebarButton("Explore", "/explore", "th")
SidebarButton("Calendar", "/calendar", "calendar") SidebarButton("Calendar", "/calendar", "calendar")
SidebarButton("Genres", "/genres", "clone")
SidebarButton("Soundtracks", "/soundtracks", "headphones") SidebarButton("Soundtracks", "/soundtracks", "headphones")
if user != nil && user.Role == "admin" if user != nil && user.Role == "admin"
SidebarButton("Companies", "/companies", "building")
SidebarButton("Users", "/users", "globe") SidebarButton("Users", "/users", "globe")
@ -34,6 +35,7 @@ component Sidebar(user *arn.User)
//- SidebarButton("Games", "/games", "gamepad") //- SidebarButton("Games", "/games", "gamepad")
//- SidebarButton("Groups", "/groups", "users") //- SidebarButton("Groups", "/groups", "users")
//- SidebarButton("Statistics", "/statistics", "pie-chart") //- SidebarButton("Statistics", "/statistics", "pie-chart")
//- SidebarButton("Companies", "/companies", "building")
.spacer .spacer

View File

@ -4,11 +4,14 @@ import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
) )
// Get ... // Get ...
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
var genres []string user := utils.GetUser(ctx)
genres := []string{}
genreToAnime := map[string]*arn.Anime{}
for _, genre := range arn.Genres { for _, genre := range arn.Genres {
if genre == "Hentai" { if genre == "Hentai" {
@ -18,5 +21,30 @@ func Get(ctx *aero.Context) string {
genres = append(genres, genre) genres = append(genres, genre)
} }
return ctx.HTML(components.Genres(genres)) allAnime := arn.AllAnime()
arn.SortAnimeByQuality(allAnime, "")
added := 0
for _, anime := range allAnime {
for _, genre := range anime.Genres {
// Skip genre that we don't care about
if !arn.Contains(genres, genre) {
continue
}
_, exists := genreToAnime[genre]
if !exists {
genreToAnime[genre] = anime
added++
}
}
if added >= len(genres) {
break
}
}
return ctx.HTML(components.Genres(genres, genreToAnime, user))
} }

View File

@ -1,13 +1,12 @@
component Genres(genres []string) component Genres(genres []string, genreToAnime map[string]*arn.Anime, user *arn.User)
h1 Genres h1 Genres
.genres .genres
each genre in genres each genre in genres
a.genre.ajax(href="/genre/" + strings.ToLower(genre)) a.genre.mountable.ajax(href="/genre/" + strings.ToLower(genre))
.genre-text.front .genre-text.front
.genre-icon .genre-icon
RawIcon(arn.GetGenreIcon(genre)) RawIcon(arn.GetGenreIcon(genre))
span= genre span= genre
//- if len(genre.AnimeList) > 0 img.genre-image.back(src=genreToAnime[genre].Image("medium"), alt=genreToAnime[genre].Title.ByUser(user), title=genre)
//- img.genre-image.back(src=genre.AnimeList[0].Image, alt=genre.AnimeList[0].Title.Romaji, title=genre.AnimeList[0].Title.Romaji + "\n" + genre.Name + " #1")