diff --git a/app/assets/stylesheets/maps.scss b/app/assets/stylesheets/maps.scss index 0d69e7481..f7dda3343 100644 --- a/app/assets/stylesheets/maps.scss +++ b/app/assets/stylesheets/maps.scss @@ -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%; diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 833d7f6a5..54a3aee9f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0f1edf5b1..cd1e17bf7 100644 --- a/app/controllers/tags_controller.rb +++ b/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] @@ -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( @@ -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 @@ -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 diff --git a/app/views/tags/show.html.haml b/app/views/tags/show.html.haml index 15551b9bf..38cce2ddf 100644 --- a/app/views/tags/show.html.haml +++ b/app/views/tags/show.html.haml @@ -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 diff --git a/config/authorization_rules.rb b/config/authorization_rules.rb index bcae5c835..715a76d1e 100644 --- a/config/authorization_rules.rb +++ b/config/authorization_rules.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index dce978a55..95c748529 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"