Class: Netzke::Basepack::SearchPanel

Inherits:
Base
  • Object
show all
Includes:
DataAccessor
Defined in:
lib/netzke/basepack/search_panel.rb

Overview

Configuration

load_last_preset - on load, tries to load the latest saved preset

Constant Summary

ATTRIBUTE_OPERATORS_MAP =
{
  integer: [
    ["eq", I18n.t(i18n_path % 'equals')],
    ["gt", I18n.t(i18n_path % 'greater_than')],
    ["lt", I18n.t(i18n_path % 'less_than')]
  ],
  text: [
    ["contains", I18n.t(i18n_path % 'contains')] # same as matches => %string%
  ],
  string: [
    ["contains", I18n.t(i18n_path % 'contains')], # same as matches => %string%
    ["matches", I18n.t(i18n_path % 'matches')]
  ],
  boolean: [
    ["is_any", I18n.t(i18n_path % 'is_true')],
    ["is_true", I18n.t(i18n_path % 'is_true')],
    ["is_false", I18n.t(i18n_path % 'is_false')]
  ],
  date: [
    ["eq", I18n.t(i18n_path % 'date_equals')],
    ["gt", I18n.t(i18n_path % 'after')],
    ["lt", I18n.t(i18n_path % 'before')],
    ["gteq", I18n.t(i18n_path % 'on_or_after')],
    ["lteq", I18n.t(i18n_path % 'on_or_before')]
  ]
}

Instance Method Summary collapse

Methods included from DataAccessor

#model, #model_adapter

Instance Method Details

#attributesObject



56
57
58
59
60
61
# File 'lib/netzke/basepack/search_panel.rb', line 56

def attributes
  config[:fields].map do |f|
    f[:type] ||= :string
    {name: f[:name], field_label: f[:field_label], type: f[:type]}
  end
end

#configure_client(c) ⇒ Object



50
51
52
53
54
# File 'lib/netzke/basepack/search_panel.rb', line 50

def configure_client(c)
  super
  c.attrs = config[:fields]
  c.preset_query = (config[:load_last_preset] ? last_preset.try(:fetch, "query") : config[:query]) || []
end

#last_presetObject



63
64
65
# File 'lib/netzke/basepack/search_panel.rb', line 63

def last_preset
  (state[:presets] || []).last
end