aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-01-23 14:57:07 +0100
committerZog2018-01-25 17:18:01 +0100
commit6c969baf047a7c13b871c5fea41cda54e2b1f7fd (patch)
tree074efafff1a6be07a8dbb64e0f2aed85f1afa7df
parent4e034f42107a2016db3a032d3c0cd1a5f8e43635 (diff)
downloadchouette-core-6c969baf047a7c13b871c5fea41cda54e2b1f7fd.tar.bz2
NetworkDecorator: Convert to new action links interface
And remove the "create" link from the gear menu and header links of the :show page because it didn't make sense there. Leave a "create" link on the index page though. Refs #5586
-rw-r--r--app/controllers/networks_controller.rb3
-rw-r--r--app/decorators/network_decorator.rb51
-rw-r--r--app/views/networks/index.html.slim3
-rw-r--r--app/views/networks/show.html.slim10
4 files changed, 27 insertions, 40 deletions
diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb
index 79a5eb97b..1c69b1240 100644
--- a/app/controllers/networks_controller.rb
+++ b/app/controllers/networks_controller.rb
@@ -89,9 +89,8 @@ class NetworksController < ChouetteController
end
def decorate_networks(networks)
- ModelDecorator.decorate(
+ NetworkDecorator.decorate(
networks,
- with: NetworkDecorator,
context: {
line_referential: line_referential
}
diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb
index b0a19cf60..cfa19dca5 100644
--- a/app/decorators/network_decorator.rb
+++ b/app/decorators/network_decorator.rb
@@ -1,44 +1,43 @@
-class NetworkDecorator < Draper::Decorator
+class NetworkDecorator < AF83::Decorator
decorates Chouette::Network
- delegate_all
-
- # Requires:
+ # Action links require:
# context: {
# line_referential: ,
# }
- def action_links
- links = []
- if h.policy(Chouette::Network).create?
- links << Link.new(
- content: h.t('networks.actions.new'),
- href: h.new_line_referential_network_path(context[:line_referential])
- )
+ create_action_link do |l|
+ l.content t('networks.actions.new')
+ l.href { h.new_line_referential_network_path(context[:line_referential]) }
+ l.class 'btn btn-primary'
+ end
+
+ with_instance_decorator do |instance_decorator|
+ instance_decorator.show_action_link do |l|
+ l.href do
+ h.line_referential_network_path(context[:line_referential], object)
+ end
end
- if h.policy(object).update?
- links << Link.new(
- content: h.t('networks.actions.edit'),
- href: h.edit_line_referential_network_path(
+ instance_decorator.action_link secondary: true, policy: :edit do |l|
+ l.content t('networks.actions.edit')
+ l.href do
+ h.edit_line_referential_network_path(
context[:line_referential],
object
)
- )
+ end
end
- if h.policy(object).destroy?
- links << Link.new(
- content: h.destroy_link_content('networks.actions.destroy'),
- href: h.line_referential_network_path(
+ instance_decorator.destroy_action_link do |l|
+ l.content h.destroy_link_content('networks.actions.destroy')
+ l.href do
+ h.line_referential_network_path(
context[:line_referential],
object
- ),
- method: :delete,
- data: { confirm: h.t('networks.actions.destroy_confirm') }
- )
+ )
+ end
+ l.data confirm: h.t('networks.actions.destroy_confirm')
end
-
- links
end
end
diff --git a/app/views/networks/index.html.slim b/app/views/networks/index.html.slim
index b13c73e9e..6aeb140cc 100644
--- a/app/views/networks/index.html.slim
+++ b/app/views/networks/index.html.slim
@@ -1,7 +1,4 @@
- breadcrumb :networks, @line_referential
-- content_for :page_header_actions do
- - if policy(Chouette::Network).create?
- = link_to(t('networks.actions.new'), new_line_referential_network_path(@line_referential), class: 'btn btn-primary')
.page_content
.container-fluid
diff --git a/app/views/networks/show.html.slim b/app/views/networks/show.html.slim
index 8e40a13b2..527fb8d5b 100644
--- a/app/views/networks/show.html.slim
+++ b/app/views/networks/show.html.slim
@@ -1,14 +1,6 @@
- breadcrumb :network, @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
+
.page_content
.container-fluid
.row