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

Instance Method Summary collapse

Methods included from DataAccessor

#association_attr?, #combobox_options_for_column, #data_adapter, #normalize_attr, #normalize_attrs, #primary_key_attr?, #set_default_virtual

Instance Method Details

#attributesObject



67
68
69
70
71
# File 'lib/netzke/basepack/search_panel.rb', line 67

def attributes
  config[:fields].map do |field|
    [field[:name], field[:field_label]]
  end
end

#data_classObject



54
55
56
# File 'lib/netzke/basepack/search_panel.rb', line 54

def data_class
  @data_class ||= config[:model].constantize
end

#default_queryObject

Builds default query search panel, where each field is presented



46
47
48
49
50
51
52
# File 'lib/netzke/basepack/search_panel.rb', line 46

def default_query
  data_class.column_names.map do |c|
    column_type = data_class.columns_hash[c].type
    operator = (self.class.js_property(:attribute_operators_map)[column_type] || []).first.try(:fetch, 0) || "matches"
    {:attr => c, :attr_type => column_type, :operator => operator}
  end
end

#js_configObject



58
59
60
61
62
63
64
65
# File 'lib/netzke/basepack/search_panel.rb', line 58

def js_config
  super.merge(
    :attrs => attributes,
    :attrs_hash => data_class.column_names.inject({}){ |hsh,c| 
      hsh.merge(c => data_adapter.get_property_type(data_class.columns_hash[c])) },
    :preset_query => (config[:load_last_preset] ? last_preset.try(:fetch, "query") : config[:query]) || []
  )
end

#last_presetObject



73
74
75
# File 'lib/netzke/basepack/search_panel.rb', line 73

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