4 class FilterList < Base
12 @filter_item_name = @model_list_manifest.filter_item_name
13 @filter_key = @model_list_manifest.filter_key
16 def where_condition filter_item_id
17 w = self.base_where_condition
18 w += ' and ' unless w.blank?
19 [w + @table_name + '.' + @filter_key + ' = ?', filter_item_id]
24 w.merge!({@filter_item_name => {} }) unless w[@filter_item_name]
28 def items operators, options, offset, page_size
29 filter_item_id = options[:id]
30 @model.where(self.where_condition(filter_item_id)).includes(self.include_hash).order(self.order).offset(offset).limit(page_size)
33 def count operators, options
34 filter_item_id = options[:id]
35 @model.where(self.where_condition(filter_item_id)).includes(self.include_hash).count
38 def self._add_action item_name, action_name, list_name, list_conf
40 model = item_name.classify.constantize
41 controller_name = model.plural + 'Controller'
42 controller = controller_name.constantize
43 list_list_conf = Pettanr::Application::manifest.list(item_name).lists[list_name] || {}
44 from = list_list_conf['from']
45 filter_model = from.classify.constantize
46 filter_key = list_list_conf['filter_key']
47 return if controller.method_defined?(action_name)
48 controller.define_method(action_name) do
49 filter_list filter_model, params