Add map locations. Each map location can belongs to proposal or budget investment.
This commit is contained in:
@@ -16,20 +16,15 @@ App.Map =
|
|||||||
latitudeInputSelector = $(element).data('latitude-input-selector')
|
latitudeInputSelector = $(element).data('latitude-input-selector')
|
||||||
longitudeInputSelector = $(element).data('longitude-input-selector')
|
longitudeInputSelector = $(element).data('longitude-input-selector')
|
||||||
zoomInputSelector = $(element).data('zoom-input-selector')
|
zoomInputSelector = $(element).data('zoom-input-selector')
|
||||||
|
removeMarkerSelector = $(element).data('remove-marker-selector')
|
||||||
|
attribution = $(mapAttributionSelector)
|
||||||
|
marker_icon = L.divIcon(
|
||||||
|
iconSize: null
|
||||||
|
html: '<div class="map-marker"></div>')
|
||||||
|
|
||||||
latLng = new (L.LatLng)(latitude, longitude)
|
placeMarker = (e) ->
|
||||||
map = L.map(element.id).setView(latLng, zoom)
|
|
||||||
attribution = $(mapAttributionSelector)
|
|
||||||
L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map
|
|
||||||
|
|
||||||
marker_icon = L.divIcon(
|
|
||||||
iconSize: null
|
|
||||||
html: '<div class="map-marker"></div>')
|
|
||||||
marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' })
|
|
||||||
marker.addTo(map)
|
|
||||||
|
|
||||||
onMapClick = (e) ->
|
|
||||||
marker.setLatLng(e.latlng)
|
marker.setLatLng(e.latlng)
|
||||||
|
marker.addTo(map)
|
||||||
updateFormfields()
|
updateFormfields()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -39,6 +34,25 @@ App.Map =
|
|||||||
$(zoomInputSelector).val map.getZoom()
|
$(zoomInputSelector).val map.getZoom()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
clearFormfields = ->
|
||||||
|
$(latitudeInputSelector).val ''
|
||||||
|
$(longitudeInputSelector).val ''
|
||||||
|
$(zoomInputSelector).val ''
|
||||||
|
return
|
||||||
|
|
||||||
|
removeMarker = (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
map.removeLayer(marker)
|
||||||
|
clearFormfields()
|
||||||
|
return
|
||||||
|
|
||||||
|
latLng = new (L.LatLng)(latitude, longitude)
|
||||||
|
map = L.map(element.id).setView(latLng, zoom)
|
||||||
|
marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' })
|
||||||
|
L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map
|
||||||
|
marker.addTo(map)
|
||||||
|
|
||||||
|
$(removeMarkerSelector).on 'click', removeMarker
|
||||||
marker.on 'dragend', updateFormfields
|
marker.on 'dragend', updateFormfields
|
||||||
map.on 'zoomend', updateFormfields
|
map.on 'zoomend', updateFormfields
|
||||||
map.on 'click', onMapClick
|
map.on 'click', placeMarker
|
||||||
@@ -107,7 +107,8 @@ module Budgets
|
|||||||
.permit(:title, :description, :external_url, :heading_id, :tag_list,
|
.permit(:title, :description, :external_url, :heading_id, :tag_list,
|
||||||
:organization_name, :location, :terms_of_service,
|
:organization_name, :location, :terms_of_service,
|
||||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||||
|
map_location_attributes: [:latitude, :longitude, :zoom])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_ballot
|
def load_ballot
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ class ProposalsController < ApplicationController
|
|||||||
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url,
|
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url,
|
||||||
:responsible_name, :tag_list, :terms_of_service, :geozone_id,
|
:responsible_name, :tag_list, :terms_of_service, :geozone_id,
|
||||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] )
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||||
|
map_location_attributes: [:latitude, :longitude, :zoom])
|
||||||
end
|
end
|
||||||
|
|
||||||
def retired_params
|
def retired_params
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class Budget
|
|||||||
has_many :valuators, through: :valuator_assignments
|
has_many :valuators, through: :valuator_assignments
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :milestones
|
has_many :milestones
|
||||||
|
has_one :map_location
|
||||||
|
accepts_nested_attributes_for :map_location
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
|
|||||||
6
app/models/map_location.rb
Normal file
6
app/models/map_location.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class MapLocation < ActiveRecord::Base
|
||||||
|
|
||||||
|
belongs_to :proposal
|
||||||
|
belongs_to :investment
|
||||||
|
|
||||||
|
end
|
||||||
@@ -25,6 +25,8 @@ class Proposal < ActiveRecord::Base
|
|||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
|
has_one :map_location
|
||||||
|
accepts_nested_attributes_for :map_location
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :proposal_notifications
|
has_many :proposal_notifications
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,7 @@
|
|||||||
data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
||||||
data-latitude-input-selector="#latitude"
|
data-latitude-input-selector="#latitude"
|
||||||
data-longitude-input-selector="#longitude"
|
data-longitude-input-selector="#longitude"
|
||||||
data-zoom-input-selector="#zoom"
|
data-zoom-input-selector="#zoom">
|
||||||
data-marker-selector="#admin-map-marker">
|
|
||||||
</div>
|
</div>
|
||||||
<div id="admin-map-attribution" class="map-attributtion">
|
<div id="admin-map-attribution" class="map-attributtion">
|
||||||
© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors
|
© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors
|
||||||
|
|||||||
@@ -29,6 +29,19 @@
|
|||||||
<%= render 'documents/nested_documents', documentable: @investment, f: f %>
|
<%= render 'documents/nested_documents', documentable: @investment, f: f %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if feature?(:map) %>
|
||||||
|
<div class="small-12 column">
|
||||||
|
|
||||||
|
<%= render 'map_locations/form_fields',
|
||||||
|
form: f,
|
||||||
|
map_location: @investment.map_location || MapLocation.new,
|
||||||
|
label: t("proposals.form.map_location"),
|
||||||
|
help: t("proposals.form.map_location_instructions"),
|
||||||
|
parent_class: "budget_investment" %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= f.text_field :location %>
|
<%= f.text_field :location %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
25
app/views/map_locations/_form_fields.html.erb
Normal file
25
app/views/map_locations/_form_fields.html.erb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<%= form.label :map_location, label %>
|
||||||
|
<p class="help-text" id="tag-list-help-text"><%= help %></p>
|
||||||
|
<div id="location-map" class="map" data-map
|
||||||
|
data-latitude="<%= map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] %>"
|
||||||
|
data-longitude="<%= map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] %>"
|
||||||
|
data-zoom="<%= map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] %>"
|
||||||
|
data-tiles-attribution-selector="#map-location-attribution"
|
||||||
|
data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
||||||
|
data-latitude-input-selector="#<%= parent_class %>_map_location_attributes_latitude"
|
||||||
|
data-longitude-input-selector="#<%= parent_class %>_map_location_attributes_longitude"
|
||||||
|
data-zoom-input-selector="#<%= parent_class %>_map_location_attributes_zoom"
|
||||||
|
data-remove-marker-selector=".location-map-remove-marker-button">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="map-location-attribution" class="map-attributtion">
|
||||||
|
© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a class="location-map-remove-marker-button" href="#">Remove marker</a>
|
||||||
|
|
||||||
|
<%= form.fields_for :map_location, map_location do |map_location_fields| %>
|
||||||
|
<%= map_location_fields.hidden_field :latitude, value: map_location.latitude, id: "#{parent_class}_map_location_attributes_latitude" %>
|
||||||
|
<%= map_location_fields.hidden_field :longitude, value: map_location.longitude, id: "#{parent_class}_map_location_attributes_longitude" %>
|
||||||
|
<%= map_location_fields.hidden_field :zoom, value: map_location.zoom, id: "#{parent_class}_map_location_attributes_zoom" %>
|
||||||
|
<% end %>
|
||||||
@@ -59,6 +59,19 @@
|
|||||||
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
|
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if feature?(:map) %>
|
||||||
|
<div class="small-12 column">
|
||||||
|
|
||||||
|
<%= render 'map_locations/form_fields',
|
||||||
|
form: f,
|
||||||
|
map_location: @proposal.map_location || MapLocation.new,
|
||||||
|
label: t("proposals.form.map_location"),
|
||||||
|
help: t("proposals.form.map_location_instructions"),
|
||||||
|
parent_class: "proposal" %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= f.label :tag_list, t("proposals.form.tags_label") %>
|
<%= f.label :tag_list, t("proposals.form.tags_label") %>
|
||||||
<p class="help-text" id="tag-list-help-text"><%= t("proposals.form.tags_instructions") %></p>
|
<p class="help-text" id="tag-list-help-text"><%= t("proposals.form.tags_instructions") %></p>
|
||||||
|
|||||||
@@ -333,6 +333,8 @@ en:
|
|||||||
tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
|
tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
|
||||||
tags_label: Tags
|
tags_label: Tags
|
||||||
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
|
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
|
||||||
|
map_location: "Map location"
|
||||||
|
map_location_instructions: "Navigate the map to the location and place the marker."
|
||||||
index:
|
index:
|
||||||
featured_proposals: Featured
|
featured_proposals: Featured
|
||||||
filter_topic:
|
filter_topic:
|
||||||
|
|||||||
@@ -333,6 +333,8 @@ es:
|
|||||||
tags_label: Temas
|
tags_label: Temas
|
||||||
tag_category_label: "Categorías"
|
tag_category_label: "Categorías"
|
||||||
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
||||||
|
map_location: "Ubicación en el mapa"
|
||||||
|
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
|
||||||
index:
|
index:
|
||||||
featured_proposals: Destacadas
|
featured_proposals: Destacadas
|
||||||
filter_topic:
|
filter_topic:
|
||||||
|
|||||||
11
db/migrate/20170805132736_create_map_locations.rb
Normal file
11
db/migrate/20170805132736_create_map_locations.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class CreateMapLocations < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :map_locations do |t|
|
||||||
|
t.float :latitude
|
||||||
|
t.float :longitude
|
||||||
|
t.integer :zoom
|
||||||
|
t.integer :proposal_id, index: true
|
||||||
|
t.integer :investment_id, index: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/schema.rb
11
db/schema.rb
@@ -549,6 +549,17 @@ ActiveRecord::Schema.define(version: 20170918231410) do
|
|||||||
|
|
||||||
add_index "managers", ["user_id"], name: "index_managers_on_user_id", using: :btree
|
add_index "managers", ["user_id"], name: "index_managers_on_user_id", using: :btree
|
||||||
|
|
||||||
|
create_table "map_locations", force: :cascade do |t|
|
||||||
|
t.float "latitude"
|
||||||
|
t.float "longitude"
|
||||||
|
t.integer "zoom"
|
||||||
|
t.integer "proposal_id"
|
||||||
|
t.integer "investment_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "map_locations", ["investment_id"], name: "index_map_locations_on_investment_id", using: :btree
|
||||||
|
add_index "map_locations", ["proposal_id"], name: "index_map_locations_on_proposal_id", using: :btree
|
||||||
|
|
||||||
create_table "moderators", force: :cascade do |t|
|
create_table "moderators", force: :cascade do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user