aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-01-24 13:25:28 +0100
committerZog2018-01-25 17:18:01 +0100
commit8957ab3e9b28e7548d3a4028308558bec1403c33 (patch)
treeaa7aa34c6c905c3817c34ede8aa59c5db3a75901
parent766dd36e253cfe00f0cec96e7fa55687428b0f2a (diff)
downloadchouette-core-8957ab3e9b28e7548d3a4028308558bec1403c33.tar.bz2
ReferentialLineDecorator: Convert action links to new interface
Refs #5586
-rw-r--r--app/controllers/referentials_controller.rb3
-rw-r--r--app/decorators/referential_line_decorator.rb53
-rw-r--r--app/views/referential_lines/show.html.slim9
-rw-r--r--app/views/referentials/show.html.slim4
4 files changed, 31 insertions, 38 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 41ddc3870..0ed3f75dd 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -32,9 +32,8 @@ class ReferentialsController < ChouetteController
show! do |format|
@referential = @referential.decorate(context: { current_workbench_id: params[:current_workbench_id] } )
@reflines = lines_collection.paginate(page: params[:page], per_page: 10)
- @reflines = ModelDecorator.decorate(
+ @reflines = ReferentialLineDecorator.decorate(
@reflines,
- with: ReferentialLineDecorator,
context: {
referential: referential,
current_organisation: current_organisation
diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb
index dceb3e2a9..8f884a8e0 100644
--- a/app/decorators/referential_line_decorator.rb
+++ b/app/decorators/referential_line_decorator.rb
@@ -1,40 +1,43 @@
-class ReferentialLineDecorator < Draper::Decorator
+class ReferentialLineDecorator < AF83::Decorator
decorates Chouette::Line
- delegate_all
-
- # Requires:
+ # Action links require:
# context: {
# referential: ,
# current_organisation:
# }
- def action_links
- links = []
- links << Link.new(
- content: Chouette::Line.human_attribute_name(:footnotes),
- href: h.referential_line_footnotes_path(context[:referential], object)
- )
+ with_instance_decorator do |instance_decorator|
+ instance_decorator.show_action_link do |l|
+ l.href { h.referential_line_path(context[:referential], object) }
+ end
- links << Link.new(
- content: h.t('routing_constraint_zones.index.title'),
- href: h.referential_line_routing_constraint_zones_path(
- context[:referential],
- object
- )
- )
+ instance_decorator.action_link secondary: true do |l|
+ l.content Chouette::Line.human_attribute_name(:footnotes)
+ l.href { h.referential_line_footnotes_path(context[:referential], object) }
+ end
- if !object.hub_restricted? ||
- (object.hub_restricted? && object.routes.size < 2)
- if h.policy(Chouette::Route).create? &&
- context[:referential].organisation == context[:current_organisation]
- links << Link.new(
- content: h.t('routes.actions.new'),
- href: h.new_referential_line_route_path(context[:referential], object)
+ instance_decorator.action_link secondary: true do |l|
+ l.content h.t('routing_constraint_zones.index.title')
+ l.href do
+ h.referential_line_routing_constraint_zones_path(
+ context[:referential],
+ object
)
end
end
- links
+ instance_decorator.action_link(
+ if: ->() {
+ (!object.hub_restricted? ||
+ (object.hub_restricted? && object.routes.size < 2)) &&
+ (h.policy(Chouette::Route).create? &&
+ context[:referential].organisation == context[:current_organisation])
+ },
+ secondary: true
+ ) do |l|
+ l.content h.t('routes.actions.new')
+ l.href { h.new_referential_line_route_path(context[:referential], object) }
+ end
end
end
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index 70f4048b3..02d605d8c 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -1,13 +1,4 @@
- breadcrumb :referential_line, @referential, @line
-- content_for :page_header_content do
- .row
- .col-lg-12.text-right.mb-sm
- - @line.action_links.each do |link|
- = link_to link.href,
- method: link.method,
- data: link.data,
- class: 'btn btn-primary' do
- = link.content
- page_header_content_for @line
.page_content
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 46019be35..6c88f5b81 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -56,8 +56,8 @@
attribute: Proc.new { |n| n&.company&.name || "-" } \
) \
],
- links: [:show],
- cls: 'table has-filter has-search'
+ cls: 'table has-filter has-search',
+ action: :index
= new_pagination @reflines, 'pull-right'