Added characters page
This commit is contained in:
parent
e8c66f28ab
commit
8a8b363e03
@ -205,5 +205,9 @@ func importCharacter(malCharacter *mal.Character) *arn.Character {
|
|||||||
|
|
||||||
// Save character in DB
|
// Save character in DB
|
||||||
character.Save()
|
character.Save()
|
||||||
|
|
||||||
|
// Add to character finder so we don't create duplicates of this character
|
||||||
|
characterFinder.Add(character)
|
||||||
|
|
||||||
return character
|
return character
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@ component Sidebar(user *arn.User)
|
|||||||
SidebarButton("AMVs", "/amvs", "video-camera")
|
SidebarButton("AMVs", "/amvs", "video-camera")
|
||||||
SidebarButton("Soundtracks", "/soundtracks", "headphones")
|
SidebarButton("Soundtracks", "/soundtracks", "headphones")
|
||||||
SidebarButton("Quotes", "/quotes", "quote-left")
|
SidebarButton("Quotes", "/quotes", "quote-left")
|
||||||
|
if user != nil && (user.Role == "editor" || user.Role == "admin")
|
||||||
|
SidebarButton("Characters", "/characters", "child")
|
||||||
SidebarButton("Companies", "/companies", "building")
|
SidebarButton("Companies", "/companies", "building")
|
||||||
SidebarButton("Users", "/users", "globe")
|
SidebarButton("Users", "/users", "globe")
|
||||||
|
|
||||||
|
22
pages/characters/best.go
Normal file
22
pages/characters/best.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package characters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Best characters.
|
||||||
|
func Best(ctx *aero.Context) string {
|
||||||
|
characters := fetchAll()
|
||||||
|
|
||||||
|
sort.Slice(characters, func(i, j int) bool {
|
||||||
|
if len(characters[i].Likes) == len(characters[j].Likes) {
|
||||||
|
return characters[i].Name.Canonical < characters[j].Name.Canonical
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(characters[i].Likes) > len(characters[j].Likes)
|
||||||
|
})
|
||||||
|
|
||||||
|
return render(ctx, characters)
|
||||||
|
}
|
@ -14,19 +14,19 @@ component Characters(characters []*arn.Character, nextIndex int, tag string, use
|
|||||||
Icon("pencil")
|
Icon("pencil")
|
||||||
span Edit draft
|
span Edit draft
|
||||||
|
|
||||||
//- #load-more-target.characters.characters-page
|
#load-more-target.characters.characters-page
|
||||||
//- CharactersScrollable(characters, user)
|
CharactersScrollable(characters, user)
|
||||||
|
|
||||||
//- if nextIndex != -1
|
if nextIndex != -1
|
||||||
//- .buttons
|
.buttons
|
||||||
//- LoadMore(nextIndex)
|
LoadMore(nextIndex)
|
||||||
|
|
||||||
component CharactersScrollable(characters []*arn.Character, user *arn.User)
|
component CharactersScrollable(characters []*arn.Character, user *arn.User)
|
||||||
each character in characters
|
each character in characters
|
||||||
Character(character, user)
|
Character(character, user)
|
||||||
|
|
||||||
component CharactersTabs(tag string)
|
component CharactersTabs(tag string)
|
||||||
//- .tab-groups
|
.tab-groups
|
||||||
//- .tabs
|
.tabs
|
||||||
//- Tab("Latest", "video-camera", "/characters")
|
Tab("Latest", "child", "/characters")
|
||||||
//- Tab("Best", "heart", "/characters/best")
|
Tab("Best", "heart", "/characters/best")
|
9
pages/characters/fetch.go
Normal file
9
pages/characters/fetch.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package characters
|
||||||
|
|
||||||
|
import "github.com/animenotifier/arn"
|
||||||
|
|
||||||
|
func fetchAll() []*arn.Character {
|
||||||
|
return arn.FilterCharacters(func(character *arn.Character) bool {
|
||||||
|
return !character.IsDraft
|
||||||
|
})
|
||||||
|
}
|
18
pages/characters/latest.go
Normal file
18
pages/characters/latest.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package characters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Latest characters.
|
||||||
|
func Latest(ctx *aero.Context) string {
|
||||||
|
characters := fetchAll()
|
||||||
|
|
||||||
|
sort.Slice(characters, func(i, j int) bool {
|
||||||
|
return characters[i].Created > characters[j].Created
|
||||||
|
})
|
||||||
|
|
||||||
|
return render(ctx, characters)
|
||||||
|
}
|
44
pages/characters/render.go
Normal file
44
pages/characters/render.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package characters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
|
"github.com/animenotifier/notify.moe/utils/infinitescroll"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
charactersFirstLoad = 104
|
||||||
|
charactersPerScroll = 39
|
||||||
|
)
|
||||||
|
|
||||||
|
// render renders the characters page with the given characters.
|
||||||
|
func render(ctx *aero.Context, allCharacters []*arn.Character) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
index, _ := ctx.GetInt("index")
|
||||||
|
tag := ctx.Get("tag")
|
||||||
|
|
||||||
|
// Slice the part that we need
|
||||||
|
characters := allCharacters[index:]
|
||||||
|
maxLength := charactersFirstLoad
|
||||||
|
|
||||||
|
if index > 0 {
|
||||||
|
maxLength = charactersPerScroll
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(characters) > maxLength {
|
||||||
|
characters = characters[:maxLength]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next index
|
||||||
|
nextIndex := infinitescroll.NextIndex(ctx, len(allCharacters), maxLength, index)
|
||||||
|
|
||||||
|
// In case we're scrolling, send Characters only (without the page frame)
|
||||||
|
if index > 0 {
|
||||||
|
return ctx.HTML(components.CharactersScrollable(characters, user))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, send the full page
|
||||||
|
return ctx.HTML(components.Characters(characters, nextIndex, tag, user))
|
||||||
|
}
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/pages/apiview/apidocs"
|
"github.com/animenotifier/notify.moe/pages/apiview/apidocs"
|
||||||
"github.com/animenotifier/notify.moe/pages/calendar"
|
"github.com/animenotifier/notify.moe/pages/calendar"
|
||||||
"github.com/animenotifier/notify.moe/pages/character"
|
"github.com/animenotifier/notify.moe/pages/character"
|
||||||
|
"github.com/animenotifier/notify.moe/pages/characters"
|
||||||
"github.com/animenotifier/notify.moe/pages/charge"
|
"github.com/animenotifier/notify.moe/pages/charge"
|
||||||
"github.com/animenotifier/notify.moe/pages/companies"
|
"github.com/animenotifier/notify.moe/pages/companies"
|
||||||
"github.com/animenotifier/notify.moe/pages/company"
|
"github.com/animenotifier/notify.moe/pages/company"
|
||||||
@ -140,6 +141,12 @@ func Configure(app *aero.Application) {
|
|||||||
l.Page("/anime/:id/edit/history", editanime.History)
|
l.Page("/anime/:id/edit/history", editanime.History)
|
||||||
|
|
||||||
// Characters
|
// Characters
|
||||||
|
l.Page("/characters", characters.Latest)
|
||||||
|
l.Page("/characters/from/:index", characters.Latest)
|
||||||
|
l.Page("/characters/best", characters.Best)
|
||||||
|
l.Page("/characters/best/from/:index", characters.Best)
|
||||||
|
|
||||||
|
// Character
|
||||||
l.Page("/character/:id", character.Get)
|
l.Page("/character/:id", character.Get)
|
||||||
l.Page("/character/:id/edit", character.Edit)
|
l.Page("/character/:id/edit", character.Edit)
|
||||||
l.Page("/character/:id/edit/images", character.EditImages)
|
l.Page("/character/:id/edit/images", character.EditImages)
|
||||||
@ -150,6 +157,8 @@ func Configure(app *aero.Application) {
|
|||||||
l.Page("/amvs/from/:index", amvs.Latest)
|
l.Page("/amvs/from/:index", amvs.Latest)
|
||||||
l.Page("/amvs/best", amvs.Best)
|
l.Page("/amvs/best", amvs.Best)
|
||||||
l.Page("/amvs/best/from/:index", amvs.Best)
|
l.Page("/amvs/best/from/:index", amvs.Best)
|
||||||
|
|
||||||
|
// AMV
|
||||||
l.Page("/amv/:id", amv.Get)
|
l.Page("/amv/:id", amv.Get)
|
||||||
l.Page("/amv/:id/edit", amv.Edit)
|
l.Page("/amv/:id/edit", amv.Edit)
|
||||||
l.Page("/amv/:id/history", amv.History)
|
l.Page("/amv/:id/history", amv.History)
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
color.Yellow("Adding creation dates")
|
||||||
|
|
||||||
|
defer color.Green("Finished")
|
||||||
|
defer arn.Node.Close()
|
||||||
|
|
||||||
|
baseTime := time.Now().Add(-2 * 30 * 24 * time.Hour)
|
||||||
|
irregular := time.Duration(0)
|
||||||
|
|
||||||
|
for character := range arn.StreamCharacters() {
|
||||||
|
malID := character.GetMapping("myanimelist/character")
|
||||||
|
|
||||||
|
if malID != "" {
|
||||||
|
malIDNumber, err := strconv.Atoi(malID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
character.Created = baseTime.Add(time.Duration(malIDNumber) * time.Minute).Format(time.RFC3339)
|
||||||
|
} else {
|
||||||
|
irregular++
|
||||||
|
character.Created = baseTime.Add(-irregular * time.Minute).Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
|
||||||
|
character.Save()
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
color.Yellow("Merging duplicate characters")
|
||||||
|
|
||||||
|
defer color.Green("Finished")
|
||||||
|
defer arn.Node.Close()
|
||||||
|
|
||||||
|
malIDToCharacters := map[string][]*arn.Character{}
|
||||||
|
|
||||||
|
for character := range arn.StreamCharacters() {
|
||||||
|
malID := character.GetMapping("myanimelist/character")
|
||||||
|
|
||||||
|
if malID != "" {
|
||||||
|
malIDToCharacters[malID] = append(malIDToCharacters[malID], character)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, characters := range malIDToCharacters {
|
||||||
|
if len(characters) > 1 {
|
||||||
|
sort.Slice(characters, func(i, j int) bool {
|
||||||
|
return len(characters[i].Likes) > len(characters[j].Likes)
|
||||||
|
})
|
||||||
|
|
||||||
|
for index, character := range characters {
|
||||||
|
if index == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Merging '%s' with '%s' (%s to %s)\n", color.YellowString(character.String()), color.YellowString(characters[0].String()), character.ID, characters[0].ID)
|
||||||
|
character.Merge(characters[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user