diff options
| -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 |
