Add filter for duplicate mappings

This commit is contained in:
Eduard Urbach 2018-03-23 03:37:14 +01:00
parent fc5da638c0
commit fae6f641be
3 changed files with 32 additions and 27 deletions

View File

@ -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("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("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("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/") if strings.Contains(url, "/editor/anime/image/")
.tabs .tabs

View File

@ -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,
)
}

View File

@ -249,33 +249,6 @@ func Configure(app *aero.Application) {
// Editor links can be filtered by year, status and type // Editor links can be filtered by year, status and type
editorFilterable := func(route string, handler func(ctx *aero.Context) string) { 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) 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/shoboi", filteranime.Shoboi)
editorFilterable("/editor/anime/mapping/anilist", filteranime.AniList) editorFilterable("/editor/anime/mapping/anilist", filteranime.AniList)
editorFilterable("/editor/anime/mapping/mal", filteranime.MAL) 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/lowres", filteranime.LowResolutionAnimeImages)
editorFilterable("/editor/anime/image/ultralowres", filteranime.UltraLowResolutionAnimeImages) editorFilterable("/editor/anime/image/ultralowres", filteranime.UltraLowResolutionAnimeImages)