From ac5fef5737bc82082c6ea13244b890336e345181 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 7 Mar 2018 04:03:15 +0100 Subject: [PATCH] Display anime without genres for editors --- mixins/AnimeEditorList.pixy | 21 +++++++++++++++++++ pages/editor/anilist.go | 4 +++- pages/editor/anilist.pixy | 27 +++---------------------- pages/editor/editor.pixy | 2 +- pages/editor/genres.go | 40 +++++++++++++++++++++++++++++++++++++ pages/editor/genres.pixy | 4 ++++ pages/editor/shoboi.go | 4 +++- pages/editor/shoboi.pixy | 27 +++---------------------- pages/index.go | 1 + 9 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 mixins/AnimeEditorList.pixy create mode 100644 pages/editor/genres.go create mode 100644 pages/editor/genres.pixy diff --git a/mixins/AnimeEditorList.pixy b/mixins/AnimeEditorList.pixy new file mode 100644 index 00000000..faf7ba1f --- /dev/null +++ b/mixins/AnimeEditorList.pixy @@ -0,0 +1,21 @@ +component AnimeEditorList(animes []*arn.Anime, generateSearchLink func(*arn.Anime) string) + table + thead + tr.mountable + th(title="Popularity") Pop. + th Title + th Type + th Year + th Tools + tbody + each anime in animes + tr.mountable + td= anime.Popularity.Total() + td + a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical + td= anime.Type + td + if len(anime.StartDate) >= 4 + span= anime.StartDate[:4] + td + a(href=generateSearchLink(anime), target="_blank", rel="noopener") Search \ No newline at end of file diff --git a/pages/editor/anilist.go b/pages/editor/anilist.go index f3c1415f..e2c19d90 100644 --- a/pages/editor/anilist.go +++ b/pages/editor/anilist.go @@ -34,5 +34,7 @@ func AniList(ctx *aero.Context) string { missing = missing[:maxAniListEntries] } - return ctx.HTML(components.AniListMissingMapping(missing)) + return ctx.HTML(components.AniListMissingMapping(missing, func(anime *arn.Anime) string { + return "https://anilist.co/search?type=anime&q=" + anime.Title.Canonical + })) } diff --git a/pages/editor/anilist.pixy b/pages/editor/anilist.pixy index be296eca..482fb639 100644 --- a/pages/editor/anilist.pixy +++ b/pages/editor/anilist.pixy @@ -1,25 +1,4 @@ -component AniListMissingMapping(missing []*arn.Anime) - h1.page-title Anime without Anilist links - +component AniListMissingMapping(missing []*arn.Anime, generateSearchLink func(*arn.Anime) string) EditorTabs - - table - thead - tr - th(title="Popularity") Pop. - th Title - th Type - th Year - th Tools - tbody - each anime in missing - tr.mountable - td= anime.Popularity.Total() - td - a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical - td= anime.Type - td - if len(anime.StartDate) >= 4 - span= anime.StartDate[:4] - td - a(href="https://anilist.co/search?type=anime&q=" + anime.Title.Canonical, target="_blank", rel="noopener") Search + h1.mountable Anime without Anilist links + AnimeEditorList(missing, generateSearchLink) \ No newline at end of file diff --git a/pages/editor/editor.pixy b/pages/editor/editor.pixy index c8b28fcf..8bdc1928 100644 --- a/pages/editor/editor.pixy +++ b/pages/editor/editor.pixy @@ -8,10 +8,10 @@ component Editor component EditorTabs .tabs Tab("Editor", "pencil", "/editor") - Tab("Search", "search", "/database") Tab("Shoboi", "list", "/editor/shoboi") Tab("AniList", "list", "/editor/anilist") Tab("Genres", "list", "/editor/genres") + Tab("Search", "search", "/database") //- a.tab.ajax(href="/admin", aria-label="Admin") //- Icon("wrench") diff --git a/pages/editor/genres.go b/pages/editor/genres.go new file mode 100644 index 00000000..7153efee --- /dev/null +++ b/pages/editor/genres.go @@ -0,0 +1,40 @@ +package editor + +import ( + "sort" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +const maxGenreEntries = 70 + +// Genres ... +func Genres(ctx *aero.Context) string { + missing := arn.FilterAnime(func(anime *arn.Anime) bool { + return len(anime.Genres) == 0 + }) + + sort.Slice(missing, func(i, j int) bool { + a := missing[i] + b := missing[j] + + aPop := a.Popularity.Total() + bPop := b.Popularity.Total() + + if aPop == bPop { + return a.Title.Canonical < b.Title.Canonical + } + + return aPop > bPop + }) + + if len(missing) > maxGenreEntries { + missing = missing[:maxGenreEntries] + } + + return ctx.HTML(components.AnimeWithoutGenres(missing, func(anime *arn.Anime) string { + return "https://anilist.co/search?type=anime&q=" + anime.Title.Canonical + })) +} diff --git a/pages/editor/genres.pixy b/pages/editor/genres.pixy new file mode 100644 index 00000000..a799c270 --- /dev/null +++ b/pages/editor/genres.pixy @@ -0,0 +1,4 @@ +component AnimeWithoutGenres(missing []*arn.Anime, generateSearchLink func(*arn.Anime) string) + EditorTabs + h1.mountable Anime without genres + AnimeEditorList(missing, generateSearchLink) \ No newline at end of file diff --git a/pages/editor/shoboi.go b/pages/editor/shoboi.go index 96a1df94..01b5bbcc 100644 --- a/pages/editor/shoboi.go +++ b/pages/editor/shoboi.go @@ -34,5 +34,7 @@ func Shoboi(ctx *aero.Context) string { missing = missing[:maxShoboiEntries] } - return ctx.HTML(components.ShoboiMissingMapping(missing)) + return ctx.HTML(components.ShoboiMissingMapping(missing, func(anime *arn.Anime) string { + return "http://cal.syoboi.jp/find?type=quick&sd=1&kw=" + anime.Title.Japanese + })) } diff --git a/pages/editor/shoboi.pixy b/pages/editor/shoboi.pixy index 9783b645..16481268 100644 --- a/pages/editor/shoboi.pixy +++ b/pages/editor/shoboi.pixy @@ -1,25 +1,4 @@ -component ShoboiMissingMapping(missing []*arn.Anime) - h1.page-title Anime without Shoboi links - +component ShoboiMissingMapping(missing []*arn.Anime, generateSearchLink func(*arn.Anime) string) EditorTabs - - table - thead - tr - th(title="Popularity") Pop. - th Title - th Type - th Year - th Tools - tbody - each anime in missing - tr.mountable - td= anime.Popularity.Total() - td - a(href=anime.Link(), target="_blank", rel="noopener")= anime.Title.Canonical - td= anime.Type - td - if len(anime.StartDate) >= 4 - span= anime.StartDate[:4] - td - a(href="http://cal.syoboi.jp/find?type=quick&sd=1&kw=" + anime.Title.Japanese, target="_blank", rel="noopener") Search + h1.mountable Anime without Shoboi links + AnimeEditorList(missing, generateSearchLink) diff --git a/pages/index.go b/pages/index.go index a019ca15..61617b35 100644 --- a/pages/index.go +++ b/pages/index.go @@ -200,6 +200,7 @@ func Configure(app *aero.Application) { l.Page("/editor", editor.Get) l.Page("/editor/anilist", editor.AniList) l.Page("/editor/shoboi", editor.Shoboi) + l.Page("/editor/genres", editor.Genres) // Mixed l.Page("/database", database.Get)