diff --git a/.gitignore b/.gitignore index fc1d6c38..bc06f83d 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,5 @@ capybara-*html # vendor/extensions dummy applications. vendor/extensions/**/spec/dummy +# exuberant-ctags +tags diff --git a/Gemfile b/Gemfile index 6931bf0c..9e5839ea 100644 --- a/Gemfile +++ b/Gemfile @@ -69,6 +69,9 @@ gem 'simple_calendar', github: 'echarp/simple_calendar' # Markdown display gem 'redcarpet' +# Carte openstreetmap +gem 'openlayers-rails' + group :development do gem 'guard-livereload' gem 'guard-bundler' diff --git a/Gemfile.lock b/Gemfile.lock index bb72f030..6fd92e7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -196,6 +196,8 @@ GEM multi_json (1.9.2) mysql2 (0.3.15) nio4r (1.0.0) + openlayers-rails (0.0.4) + railties (>= 3.1) orm_adapter (0.5.0) polyglot (0.3.4) pry (0.9.12.6) @@ -293,6 +295,7 @@ DEPENDENCIES jquery-turbolinks modernizr-rails mysql2 + openlayers-rails polyamorous! quiet_assets rails (~> 4.1.0.rc1) diff --git a/app/assets/images/team.png b/app/assets/images/team.png new file mode 100644 index 00000000..13af6148 Binary files /dev/null and b/app/assets/images/team.png differ diff --git a/app/assets/javascripts/maps.js.coffee b/app/assets/javascripts/maps.js.coffee new file mode 100644 index 00000000..0f05d418 --- /dev/null +++ b/app/assets/javascripts/maps.js.coffee @@ -0,0 +1,18 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ + +#= require openlayers-rails + +$(document).ready -> + map = new OpenLayers.Map 'map' + layer = new OpenLayers.Layer.WMS 'OpenLayers WMS', + 'http://vmap0.tiles.osgeo.org/wms/vmap0', { + layers: 'basic' + } + map.addLayer layer + map.setCenter new OpenLayers.LonLat(2.5, 47), 6 + map.addControl new OpenLayers.Control.LayerSwitcher() + + map.addLayer eventsLayer + map.addLayer lugsLayer diff --git a/app/assets/stylesheets/maps.css.sass b/app/assets/stylesheets/maps.css.sass new file mode 100644 index 00000000..61c0e077 --- /dev/null +++ b/app/assets/stylesheets/maps.css.sass @@ -0,0 +1,3 @@ +#map + width: 100% + height: 40em diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb new file mode 100644 index 00000000..7af67f68 --- /dev/null +++ b/app/controllers/maps_controller.rb @@ -0,0 +1,19 @@ +class MapsController < ApplicationController + def index + @events = Event + if (params[:region] && params[:region].present? && params[:region] != 'all') + @events = @events.region(params[:region]) + end + @events = @events.tag(params[:tag]) if (params[:tag]) + + @events = @events.where('start_time > ?', 360.days.ago).order :id + + @cities_event = @events.collect { |event| + City.find_by_majname event.city.gsub('-', ' ').upcase + }.uniq.keep_if { |city| city } + + @cities_lug = Lug.all.collect { |lug| + City.find_by_majname lug.city.gsub('-', ' ').upcase + }.uniq.keep_if { |city| city } + end +end diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb new file mode 100644 index 00000000..88ee3d5c --- /dev/null +++ b/app/helpers/maps_helper.rb @@ -0,0 +1,2 @@ +module MapsHelper +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 3dc9e16b..f9de45e7 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -65,7 +65,7 @@ = link_to t('.propose'), new_event_path = link_to t('.rss'), regions_url = link_to t('.ical'), icallist_regions_url - = link_to t('.map'), users_url + = link_to t('.map'), maps_url = link_to t('.tags'), tags_url = link_to t('.infos'), users_url = link_to t('.stats'), stats_regions_url diff --git a/app/views/maps/index.html.haml b/app/views/maps/index.html.haml new file mode 100644 index 00000000..f52dfb18 --- /dev/null +++ b/app/views/maps/index.html.haml @@ -0,0 +1,31 @@ +%h2=t '.title' + +#map + +:javascript + var eventsLayer = new OpenLayers.Layer.Markers("#{t '.events'}"); + eventsLayer.setVisibility(true); + var iconSize = new OpenLayers.Size(20, 20); + var iconOffset = new OpenLayers.Pixel(-(iconSize.w/2), -iconSize.h); + +- for city in @cities_event + :coffee + marker = new OpenLayers.Marker( + new OpenLayers.LonLat(#{city.longitude}, #{city.latitude}) + #new OpenLayers.Icon(<>, iconSize, iconOffset) + ) + eventsLayer.addMarker marker + +:javascript + var lugsLayer = new OpenLayers.Layer.Markers("#{t '.lugs'}"); + lugsLayer.setVisibility(true); + var iconSize = new OpenLayers.Size(20, 20); + var iconOffset = new OpenLayers.Pixel(-(iconSize.w/2), -iconSize.h); + +- for city in @cities_lug + :coffee + marker = new OpenLayers.Marker( + new OpenLayers.LonLat(#{city.longitude}, #{city.latitude}) + new OpenLayers.Icon("/assets/team.png", iconSize, iconOffset) + ) + lugsLayer.addMarker marker diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 5172d285..2dd52c48 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -164,6 +164,11 @@ fr: title: Ajout d'une note de modération actions: added: La note a bien été ajoutée, merci! + maps: + index: + title: Carte des évènements + events: Évènements + lugs: Lugs users: sign_in: title: Identification diff --git a/config/routes.rb b/config/routes.rb index 2d3b402f..c9daf4ac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ Rails.application.routes.draw do + get 'maps/index' + + get 'map/index' + resources :users resources :events resources :moderations do @@ -9,6 +13,7 @@ Rails.application.routes.draw do get 'stats', on: :collection end resources :tags, only: [ :index, :show ] + resources :maps, only: [:index] get 'ical.php' => 'events#index', format: :ics get ':format.php' => 'events#index' diff --git a/test/controllers/maps_controller_test.rb b/test/controllers/maps_controller_test.rb new file mode 100644 index 00000000..7972cdc7 --- /dev/null +++ b/test/controllers/maps_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class MapsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/test/helpers/map_helper_test.rb b/test/helpers/map_helper_test.rb new file mode 100644 index 00000000..d0728861 --- /dev/null +++ b/test/helpers/map_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MapHelperTest < ActionView::TestCase +end diff --git a/test/helpers/maps_helper_test.rb b/test/helpers/maps_helper_test.rb new file mode 100644 index 00000000..0a0efccd --- /dev/null +++ b/test/helpers/maps_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MapsHelperTest < ActionView::TestCase +end