diff options
| author | Teddy Wing | 2017-07-11 18:48:42 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-07-12 11:11:14 +0200 |
| commit | ef937098ef2c5e7ad8a05c5d84b8a201cb6358e8 (patch) | |
| tree | 8789af620646b83a9db828523b3cd704e8766ed4 | |
| parent | dc155d36bdf0dc1c056888794586fca10c1f11b0 (diff) | |
| download | chouette-core-ef937098ef2c5e7ad8a05c5d84b8a201cb6358e8.tar.bz2 | |
StopAreaReferentials#show: Move header links to decorator
On the
http://stif-boiv.dev:3000/stop_area_referentials/1/stop_areas/139416
page, move the header links into a decorator to allow us to use them in
the table of stop areas on StopAreaReferentials#index.
Refs #3479
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 3 | ||||
| -rw-r--r-- | app/decorators/stop_area_decorator.rb | 42 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 14 |
3 files changed, 51 insertions, 8 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index ae3edbd3e..e97aad8d3 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -90,6 +90,9 @@ class StopAreasController < BreadcrumbController } end + + @stop_area = @stop_area.decorate + build_breadcrumb :show end end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb new file mode 100644 index 000000000..1f3b3d16c --- /dev/null +++ b/app/decorators/stop_area_decorator.rb @@ -0,0 +1,42 @@ +class StopAreaDecorator < Draper::Decorator + decorates Chouette::StopArea + + delegate_all + + def action_links + links = [] + + if h.policy(Chouette::StopArea).new? + links << Link.new( + content: h.t('stop_areas.actions.new'), + href: h.new_stop_area_referential_stop_area_path( + object.stop_area_referential + ) + ) + end + + if h.policy(object).update? + links << Link.new( + content: h.t('stop_areas.actions.edit'), + href: h.edit_stop_area_referential_stop_area_path( + object.stop_area_referential, + object + ) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('stop_areas.actions.destroy'), + href: h.stop_area_referential_stop_area_path( + object.stop_area_referential, + object + ), + method: :delete, + data: { confirm: t('stop_areas.actions.destroy_confirm') } + ) + end + + links + end +end diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index 0427554ef..05f66a33a 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -5,14 +5,12 @@ .row .col-lg-12.text-right.mb-sm - - if policy(Chouette::StopArea).new? - = link_to t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), class: 'btn btn-primary' - - if policy(@stop_area).update? - = link_to t('stop_areas.actions.edit'), edit_stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), class: 'btn btn-primary' - - if policy(@stop_area).destroy? - = link_to stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), method: :delete, data: {confirm: t('stop_areas.actions.destroy_confirm')}, class: 'btn btn-primary' do - span.fa.fa-trash - span = t('stop_areas.actions.destroy') + - @stop_area.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 |
