diff options
| author | Teddy Wing | 2017-06-19 15:31:19 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-19 15:31:19 +0200 |
| commit | 84ebcffb06d9ba9a56cc29d1739f1f950649f82e (patch) | |
| tree | be26f797750b961bdcb2a9181167b8e5c371571a | |
| parent | ce105d1ddb7f019cf8b55e41aa69c51e651c8ac9 (diff) | |
| download | chouette-core-84ebcffb06d9ba9a56cc29d1739f1f950649f82e.tar.bz2 | |
Routes#show: Use RouteDecorator#action_links to render header links
Instead of defining the header links in the view, get them from our
decorator so we can reuse them. Need to wrap `@route` in the decorator
in the controller and pass it the necessary context in order for it to
be able to properly build links.
Move `Chouette::RouteDecorator` to the top level app/decorators/
directory and remove it from the `Chouette` namespace. I had put it
there to make it more similar to our model directory layout, but Draper
isn't intelligent enough to look in subdirectories of `decorators` when
using the `ActiveRecord::Base#decorate` method. Otherwise I suppose I
could do `Chouette::RouteDecorator.decorate(@route)`, but that seemed
not as clean since it doesn't take advantage of the default behaviour of
Draper. Now going to have to do this for the other decorators.
Refs #3479
| -rw-r--r-- | app/controllers/routes_controller.rb | 6 | ||||
| -rw-r--r-- | app/decorators/route_decorator.rb (renamed from app/decorators/chouette/route_decorator.rb) | 4 | ||||
| -rw-r--r-- | app/views/routes/show.html.slim | 17 |
3 files changed, 15 insertions, 12 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 73febc4b9..786bd57cc 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -42,6 +42,12 @@ class RoutesController < ChouetteController end show! do + @route = @route.decorate(context: { + referential: @referential, + line: @line, + route_sp: @route_sp + }) + build_breadcrumb :show end end diff --git a/app/decorators/chouette/route_decorator.rb b/app/decorators/route_decorator.rb index f98fbfcb1..99b174dff 100644 --- a/app/decorators/chouette/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -1,4 +1,6 @@ -class Chouette::RouteDecorator < Draper::Decorator +class RouteDecorator < Draper::Decorator + decorates Chouette::Route + delegate_all # Requires: diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index 6d2d4e90d..92a5080ae 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -8,17 +8,12 @@ / Below is secundary actions & optional contents (filters, ...) .row.mb-sm .col-lg-12.text-right - - if @route_sp.any? - = link_to t('journey_patterns.index.title'), [@referential, @line, @route, :journey_patterns_collection], class: 'btn btn-primary' - - if @route.journey_patterns.present? - = link_to t('vehicle_journeys.actions.index'), [@referential, @line, @route, :vehicle_journeys], class: 'btn btn-primary' - - = link_to t('vehicle_journey_exports.new.title'), referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, format: :zip), class: 'btn btn-primary' - - - if policy(@route).destroy? - = link_to referential_line_route_path(@referential, @line, @route), method: :delete, data: {confirm: t('routes.actions.destroy_confirm')}, class: 'btn btn-primary' do - span.fa.fa-trash - span = t('actions.destroy') + - @route.action_links.each do |link| + = link_to link.href, + method: link.method, + data: link.data, + class: 'btn btn-primary' do + = link.content / PageContent .page_content |
