Skip to content

Commit

Permalink
Add rough tag map
Browse files Browse the repository at this point in the history
Re #927
  • Loading branch information
nikolai-b committed Feb 26, 2020
1 parent df162e4 commit c4d19de
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/maps.scss
Expand Up @@ -6,6 +6,13 @@
border:1px solid black;
margin-top: 1em;
}
.map-tag {
position: relative;
float: right;
width: calc(100% - 980px);
min-width: 265px;
height: 400px;
}

#large-map {
height: 72%;
Expand Down
24 changes: 1 addition & 23 deletions app/controllers/issues_controller.rb
Expand Up @@ -2,6 +2,7 @@

class IssuesController < ApplicationController
include MessageCreator
include IssueFeature

filter_access_to %i[edit update destroy], attribute_check: true
protect_from_forgery except: :vote_detail
Expand Down Expand Up @@ -140,29 +141,6 @@ def index_start_location
SiteConfig.first.nowhere_location
end

def issue_feature(issue, bbox = nil)
geom = bbox.to_geometry if bbox
creator_name = if permitted_to? :view_profile, issue.created_by
issue.created_by.name
else
issue.created_by.display_name_or_anon
end
creator_url = if permitted_to? :view_profile, issue.created_by
view_context.url_for user_profile_path(issue.created_by)
else
"#"
end

issue.loc_feature(thumbnail: issue.medium_icon_path,
anchor: issue.medium_icon_anchor,
image_url: issue.tip_icon_path,
title: issue.title,
size_ratio: issue.size_ratio(geom),
url: view_context.url_for(issue),
created_by: creator_name,
created_by_url: creator_url)
end

def issue
@issue ||= Issue.find(params[:id])
end
Expand Down
23 changes: 22 additions & 1 deletion app/controllers/tags_controller.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class TagsController < ApplicationController
include IssueFeature

def autocomplete_tag_name
term = params[:term]

Expand All @@ -22,6 +24,10 @@ def show
@query = @tag.name
issues = Issue.find_by_tag(@tag).order(updated_at: :desc).page(params[:issue_page])
issues = issues.intersects(current_group.profile.location) if current_group
bbox = RGeo::Cartesian::BoundingBox.new(RGeo::Geographic.spherical_factory(srid: 4326))
issues.each { |iss| bbox.add(iss.location) }
@start_location = { fitBounds: [[bbox.min_y, bbox.min_x], [bbox.max_y, bbox.max_x]] }.to_json

@issues = IssueDecorator.decorate_collection issues
unfiltered_results = MessageThread.find_by_tag(@tag).includes(:issue, :group).order(updated_at: :desc)
threads = Kaminari.paginate_array(
Expand All @@ -36,7 +42,7 @@ def show
.includes(:users, :issue)
.page params[:planning_page]
@planning_applications = PlanningApplicationDecorator.decorate_collection planning_applications

@full_page = true
else
@unrecognised_tag_name = params[:id]
end
Expand All @@ -45,4 +51,19 @@ def show
def index
@tags = Tag.top_tags(200)
end

def all_geometries
tag = Tag.find_by name: params[:id]
bbox = bbox_from_string(params[:bbox], Issue.rgeo_factory)
issues = Issue.find_by_tag(tag).by_most_recent
issues = issues.intersects(current_group.profile.location) if current_group
issues = issues.intersects_not_covered(bbox.to_geometry) if bbox

# TODO: refactor this into decorater
decorated_issues = issues.select_area.order(:area).map { |issue| issue_feature(IssueDecorator.decorate(issue), bbox) }
collection = RGeo::GeoJSON::EntityFactory.new.feature_collection(decorated_issues)
respond_to do |format|
format.json { render json: RGeo::GeoJSON.encode(collection) }
end
end
end
5 changes: 5 additions & 0 deletions app/views/tags/show.html.haml
Expand Up @@ -2,6 +2,11 @@
%h1= t ".heading", name: @tag.name
- if current_group
%p= t ".introduction_groupwise_html", area_of_group_link: link_to(t(".area_of_group", group_name: current_group.name), root_path)
- map_id = "leaflet-all-tags"
.map-tag{id: map_id}
.hidden
.map-data{"data-center" => @start_location,
"data-opts" => {domid: map_id, search: true, remote: {'Issues' => all_geometries_tag_path(@tag, :json)}}.to_json}
= render partial: 'shared/search'
- else
Expand Down
2 changes: 1 addition & 1 deletion config/authorization_rules.rb
Expand Up @@ -237,7 +237,7 @@
has_permission_on :pages, to: :show
has_permission_on :api_v1_issues, to: :index
has_permission_on :site_comments, to: %i[new create]
has_permission_on :tags, to: %i[show autocomplete_tag_name index]
has_permission_on :tags, to: %i[show autocomplete_tag_name index all_geometries]
has_permission_on :user_profiles, to: :view do
if_permitted_to :view_profile
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -178,6 +178,7 @@ def issues_route(opts = {})

resources :tags, only: %i[show index] do
get :autocomplete_tag_name, as: :autocomplete, on: :collection
get :all_geometries, on: :member
end
resource :home, only: [:show], controller: "home"

Expand Down

0 comments on commit c4d19de

Please sign in to comment.