Module: Card::Set::Abstract::Filter::FilterForm::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb,
card/tmpsets/set/mod036-card-mod-search/abstract/03_filter/filter_form.rb

Instance Method Summary collapse

Instance Method Details

#active_filter?(field) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 72

def active_filter? field
  if filter_keys_from_params.present?
    filter_hash.key? field
  else
    default_filter? field
  end
end

#custom_quick_filtersObject

for override



46
47
48
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 46

def custom_quick_filters
  ""
end

#default_filter?(field) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 80

def default_filter? field
  default_filter_hash.key? field
end

#filter_action_pathObject



98
99
100
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 98

def filter_action_path
  path
end

#filter_fields(slot_selector: nil, sort_field: nil) ⇒ Object



58
59
60
61
62
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 58

def filter_fields slot_selector: nil, sort_field: nil
  form_args = { action: filter_action_path, class: "slotter" }
  form_args["data-slot-selector"] = slot_selector if slot_selector
  filter_form filter_form_data, sort_field, form_args
end

#filter_form(data = {}, sort_input_field = nil, form_args = {}) ⇒ Object

Parameters:

  • data (Hash) (defaults to: {})

    the filter categories. The hash needs for every category a hash with a label and a input_field entry.



52
53
54
55
56
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 52

def filter_form data={}, sort_input_field=nil, form_args={}
  haml :filter_form, categories: data,
                     sort_input_field: sort_input_field,
                     form_args: form_args
end

#filter_form_dataObject



64
65
66
67
68
69
70
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 64

def filter_form_data
  all_filter_keys.each_with_object({}) do |cat, h|
    h[cat] = { label: filter_label(cat),
               input_field: _render("filter_#{cat}_formgroup"),
               active: active_filter?(cat) }
  end
end

#filter_label(field) ⇒ Object



84
85
86
87
88
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 84

def filter_label field
  # return "Keyword" if field.to_sym == :name
  #
  filter_label_from_method(field) || filter_label_from_name(field)
end

#filter_label_from_method(field) ⇒ Object



90
91
92
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 90

def filter_label_from_method field
  try "#{field}_filter_label"
end

#filter_label_from_name(field) ⇒ Object



94
95
96
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 94

def filter_label_from_name field
  Card.fetch_name(field) { field.to_s.titleize }
end

#normalized_quick_filter_listObject



21
22
23
24
25
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 21

def normalized_quick_filter_list
  quick_filter_list.map do |hash|
    quick_filter_item hash.clone, hash.keys.first
  end
end

#quick_filter_item(hash, filter_key) ⇒ Object



31
32
33
34
35
36
37
38
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 31

def quick_filter_item hash, filter_key
  {
    text: (hash.delete(:text) || hash[filter_key]),
    class: css_classes(hash.delete(:class),
                       "_filter-link quick-filter-by-#{filter_key}"),
    filter: JSON(hash[:filter] || hash)
  }
end

#quick_filter_listObject

for override



41
42
43
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 41

def quick_filter_list
  []
end

#reset_filter_dataObject



27
28
29
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 27

def reset_filter_data
  JSON default_filter_hash
end

#view: filter_formObject

sort and filter ui



10
11
12
13
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 10

view :filter_form, cache: :never do
  filter_fields slot_selector: "._filter-result-slot",
                sort_field: _render(:sort_formgroup)
end

#view: quick_filtersObject



15
16
17
18
19
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 15

view :quick_filters, cache: :never do
  return "" unless quick_filter_list.present?

  haml :quick_filters, filter_list: normalized_quick_filter_list
end

#view: sort_formgroupObject



102
103
104
105
106
107
# File 'card/tmpsets/set/mod035-card-mod-search/abstract/03_filter/filter_form.rb', line 102

view :sort_formgroup, cache: :never do
  select_tag "sort",
             options_for_select(sort_options, current_sort),
             class: "pointer-select _filter-sort form-control",
             "data-minimum-results-for-search": "Infinity"
end