diff options
| author | Teddy Wing | 2017-06-15 12:33:57 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-15 13:52:31 +0200 |
| commit | d79a0db0301d14e0ab4e5ecb2d8b60560f4490a9 (patch) | |
| tree | 9749f6cdde5431a013028ce8e9e1944ddf6febb0 /app/helpers/table_builder_helper | |
| parent | 34ee3f25dd9e903e27bbbbcdf85ae2803a869c76 (diff) | |
| download | chouette-core-d79a0db0301d14e0ab4e5ecb2d8b60560f4490a9.tar.bz2 | |
TableBuilder: Make table-level `sortable` work
We need the ability to say that an entire table is not sortable. By
default, all tables are sortable, and individual columns can have
sorting deactivated. This blanket deactivates sorting for all columns.
Take our `sortable` argument and pass it to `#thead`. Then
`#build_column_header` takes that value into account when creating a
header column value.
The actual label used in the column header is determined by the old
`#column_header_label` method. We've now moved it into the
`TableBuilderHelper::Column` class because it makes more sense there.
The method will now return the column's `:name` property if it was
defined, and otherwise gets the translation for `:key` as before.
Add a test on `TableBuilderHelper` that verifies that a table with
`sortable: false` returns the correct HTML without sorting links.
Refs #3479
Diffstat (limited to 'app/helpers/table_builder_helper')
| -rw-r--r-- | app/helpers/table_builder_helper/column.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb index 54e63104d..b2fdf2b73 100644 --- a/app/helpers/table_builder_helper/column.rb +++ b/app/helpers/table_builder_helper/column.rb @@ -20,6 +20,15 @@ module TableBuilderHelper obj.try(@attribute) end end + + def header_label(model = nil) + return @name unless name.empty? + + # Transform `Chouette::Line` into "line" + model_key = model.to_s.demodulize.underscore + + I18n.t("activerecord.attributes.#{model_key}.#{@key}") + end end |
