Added close companies to company pages
This commit is contained in:
parent
600c72efb0
commit
961ceb702c
@ -2,6 +2,7 @@ package company
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -50,5 +51,30 @@ func Get(ctx *aero.Context) string {
|
|||||||
|
|
||||||
studioAnime, producedAnime, licensedAnime := company.Anime()
|
studioAnime, producedAnime, licensedAnime := company.Anime()
|
||||||
|
|
||||||
return ctx.HTML(components.CompanyPage(company, studioAnime, producedAnime, licensedAnime, user))
|
// Find close companies
|
||||||
|
var closeCompanies []*arn.Company
|
||||||
|
distances := map[string]float64{}
|
||||||
|
|
||||||
|
if company.Location.IsValid() {
|
||||||
|
closeCompanies = arn.FilterCompanies(func(closeCompany *arn.Company) bool {
|
||||||
|
if closeCompany.ID == company.ID {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !closeCompany.Location.IsValid() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
distance := company.Location.Distance(closeCompany.Location)
|
||||||
|
distances[closeCompany.ID] = distance
|
||||||
|
|
||||||
|
return distance <= 1.0
|
||||||
|
})
|
||||||
|
|
||||||
|
sort.Slice(closeCompanies, func(i, j int) bool {
|
||||||
|
return distances[closeCompanies[i].ID] < distances[closeCompanies[j].ID]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.HTML(components.CompanyPage(company, studioAnime, producedAnime, licensedAnime, closeCompanies, distances, user))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensedAnime []*arn.Anime, user *arn.User)
|
component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensedAnime []*arn.Anime, closeCompanies []*arn.Company, distances map[string]float64, user *arn.User)
|
||||||
CompanyTabs(company, user)
|
CompanyTabs(company, user)
|
||||||
|
|
||||||
.company-page
|
.company-page
|
||||||
@ -19,11 +19,21 @@ component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensed
|
|||||||
|
|
||||||
if len(company.Links) > 0
|
if len(company.Links) > 0
|
||||||
h3.mountable Links
|
h3.mountable Links
|
||||||
|
|
||||||
ul.mountable
|
ul.mountable
|
||||||
each link in company.Links
|
each link in company.Links
|
||||||
li
|
li.mountable(data-mountable-type="company-link")
|
||||||
a(href=link.URL, target="_blank", rel="noopener")= link.Title
|
a(href=link.URL, target="_blank", rel="noopener")= link.Title
|
||||||
|
|
||||||
|
if len(closeCompanies) > 0
|
||||||
|
h3.mountable Within 1 km radius
|
||||||
|
|
||||||
|
ul.mountable
|
||||||
|
each closeCompany in closeCompanies
|
||||||
|
li.mountable(data-mountable-type="close-company")
|
||||||
|
a(href=closeCompany.Link())= closeCompany.Name.English
|
||||||
|
span= fmt.Sprintf(" (%.0f m)", distances[closeCompany.ID] * 1000)
|
||||||
|
|
||||||
//- if len(company.Name.Synonyms) > 0
|
//- if len(company.Name.Synonyms) > 0
|
||||||
//- h3 Synonyms
|
//- h3 Synonyms
|
||||||
//- ul
|
//- ul
|
||||||
|
Loading…
Reference in New Issue
Block a user