diff options
| -rw-r--r-- | app/controllers/referentials_controller.rb | 8 | ||||
| -rw-r--r-- | app/decorators/referential_line_decorator.rb | 64 | ||||
| -rw-r--r-- | app/views/referentials/_filters.html.slim | 6 | ||||
| -rw-r--r-- | app/views/referentials/show.html.slim | 45 |
4 files changed, 109 insertions, 14 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 9505a47f3..838c46168 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -27,6 +27,14 @@ class ReferentialsController < BreadcrumbController show! do |format| @referential = @referential.decorate @reflines = lines_collection.paginate(page: params[:page], per_page: 10) + @reflines = ModelDecorator.decorate( + @reflines, + with: ReferentialLineDecorator, + context: { + referential: referential, + current_organisation: current_organisation + } + ) format.json { render :json => { :lines_count => resource.lines.count, diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb new file mode 100644 index 000000000..55acf7ed9 --- /dev/null +++ b/app/decorators/referential_line_decorator.rb @@ -0,0 +1,64 @@ +class ReferentialLineDecorator < Draper::Decorator + decorates Chouette::Line + + delegate_all + + # Requires: + # 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) + ) + + links << Link.new( + content: h.t('routing_constraint_zones.index.title'), + href: h.referential_line_routing_constraint_zones_path( + context[:referential], + object + ) + ) + + if h.policy(Chouette::Line).create? && + context[:referential].organisation == context[:current_organisation] + links << Link.new( + content: h.t('actions.new'), + href: h.new_referential_line_path(context[:referential]) + ) + end + + if h.policy(object).update? + links << Link.new( + content: h.t('actions.edit'), + href: h.edit_referential_line_path(context[:referential], object) + ) + end + + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('actions.destroy'), + href: h.referential_line_path(context[:referential], object), + method: :delete, + data: { confirm: t('lines.actions.destroy_confirm') } + ) + 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) + ) + end + end + + links + end +end diff --git a/app/views/referentials/_filters.html.slim b/app/views/referentials/_filters.html.slim index 4b09ce1a6..9302ccaa8 100644 --- a/app/views/referentials/_filters.html.slim +++ b/app/views/referentials/_filters.html.slim @@ -8,15 +8,15 @@ .ffg-row .form-group.togglable - = f.label @reflines.human_attribute_name(:transport_mode), required: false, class: 'control-label' + = f.label Chouette::Line.human_attribute_name(:transport_mode), required: false, class: 'control-label' = f.input :transport_mode_eq_any, collection: @referential.lines.pluck(:transport_mode).uniq.compact, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.line.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } .form-group.togglable - = f.label @reflines.human_attribute_name(:network), required: false, class: 'control-label' + = f.label Chouette::Line.human_attribute_name(:network), required: false, class: 'control-label' = f.input :network_id_eq_any, collection: LineReferential.first.networks.order('name').pluck(:id), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>#{LineReferential.first.networks.find(l).name}</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } .form-group.togglable - = f.label @reflines.human_attribute_name(:company), required: false, class: 'control-label' + = f.label Chouette::Line.human_attribute_name(:company), required: false, class: 'control-label' = f.input :company_id_eq_any, collection: LineReferential.first.companies.order('name').pluck(:id), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>#{LineReferential.first.companies.find(l).name}</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } .actions diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index 17ba8ad88..d3687c3a7 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -38,17 +38,40 @@ .row .col-lg-12 / ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes] - = table_builder @reflines, - { 'ID Codifligne' => Proc.new { |n| n.objectid.local_id }, - :number => 'number', - :name => 'name', - :deactivated => Proc.new{ |n| n.deactivated? ? t('false') : t('true') }, - :transport_mode => Proc.new{ |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, - 'networks.name' => Proc.new { |n| n.try(:network).try(:name) }, - 'companies.name' => Proc.new { |n| n.try(:company).try(:name) } }, - [:show], - [], - 'table has-filter has-search' + = table_builder_2 @reflines, + [ \ + TableBuilderHelper::Column.new( \ + name: 'ID Codifligne', \ + attribute: Proc.new { |n| n.objectid.local_id }, \ + sortable: false \ + ), \ + TableBuilderHelper::Column.new( \ + key: :number, \ + attribute: 'number' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :name, \ + attribute: 'name' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :deactivated, \ + attribute: Proc.new { |n| n.deactivated? ? t('false') : t('true') } \ + ), \ + TableBuilderHelper::Column.new( \ + key: :transport_mode, \ + attribute: Proc.new { |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, \ + ), \ + TableBuilderHelper::Column.new( \ + key: 'networks.name', \ + attribute: Proc.new { |n| n.try(:network).try(:name) } \ + ), \ + TableBuilderHelper::Column.new( \ + key: 'companies.name', \ + attribute: Proc.new { |n| n.try(:company).try(:name) } \ + ) \ + ], + links: [:show], + cls: 'table has-filter has-search' = new_pagination @reflines, 'pull-right' |
