Added companies sorted by popularity
This commit is contained in:
parent
e9f15eacbc
commit
cbf640710c
@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get renders the companies page.
|
// All renders the companies page.
|
||||||
func Get(ctx *aero.Context) string {
|
func All(ctx *aero.Context) string {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
|
||||||
companies := arn.FilterCompanies(func(company *arn.Company) bool {
|
companies := arn.FilterCompanies(func(company *arn.Company) bool {
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
component Companies(groups [][]*arn.Company, user *arn.User)
|
component Companies(groups [][]*arn.Company, user *arn.User)
|
||||||
h1 Companies
|
CompaniesTabs(user)
|
||||||
|
|
||||||
|
.companies
|
||||||
|
each group in groups
|
||||||
|
.companies-group
|
||||||
|
h3= group[0].Name.English[:1]
|
||||||
|
|
||||||
|
ul
|
||||||
|
each company in group
|
||||||
|
li.mountable
|
||||||
|
a.ajax(href=company.Link())= company.Name.English
|
||||||
|
|
||||||
|
component CompaniesTabs(user *arn.User)
|
||||||
|
.tabs
|
||||||
|
Tab("All", "font", "/companies")
|
||||||
|
Tab("Popular", "globe", "/companies/popular")
|
||||||
|
|
||||||
.corner-buttons
|
.corner-buttons
|
||||||
if user != nil
|
if user != nil
|
||||||
if user.DraftIndex().CompanyID == ""
|
if user.DraftIndex().CompanyID == ""
|
||||||
@ -10,14 +25,4 @@ component Companies(groups [][]*arn.Company, user *arn.User)
|
|||||||
else
|
else
|
||||||
a.button.ajax(href="/company/" + user.DraftIndex().CompanyID + "/edit")
|
a.button.ajax(href="/company/" + user.DraftIndex().CompanyID + "/edit")
|
||||||
Icon("pencil")
|
Icon("pencil")
|
||||||
span Edit draft
|
span Edit draft
|
||||||
|
|
||||||
.companies
|
|
||||||
each group in groups
|
|
||||||
.companies-group
|
|
||||||
h3= group[0].Name.English[:1]
|
|
||||||
|
|
||||||
ul
|
|
||||||
each company in group
|
|
||||||
li
|
|
||||||
a.ajax(href=company.Link())= company.Name.English
|
|
57
pages/companies/popular.go
Normal file
57
pages/companies/popular.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package companies
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const maxPopularCompanies = 100
|
||||||
|
|
||||||
|
// Popular renders the companies sorted by popularity.
|
||||||
|
func Popular(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
companies := []*arn.Company{}
|
||||||
|
|
||||||
|
// ID to popularity
|
||||||
|
popularity := map[string]int{}
|
||||||
|
|
||||||
|
for anime := range arn.StreamAnime() {
|
||||||
|
for _, studio := range anime.Studios() {
|
||||||
|
popularity[studio.ID] += anime.Popularity.Watching + anime.Popularity.Completed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for companyID := range popularity {
|
||||||
|
company, err := arn.GetCompany(companyID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
companies = append(companies, company)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(companies, func(i, j int) bool {
|
||||||
|
a := companies[i]
|
||||||
|
b := companies[j]
|
||||||
|
|
||||||
|
aPopularity := popularity[a.ID]
|
||||||
|
bPopularity := popularity[b.ID]
|
||||||
|
|
||||||
|
if aPopularity == bPopularity {
|
||||||
|
return a.Name.English < b.Name.English
|
||||||
|
}
|
||||||
|
|
||||||
|
return aPopularity > bPopularity
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(companies) > maxPopularCompanies {
|
||||||
|
companies = companies[:maxPopularCompanies]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.HTML(components.PopularCompanies(companies, popularity, user))
|
||||||
|
}
|
9
pages/companies/popular.pixy
Normal file
9
pages/companies/popular.pixy
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
component PopularCompanies(companies []*arn.Company, popularity map[string]int, user *arn.User)
|
||||||
|
CompaniesTabs(user)
|
||||||
|
|
||||||
|
.companies
|
||||||
|
ol
|
||||||
|
each company in companies
|
||||||
|
li.mountable
|
||||||
|
a.ajax(href=company.Link())= company.Name.English
|
||||||
|
span= " (" + strconv.Itoa(popularity[company.ID]) + ")"
|
@ -105,7 +105,8 @@ func Configure(app *aero.Application) {
|
|||||||
// Companies
|
// Companies
|
||||||
l.Page("/company/:id", company.Get)
|
l.Page("/company/:id", company.Get)
|
||||||
l.Page("/company/:id/edit", company.Edit)
|
l.Page("/company/:id/edit", company.Edit)
|
||||||
l.Page("/companies", companies.Get)
|
l.Page("/companies", companies.All)
|
||||||
|
l.Page("/companies/popular", companies.Popular)
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
l.Page("/settings", settings.Get(components.SettingsPersonal))
|
l.Page("/settings", settings.Get(components.SettingsPersonal))
|
||||||
|
@ -17,6 +17,10 @@ strong
|
|||||||
em
|
em
|
||||||
font-style italic
|
font-style italic
|
||||||
|
|
||||||
|
ol
|
||||||
|
li
|
||||||
|
list-style-type decimal
|
||||||
|
|
||||||
hr
|
hr
|
||||||
border none
|
border none
|
||||||
border-bottom 1px solid text-color
|
border-bottom 1px solid text-color
|
||||||
|
Loading…
Reference in New Issue
Block a user