aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-07-06 15:57:09 +0200
committerTeddy Wing2017-07-07 12:58:11 +0200
commita59bf68668a74d9be6cdc64dca5ad801c833708c (patch)
tree3bfad1a2ccb310b0ff2e5762cd44ef2d356c18cc
parent72c90c1b3da9b09319a435bd549ba3b5070df31a (diff)
downloadchouette-core-a59bf68668a74d9be6cdc64dca5ad801c833708c.tar.bz2
ReferentialLines#show: Use new table builder helper
Convert the table of `Route`s on this page to use the new table builder helper. This gives us the links from the `RouteDecorator` in the gear menu next to each row in the table. Ended up removing the `route_sp` field from the `RouteDecorator` context because it seems like we can just grab that collection directly from the `Route` object. At first I thought about renaming it because after coming back to this code I thought, 'what does sp mean?'. Then after some investigation, it appears that we don't need to pass it in explicitly. Now, no need to bother with that from the ReferentialLines controller. The RoutesController does create a separate `@route_sp` variable, but this only changes the sort order of the stop points, not the contents of the collection. Thus it seems safe to get them directly from the Route in the decorator. Refs #3479
-rw-r--r--app/controllers/referential_lines_controller.rb9
-rw-r--r--app/controllers/routes_controller.rb3
-rw-r--r--app/decorators/route_decorator.rb5
-rw-r--r--app/views/referential_lines/show.html.slim52
4 files changed, 52 insertions, 17 deletions
diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb
index 5d36e7da7..4b4a822b4 100644
--- a/app/controllers/referential_lines_controller.rb
+++ b/app/controllers/referential_lines_controller.rb
@@ -39,6 +39,15 @@ class ReferentialLinesController < ChouetteController
@routes = @routes.paginate(page: params[:page], per_page: 10)
+ @routes = ModelDecorator.decorate(
+ @routes,
+ with: RouteDecorator,
+ context: {
+ referential: referential,
+ line: @line
+ }
+ )
+
show! do
build_breadcrumb :show
end
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index 786bd57cc..4781d0d16 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -44,8 +44,7 @@ class RoutesController < ChouetteController
show! do
@route = @route.decorate(context: {
referential: @referential,
- line: @line,
- route_sp: @route_sp
+ line: @line
})
build_breadcrumb :show
diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb
index 99b174dff..484c3db04 100644
--- a/app/decorators/route_decorator.rb
+++ b/app/decorators/route_decorator.rb
@@ -6,13 +6,12 @@ class RouteDecorator < Draper::Decorator
# Requires:
# context: {
# referential: ,
- # line: ,
- # route_sp
+ # line:
# }
def action_links
links = []
- if context[:route_sp].any?
+ if object.stop_points.any?
links << Link.new(
content: h.t('journey_patterns.index.title'),
href: [
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index 0bb6d9032..327906c9c 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -51,18 +51,46 @@
- if @routes.any?
.row
.col-lg-12
- = table_builder @routes,
- { 'ID' => Proc.new { |n| n.objectid.local_id },
- :name => 'name',
- :published_name => 'published_name',
- :wayback => 'wayback_text',
- 'Arrêt de départ' => Proc.new{|r| r.try(:stop_points).first.try(:stop_area).try(:name)},
- "Arrêt d'arrivée" => Proc.new{|r| r.try(:stop_points).last.try(:stop_area).try(:name)},
- :stop_points => Proc.new{|r| r.try(:stop_points).count},
- :journey_patterns => Proc.new{|r| r.try(:journey_patterns).count} },
- [:show, :edit, :delete],
- [],
- 'table has-search'
+ = table_builder_2 @routes,
+ [ \
+ TableBuilderHelper::Column.new( \
+ name: 'ID', \
+ attribute: Proc.new { |n| n.objectid.local_id }, \
+ sortable: false \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :name, \
+ attribute: 'name' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :published_name, \
+ attribute: 'published_name' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :wayback, \
+ attribute: 'wayback_text' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ name: 'Arrêt de départ', \
+ attribute: Proc.new { |r| r.try(:stop_points).first.try(:stop_area).try(:name) }, \
+ sortable: false \
+ ), \
+ TableBuilderHelper::Column.new( \
+ name: 'Arrêt d'arrivée', \
+ attribute: Proc.new{ |r| r.try(:stop_points).last.try(:stop_area).try(:name) }, \
+ sortable: false \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :stop_points, \
+ attribute: Proc.new{ |r| r.try(:stop_points).count } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :journey_patterns, \
+ attribute: Proc.new{ |r| r.try(:journey_patterns).count } \
+ ) \
+ ],
+ links: [:show, :edit],
+ cls: 'table has-search'
= new_pagination @routes, 'pull-right'