aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/lines_controller.rb8
-rw-r--r--app/decorators/line_decorator.rb106
-rw-r--r--app/views/layouts/navigation/_page_header.html.slim1
-rw-r--r--app/views/lines/index.html.slim3
4 files changed, 63 insertions, 55 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 7041a3a26..10ecc7e9d 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -15,9 +15,8 @@ class LinesController < ChouetteController
def index
@hide_group_of_line = line_referential.group_of_lines.empty?
index! do |format|
- @lines = ModelDecorator.decorate(
+ @lines = LineDecorator.decorate(
@lines,
- with: LineDecorator,
context: {
line_referential: @line_referential,
current_organisation: current_organisation
@@ -69,9 +68,14 @@ class LinesController < ChouetteController
respond_to do |format|
format.json { render :json => filtered_lines_maps}
end
+ end
+ def decorated_collection
+ @lines
end
+ helper_method :decorated_collection
+
protected
def filtered_lines_maps
diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb
index 9325c6a8b..728543592 100644
--- a/app/decorators/line_decorator.rb
+++ b/app/decorators/line_decorator.rb
@@ -1,67 +1,73 @@
class LineDecorator < AF83::Decorator
decorates Chouette::Line
- delegate_all
-
- ### primary (and secondary) can be
- ### - a single action
- ### - an array of actions
- ### - a boolean
-
- action_link primary: :index, on: :index do |l|
- l.content h.t('lines.actions.show')
- l.href { [context[:line_referential], object] }
+ action_link on: :index, primary: :index, policy: :create do |l|
+ l.content { h.t('lines.actions.new') }
+ l.href { h.new_line_referential_line_path(context[:line_referential]) }
end
- action_link do |l|
- l.content h.t('lines.actions.show_network')
- l.href { [context[:line_referential], object.network] }
- end
+ with_instance_decorator do |instance_decorator|
+ instance_decorator.delegate_all
+ ### primary (and secondary) can be
+ ### - a single action
+ ### - an array of actions
+ ### - a boolean
- action_link do |l|
- l.content { h.t('lines.actions.show_company') }
- l.href { [context[:line_referential], object.company] }
- l.disabled { object.company.nil? }
- end
+ instance_decorator.action_link primary: :index, on: :index do |l|
+ l.content h.t('lines.actions.show')
+ l.href { [context[:line_referential], object] }
+ end
- can_edit_line = ->(){ h.policy(Chouette::Line).create? && context[:line_referential].organisations.include?(context[:current_organisation]) }
+ instance_decorator.action_link do |l|
+ l.content h.t('lines.actions.show_network')
+ l.href { [context[:line_referential], object.network] }
+ end
- with_condition can_edit_line do
- action_link on: %i(index show), primary: :show, secondary: :index do |l|
- l.content { h.t('lines.actions.edit') }
- l.href { h.edit_line_referential_line_path(context[:line_referential], object.id) }
+ instance_decorator.action_link do |l|
+ l.content { h.t('lines.actions.show_company') }
+ l.href { [context[:line_referential], object.company] }
+ l.disabled { object.company.nil? }
end
- action_link on: :index, secondary: :index do |l|
- l.content { h.t('lines.actions.new') }
- l.href { h.new_line_referential_line_path(context[:line_referential]) }
+ can_edit_line = ->(){ h.policy(Chouette::Line).create? && context[:line_referential].organisations.include?(context[:current_organisation]) }
+
+ instance_decorator.with_condition can_edit_line do
+ action_link on: %i(index show), primary: :show, secondary: :index do |l|
+ l.content { h.t('lines.actions.edit') }
+ l.href { h.edit_line_referential_line_path(context[:line_referential], object.id) }
+ end
+
+ action_link on: :index, secondary: :index do |l|
+ l.content { h.t('lines.actions.new') }
+ l.href { h.new_line_referential_line_path(context[:line_referential]) }
+ end
end
- end
- ### the option :policy will automatically check for the corresponding method
- ### on the object's policy
+ ### the option :policy will automatically check for the corresponding method
+ ### on the object's policy
- action_link policy: :deactivate, secondary: :show, footer: :index do |l|
- l.content { h.deactivate_link_content('lines.actions.deactivate') }
- l.href { h.deactivate_line_referential_line_path(context[:line_referential], object) }
- l.method :put
- l.data confirm: h.t('lines.actions.deactivate_confirm')
- l.extra_class "delete-action"
- end
+ instance_decorator.action_link policy: :deactivate, secondary: :show, footer: :index do |l|
+ l.content { h.deactivate_link_content('lines.actions.deactivate') }
+ l.href { h.deactivate_line_referential_line_path(context[:line_referential], object) }
+ l.method :put
+ l.data confirm: h.t('lines.actions.deactivate_confirm')
+ l.extra_class "delete-action"
+ end
- action_link policy: :activate, secondary: :show, footer: :index do |l|
- l.content { h.activate_link_content('lines.actions.activate') }
- l.href { h.activate_line_referential_line_path(context[:line_referential], object) }
- l.method :put
- l.data confirm: h.t('lines.actions.activate_confirm')
- l.extra_class "delete-action"
- end
+ instance_decorator.action_link policy: :activate, secondary: :show, footer: :index do |l|
+ l.content { h.activate_link_content('lines.actions.activate') }
+ l.href { h.activate_line_referential_line_path(context[:line_referential], object) }
+ l.method :put
+ l.data confirm: h.t('lines.actions.activate_confirm')
+ l.extra_class "delete-action"
+ end
- action_link policy: :destroy, footer: true do |l|
- l.content { h.destroy_link_content('lines.actions.destroy') }
- l.href { h.line_referential_line_path(context[:line_referential], object) }
- l.method :delete
- l.data confirm: h.t('lines.actions.destroy_confirm')
- l.extra_class "delete-action"
+ instance_decorator.action_link policy: :destroy, footer: true do |l|
+ l.content { h.destroy_link_content('lines.actions.destroy') }
+ l.href { h.line_referential_line_path(context[:line_referential], object) }
+ l.method :delete
+ l.data confirm: h.t('lines.actions.destroy_confirm')
+ l.extra_class "delete-action"
+ end
end
end
diff --git a/app/views/layouts/navigation/_page_header.html.slim b/app/views/layouts/navigation/_page_header.html.slim
index 076c76de4..353361992 100644
--- a/app/views/layouts/navigation/_page_header.html.slim
+++ b/app/views/layouts/navigation/_page_header.html.slim
@@ -20,6 +20,7 @@ div.page_header
= yield :page_header_actions
- action_links = resource.action_links(params[:action]) rescue nil
+ - action_links ||= decorated_collection.action_links(params[:action]) rescue nil
- if action_links&.primary&.any? || action_links&.secondary&.any?
.row
.col-lg-12.text-right.mb-sm
diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim
index 399a2d8e1..2d64e5f73 100644
--- a/app/views/lines/index.html.slim
+++ b/app/views/lines/index.html.slim
@@ -1,7 +1,4 @@
- breadcrumb :lines, @line_referential
-- content_for :page_header_actions do
- - if policy(Chouette::Line).create?
- = link_to(t('lines.actions.new'), new_line_referential_line_path(@line_referential), class: 'btn btn-primary')
.page_content
.container-fluid