Added close companies to company pages

This commit is contained in:
Eduard Urbach 2018-04-08 09:31:31 +02:00
parent 600c72efb0
commit 961ceb702c
2 changed files with 39 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package company
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
@ -50,5 +51,30 @@ func Get(ctx *aero.Context) string {
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))
}

View File

@ -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)
.company-page
@ -19,11 +19,21 @@ component CompanyPage(company *arn.Company, studioAnime, producedAnime, licensed
if len(company.Links) > 0
h3.mountable Links
ul.mountable
each link in company.Links
li
li.mountable(data-mountable-type="company-link")
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
//- h3 Synonyms
//- ul