From 44803adc2de5acce5b8e10610f5a556cb5812ea8 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 5 Jul 2017 16:52:24 +0200 Subject: [PATCH] Started working on status filter --- main.go | 7 +++++- pages/anime/anime.pixy | 2 +- pages/animelist/status.go | 46 +++++++++++++++++++++++++++++++++++ pages/animelist/watching.pixy | 8 ++++++ pages/profile/profile.pixy | 24 ++++++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 pages/animelist/status.go create mode 100644 pages/animelist/watching.pixy diff --git a/main.go b/main.go index dd2b9390..dfc2eb8c 100644 --- a/main.go +++ b/main.go @@ -76,7 +76,12 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/user/:nick/posts", profile.GetPostsByUser) app.Ajax("/user/:nick/tracks", profile.GetSoundTracksByUser) app.Ajax("/user/:nick/animelist", animelist.Get) - app.Ajax("/user/:nick/animelist/:id", animelistitem.Get) + app.Ajax("/user/:nick/animelist/watching", animelist.FilterByStatus(arn.AnimeListStatusWatching)) + app.Ajax("/user/:nick/animelist/completed", animelist.FilterByStatus(arn.AnimeListStatusCompleted)) + app.Ajax("/user/:nick/animelist/planned", animelist.FilterByStatus(arn.AnimeListStatusPlanned)) + app.Ajax("/user/:nick/animelist/hold", animelist.FilterByStatus(arn.AnimeListStatusHold)) + app.Ajax("/user/:nick/animelist/dropped", animelist.FilterByStatus(arn.AnimeListStatusDropped)) + app.Ajax("/user/:nick/animelist/anime/:id", animelistitem.Get) app.Ajax("/new/thread", newthread.Get) app.Ajax("/new/soundtrack", newsoundtrack.Get) app.Ajax("/settings", settings.Get) diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index 854807bd..72f14599 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -27,7 +27,7 @@ component Anime(anime *arn.Anime, tracks []*arn.SoundTrack, user *arn.User, epis span Edit anime if user.AnimeList().Contains(anime.ID) - a.button.ajax(href="/+" + user.Nick + "/animelist/" + anime.ID) + a.button.ajax(href="/+" + user.Nick + "/animelist/anime/" + anime.ID) Icon("pencil") span Edit in collection else diff --git a/pages/animelist/status.go b/pages/animelist/status.go new file mode 100644 index 00000000..0db10e03 --- /dev/null +++ b/pages/animelist/status.go @@ -0,0 +1,46 @@ +package animelist + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// FilterByStatus returns a handler for the given anime list item status. +func FilterByStatus(status string) aero.Handle { + return func(ctx *aero.Context) string { + user := utils.GetUser(ctx) + list, response := statusList(ctx, status) + + if response != "" { + return response + } + + return ctx.HTML(components.AnimeListFilteredByStatus(list, list.User(), user)) + } +} + +// statusList handles the request for an anime list with a given status. +func statusList(ctx *aero.Context, status string) (*arn.AnimeList, string) { + nick := ctx.Get("nick") + viewUser, err := arn.GetUserByNick(nick) + + if err != nil { + return nil, ctx.Error(http.StatusNotFound, "User not found", err) + } + + animeList := viewUser.AnimeList() + + if animeList == nil { + return nil, ctx.Error(http.StatusNotFound, "Anime list not found", nil) + } + + watchingList := animeList.FilterStatus(status) + watchingList.PrefetchAnime() + watchingList.Sort() + + return watchingList, "" +} diff --git a/pages/animelist/watching.pixy b/pages/animelist/watching.pixy new file mode 100644 index 00000000..6073b83f --- /dev/null +++ b/pages/animelist/watching.pixy @@ -0,0 +1,8 @@ +component AnimeListFilteredByStatus(animeList *arn.AnimeList, viewUser *arn.User, user *arn.User) + ProfileHeader(viewUser, user) + + if len(animeList.Items) == 0 + p.no-data.mountable= viewUser.Nick + " hasn't added any anime to this list yet." + else + .anime-list-container + AnimeList(animeList, viewUser, user) \ No newline at end of file diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 483c923b..8385c658 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -67,6 +67,30 @@ component ProfileNavigation(viewUser *arn.User) a.button.tab.action(href="/+" + viewUser.Nick + "/tracks", data-action="diff", data-trigger="click") Icon("music") span.tab-text Tracks + + StatusTabs("/+" + viewUser.Nick + "/animelist") + +component StatusTabs(urlPrefix string) + .buttons.tabs + a.button.tab.action(href=urlPrefix + "/watching", data-action="diff", data-trigger="click") + Icon("play") + span.tab-text Watching + + a.button.tab.action(href=urlPrefix + "/completed", data-action="diff", data-trigger="click") + Icon("check") + span.tab-text Completed + + a.button.tab.action(href=urlPrefix + "/planned", data-action="diff", data-trigger="click") + Icon("forward") + span.tab-text Planned + + a.button.tab.action(href=urlPrefix + "/hold", data-action="diff", data-trigger="click") + Icon("pause") + span.tab-text On Hold + + a.button.tab.action(href=urlPrefix + "/dropped", data-action="diff", data-trigger="click") + Icon("stop") + span.tab-text Dropped component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, threads []*arn.Thread, posts []*arn.Post, tracks []*arn.SoundTrack) ProfileHeader(viewUser, user)