From fae6f641bef72fcb100246614f41041384600d26 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 23 Mar 2018 03:37:14 +0100 Subject: [PATCH] Add filter for duplicate mappings --- pages/editor/editor.pixy | 1 + pages/editor/filteranime/duplicate-mapping.go | 30 +++++++++++++++++++ pages/index.go | 28 +---------------- 3 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 pages/editor/filteranime/duplicate-mapping.go diff --git a/pages/editor/editor.pixy b/pages/editor/editor.pixy index fa2e0264..d35b1783 100644 --- a/pages/editor/editor.pixy +++ b/pages/editor/editor.pixy @@ -40,6 +40,7 @@ component EditorTabs(url string, user *arn.User) Tab("MAL", "arrows-h", "/editor/anime/mapping/mal" + user.Settings().Editor.Filter.Suffix()) Tab("Shoboi", "arrows-h", "/editor/anime/mapping/shoboi" + user.Settings().Editor.Filter.Suffix()) Tab("AniList", "arrows-h", "/editor/anime/mapping/anilist" + user.Settings().Editor.Filter.Suffix()) + Tab("Duplicate", "exclamation-circle", "/editor/anime/mapping/duplicate" + user.Settings().Editor.Filter.Suffix()) if strings.Contains(url, "/editor/anime/image/") .tabs diff --git a/pages/editor/filteranime/duplicate-mapping.go b/pages/editor/filteranime/duplicate-mapping.go new file mode 100644 index 00000000..43093a9d --- /dev/null +++ b/pages/editor/filteranime/duplicate-mapping.go @@ -0,0 +1,30 @@ +package filteranime + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" +) + +// DuplicateMappings ... +func DuplicateMappings(ctx *aero.Context) string { + return editorList( + ctx, + "Anime with duplicate mappings", + func(anime *arn.Anime) bool { + all := map[string]bool{} + + for _, mapping := range anime.Mappings { + _, exists := all[mapping.Service] + + if exists { + return true + } + + all[mapping.Service] = true + } + + return false + }, + nil, + ) +} diff --git a/pages/index.go b/pages/index.go index b58bb903..0f8986fd 100644 --- a/pages/index.go +++ b/pages/index.go @@ -249,33 +249,6 @@ func Configure(app *aero.Application) { // Editor links can be filtered by year, status and type editorFilterable := func(route string, handler func(ctx *aero.Context) string) { - // l.Page(route, func(ctx *aero.Context) string { - // user := utils.GetUser(ctx) - - // if user == nil { - // return ctx.Error(http.StatusUnauthorized, "Not logged in", nil) - // } - - // settings := user.Settings().Editor - - // year := settings.Filter.Year - // status := settings.Filter.Status - // typ := settings.Filter.Type - - // if year == "" { - // year = "any" - // } - - // if status == "" { - // status = "any" - // } - - // if typ == "" { - // typ = "any" - // } - - // return ctx.Redirect(fmt.Sprintf("%s/%s/%s/%s", ctx.URI(), year, status, typ)) - // }) l.Page(route+"/:year/:status/:type", handler) } @@ -286,6 +259,7 @@ func Configure(app *aero.Application) { editorFilterable("/editor/anime/mapping/shoboi", filteranime.Shoboi) editorFilterable("/editor/anime/mapping/anilist", filteranime.AniList) editorFilterable("/editor/anime/mapping/mal", filteranime.MAL) + editorFilterable("/editor/anime/mapping/duplicate", filteranime.DuplicateMappings) editorFilterable("/editor/anime/image/lowres", filteranime.LowResolutionAnimeImages) editorFilterable("/editor/anime/image/ultralowres", filteranime.UltraLowResolutionAnimeImages)