3 class FilterList < Base
11 @filter_item_name = @model_list_manifest.filter_item_name
12 @filter_key = @model_list_manifest.filter_key
15 def where_condition filter_item_id
17 w += ' and ' unless w.blank?
18 [w + @table_name + '.' + @filter_key + ' = ?', filter_item_id]
23 w.merge({@filter_item_name => {} }) unless w[@filter_item_name]
26 def items operators, options, offset, page_size
27 filter_item_id = options[:id]
28 @model.where(self.where_condition(filter_item_id)).includes(self.include_hash).order(self.order).offset(offset).limit(page_size)
31 def count operators, options
32 filter_item_id = options[:id]
33 @model.where(self.where_condition(filter_item_id)).includes(self.include_hash).count
36 def self._add_action item_name, action_name, list_name, list_conf
38 model = item_name.classify.constantize
39 controller_name = model.plural + 'Controller'
40 controller = controller_name.constantize
41 list_list_conf = Pettanr::Application::manifest.list(item_name).lists[list_name] || {}
42 from = list_list_conf['from']
43 filter_model = from.classify.constantize
44 filter_key = list_list_conf['filter_key']
45 return if controller.method_defined?(action_name)
46 controller.define_method(action_name) do
47 filter_list filter_model, params