fix map rendering for budget headings
This commit is contained in:
@@ -879,6 +879,13 @@ footer {
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-map {
|
||||
|
||||
.map {
|
||||
z-index: -1;
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
border-top: 2px solid $brand;
|
||||
display: inline-block;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module Budgets
|
||||
class InvestmentsController < ApplicationController
|
||||
OSM_DISTRICT_LEVEL_ZOOM = 12
|
||||
|
||||
include FeatureFlags
|
||||
include CommentableActions
|
||||
@@ -180,10 +179,7 @@ module Budgets
|
||||
end
|
||||
|
||||
def load_map
|
||||
@map_location = MapLocation.new
|
||||
@map_location.zoom = OSM_DISTRICT_LEVEL_ZOOM
|
||||
@map_location.latitude = @heading.latitude.to_f
|
||||
@map_location.longitude = @heading.longitude.to_f
|
||||
@map_location = MapLocation.load_from_heading(@heading)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Budget
|
||||
class Heading < ActiveRecord::Base
|
||||
OSM_DISTRICT_LEVEL_ZOOM = 12.freeze
|
||||
|
||||
include Sluggable
|
||||
|
||||
belongs_to :group
|
||||
@@ -12,9 +14,9 @@ class Budget
|
||||
validates :price, presence: true
|
||||
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
||||
validates :population, numericality: { greater_than: 0 }, allow_nil: true
|
||||
validates :latitude, length: { maximum: 22, minimum: 1 }, presence: true, \
|
||||
validates :latitude, length: { maximum: 22 }, allow_blank: true, \
|
||||
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
|
||||
validates :longitude, length: { maximum: 22, minimum: 1}, presence: true, \
|
||||
validates :longitude, length: { maximum: 22 }, allow_blank: true, \
|
||||
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
|
||||
|
||||
delegate :budget, :budget_id, to: :group, allow_nil: true
|
||||
|
||||
@@ -18,4 +18,12 @@ class MapLocation < ActiveRecord::Base
|
||||
}
|
||||
end
|
||||
|
||||
def self.load_from_heading(heading)
|
||||
map = new
|
||||
map.zoom = Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM
|
||||
map.latitude = heading.latitude.to_f if heading.latitude.present?
|
||||
map.longitude = heading.longitude.to_f if heading.latitude.present?
|
||||
map
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -9,3 +9,5 @@ $("#<%= dom_id(@investment) %>_ballot").html('<%= j render("/budgets/investments
|
||||
investment: @investment,
|
||||
investment_ids: @investment_ids,
|
||||
ballot: @ballot %>
|
||||
|
||||
App.Map.initialize();
|
||||
|
||||
@@ -10,3 +10,5 @@ $("#<%= dom_id(@investment) %>_ballot").html('<%= j render("/budgets/investments
|
||||
investment: @investment,
|
||||
investment_ids: @investment_ids,
|
||||
ballot: @ballot %>
|
||||
|
||||
App.Map.initialize();
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
<% if @heading && !@heading.content_blocks.where(locale: I18n.locale).empty? %>
|
||||
<%= render 'budgets/investments/content_blocks' %>
|
||||
<% end %>
|
||||
<% if @map_location&.available? %>
|
||||
<%= render 'budgets/investments/map' %>
|
||||
<% end %>
|
||||
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
|
||||
<%= render 'budgets/investments/categories' %>
|
||||
|
||||
|
||||
@@ -89,6 +89,22 @@ feature 'Budget Investments' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Index should show a map if heading has coordinates defined', :js do
|
||||
create(:budget_investment, heading: heading)
|
||||
visit budget_investments_path(budget, heading_id: heading.id)
|
||||
within("#sidebar") do
|
||||
expect(page).to have_css(".map_location")
|
||||
end
|
||||
|
||||
unlocated_heading = create(:budget_heading, name: "No Map", price: 500, group: group,
|
||||
longitude: nil, latitude: nil)
|
||||
create(:budget_investment, heading: unlocated_heading)
|
||||
visit budget_investments_path(budget, heading_id: unlocated_heading.id)
|
||||
within("#sidebar") do
|
||||
expect(page).not_to have_css(".map_location")
|
||||
end
|
||||
end
|
||||
|
||||
context("Search") do
|
||||
|
||||
scenario 'Search by text' do
|
||||
|
||||
@@ -7,6 +7,12 @@ describe Budget::Heading do
|
||||
|
||||
it_behaves_like "sluggable", updatable_slug_trait: :drafting_budget
|
||||
|
||||
describe "::OSM_DISTRICT_LEVEL_ZOOM" do
|
||||
it "should be defined" do
|
||||
expect(Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM).to be 12
|
||||
end
|
||||
end
|
||||
|
||||
describe "name" do
|
||||
before do
|
||||
create(:budget_heading, group: group, name: 'object name')
|
||||
@@ -45,13 +51,6 @@ describe Budget::Heading do
|
||||
end
|
||||
|
||||
describe "save latitude" do
|
||||
it "Doesn't allow latitude == nil" do
|
||||
expect(build(:budget_heading, group: group, name: 'Latitude is nil', population: 12412512, latitude: nil, longitude: '12.123412')).not_to be_valid
|
||||
end
|
||||
|
||||
it "Doesn't allow latitude == ''" do
|
||||
expect(build(:budget_heading, group: group, name: 'Latitude is an empty string', population: 12412512, latitude: '', longitude: '12.123412')).not_to be_valid
|
||||
end
|
||||
|
||||
it "Doesn't allow latitude < -90" do
|
||||
heading = create(:budget_heading, group: group, name: 'Latitude is < -90')
|
||||
@@ -150,13 +149,6 @@ describe Budget::Heading do
|
||||
|
||||
|
||||
describe "save longitude" do
|
||||
it "Doesn't allow longitude == nil" do
|
||||
expect(build(:budget_heading, group: group, name: 'Longitude is nil', population: 12412512, latitude: '12.123412', longitude: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "Doesn't allow longitude == ''" do
|
||||
expect(build(:budget_heading, group: group, name: 'Longitude is an empty string', population: 12412512, latitude: '12.127412', longitude: '')).not_to be_valid
|
||||
end
|
||||
|
||||
it "Doesn't allow longitude < -180" do
|
||||
heading = create(:budget_heading, group: group, name: 'Longitude is < -180')
|
||||
|
||||
Reference in New Issue
Block a user