Skip to content

Commit

Permalink
display grouped by when human_conditions is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Aug 11, 2017
1 parent ed1db88 commit 6907116
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<%= columns.collect {|column| active_scaffold_human_condition_for(column)}.compact.to_sentence %>
<%= columns.collect {|column| active_scaffold_human_condition_for(column)}.compact.to_sentence %>
<%= tag(:br) if columns.present? && grouped_search? %>
<%= as_(:grouped_by, column: active_scaffold_grouped_by_label) if grouped_search? %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ en:
found: Found
future: Future
group_by: Group by
grouped_by: Grouped by %{column}
hide: "(Hide)"
hours: Hours
human_conditions:
Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/actions/field_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def do_search
active_scaffold_conditions << search_condition
filtered_columns << column
end
if filtered_columns.present?
if filtered_columns.present? || grouped_search?
@filtered = active_scaffold_config.field_search.human_conditions ? filtered_columns : true
end

Expand Down
7 changes: 7 additions & 0 deletions lib/active_scaffold/helpers/human_condition_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def active_scaffold_human_condition_for(column)
end
end

def active_scaffold_grouped_by_label
text, _ = active_scaffold_config.field_search.group_options.find do |text, value|
(value || text) == field_search_params['active_scaffold_group']
end
active_scaffold_translated_option(active_scaffold_group_column, text).first if text
end

def format_human_condition(column, opt, from = nil, to = nil)
attribute = column.active_record_class.human_attribute_name(column.name)
"#{attribute} #{as_(opt).downcase} #{from} #{to}"
Expand Down

0 comments on commit 6907116

Please sign in to comment.