Added list import preview

This commit is contained in:
2017-07-03 19:33:52 +02:00
parent 4f6ffd969d
commit 7262f4db7b
7 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package listimport
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Get ...
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
}
return ctx.HTML(components.ImportLists(user))
}

View File

@ -0,0 +1,8 @@
component ImportLists(user *arn.User)
.buttons
if user.Accounts.AniList.Nick != ""
a.button.mountable.ajax(href="/import/anilist/animelist")
Icon("refresh")
span Import AniList Anime List
else
p No imports available.

View File

@ -0,0 +1,62 @@
package listimportanilist
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Get ...
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
}
authErr := arn.AniList.Authorize()
if authErr != nil {
return ctx.Error(http.StatusBadRequest, "Couldn't authorize the Anime Notifier app on AniList", authErr)
}
allAnime, allErr := arn.AllAnime()
if allErr != nil {
return ctx.Error(http.StatusBadRequest, "Couldn't load notify.moe list of all anime", allErr)
}
animeList, err := arn.AniList.GetAnimeList(user)
if err != nil {
return ctx.Error(http.StatusBadRequest, "Couldn't load your anime list from AniList", err)
}
matches := []*arn.AniListMatch{}
matches = importList(matches, allAnime, animeList.Lists.Watching)
matches = importList(matches, allAnime, animeList.Lists.Completed)
matches = importList(matches, allAnime, animeList.Lists.PlanToWatch)
matches = importList(matches, allAnime, animeList.Lists.OnHold)
matches = importList(matches, allAnime, animeList.Lists.Dropped)
for _, list := range animeList.CustomLists {
matches = importList(matches, allAnime, list)
}
return ctx.HTML(components.ImportAnilist(user, matches))
}
func importList(matches []*arn.AniListMatch, allAnime []*arn.Anime, animeListItems []*arn.AniListAnimeListItem) []*arn.AniListMatch {
for _, item := range animeListItems {
matches = append(matches, &arn.AniListMatch{
AniListAnime: item.Anime,
ARNAnime: arn.FindAniListAnime(item.Anime, allAnime),
})
}
return matches
}

View File

@ -0,0 +1,23 @@
component ImportAnilist(user *arn.User, matches []*arn.AniListMatch)
h2= "Import: anilist.co"
table
thead
tr
th anilist.co
th notify.moe
tbody
each match in matches
tr
td
a(href=match.AniListAnime.Link(), target="_blank", rel="noopener")= match.AniListAnime.TitleRomaji
td
if match.ARNAnime == nil
span.import-error Not found on notify.moe
else
a(href=match.ARNAnime.Link(), target="_blank", rel="noopener")= match.ARNAnime.Title.Canonical
.buttons
.button.mountable.action(data-action="soon", data-trigger="click")
Icon("refresh")
span Import