From 92105b0b9c6c596602ebebca238d5d95d0a2eb7d Mon Sep 17 00:00:00 2001 From: echarp Date: Mon, 28 Apr 2014 00:33:21 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20carte=20des=20prochains=20?= =?UTF-8?q?=C3=A9v=C3=A9nements=20et=20des=20lugs,=20pour=20l'instant=20no?= =?UTF-8?q?n=20cliquable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ Gemfile | 3 +++ Gemfile.lock | 3 +++ app/assets/images/team.png | Bin 0 -> 3586 bytes app/assets/javascripts/maps.js.coffee | 18 +++++++++++++ app/assets/stylesheets/maps.css.sass | 3 +++ app/controllers/maps_controller.rb | 19 ++++++++++++++ app/helpers/maps_helper.rb | 2 ++ app/views/layouts/application.html.haml | 2 +- app/views/maps/index.html.haml | 31 +++++++++++++++++++++++ config/locales/fr.yml | 5 ++++ config/routes.rb | 5 ++++ test/controllers/maps_controller_test.rb | 9 +++++++ test/helpers/map_helper_test.rb | 4 +++ test/helpers/maps_helper_test.rb | 4 +++ 15 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 app/assets/images/team.png create mode 100644 app/assets/javascripts/maps.js.coffee create mode 100644 app/assets/stylesheets/maps.css.sass create mode 100644 app/controllers/maps_controller.rb create mode 100644 app/helpers/maps_helper.rb create mode 100644 app/views/maps/index.html.haml create mode 100644 test/controllers/maps_controller_test.rb create mode 100644 test/helpers/map_helper_test.rb create mode 100644 test/helpers/maps_helper_test.rb 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 0000000000000000000000000000000000000000..13af6148c58239942645cc9222e764158d981017 GIT binary patch literal 3586 zcmV+d4*l_oP)=k98E-;aB5|9Ed#&%zX$nwIX&nX~Whd;8A!oO{0KoVyGE&tKwy={fDd1=s%Z zRbLz$8t#~woT#sK5Scl^b-|Lx-x;r0vGu6btj=I71u&@rRD zf>G{-@tqOll?IJhJZjv+A>-z|%+pUjVm^E0M)RG&z4Kci8{?asn}4={-ygiO(c?xd z$7sJ~l$STYGiLnqu5Dgb-~G7)juG1^7@ zMYJk|F#!0!MENe-FNb#-?!4n>=FZLD`ja1gYr|}wV}C^U-&CJXub4l-nd7~$d->c% ztf_S=@l+F*tV0S9X~mJ!r%-UnPmbUm*@|1+%(AmDBwL@Zf9?0XZwLP4qXh63;AY?= zpaB>I-UR*~kXK%Dc^aeW>mRbq+kQa5kqk|G6v~E}Em0a`79=b~x<-($m9(t;JX$M0 zf6F!8cmJc;d{hy*40secXU6#kU}GplE%Tb{jP@DmIV8@TTf<~g)0l~)jX)#N29(mo zgu?X{!f5(;Z>DzM3fkM6IeXPv*&vxL*=>+f@;MrMRH}Af``v=ZiaV8nt$M}Y9 z%0@^TNSMUN7_{$Ga-dw+j1>x$MtaCLHnMW%3LCiKg8*2kVEoE(P0kwhrsrQ`{kij4 zTsIMv%qaO7gE0o96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f7e^=|NZkAt=|H^7oo@s!_4}3;uMesnt&^Ti-B{26+o<^bumqCi^(*$kjyj? zuSpS$#}Sr|5E9QVbJmh}4)zX)hAMpD!*d;+Vu50AoWl4J;{!cR3>~Rd)lT4TUYeSplQJUycrMJ38M{%n)>gZ?WaW*8?U#uJIa z%;PAdMY%f4CMu%U45Lrk@Kf0r5+~6!Blmtg8O){_{ZC&11)bi$*<8C}AOHXW07*qo IM6N<$f + 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