diff options
| author | jpl | 2017-02-21 16:46:11 +0100 |
|---|---|---|
| committer | jpl | 2017-02-21 16:46:11 +0100 |
| commit | 0777b3af6bc7c24ef9b98e00bb7b76bffdc5d632 (patch) | |
| tree | f9e2c63b880321e3a9e36c123203b61213a3c2af | |
| parent | eae4f70c40464c011a31b56b3d7bf755ef7a3f1d (diff) | |
| download | chouette-core-0777b3af6bc7c24ef9b98e00bb7b76bffdc5d632.tar.bz2 | |
Refs #2629: updating routes#show
| -rw-r--r-- | app/controllers/routes_controller.rb | 30 | ||||
| -rw-r--r-- | app/views/routes/show.html.slim | 4 | ||||
| -rw-r--r-- | spec/views/routes/show.html.erb_spec.rb | 11 |
3 files changed, 36 insertions, 9 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 4ee235cd2..29b9144e9 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -34,6 +34,14 @@ class RoutesController < ChouetteController def show @map = RouteMap.new(route).with_helpers(self) + + @route_sp = route.stop_points + if sort_sp_column && sort_sp_direction + @route_sp = @route_sp.order(sort_sp_column + ' ' + sort_sp_direction) + else + @route_sp = @route_sp.order(:position) + end + show! do build_breadcrumb :show end @@ -88,8 +96,28 @@ class RoutesController < ChouetteController private + def sort_sp_column + @route_sp.column_names.include?(params[:sort]) ? params[:sort] : 'position' + end + def sort_sp_direction + %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' + end + def route_params - params.require(:route).permit( :line_id, :objectid, :object_version, :creator_id, :name, :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, { stop_points_attributes: [ :id, :_destroy, :position, :stop_area_id, :for_boarding, :for_alighting ] } ) + params.require(:route).permit( + :line_id, + :objectid, + :object_version, + :creator_id, + :name, + :comment, + :opposite_route_id, + :published_name, + :number, + :direction, + :wayback, + stop_points_attributes: [:id, :_destroy, :position, :stop_area_id, :for_boarding, :for_alighting] + ) end end diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index 151799ff3..428c82c58 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -31,8 +31,8 @@ .row .col-lg-12 - - if @route.stop_points.any? - = table_builder @route.stop_points, + - if @route_sp.any? + = table_builder @route_sp, { 'ID Reflex' => Proc.new {|s| s.try(:stop_area).try(:user_objectid)}, Chouette::StopArea.human_attribute_name(:name) => Proc.new {|s| s.try(:stop_area).try(:name)}, Chouette::StopArea.human_attribute_name(:zip_code) => Proc.new {|s| s.try(:stop_area).try(:zip_code)}, diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 1984a0d25..327ed1588 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' describe "/routes/show", :type => :view do - + assign_referential let!(:line) { assign :line, create(:line) } let!(:route) { assign :route, create(:route, :line => line) } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } - it "should render h2 with the route name" do + it "should render h1 with the route name" do render - expect(rendered).to have_selector("h2", :text => Regexp.new(line.name)) + expect(rendered).to have_selector("h1", :text => Regexp.new(line.name)) end # it "should display a map with class 'line'" do @@ -19,13 +19,12 @@ describe "/routes/show", :type => :view do it "should render a link to edit the route" do render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_line_route_path(referential, line, route)}']") + expect(rendered).to have_selector("a[href='#{view.edit_referential_line_route_path(referential, line, route)}']") end it "should render a link to remove the route" do render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_line_route_path(referential, line, route)}'][class='remove']") + expect(rendered).to have_selector("a[href='#{view.referential_line_route_path(referential, line, route)}']") end end - |
