diff options
| -rw-r--r-- | app/controllers/referential_networks_controller.rb | 7 | ||||
| -rw-r--r-- | app/decorators/referential_network_decorator.rb | 60 | ||||
| -rw-r--r-- | app/views/referential_networks/index.html.slim | 3 | ||||
| -rw-r--r-- | app/views/referential_networks/show.html.slim | 9 |
4 files changed, 36 insertions, 43 deletions
diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb index b2d83f953..fe00a99df 100644 --- a/app/controllers/referential_networks_controller.rb +++ b/app/controllers/referential_networks_controller.rb @@ -56,6 +56,10 @@ class ReferentialNetworksController < ChouetteController end end + def collection_name + 'networks' + end + def resource_url(network = nil) referential_network_path(referential, network || resource) end @@ -78,9 +82,8 @@ class ReferentialNetworksController < ChouetteController end def decorate_networks(networks) - ModelDecorator.decorate( + ReferentialNetworkDecorator.decorate( networks, - with: ReferentialNetworkDecorator, context: { referential: referential } diff --git a/app/decorators/referential_network_decorator.rb b/app/decorators/referential_network_decorator.rb index 1260a38cb..957c37966 100644 --- a/app/decorators/referential_network_decorator.rb +++ b/app/decorators/referential_network_decorator.rb @@ -1,38 +1,40 @@ -class ReferentialNetworkDecorator < Draper::Decorator +class ReferentialNetworkDecorator < AF83::Decorator decorates Chouette::Network - delegate_all + # Action links require: + # context: { + # referential: , + # } -# Requires: -# context: { -# referential: , -# } -def action_links - links = [] - - if h.policy(Chouette::Network).create? - links << Link.new( - content: h.t('networks.actions.new'), - href: h.new_referential_network_path(context[:referential]) - ) + create_action_link do |l| + l.content t('networks.actions.new') + l.href { h.new_referential_network_path(context[:referential]) } end - if h.policy(object).update? - links << Link.new( - content: h.t('networks.actions.edit'), - href: h.edit_referential_network_path(context[:referential], object) - ) - end + with_instance_decorator do |instance_decorator| + instance_decorator.show_action_link do |l| + l.href { h.referential_network_path(context[:referential], object) } + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('networks.actions.destroy'), - href: h.referential_network_path(context[:referential], object), - method: :delete, - data: { confirm: t('networks.actions.destroy_confirm') } - ) - end + instance_decorator.action_link secondary: true, policy: :edit do |l| + l.content t('networks.actions.edit') + l.href do + h.edit_referential_network_path( + context[:referential], + object + ) + end + end - links + instance_decorator.destroy_action_link do |l| + l.content h.destroy_link_content('networks.actions.destroy') + l.href do + h.referential_network_path( + context[:referential], + object + ) + end + l.data confirm: h.t('networks.actions.destroy_confirm') + end end end
\ No newline at end of file diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim index d556e7e5e..efa28dc05 100644 --- a/app/views/referential_networks/index.html.slim +++ b/app/views/referential_networks/index.html.slim @@ -1,7 +1,4 @@ - breadcrumb :referential_networks, @referential -- if policy(Chouette::Network).create? - - content_for :page_header_actions do - = link_to(t('networks.actions.new'), new_referential_network_path(@referential), class: 'btn btn-default') .page_content .container-fluid diff --git a/app/views/referential_networks/show.html.slim b/app/views/referential_networks/show.html.slim index 7de304671..3d13d9211 100644 --- a/app/views/referential_networks/show.html.slim +++ b/app/views/referential_networks/show.html.slim @@ -1,14 +1,5 @@ - breadcrumb :referential_network, @referential, @network - page_header_content_for @network -- content_for :page_header_content do - .row - .col-lg-12.text-right.mb-sm - - @network.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 |
