diff options
| author | Michel Etienne | 2012-05-03 09:18:32 +0200 |
|---|---|---|
| committer | Michel Etienne | 2012-05-03 09:18:32 +0200 |
| commit | 32c1a5676e0df8524d534a71c78363ce215f92d3 (patch) | |
| tree | 09ed04c7d6c5cb5671654e44e88dd8d861649d1d | |
| parent | 14094a6e94a6cad6756cde3b47beb0283a4a8d08 (diff) | |
| download | chouette-core-32c1a5676e0df8524d534a71c78363ce215f92d3.tar.bz2 | |
add map on connection-link and enable parent/children management on area types
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/controllers/connection_links_controller.rb | 5 | ||||
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 1 | ||||
| -rw-r--r-- | app/maps/connection_link_map.rb | 32 | ||||
| -rw-r--r-- | app/views/connection_links/show.html.erb | 3 | ||||
| -rw-r--r-- | app/views/help/index.textile | 1 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.erb | 8 | ||||
| -rw-r--r-- | config/routes.rb | 7 | ||||
| -rw-r--r-- | spec/requests/connection_links_spec.rb | 8 | ||||
| -rw-r--r-- | spec/views/connection_links/show.html.erb_spec.rb | 11 | ||||
| -rw-r--r-- | spec/views/stop_areas/edit.html.erb_spec.rb | 24 | ||||
| -rw-r--r-- | spec/views/stop_areas/index.html.erb_spec.rb | 25 | ||||
| -rw-r--r-- | spec/views/stop_areas/new.html.erb_spec.rb | 17 | ||||
| -rw-r--r-- | spec/views/stop_areas/show.html.erb_spec.rb | 30 |
14 files changed, 160 insertions, 14 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 5a369b338..1c6d630f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://chouette.dryade.priv/ninoxe - revision: 2ac65f975c031bc6c1d69b6e9f2965c0484f2279 + revision: 89f04226273fefe0eeac7f11d136c287590faf83 specs: ninoxe (0.0.8) GeoRuby diff --git a/app/controllers/connection_links_controller.rb b/app/controllers/connection_links_controller.rb index 8790426f7..3da6b1417 100644 --- a/app/controllers/connection_links_controller.rb +++ b/app/controllers/connection_links_controller.rb @@ -8,6 +8,11 @@ class ConnectionLinksController < ChouetteController respond_to :html, :xml, :json + def show + @map = ConnectionLinkMap.new referential, resource + show! + end + def select_areas @connection_link = connection_link @departure = connection_link.departure diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 98111a804..d881baae7 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -4,6 +4,7 @@ class StopAreasController < ChouetteController belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true belongs_to :network, :parent_class => Chouette::Network, :optional => true, :polymorphic => true + belongs_to :connection_link, :parent_class => Chouette::Network, :optional => true, :polymorphic => true end respond_to :html, :kml, :xml, :json diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb new file mode 100644 index 000000000..fe79ce9a4 --- /dev/null +++ b/app/maps/connection_link_map.rb @@ -0,0 +1,32 @@ + +class ConnectionLinkMap < ApplicationMap + + attr_reader :referential, :connection_link, :connection_link_style + + def initialize(referential, connection_link, connection_link_style = nil) + @referential = referential + @connection_link = connection_link + @connection_link_style = connection_link_style + end + + def map + @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page| + page << map.add_layer(MapLayers::OSM_MAPNIK) + page << map.add_layer(google_physical) + page << map.add_layer(google_streets) + page << map.add_layer(google_hybrid) + page << map.add_layer(google_satellite) + + #page << map.add_layer(kml_layer(connection_link, :styleMap => StyleMap::ConnectionLinkStyleMap.new( :style => connection_link_style).style_map)) + page << map.add_layer(kml_layer(polymorphic_path([referential, connection_link, :stop_areas], :format => :kml), :styleMap => StyleMap::StopAreasStyleMap.new(true).style_map)) + page << map.zoom_to_extent(bounds) if bounds + end + end + + def bounds + wgs84_bounds = Chouette::StopArea.bounds + @bounds ||= OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) + + end + +end diff --git a/app/views/connection_links/show.html.erb b/app/views/connection_links/show.html.erb index c81159191..0adb3e1b0 100644 --- a/app/views/connection_links/show.html.erb +++ b/app/views/connection_links/show.html.erb @@ -1,7 +1,8 @@ <%= title_tag t('connection_links.show.title', :connection_link => @connection_link.name ) %> <div class="connection_link_show"> - + <%= @map.to_html.html_safe %> + <div class="summary"> <p> <label><%= @connection_link.human_attribute_name(:departure) %>: </label> diff --git a/app/views/help/index.textile b/app/views/help/index.textile index 4d30f2e46..c793ff0f6 100644 --- a/app/views/help/index.textile +++ b/app/views/help/index.textile @@ -29,5 +29,4 @@ les action suivantes ne sont pas encore disponible : * associer des arrêts à une séquences d'arrêts * ajouter des fils à un arrêt * associer une ITL à une ligne -* affichage de la carte des arrêts d'une correspondance diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index 6536ac5cb..6912db830 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -125,8 +125,12 @@ <ul class="actions"> <li><%= link_to t('stop_areas.actions.edit'), edit_referential_stop_area_path(@referential, @stop_area), :class => "edit" %></li> <li><%= link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), :method => :delete, :confirm => t('stop_areas.actions.destroy_confirm'), :class => "remove" %></li> - <li><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "select_parent" %></li> - <li><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "add_children" %></li> + <% if @stop_area.type != 'itl' %> + <li><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "select_parent" %></li> + <% end %> + <% if @stop_area.type != 'boarding_position' && @stop_area.type != 'quay' %> + <li><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "add_children" %></li> + <% end %> <br> </ul> <% end %> diff --git a/config/routes.rb b/config/routes.rb index eb7af8b9c..e5ad83ca6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,6 +48,13 @@ ChouetteIhm::Application.routes.draw do get 'select_arrival' get 'select_areas' end + resources :stop_areas do + resources :stop_area_parents + member do + get 'add_children' + get 'select_parent' + end + end end end diff --git a/spec/requests/connection_links_spec.rb b/spec/requests/connection_links_spec.rb index e137a330b..0c8b06c0f 100644 --- a/spec/requests/connection_links_spec.rb +++ b/spec/requests/connection_links_spec.rb @@ -26,10 +26,10 @@ describe "ConnectionLinks" do it "display map" do pending ": map not yet implemented" -# subject.stub(:stop_areas).and_return(Array.new(2) { Factory(:stop_area) }) -# visit referential_connection_links_path(referential) -# click_link "#{connection_links.first.name}" -# page.should have_selector("#map", :class => 'connection_link') + subject.stub(:stop_areas).and_return(Array.new(2) { Factory(:stop_area) }) + visit referential_connection_links_path(referential) + click_link "#{connection_links.first.name}" + page.should have_selector("#map", :class => 'connection_link') end end diff --git a/spec/views/connection_links/show.html.erb_spec.rb b/spec/views/connection_links/show.html.erb_spec.rb index bc8d075cf..8a03f5339 100644 --- a/spec/views/connection_links/show.html.erb_spec.rb +++ b/spec/views/connection_links/show.html.erb_spec.rb @@ -4,17 +4,18 @@ describe "/connection_links/show" do let!(:referential) { assign(:referential, create(:referential)) } let!(:connection_link) { assign(:connection_link, create(:connection_link)) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } it "should render h2 with the connection_link name" do render rendered.should have_selector("h2", :text => Regexp.new(connection_link.name)) end - it "should display a map with class 'connection_link'" do - pending ": map not yet implemented" - # render - # rendered.should have_selector("#map", :class => 'connection_link') - end +# it "should display a map with class 'connection_link'" do +# pending ": map not yet implemented" +# render +# rendered.should have_selector("#map", :class => 'connection_link') +# end it "should render a link to edit the connection_link" do render diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb new file mode 100644 index 000000000..c3b89918d --- /dev/null +++ b/spec/views/stop_areas/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "/stop_areas/edit" do + let!(:referential) { assign(:referential, create(:referential)) } + let!(:stop_area) { assign(:stop_area, create(:stop_area)) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + + describe "test" do + it "should render h2 with the group name" do + render + rendered.should have_selector("h2", :text => Regexp.new(stop_area.name)) + end + end + + describe "form" do + it "should render input for name" do + render + rendered.should have_selector("form") do + with_tag "input[type=text][name='stop_area[name]'][value=?]", stop_area.name + end + end + + end +end diff --git a/spec/views/stop_areas/index.html.erb_spec.rb b/spec/views/stop_areas/index.html.erb_spec.rb new file mode 100644 index 000000000..3adecdd0d --- /dev/null +++ b/spec/views/stop_areas/index.html.erb_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe "/stop_areas/index" do + + let!(:referential) { assign :referential, create(:referential) } + let!(:stop_areas) { assign :stop_areas, Array.new(2) { create(:stop_area) }.paginate } + let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } + + before :each do + view.stub(:link_with_search).and_return("#") + end + + it "should render a show link for each group" do + render + stop_areas.each do |stop_area| + rendered.should have_selector(".stop_area a[href='#{view.referential_stop_area_path(referential, stop_area)}']", :text => stop_area.name) + end + end + + it "should render a link to create a new group" do + render + view.content_for(:sidebar).should have_selector(".actions a[href='#{new_referential_stop_area_path(referential)}']") + end + +end diff --git a/spec/views/stop_areas/new.html.erb_spec.rb b/spec/views/stop_areas/new.html.erb_spec.rb new file mode 100644 index 000000000..be1b7593b --- /dev/null +++ b/spec/views/stop_areas/new.html.erb_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe "/stop_areas/new" do + let!(:referential) { assign(:referential, create(:referential)) } + let!(:stop_area) { assign(:stop_area, build(:stop_area)) } + + describe "form" do + + it "should render input for name" do + render + rendered.should have_selector("form") do + with_selector "input[type=text][name=?]", stop_area.name + end + end + + end +end diff --git a/spec/views/stop_areas/show.html.erb_spec.rb b/spec/views/stop_areas/show.html.erb_spec.rb new file mode 100644 index 000000000..443a37232 --- /dev/null +++ b/spec/views/stop_areas/show.html.erb_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe "/stop_areas/show" do + + let!(:referential) { assign :referential, create(:referential) } + let!(:stop_area) { assign :stop_area, create(:stop_area) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + + it "should render h2 with the stop_area name" do + render + rendered.should have_selector("h2", :text => Regexp.new(stop_area.name)) + end + + # it "should display a map with class 'stop_area'" do + # render + # rendered.should have_selector("#map", :class => 'stop_area') + # end + + it "should render a link to edit the stop_area" do + render + view.content_for(:sidebar).should have_selector(".actions a[href='#{view.edit_referential_stop_area_path(referential, stop_area)}']") + end + + it "should render a link to remove the stop_area" do + render + view.content_for(:sidebar).should have_selector(".actions a[href='#{view.referential_stop_area_path(referential, stop_area)}'][class='remove']") + end + +end + |
