Show character ranking in info table

This commit is contained in:
2018-10-27 11:01:21 +09:00
parent 24103d10cb
commit 252d021d90
5 changed files with 74 additions and 19 deletions

View File

@ -60,18 +60,24 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
component CharacterSidebar(character *arn.Character, friends []*arn.User, relevantCharacters []*arn.Character, user *arn.User)
.character-sidebar
if len(character.Attributes) > 0
h3.mountable(data-mountable-type="sidebar") Information
h3.mountable(data-mountable-type="sidebar") Information
table.character-attributes.mountable(data-mountable-type="sidebar")
each attribute in character.Attributes
tr.mountable(data-mountable-type="info")
td.character-attributes-name= attribute.Name + ":"
table.character-attributes.mountable(data-mountable-type="sidebar")
//- Ranking
tr.mountable(data-mountable-type="info")
td.character-attributes-name Ranking:
td.character-attributes-value
a.character-ranking(href="/characters/best", data-character-id=character.ID) View
//- Attributes
each attribute in character.Attributes
tr.mountable(data-mountable-type="info")
td.character-attributes-name= attribute.Name + ":"
if strings.Contains(attribute.Value, "<")
td.character-attributes-value!= markdown.Render(attribute.Value)
else
td.character-attributes-value= attribute.Value
if strings.Contains(attribute.Value, "<")
td.character-attributes-value!= markdown.Render(attribute.Value)
else
td.character-attributes-value= attribute.Value
if len(relevantCharacters) > 0
h3.mountable(data-mountable-type="sidebar") Relevant

View File

@ -0,0 +1,33 @@
package character
import (
"net/http"
"strconv"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
)
// Ranking returns the ranking information for the character via the API.
func Ranking(ctx *aero.Context) string {
id := ctx.Get("id")
_, err := arn.GetCharacter(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Character not found", err)
}
characters := arn.FilterCharacters(func(character *arn.Character) bool {
return !character.IsDraft
})
arn.SortCharactersByLikes(characters)
for index, character := range characters {
if character.ID == id {
return strconv.Itoa(index + 1)
}
}
return ""
}