Module: PureAdmin::TableFiltersHelper
- Defined in:
- app/helpers/pure_admin/table_filters_helper.rb
Overview
Helper methods for table filters functionality.
The recommended way of using this helper is
filters_for admin_members_path do |filter|
filter.on :query the default is a text field
filter.on :answer, options: %w(Yes No) if given an options hash, a select will be used
filter.on :status, as: :active_status when given :active_status it will use the options
All, Active, and Inactive and the default of
Active. However these can be overridden by
:options and :default respectively.
filter.on :starts_on, as: :date when given :date, it will enable the pure_date
input type
end
Defined Under Namespace
Classes: TableFiltersBuilder
Instance Method Summary collapse
-
#filters_for(path, options = {}) { ... } ⇒ Object
Renders a table filters section to the view using the table filter builder DSL.
-
#table_filter_item(attribute, options = {}) { ... } ⇒ Object
Renders a table filter item to the view.
-
#table_filters(path, options = {}) { ... } ⇒ Object
Renders the table filters form to the view.
Instance Method Details
#filters_for(path, options = {}) { ... } ⇒ Object
Renders a table filters section to the view using the table filter builder DSL.
113 114 115 116 117 118 |
# File 'app/helpers/pure_admin/table_filters_helper.rb', line 113 def filters_for(path, = {}, &block) builder = TableFiltersBuilder.new(self) table_filters(path, ) do capture(builder, &block) end end |
#table_filter_item(attribute, options = {}) { ... } ⇒ Object
Renders a table filter item to the view.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/pure_admin/table_filters_helper.rb', line 57 def table_filter_item(attribute, = {}, &block) if block_given? field = capture(&block) else type = .delete(:as) || :string # If we're given an options array, we assume it to be a select filter. # This allows for more concise code in the form # table_filter_item :status, options: %w(Yes No) # or # filter.on :status, options %W(Yes No) type = :select if [:options].present? # We define the :active_status type to shortcut a common filter type. if type == :active_status type = :select [:options] ||= %w(All Active Inactive) [:default] ||= 'Active' end input_html = .delete(:input_html) || {} input_html[:class] = merge_html_classes('filter-control', input_html[:class]) # Defaulting to a simple text field, we choose which field to output here. # @note if at some point we wish to add a new field type, here is the place to add it case type when :select [:options] ||= [] field = select_tag(attribute, ([:options], params[attribute.to_sym] || [:default]), input_html) when :date input_html[:class] = merge_html_classes('pure-admin-date', input_html[:class]) field = text_field_tag(attribute, params[attribute.to_sym], input_html) icon = content_tag(:span, nil, class: 'input-addon fa fa-fw fa-calendar') field = content_tag(:div, icon + field, class: 'addon-wrapper') else # :string field = text_field_tag(attribute, params[attribute.to_sym], input_html) end end label = ''.html_safe if [:label] != false label_html = .delete(:label_html) || {} label_text = .delete(:label) || attribute.to_s.titleize label = label_tag(attribute, label_text, label_html) end content_tag(:div, label + field, class: 'filter-group') end |
#table_filters(path, options = {}) { ... } ⇒ Object
Renders the table filters form to the view.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/pure_admin/table_filters_helper.rb', line 22 def table_filters(path, = {}, &block) [:class] = merge_html_classes('pure-form pure-form-stacked table-filters js-partial-refresh clear-fix', [:class]) [:remote] = false || [:remote] [:method] ||= :get content = capture(&block) if content content << content_tag(:div, submit_tag('Go', class: 'pure-button pure-button-primary'), class: 'filter-group filter-submit') content << hidden_field_tag(:sort, params[:sort]) content << hidden_field_tag(:reverse_order, params[:reverse_order]) form_tag path, do content end end end |