aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-11-11 22:27:18 +0100
committerhellekin <hellekin@cepheide.org>2020-11-11 22:27:18 +0100
commitb6aeac4d9274f17e748efb3715aa08f4b7c361f2 (patch)
tree30982cb6ca6b0febc5687580313d9f31d085d7cf
parent2d17bcf4d599f390bce4898a407aef1a4e7454dc (diff)
downloadincommon-map-b6aeac4d9274f17e748efb3715aa08f4b7c361f2.tar.gz
Add map support
This commit creates a dedicated Map model and moves the JavaScript from view to a Stimulus controller. - Stimulus.js https://stimulusjs.org - Leaflet.js https://leafletjs.org Upcoming resources: - https://discourse.stimulusjs.org/t/leafletjs-with-stimulusjs-on-rails-6/1343/4 - https://github.com/ghybs/leaflet-defaulticon-compatibility
-rw-r--r--app/controllers/welcome_controller.rb1
-rw-r--r--app/helpers/application_helper.rb14
-rw-r--r--app/models/map.rb4
-rw-r--r--app/views/welcome/index.html.erb32
-rw-r--r--db/schema.rb17
5 files changed, 45 insertions, 23 deletions
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index 0c41e5a..ee76eb6 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -1,6 +1,7 @@
class WelcomeController < ApplicationController
# GET /
def index
+ @map = Map.first
@resources = Resource.order(:uuid).page params[:page]
Rails.logger.info "WECLOME ///// #{@resources&.count || 0}"
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0b22f4b..aa3a8d7 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -7,4 +7,18 @@ module ApplicationHelper
current_agency.send(:"#{role}?")
end
end
+
+ def map_container(map = Map.first)
+ raw tag.div(
+ tag.div(id: 'map',
+ data: {
+ target: 'map.container'
+ }),
+ data: {
+ controller: 'map',
+ 'map-latitude': map.latitude,
+ 'map-longitude': map.longitude,
+ 'map-zoom': map.zoom
+ })
+ end
end
diff --git a/app/models/map.rb b/app/models/map.rb
new file mode 100644
index 0000000..10a55f6
--- /dev/null
+++ b/app/models/map.rb
@@ -0,0 +1,4 @@
+class Map < ApplicationRecord
+ include UUIDParameter
+ belongs_to :taxonomy
+end
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb
index 1b6ab77..eac1eff 100644
--- a/app/views/welcome/index.html.erb
+++ b/app/views/welcome/index.html.erb
@@ -9,7 +9,17 @@
<h1>Bienvenue à l'atelier carto d'IN COMMON</h1>
-<%= tag.div(id: 'map') %>
+<%= map_container %>
+
+<% content_for :aside do %>
+ <div data-controller="taxonomy" data-taxonomy-id="2519915f-d19c-4281-b758-f5ddb889d7fa">
+ <div class="leaflet-bar leaftlet-control" id="taxonomy-toggle">
+ <button data-action="taxonomy#toggle"></button>
+ </div>
+ <nav data-target="taxonomy.filter">
+ </nav>
+ </div>
+<% end %>
<% content_for :debug do %>
<% if current_user.present? %>
@@ -19,23 +29,3 @@
<p><%= res.feature["geometry"]["coordinates"] %></p>
<% end %><%# ensure it does not break when we don't have a record... %>
<% end %>
-
-<% content_for :body_end do %>
-<script>
- var mymap = L.map('map').setView([50.8503396, 4.3517103],13);
-
- L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
- attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery <a href="https://www.mapbox.com/">Mapbox</a>',
- maxZoom: 18,
- id: 'mapbox/streets-v11',
- tileSize: 512,
- zoomOffset: -1,
- accessToken: 'pk.eyJ1IjoibmVtYWVsIiwiYSI6ImNrZzBrYjBudTB3bnMyenFmNWtrN3h3bmMifQ.Rkeyhm-9iIQOV7NAMA5LaA'
- }).addTo(mymap);
- var marker = L.marker([50.850, 4.351]).addTo(mymap);
- //CONTINUER AVEC LES WHILE ET CONDITIONS, @resources ne contient que 25 elements (lié au nombre d'élément par page?) -- oui
- //OU PLUTOT UTILISER POSTGRES POUR FAIRE DES REQUESTES SUR @resources
- var count = 0
- console.log(count)
-</script>
-<% end %>
diff --git a/db/schema.rb b/db/schema.rb
index 0660ef9..fa53f85 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_10_09_061548) do
+ActiveRecord::Schema.define(version: 2020_11_10_225447) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -55,9 +55,21 @@ ActiveRecord::Schema.define(version: 2020_10_09_061548) do
t.bigint "section_id", null: false
end
+ create_table "maps", force: :cascade do |t|
+ t.uuid "uuid", null: false
+ t.decimal "latitude", precision: 9, scale: 7
+ t.decimal "longitude", precision: 10, scale: 7
+ t.integer "zoom", default: 13
+ t.bigint "taxonomy_id", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["taxonomy_id"], name: "index_maps_on_taxonomy_id"
+ t.index ["uuid"], name: "index_maps_on_uuid", unique: true
+ end
+
create_table "resources", force: :cascade do |t|
t.uuid "uuid"
- t.jsonb "feature", default: {"geometry"=>{"type"=>"Point", "coordinates"=>[0, 0]}, "properties"=>{"city"=>"", "name"=>"", "srid"=>4326, "email"=>"", "source"=>"incommon", "address"=>"", "website"=>"", "categories"=>[], "description"=>"", "postal_code"=>"", "entry_number"=>nil, "phone_number"=>""}}
+ t.jsonb "feature", default: {"geometry"=>{"type"=>"Point", "coordinates"=>[0, 0]}, "properties"=>{"city"=>"", "name"=>"", "srid"=>4326, "email"=>"", "source"=>"incommon", "address"=>"", "website"=>"", "categories"=>[], "description"=>"", "postal_code"=>"", "entry_number"=>"", "phone_number"=>""}}
t.bigint "agent_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
@@ -109,6 +121,7 @@ ActiveRecord::Schema.define(version: 2020_10_09_061548) do
add_foreign_key "agencies", "agents"
add_foreign_key "agencies", "users"
add_foreign_key "categories", "taxonomies"
+ add_foreign_key "maps", "taxonomies"
add_foreign_key "resources", "agents"
add_foreign_key "sections", "categories"
add_foreign_key "taxonomies", "agents"