diff options
| author | Teddy Wing | 2017-06-12 14:34:46 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-12 14:34:46 +0200 | 
| commit | e89aead78b6182a0789d53e46b230df54aee82f3 (patch) | |
| tree | f663a160e1ed68507ad8a1f962d335431c9fe6a6 /spec | |
| parent | 91f6bc0b56d4b51645470c9f470d874f92d38b50 (diff) | |
| download | chouette-core-e89aead78b6182a0789d53e46b230df54aee82f3.tar.bz2 | |
TableBuilder: Support a column-level sortable flag
Provides an option to set a column as non-sortable when defining the
column in the `table_builder` call.
Not written well, but it gets the idea across.
We allow column hash values to be hashes themselves (while continuing to
allow them to be `Proc`s and strings, this mixing of types is what I
really don't like). In that column-level hash, we can pass
`sortable: false` to disable sorting on that column. By default, sorting
is turned on for all columns.
Change the method signature of `sortable_columns`. Rename it to
`build_column_header`, as it will now generate a correct column header
regardless of whether the column is supposed to be sortable or not. I
moved some dependencies outside of the method, like `collection` (since
we only need the model from the collection), and the sort fields on
`params`. Unfortunately wasn't able to completely extricate `params` for
this method. Left the `params.merge` call that builds a link in this
method. Ideally I'd like that removed so that the method no longer
depends on global variables.
In `build_column_header`, if the column is not sortable, we return the
label defined by the key in the columns hash defined by the
`table_builder` caller. Otherwise, we build some HTML that includes
links on a couple of arrow buttons to enable sorting.
In `#thead`, we check to see if the columns hash value has a `sortable`
defined, in which case that flag gets used to determine what the column
header will be. I renamed the block variables here to be more
descriptive. Still not a huge fan of `attribute` as a name, though,
because it can now also be a Hash. Another aspect of this change that I
don't like.
In `#tbody`, needed to add a few extra lines to check whether
`attribute` is a Hash and get the real attribute if so. Really don't
like that either because it doesn't look good.
Update the sortable spec to pass a hash as the value of the column that
should not be sorted. It defines a `:sortable` key that tells the
builder not to allow this column to be sorted.
Refs #3479
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 5 | 
1 files changed, 4 insertions, 1 deletions
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index e29112653..029748dd2 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -191,7 +191,10 @@ describe TableBuilderHelper, type: :helper do        html_str = helper.table_builder_2(          companies,          { -          'ID Codif' => Proc.new { |n| n.try(:objectid).try(:local_id) }, +          'ID Codif' => { +            attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, +            sortable: false +          },            :name => 'name',            :phone => 'phone',            :email => 'email',  | 
