aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-01-24 13:49:29 +0100
committerZog2018-01-25 17:18:01 +0100
commit5e41dbed021522331532eb0151ac441553be2d13 (patch)
tree9fdb81088c7fb402717b5a67823ceb52e8e8a3e4
parent8957ab3e9b28e7548d3a4028308558bec1403c33 (diff)
downloadchouette-core-5e41dbed021522331532eb0151ac441553be2d13.tar.bz2
RoutingConstraintZoneDecorator: Convert action links to new interface
Refs #5586
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb3
-rw-r--r--app/decorators/routing_constraint_zone_decorator.rb59
-rw-r--r--app/views/routing_constraint_zones/index.html.slim3
-rw-r--r--app/views/routing_constraint_zones/show.html.slim9
4 files changed, 38 insertions, 36 deletions
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index a72b288b8..47df211d0 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -13,9 +13,8 @@ class RoutingConstraintZonesController < ChouetteController
def index
index! do |format|
- @routing_constraint_zones = ModelDecorator.decorate(
+ @routing_constraint_zones = RoutingConstraintZoneDecorator.decorate(
@routing_constraint_zones,
- with: RoutingConstraintZoneDecorator,
context: {
referential: referential,
line: parent
diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb
index 0b438a554..657065310 100644
--- a/app/decorators/routing_constraint_zone_decorator.rb
+++ b/app/decorators/routing_constraint_zone_decorator.rb
@@ -1,42 +1,57 @@
-class RoutingConstraintZoneDecorator < Draper::Decorator
+class RoutingConstraintZoneDecorator < AF83::Decorator
decorates Chouette::RoutingConstraintZone
- delegate_all
-
- # Requires:
+ # Action links require:
# context: {
# referential: ,
# line:
# }
- def action_links
- links = []
- if h.policy(object).update?
- links << Link.new(
- content: h.t('actions.edit'),
- href: h.edit_referential_line_routing_constraint_zone_path(
+ create_action_link(
+ if: ->() {
+ h.policy(Chouette::RoutingConstraintZone).create? &&
+ context[:referential].organisation == h.current_organisation
+ }
+ ) do |l|
+ l.href do
+ h.new_referential_line_routing_constraint_zone_path(
+ context[:referential],
+ context[:line]
+ )
+ end
+ l.class 'btn btn-primary'
+ end
+
+ with_instance_decorator do |instance_decorator|
+ instance_decorator.show_action_link do |l|
+ l.href do
+ h.referential_line_routing_constraint_zone_path(
context[:referential],
context[:line],
object
)
- )
+ end
end
- if h.policy(object).destroy?
- links << Link.new(
- content: h.destroy_link_content,
- href: h.referential_line_routing_constraint_zone_path(
+ instance_decorator.edit_action_link do |l|
+ l.href do
+ h.edit_referential_line_routing_constraint_zone_path(
context[:referential],
context[:line],
object
- ),
- method: :delete,
- data: {
- confirm: h.t('routing_constraint_zones.actions.destroy_confirm')
- }
- )
+ )
+ end
end
- links
+ instance_decorator.destroy_action_link do |l|
+ l.href do
+ h.referential_line_routing_constraint_zone_path(
+ context[:referential],
+ context[:line],
+ object
+ )
+ end
+ l.data confirm: h.t('routing_constraint_zones.actions.destroy_confirm')
+ end
end
end
diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim
index 7c54fca68..2f67b467e 100644
--- a/app/views/routing_constraint_zones/index.html.slim
+++ b/app/views/routing_constraint_zones/index.html.slim
@@ -1,7 +1,4 @@
- breadcrumb :routing_constraint_zones, @referential, @line
-- content_for :page_header_actions do
- - if (policy(Chouette::RoutingConstraintZone).create? && @referential.organisation == current_organisation)
- = link_to(t('actions.new'), new_referential_line_routing_constraint_zone_path(@referential, @line), class: 'btn btn-primary')
.page_content
.container-fluid
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
index 3d1988545..8c8e9b17a 100644
--- a/app/views/routing_constraint_zones/show.html.slim
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -1,14 +1,5 @@
- breadcrumb :routing_constraint_zone, @referential, @line, @routing_constraint_zone
- page_header_content_for @routing_constraint_zone
-- content_for :page_header_content do
- .row
- .col-lg-12.text-right.mb-sm
- - @routing_constraint_zone.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