Added recommendations view to the UI

This commit is contained in:
Eduard Urbach 2018-02-24 15:35:34 +01:00
parent b9f8cfc79e
commit d4d7294f4e
3 changed files with 15 additions and 15 deletions

View File

@ -10,9 +10,13 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList,
a.profile-watching-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.ByUser(user) + " (" + toString(item.Episodes) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")")
img.profile-watching-list-item-image.lazy(data-src=item.Anime().Image("small"), data-webp="true", alt=item.Anime().Title.ByUser(user))
if user != nil && (user.Role == "admin" || user.Role == "editor")
.footer
.buttons
.footer
.buttons
a.button.profile-action.ajax(href="/+" + viewUser.Nick + "/recommended/anime")
Icon("tv")
span View recommendations
if user != nil && (user.Role == "admin" || user.Role == "editor")
a.button.profile-action(href="/api/user/" + viewUser.ID, target="_blank", rel="noopener")
Icon("search-plus")
span JSON

View File

@ -1,13 +1,13 @@
package recommended
import (
"fmt"
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
const (
@ -17,14 +17,15 @@ const (
// Anime shows a list of recommended anime.
func Anime(ctx *aero.Context) string {
user := utils.GetUser(ctx)
nick := ctx.Get("nick")
user, err := arn.GetUserByNick(nick)
viewUser, err := arn.GetUserByNick(nick)
if err != nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", err)
}
animeList := user.AnimeList()
animeList := viewUser.AnimeList()
genreItems := animeList.Genres()
genreAffinity := map[string]float64{}
worstGenres := []string{}
@ -57,8 +58,6 @@ func Anime(ctx *aero.Context) string {
worstGenres = worstGenres[:worstGenreCount]
}
fmt.Println(worstGenres)
// Get all anime
recommendations := arn.AllAnime()
@ -121,5 +120,5 @@ func Anime(ctx *aero.Context) string {
recommendations = recommendations[:maxRecommendations]
}
return ctx.HTML(components.RecommendedAnime(recommendations, user))
return ctx.HTML(components.RecommendedAnime(recommendations, worstGenres, viewUser, user))
}

View File

@ -1,7 +1,4 @@
component RecommendedAnime(animes []*arn.Anime, user *arn.User)
h1= "Recommended anime for " + user.Nick
component RecommendedAnime(animes []*arn.Anime, worstGenres []string, viewUser *arn.User, user *arn.User)
h1(title="This is a machine-generated list of anime recommendations.")= "Recommended anime for " + viewUser.Nick
AnimeGrid(animes, user)
//- ul
//- each anime in animes
//- li= anime.Title.Canonical