diff --git a/pages/editor/editor.pixy b/pages/editor/editor.pixy index 439a67db..d1fd4487 100644 --- a/pages/editor/editor.pixy +++ b/pages/editor/editor.pixy @@ -16,19 +16,30 @@ component Editor(url string, score int, scoreTypes map[string]int, user *arn.Use component EditorTabs(url string) .tabs Tab("Editor", "pencil", "/editor") - Tab("MAL", "exchange", "/editor/anime/maldiff") - Tab("Kitsu", "exchange", "/editor/anime/kitsu/new") - Tab("Anime", "tv", "/editor/anime/missing/shoboi") - Tab("Companies", "building", "/editor/companies/missing/description") + Tab("MAL", "exchange", "/editor/maldiff/anime") + Tab("Kitsu", "exchange", "/editor/kitsu/new/anime") + Tab("Anime", "tv", "/editor/anime/synopsis") + Tab("Companies", "building", "/editor/companies/description") Tab("Search", "search", "/database") - if strings.Contains(url, "/editor/anime/missing/") || strings.Contains(url, "/editor/anime/lowresimage") || strings.Contains(url, "/editor/anime/ultralowresimage") + if strings.Contains(url, "/editor/anime/") .tabs - Tab("Shoboi", "list", "/editor/anime/missing/shoboi") - Tab("AniList", "list", "/editor/anime/missing/anilist") - Tab("Genres", "list", "/editor/anime/missing/genres") - Tab("Low-Res", "image", "/editor/anime/lowresimage") - Tab("Ultra Low-Res", "image", "/editor/anime/ultralowresimage") + Tab("Synopsis", "align-left", "/editor/anime/synopsis") + Tab("Genres", "clone", "/editor/anime/genres") + Tab("Start date", "calendar", "/editor/anime/startdate") + Tab("Mappings", "arrows-h", "/editor/anime/mapping/mal") + Tab("Images", "image", "/editor/anime/image/lowres") + + if strings.Contains(url, "/editor/anime/mapping/") + .tabs + Tab("MAL", "arrows-h", "/editor/anime/mapping/mal") + Tab("Shoboi", "arrows-h", "/editor/anime/mapping/shoboi") + Tab("AniList", "arrows-h", "/editor/anime/mapping/anilist") + + if strings.Contains(url, "/editor/anime/image/") + .tabs + Tab("Low-Res", "image", "/editor/anime/image/lowres") + Tab("Ultra Low-Res", "image", "/editor/anime/image/ultralowres") //- a.tab.ajax(href="/admin", aria-label="Admin") //- Icon("wrench") diff --git a/pages/editor/filteranime/anilist.go b/pages/editor/filteranime/anilist.go index fb8cf998..b0788f31 100644 --- a/pages/editor/filteranime/anilist.go +++ b/pages/editor/filteranime/anilist.go @@ -3,43 +3,18 @@ package filteranime import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) -const maxAniListEntries = 70 - // AniList ... func AniList(ctx *aero.Context) string { - year, _ := ctx.GetInt("year") - animeType := ctx.Get("type") - - missing := arn.FilterAnime(func(anime *arn.Anime) bool { - if year != 0 && year != anime.StartDateTime().Year() { - return false - } - - if animeType != "" && anime.Type != animeType { - return false - } - - return anime.GetMapping("anilist/anime") == "" - }) - - arn.SortAnimeByQuality(missing) - - count := len(missing) - - if count > maxAniListEntries { - missing = missing[:maxAniListEntries] - } - - return ctx.HTML(components.AnimeEditorListFull( + return editorList( + ctx, "Anime without Anilist mappings", - missing, - count, - ctx.URI(), + func(anime *arn.Anime) bool { + return anime.GetMapping("anilist/anime") == "" + }, func(anime *arn.Anime) string { return "https://anilist.co/search?type=anime&q=" + anime.Title.Canonical }, - )) + ) } diff --git a/pages/editor/filteranime/genres.go b/pages/editor/filteranime/genres.go index 68727ce7..7116c893 100644 --- a/pages/editor/filteranime/genres.go +++ b/pages/editor/filteranime/genres.go @@ -3,41 +3,18 @@ package filteranime import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) const maxGenreEntries = 70 // Genres ... func Genres(ctx *aero.Context) string { - year, _ := ctx.GetInt("year") - animeType := ctx.Get("type") - - missing := arn.FilterAnime(func(anime *arn.Anime) bool { - if year != 0 && year != anime.StartDateTime().Year() { - return false - } - - if animeType != "" && anime.Type != animeType { - return false - } - - return len(anime.Genres) == 0 - }) - - arn.SortAnimeByQuality(missing) - - count := len(missing) - - if count > maxGenreEntries { - missing = missing[:maxGenreEntries] - } - - return ctx.HTML(components.AnimeEditorListFull( + return editorList( + ctx, "Anime without genres", - missing, - count, - ctx.URI(), + func(anime *arn.Anime) bool { + return len(anime.Genres) == 0 + }, nil, - )) + ) } diff --git a/pages/editor/filteranime/lowresimages.go b/pages/editor/filteranime/lowresimages.go index 415a96fb..a618d5fb 100644 --- a/pages/editor/filteranime/lowresimages.go +++ b/pages/editor/filteranime/lowresimages.go @@ -3,7 +3,6 @@ package filteranime import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) const maxImageEntries = 70 @@ -19,38 +18,14 @@ func UltraLowResolutionAnimeImages(ctx *aero.Context) string { } func filterAnimeImages(ctx *aero.Context, title string, minExpectedWidth int, minExpectedHeight int) string { - year, _ := ctx.GetInt("year") - animeType := ctx.Get("type") - - lowResAnime := arn.FilterAnime(func(anime *arn.Anime) bool { - if year != 0 && year != anime.StartDateTime().Year() { - return false - } - - if animeType != "" && anime.Type != animeType { - return false - } - - return anime.Image.Width < minExpectedWidth || anime.Image.Height < minExpectedHeight - }) - - // Sort - arn.SortAnimeByQuality(lowResAnime) - - // Limit - count := len(lowResAnime) - - if count > maxImageEntries { - lowResAnime = lowResAnime[:maxImageEntries] - } - - return ctx.HTML(components.AnimeEditorListFull( + return editorList( + ctx, title, - lowResAnime, - count, - ctx.URI(), + func(anime *arn.Anime) bool { + return anime.Image.Width < minExpectedWidth || anime.Image.Height < minExpectedHeight + }, googleImageSearch, - )) + ) } func googleImageSearch(anime *arn.Anime) string { diff --git a/pages/editor/filteranime/mal.go b/pages/editor/filteranime/mal.go new file mode 100644 index 00000000..0af5732f --- /dev/null +++ b/pages/editor/filteranime/mal.go @@ -0,0 +1,20 @@ +package filteranime + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" +) + +// MAL ... +func MAL(ctx *aero.Context) string { + return editorList( + ctx, + "Anime without MAL mappings", + func(anime *arn.Anime) bool { + return anime.GetMapping("myanimelist/anime") == "" + }, + func(anime *arn.Anime) string { + return "https://myanimelist.net/anime.php?q=" + anime.Title.Canonical + }, + ) +} diff --git a/pages/editor/filteranime/shoboi.go b/pages/editor/filteranime/shoboi.go index ea68d555..2ec90a58 100644 --- a/pages/editor/filteranime/shoboi.go +++ b/pages/editor/filteranime/shoboi.go @@ -3,43 +3,20 @@ package filteranime import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" ) const maxShoboiEntries = 70 // Shoboi ... func Shoboi(ctx *aero.Context) string { - year, _ := ctx.GetInt("year") - animeType := ctx.Get("type") - - missing := arn.FilterAnime(func(anime *arn.Anime) bool { - if year != 0 && year != anime.StartDateTime().Year() { - return false - } - - if animeType != "" && anime.Type != animeType { - return false - } - - return anime.GetMapping("shoboi/anime") == "" - }) - - arn.SortAnimeByQuality(missing) - - count := len(missing) - - if count > maxShoboiEntries { - missing = missing[:maxShoboiEntries] - } - - return ctx.HTML(components.AnimeEditorListFull( + return editorList( + ctx, "Anime without Shoboi mappings", - missing, - count, - ctx.URI(), + func(anime *arn.Anime) bool { + return anime.GetMapping("shoboi/anime") == "" + }, func(anime *arn.Anime) string { return "http://cal.syoboi.jp/find?type=quick&sd=1&kw=" + anime.Title.Japanese }, - )) + ) } diff --git a/pages/editor/filteranime/startdate.go b/pages/editor/filteranime/startdate.go new file mode 100644 index 00000000..feac3e12 --- /dev/null +++ b/pages/editor/filteranime/startdate.go @@ -0,0 +1,21 @@ +package filteranime + +import ( + "time" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" +) + +// StartDate ... +func StartDate(ctx *aero.Context) string { + return editorList( + ctx, + "Anime without a valid start date", + func(anime *arn.Anime) bool { + _, err := time.Parse(arn.AnimeDateFormat, anime.StartDate) + return err != nil + }, + nil, + ) +} diff --git a/pages/editor/filteranime/synopsis.go b/pages/editor/filteranime/synopsis.go new file mode 100644 index 00000000..2ef19acf --- /dev/null +++ b/pages/editor/filteranime/synopsis.go @@ -0,0 +1,18 @@ +package filteranime + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" +) + +// Synopsis ... +func Synopsis(ctx *aero.Context) string { + return editorList( + ctx, + "Anime without a long synopsis", + func(anime *arn.Anime) bool { + return len(anime.Summary) < 170 + }, + nil, + ) +} diff --git a/pages/editor/filteranime/utils.go b/pages/editor/filteranime/utils.go new file mode 100644 index 00000000..05a91e0a --- /dev/null +++ b/pages/editor/filteranime/utils.go @@ -0,0 +1,54 @@ +package filteranime + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +const maxAnimeEntries = 70 + +// editorList renders the anime list with the given title and filter. +func editorList(ctx *aero.Context, title string, filter func(*arn.Anime) bool, searchLink func(*arn.Anime) string) string { + animes, count := filterAnime(ctx, filter) + + return ctx.HTML(components.AnimeEditorListFull( + title, + animes, + count, + ctx.URI(), + searchLink, + )) +} + +// filterAnime filters anime by the given filter function and +// additionally applies year and types filters if specified. +func filterAnime(ctx *aero.Context, filter func(*arn.Anime) bool) ([]*arn.Anime, int) { + year, _ := ctx.GetInt("year") + animeType := ctx.Get("type") + + // Filter + animes := arn.FilterAnime(func(anime *arn.Anime) bool { + if year != 0 && year != anime.StartDateTime().Year() { + return false + } + + if animeType != "" && anime.Type != animeType { + return false + } + + return filter(anime) + }) + + // Sort + arn.SortAnimeByQuality(animes) + + // Limit + count := len(animes) + + if count > maxAnimeEntries { + animes = animes[:maxAnimeEntries] + } + + return animes, count +} diff --git a/pages/index.go b/pages/index.go index d759a101..7cc16112 100644 --- a/pages/index.go +++ b/pages/index.go @@ -249,33 +249,32 @@ func Configure(app *aero.Application) { l.Page("/editor", editor.Get) // Editor - Anime - l.Page("/editor/anime/missing/anilist", filteranime.AniList) - l.Page("/editor/anime/missing/anilist/:year", filteranime.AniList) - l.Page("/editor/anime/missing/anilist/:year/:type", filteranime.AniList) - l.Page("/editor/anime/missing/shoboi", filteranime.Shoboi) - l.Page("/editor/anime/missing/shoboi/:year", filteranime.Shoboi) - l.Page("/editor/anime/missing/shoboi/:year/:type", filteranime.Shoboi) - l.Page("/editor/anime/missing/genres", filteranime.Genres) - l.Page("/editor/anime/missing/genres/:year", filteranime.Genres) - l.Page("/editor/anime/missing/genres/:year/:type", filteranime.Genres) - l.Page("/editor/anime/lowresimage", filteranime.LowResolutionAnimeImages) - l.Page("/editor/anime/lowresimage/:year", filteranime.LowResolutionAnimeImages) - l.Page("/editor/anime/lowresimage/:year/:type", filteranime.LowResolutionAnimeImages) - l.Page("/editor/anime/ultralowresimage", filteranime.UltraLowResolutionAnimeImages) - l.Page("/editor/anime/ultralowresimage/:year", filteranime.UltraLowResolutionAnimeImages) - l.Page("/editor/anime/ultralowresimage/:year/:type", filteranime.UltraLowResolutionAnimeImages) + editorList := func(route string, handler func(ctx *aero.Context) string) { + l.Page(route, handler) + l.Page(route+"/:year", handler) + l.Page(route+"/:year/:type", handler) + } + + editorList("/editor/anime/synopsis", filteranime.Synopsis) + editorList("/editor/anime/genres", filteranime.Genres) + editorList("/editor/anime/startdate", filteranime.StartDate) + editorList("/editor/anime/mapping/shoboi", filteranime.Shoboi) + editorList("/editor/anime/mapping/anilist", filteranime.AniList) + editorList("/editor/anime/mapping/mal", filteranime.MAL) + editorList("/editor/anime/image/lowres", filteranime.LowResolutionAnimeImages) + editorList("/editor/anime/image/ultralowres", filteranime.UltraLowResolutionAnimeImages) // Editor - MALdiff - l.Page("/editor/anime/maldiff", editor.CompareMAL) - l.Page("/editor/anime/maldiff/:year", editor.CompareMAL) - l.Page("/editor/anime/maldiff/:year/:status", editor.CompareMAL) - l.Page("/editor/anime/maldiff/:year/:status/:type", editor.CompareMAL) + l.Page("/editor/maldiff/anime", editor.CompareMAL) + l.Page("/editor/maldiff/anime/:year", editor.CompareMAL) + l.Page("/editor/maldiff/anime/:year/:status", editor.CompareMAL) + l.Page("/editor/maldiff/anime/:year/:status/:type", editor.CompareMAL) // Editor - Kitsu - l.Page("/editor/anime/kitsu/new", editor.NewKitsuAnime) + l.Page("/editor/kitsu/new/anime", editor.NewKitsuAnime) // Editor - Companies - l.Page("/editor/companies/missing/description", filtercompanies.NoDescription) + l.Page("/editor/companies/description", filtercompanies.NoDescription) // Log l.Page("/log", editlog.Get)