Added anime list comparison
This commit is contained in:
parent
1a693fec05
commit
6c0f8a6318
4
main.go
4
main.go
@ -18,6 +18,7 @@ import (
|
||||
"github.com/animenotifier/notify.moe/pages/best"
|
||||
"github.com/animenotifier/notify.moe/pages/character"
|
||||
"github.com/animenotifier/notify.moe/pages/charge"
|
||||
"github.com/animenotifier/notify.moe/pages/compare"
|
||||
"github.com/animenotifier/notify.moe/pages/dashboard"
|
||||
"github.com/animenotifier/notify.moe/pages/database"
|
||||
"github.com/animenotifier/notify.moe/pages/editanime"
|
||||
@ -136,6 +137,9 @@ func configure(app *aero.Application) *aero.Application {
|
||||
app.Ajax("/animelist/hold", home.FilterByStatus(arn.AnimeListStatusHold))
|
||||
app.Ajax("/animelist/dropped", home.FilterByStatus(arn.AnimeListStatusDropped))
|
||||
|
||||
// Compare
|
||||
app.Ajax("/compare/animelist/:nick-1/:nick-2", compare.AnimeList)
|
||||
|
||||
// Search
|
||||
app.Ajax("/search", search.Get)
|
||||
app.Ajax("/search/:term", search.Get)
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
.anime-list-item-image-container
|
||||
padding 0
|
||||
width 39px
|
||||
|
||||
.anime-list-item-image
|
||||
width 39px
|
||||
|
74
pages/compare/animelist.go
Normal file
74
pages/compare/animelist.go
Normal file
@ -0,0 +1,74 @@
|
||||
package compare
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
)
|
||||
|
||||
// AnimeList ...
|
||||
func AnimeList(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
nickA := ctx.Get("nick-1")
|
||||
nickB := ctx.Get("nick-2")
|
||||
|
||||
a, err := arn.GetUserByNick(nickA)
|
||||
|
||||
if err != nil || a == nil {
|
||||
return ctx.Error(http.StatusNotFound, "User not found: "+nickA, err)
|
||||
}
|
||||
|
||||
b, err := arn.GetUserByNick(nickB)
|
||||
|
||||
if err != nil || b == nil {
|
||||
return ctx.Error(http.StatusNotFound, "User not found: "+nickB, err)
|
||||
}
|
||||
|
||||
comparisons := []*utils.Comparison{}
|
||||
|
||||
for _, item := range a.AnimeList().Items {
|
||||
if item.Status == arn.AnimeListStatusPlanned {
|
||||
continue
|
||||
}
|
||||
|
||||
comparisons = append(comparisons, &utils.Comparison{
|
||||
Anime: item.Anime(),
|
||||
ItemA: item,
|
||||
ItemB: b.AnimeList().Find(item.AnimeID),
|
||||
})
|
||||
}
|
||||
|
||||
for _, item := range b.AnimeList().Items {
|
||||
if Contains(comparisons, item.AnimeID) || item.Status == arn.AnimeListStatusPlanned {
|
||||
continue
|
||||
}
|
||||
|
||||
comparisons = append(comparisons, &utils.Comparison{
|
||||
Anime: item.Anime(),
|
||||
ItemA: a.AnimeList().Find(item.AnimeID),
|
||||
ItemB: item,
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(comparisons, func(i, j int) bool {
|
||||
return comparisons[i].Anime.Popularity.Total() > comparisons[j].Anime.Popularity.Total()
|
||||
})
|
||||
|
||||
return ctx.HTML(components.CompareAnimeList(a, b, comparisons, user))
|
||||
}
|
||||
|
||||
// Contains ...
|
||||
func Contains(comparisons []*utils.Comparison, animeID string) bool {
|
||||
for _, comparison := range comparisons {
|
||||
if comparison.Anime.ID == animeID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
65
pages/compare/animelist.pixy
Normal file
65
pages/compare/animelist.pixy
Normal file
@ -0,0 +1,65 @@
|
||||
component CompareAnimeList(a *arn.User, b *arn.User, comparisons []*utils.Comparison, user *arn.User)
|
||||
h1= "Anime list comparison between " + a.Nick + " and " + b.Nick
|
||||
|
||||
table.anime-list
|
||||
thead
|
||||
tr.anime-list-item.mountable
|
||||
th.anime-list-item-image-container
|
||||
th.anime-list-item-name
|
||||
th.comparison
|
||||
Avatar(a)
|
||||
th.comparison
|
||||
th.comparison
|
||||
Avatar(b)
|
||||
th.comparison
|
||||
|
||||
tbody
|
||||
each comparison in comparisons
|
||||
tr.anime-list-item.mountable
|
||||
td.anime-list-item-image-container
|
||||
a.ajax(href=comparison.Anime.Link())
|
||||
img.anime-list-item-image.lazy(data-src=comparison.Anime.Image.Tiny, alt=comparison.Anime.Title.ByUser(user))
|
||||
|
||||
td.anime-list-item-name
|
||||
a.ajax(href=comparison.Anime.Link())= comparison.Anime.Title.ByUser(user)
|
||||
|
||||
td.comparison
|
||||
if comparison.ItemA != nil
|
||||
span= comparison.ItemA.Status
|
||||
else
|
||||
span -
|
||||
|
||||
td.comparison
|
||||
if comparison.ItemA != nil
|
||||
if comparison.ItemA.Rating.Overall != 0
|
||||
if comparison.ItemB != nil && comparison.ItemB.Rating.Overall != 0 && comparison.ItemA.Rating.Overall == comparison.ItemB.Rating.Overall
|
||||
span.comparison-rating-equal= utils.FormatRating(comparison.ItemA.Rating.Overall)
|
||||
else
|
||||
span= utils.FormatRating(comparison.ItemA.Rating.Overall)
|
||||
else
|
||||
span -
|
||||
else
|
||||
span -
|
||||
|
||||
td.comparison
|
||||
if comparison.ItemB != nil
|
||||
span= comparison.ItemB.Status
|
||||
else
|
||||
span -
|
||||
|
||||
td.comparison
|
||||
if comparison.ItemB != nil
|
||||
if comparison.ItemB.Rating.Overall != 0
|
||||
if comparison.ItemA != nil && comparison.ItemA.Rating.Overall != 0
|
||||
if comparison.ItemA.Rating.Overall == comparison.ItemB.Rating.Overall
|
||||
span.comparison-rating-equal= utils.FormatRating(comparison.ItemB.Rating.Overall)
|
||||
else if comparison.ItemB.Rating.Overall > comparison.ItemA.Rating.Overall
|
||||
span.comparison-rating-higher(title=utils.FormatRating(comparison.ItemB.Rating.Overall))= "+" + utils.FormatRating(comparison.ItemB.Rating.Overall - comparison.ItemA.Rating.Overall)
|
||||
else
|
||||
span.comparison-rating-lower(title=utils.FormatRating(comparison.ItemB.Rating.Overall))= "-" + utils.FormatRating(comparison.ItemA.Rating.Overall - comparison.ItemB.Rating.Overall)
|
||||
else
|
||||
span= utils.FormatRating(comparison.ItemB.Rating.Overall)
|
||||
else
|
||||
span -
|
||||
else
|
||||
span -
|
14
pages/compare/animelist.scarlet
Normal file
14
pages/compare/animelist.scarlet
Normal file
@ -0,0 +1,14 @@
|
||||
.comparison
|
||||
width 100px
|
||||
text-align center
|
||||
horizontal
|
||||
justify-content center
|
||||
|
||||
.comparison-rating-equal
|
||||
// ...
|
||||
|
||||
.comparison-rating-lower
|
||||
color red
|
||||
|
||||
.comparison-rating-higher
|
||||
color green
|
@ -61,6 +61,10 @@ component ProfileHeader(viewUser *arn.User, user *arn.User, uri string)
|
||||
button.profile-action.action(data-action="unfollowUser", data-trigger="click", data-api="/api/userfollows/" + user.ID + "/remove/" + viewUser.ID)
|
||||
Icon("user-times")
|
||||
span Unfollow
|
||||
|
||||
a.button.profile-action.ajax(href="/compare/animelist/" + user.Nick + "/" + viewUser.Nick)
|
||||
Icon("exchange")
|
||||
span Compare
|
||||
|
||||
ProfileNavigation(viewUser, uri)
|
||||
|
||||
|
10
utils/Comparison.go
Normal file
10
utils/Comparison.go
Normal file
@ -0,0 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "github.com/animenotifier/arn"
|
||||
|
||||
// Comparison of an anime between 2 users.
|
||||
type Comparison struct {
|
||||
Anime *arn.Anime
|
||||
ItemA *arn.AnimeListItem
|
||||
ItemB *arn.AnimeListItem
|
||||
}
|
Loading…
Reference in New Issue
Block a user