aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-12 15:32:51 +0200
committerTeddy Wing2017-06-12 15:32:51 +0200
commit13d921fa0a3c263f30feacc91b337551b99b5865 (patch)
treed121a8fc821968a816fe826f36021eae01441cc6
parent6fb1431b3a2d3649bbd56ebc527fb45803248c94 (diff)
downloadchouette-core-13d921fa0a3c263f30feacc91b337551b99b5865.tar.bz2
TableBuilder#build_column_header: Take Column instead of key & sortable
Now that we have a real `Column` type, it's much easier to just pass a `Column` object to the method instead of these disconnected attributes. Now we can get the column attributes from the object itself. Remove the `#key_or_name` method as it's no longer used. Also, I decided to reorder the `#build_column_header` arguments to make `column` the first argument. Figured this made more sense as the method is all about a column, and the collection model is this weird secondary thing. Refs #3479
-rw-r--r--app/helpers/table_builder_helper.rb19
1 files changed, 6 insertions, 13 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index e13dcd6c9..4f859dfea 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -12,11 +12,6 @@ module TableBuilderHelper
@attribute = attribute
@sortable = sortable
end
-
- def key_or_name
- return @key unless @key.nil?
- return @name unless @name.empty?
- end
end
class ColumnMustHaveKeyOrNameError < StandardError; end
@@ -60,9 +55,8 @@ module TableBuilderHelper
columns.map do |column|
hcont << content_tag(:th, build_column_header(
+ column,
collection.model,
- column.key_or_name,
- column.sortable,
params[:sort],
params[:direction]
))
@@ -178,9 +172,8 @@ module TableBuilderHelper
# TODO: clean up?
def build_column_header(
+ column,
collection_model,
- key,
- sortable,
sort_on,
sort_direction
)
@@ -188,11 +181,11 @@ module TableBuilderHelper
# (byebug) collection.model
# Referential(id: integer, name: string, slug: string, created_at: datetime, updated_at: datetime, prefix: string, projection_type: string, time_zone: string, bounds: string, organisation_id: integer, geographical_bounds: text, user_id: integer, user_name: string, data_format: string, line_referential_id: integer, stop_area_referential_id: integer, workbench_id: integer, archived_at: datetime, created_from_id: integer, ready: boolean)
# params = {"controller"=>"workbenches", "action"=>"show", "id"=>"1", "q"=>{"archived_at_not_null"=>"1", "archived_at_null"=>"1"}}
- return key if !sortable
+ return column.name if !column.sortable
- direction = (key.to_s == sort_on && sort_direction == 'desc') ? 'asc' : 'desc'
+ direction = (column.key.to_s == sort_on && sort_direction == 'desc') ? 'asc' : 'desc'
- link_to(params.merge({direction: direction, sort: key})) do
+ link_to(params.merge({direction: direction, sort: column.key})) do
pic1 = content_tag :span, '', class: "fa fa-sort-asc #{(direction == 'desc') ? 'active' : ''}"
pic2 = content_tag :span, '', class: "fa fa-sort-desc #{(direction == 'asc') ? 'active' : ''}"
@@ -200,7 +193,7 @@ module TableBuilderHelper
# TODO: figure out a way to maybe explicitise the dynamicness of getting the model type from the `collection`.
# TODO: rename `pics` to something like `icons` or arrow icons or some such
- (column_header_label(collection_model, key) + pics).html_safe
+ (column_header_label(collection_model, column.key) + pics).html_safe
end
end