aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-07-03 18:34:58 +0200
committerTeddy Wing2017-07-06 12:30:59 +0200
commit205ce7c3fbdb025edc62a74b87d26cc237545f36 (patch)
treead01ab581491f6b057b21f51a7175cf183a63dcd
parent2d26c10de73fd6bfbf575dafee7b72e97844ff6b (diff)
downloadchouette-core-205ce7c3fbdb025edc62a74b87d26cc237545f36.tar.bz2
Lines#index: Use new `table_builder_2`
Convert the table of Lines to use the new version of the table builder. Update the view with the new calling format of the helper. The controller needs to decorate the `@lines` collection in order to make `#action_links` available to the table builder. Needed to update the "_filters.html.slim" template to call `#human_attribute_name` on the class instead of the collection, because we can't do that on a decorated collection. Refs #3479
-rw-r--r--app/controllers/lines_controller.rb9
-rw-r--r--app/views/lines/_filters.html.slim8
-rw-r--r--app/views/lines/index.html.slim50
3 files changed, 51 insertions, 16 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 1e2056aad..4b6448ce8 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -13,6 +13,15 @@ class LinesController < BreadcrumbController
def index
@hide_group_of_line = line_referential.group_of_lines.empty?
index! do |format|
+ @lines = ModelDecorator.decorate(
+ @lines,
+ with: LineDecorator,
+ context: {
+ line_referential: @line_referential,
+ current_organisation: current_organisation
+ }
+ )
+
format.html {
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim
index a0188f562..0e34b2e4c 100644
--- a/app/views/lines/_filters.html.slim
+++ b/app/views/lines/_filters.html.slim
@@ -8,19 +8,19 @@
.ffg-row
.form-group.togglable
- = f.label @lines.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: @line_referential.networks.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable
- = f.label @lines.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: @line_referential.companies.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable
- = f.label @lines.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: sorted_transport_mode, 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 @lines.human_attribute_name(:transport_submode), required: false, class: 'control-label'
+ = f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label'
= f.input :transport_submode_eq_any, collection: sorted_transport_submode, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.line.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.actions
diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim
index d3ee46b8a..630d63068 100644
--- a/app/views/lines/index.html.slim
+++ b/app/views/lines/index.html.slim
@@ -16,18 +16,44 @@
- if @lines.any?
.row
.col-lg-12
- = table_builder @lines,
- { 'ID Codifligne' => Proc.new { |n| n.objectid.local_id },
- :number => 'number',
- :name => 'name',
- :deactivated => Proc.new{|n| n.deactivated? ? t('false') : t('true')},
- 'networks.name' => Proc.new { |n| n.try(:network).try(:name) },
- 'companies.name' => Proc.new { |n| n.try(:company).try(:name) },
- :transport_mode => Proc.new { |n| n.transport_mode.nil? ? '-' : t("enumerize.line.transport_mode.#{n.try(:transport_mode)}") },
- :transport_submode => Proc.new { |n| n.transport_submode.nil? ? '-' : t("enumerize.line.transport_submode.#{n.try(:transport_submode)}") } },
- [:show, :delete],
- [],
- 'table has-filter has-search'
+ = table_builder_2 @lines,
+ [ \
+ 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: '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) } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :transport_mode, \
+ attribute: Proc.new { |n| n.transport_mode.nil? ? '-' : t("enumerize.line.transport_mode.#{n.try(:transport_mode)}") } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :transport_submode, \
+ attribute: Proc.new { |n| n.transport_submode.nil? ? '-' : t("enumerize.line.transport_submode.#{n.try(:transport_submode)}") } \
+ ) \
+ ],
+ links: [:show],
+ cls: 'table has-filter has-search'
= new_pagination @lines, 'pull-right'