From 961ceb702c7eba1883e49550d4633d31a8cece66 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 8 Apr 2018 09:31:31 +0200 Subject: [PATCH] Added close companies to company pages --- pages/company/company.go | 28 +++++++++++++++++++++++++++- pages/company/company.pixy | 14 ++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pages/company/company.go b/pages/company/company.go index 3a4c4894..beb0abb9 100644 --- a/pages/company/company.go +++ b/pages/company/company.go @@ -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)) } diff --git a/pages/company/company.pixy b/pages/company/company.pixy index 814f2eab..0a7a7600 100644 --- a/pages/company/company.pixy +++ b/pages/company/company.pixy @@ -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