-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
133 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class LocalAuthority::Search | ||
def initialize(scope, query) | ||
@scope = scope | ||
@query = query | ||
end | ||
|
||
def call | ||
result = @scope.order_by_distance_from(search_centre) | ||
|
||
if search_polygon | ||
result.where("ST_Intersects(geometry, ?)", search_polygon) | ||
else | ||
result.limit(3) | ||
end | ||
end | ||
|
||
def geo_result | ||
@geo_result ||= Geocoder.search(@query, params: {limit: 1, polygon_geojson: 1, countrycodes: 'gb'}).first | ||
end | ||
|
||
def search_polygon | ||
return @search_polygon if defined? @search_polygon | ||
|
||
json = geo_result && geo_result.data['geojson'] | ||
return @search_polygon = nil unless json | ||
|
||
transform RGeo::GeoJSON.decode(json.to_json) | ||
end | ||
|
||
def search_centre | ||
transform RGeo::Geographic.spherical_factory.point(geo_result.longitude, geo_result.latitude) | ||
end | ||
|
||
def transform(geo) | ||
RGeo::CoordSys::Proj4.transform( | ||
RGeo::CoordSys::Proj4.new("EPSG:4326"), | ||
geo, | ||
RGeo::CoordSys::Proj4.new("EPSG:27700"), | ||
RGeo::Cartesian.preferred_factory | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
class Hub < ApplicationRecord | ||
def self.by_local_authority(*authorities) | ||
where("areas && ARRAY[?]::varchar[]", authorities) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
class LocalAuthority < ApplicationRecord | ||
include RGeo::ActiveRecord::GeometryMixin | ||
|
||
def self.search(query) | ||
Search.new(self, query).call | ||
end | ||
|
||
def self.order_by_distance_from(point) | ||
order(Arel.sql("geometry <-> ST_Geomfromtext('#{point.as_text}')")) | ||
end | ||
|
||
def self.by_name(name) | ||
where("name ILIKE '%#{name}%'") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-xl">Teaching school hubs near <%= @search.location %></h1> | ||
</div> | ||
</div> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p> | ||
<%= link_to 'Change location', { action: :form } %> | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds hub-results"> | ||
<% @search.hubs.each do |hub| %> | ||
<div class="hub-result"> | ||
<h3 class="govuk-heading-m"> | ||
<% if hub.website %> | ||
<% | ||
address = hub.website | ||
address = "//#{address}" unless address.starts_with? /https?:\/\// | ||
%> | ||
<%= link_to hub.name, address %> | ||
<% else %> | ||
<%= hub.name %> | ||
<% end %> | ||
</h3> | ||
<p>Email: <%= mail_to hub.email %></p> | ||
<% if hub.phone.present? %> | ||
<p>Phone: <%= phone_to hub.phone %></p> | ||
<% end %> | ||
<p>Area: <%= hub.areas.join(', ') %></p> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
LocalAuthority::Importer.new.reload! | ||
Hub::Importer.new.reload! |
This file was deleted.
Oops, something went wrong.