Merge pull request #3038 from MatheusMiranda/add_map_to_heading_page
Add map to sidebar on Heading's page
This commit is contained in:
@@ -851,6 +851,7 @@ footer {
|
||||
.categories a,
|
||||
.geozone a,
|
||||
.sidebar-links a,
|
||||
.sidebar-map a,
|
||||
.tags span {
|
||||
background: #ececec;
|
||||
border-radius: rem-calc(6);
|
||||
|
||||
@@ -33,7 +33,7 @@ class Admin::BudgetHeadingsController < Admin::BaseController
|
||||
private
|
||||
|
||||
def budget_heading_params
|
||||
params.require(:budget_heading).permit(:name, :price, :population)
|
||||
params.require(:budget_heading).permit(:name, :price, :population, :latitude, :longitude)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module Budgets
|
||||
class InvestmentsController < ApplicationController
|
||||
OSM_DISTRICT_LEVEL_ZOOM = 12
|
||||
|
||||
include FeatureFlags
|
||||
include CommentableActions
|
||||
include FlagActions
|
||||
@@ -32,13 +34,17 @@ module Budgets
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
if @budget.finished?
|
||||
@investments = investments.winners.page(params[:page]).per(10).for_render
|
||||
else
|
||||
@investments = investments.page(params[:page]).per(10).for_render
|
||||
end
|
||||
all_investments = if @budget.finished?
|
||||
investments.winners
|
||||
else
|
||||
investments
|
||||
end
|
||||
|
||||
@investments = all_investments.page(params[:page]).per(10).for_render
|
||||
|
||||
@investment_ids = @investments.pluck(:id)
|
||||
@investments_map_coordinates = MapLocation.where(investment_id: all_investments).map { |l| l.json_data }
|
||||
|
||||
load_investment_votes(@investments)
|
||||
@tag_cloud = tag_cloud
|
||||
end
|
||||
@@ -142,6 +148,7 @@ module Budgets
|
||||
if params[:heading_id].present?
|
||||
@heading = @budget.headings.find(params[:heading_id])
|
||||
@assigned_heading = @ballot.try(:heading_for_group, @heading.try(:group))
|
||||
load_map
|
||||
end
|
||||
end
|
||||
|
||||
@@ -167,6 +174,13 @@ module Budgets
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -11,6 +11,10 @@ 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, \
|
||||
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
|
||||
validates :longitude, length: { maximum: 22, minimum: 1}, presence: true, \
|
||||
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
|
||||
|
||||
delegate :budget, :budget_id, to: :group, allow_nil: true
|
||||
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
<%= form_for [:admin, budget, group, heading], remote: true do |f| %>
|
||||
<%= render 'shared/errors', resource: heading %>
|
||||
<label><%= t("admin.budgets.form.heading") %></label>
|
||||
<%= f.text_field :name,
|
||||
label: false,
|
||||
label: t("admin.budgets.form.heading"),
|
||||
maxlength: 50,
|
||||
placeholder: t("admin.budgets.form.heading") %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.budgets.form.amount") %></label>
|
||||
<%= f.text_field :price,
|
||||
label: false,
|
||||
label: t("admin.budgets.form.amount"),
|
||||
maxlength: 8,
|
||||
placeholder: t("admin.budgets.form.amount") %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<label><%= t("admin.budgets.form.population") %></label>
|
||||
<p class="help-text" id="budgets-population-help-text">
|
||||
<%= t("admin.budgets.form.population_help_text") %>
|
||||
</p>
|
||||
<%= f.text_field :population,
|
||||
label: false,
|
||||
label: t("admin.budgets.form.population"),
|
||||
maxlength: 8,
|
||||
placeholder: t("admin.budgets.form.population"),
|
||||
data: {toggle_focus: "population-info"},
|
||||
@@ -34,6 +31,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :latitude,
|
||||
label: t("admin.budgets.form.latitude"),
|
||||
maxlength: 22,
|
||||
placeholder: "latitude" %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.text_field :longitude,
|
||||
label: t("admin.budgets.form.longitude"),
|
||||
maxlength: 22,
|
||||
placeholder: "longitude" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
|
||||
<% end %>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
</div>
|
||||
|
||||
<% unless current_budget.informing? %>
|
||||
<div id="map">
|
||||
<div class="map">
|
||||
<h3><%= t("budgets.index.map") %></h3>
|
||||
<%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %>
|
||||
</div>
|
||||
|
||||
8
app/views/budgets/investments/_map.html.erb
Normal file
8
app/views/budgets/investments/_map.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="sidebar-divider"></div>
|
||||
<br>
|
||||
|
||||
<ul id="sidebar-map" class="no-bullet sidebar-map">
|
||||
<div class="map">
|
||||
<%= render_map(@map_location, "budgets", false, nil, @investments_map_coordinates) %>
|
||||
</div>
|
||||
</ul>
|
||||
@@ -21,6 +21,7 @@
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= render 'budgets/investments/map' %>
|
||||
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
|
||||
<%= render 'budgets/investments/categories' %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user