@model = @item_name.classify.constantize
@offset = (@page -1) * @page_size
@table_name = @model.table_name
+ if @model.content?
+ @owner_model = @model.owner_model
+ @owner_table_name = @owner_model.table_name if @owner_model
+ end
end
def page_number prm = nil
end
def includes
- @model.list_opt
+ @owner_model ? {@owner_model.item_name => {}} : {}
end
def order
end
def paginate
- Kaminari.paginate_array(Array.new(@model.where(self.where()).includes(self.includes).count, nil)).page(@offset).per(@page_size)
+ c = @model.where(self.where()).includes(self.includes).count
+ Kaminari.paginate_array(Array.new(c, nil)).page(@offset).per(@page_size)
end
end
class PublicList < BaseList
end
- class SystemResourceList < BaseList
- def items
- @model.where(self.where()).includes(@model.list_opt).order(@model.order).offset(@offset).limit(@page_size).delete_if {|sbt|
- Pettanr::Application.manifest.system_resources.speech_balloon_templates[sbt.classname] == nil
- }
- end
-
- def all_items
- @model.where(self.where()).includes(@model.list_opt).order(@model.order).delete_if {|sbt|
- Pettanr::Application.manifest.system_resources.speech_balloon_templates[sbt.classname] == nil
- }
- end
-
- def paginate
- Kaminari.paginate_array(Array.new(@model.where(self.where()).includes(@model.list_opt).count, nil)).page(@offset).per(@page_size)
- end
-
- end
-
class PrivateList < BaseList
def where
case @model.owner_type
when :artist
operator = @operators.artist
end
- [@model.plural + '.' + @model.owner_type.to_s + '_id = ?', operator.id]
+ t = @owner_model ? @owner_table_name : @table_name
+ [t + '.' + @model.owner_type.to_s + '_id = ?', operator.id]
end
end
@association_model_name = @association_conf['model']
@association_model = @association_model_name.classify.constantize
@foreign_key = @association_conf['foreign_key']
- @with_model_name = @association_conf['with']
end
def where parent_item
w = @model.list_where
w += ' and ' unless w.blank?
+ t = @owner_model ? @owner_table_name : @table_name
[w + @association_model_name + '.' + @foreign_key + ' = ?', parent_item.id]
end
def includes
- w = @with_model_name ? {@with_model_name.classify.constantize.table_name => {}} : {}
- {@association_model.table_name => w }
+ @with_model_name ? {@with_model_name.classify.constantize.table_name => {}} : {}
+ w = @owner_model ? {@owner_model.item_name => {}} : {}
+ w.merge({@association_model.table_name => {} })
end
def items parent_item
end
def paginate parent_item
- Kaminari.paginate_array(Array.new(@model.where(self.where(parent_item)).includes(self.includes).count, nil)).page(@offset).per(@page_size)
+ Kaminari.paginate_array(Array.new(@model.where(self.where(parent_item).includes(self.includes)).count, nil)).page(@offset).per(@page_size)
end
end
end
def includes
- w = @with_model_name ? {@with_model_name => {}} : {}
- {@from => w }
+ w = @owner_model ? {@owner_model.item_name => {}} : {}
+ w.merge({@from => {} })
end
def items filter_item
end
def paginate filter_item
- Kaminari.paginate_array(Array.new(@model.where(self.where(filter_item)).includes(self.includes).count, nil)).page(@offset).per(@page_size)
+ Kaminari.paginate_array(Array.new(@model.where(self.where(filter_item).includes(self.includes)).count, nil)).page(@offset).per(@page_size)
end
end
- class WithFilterList < FilterList
+ class ThroughFilterList < FilterList
def initialize page, page_size, operators, item_name, list_name, conf, manifest
super
- @with = @list_list_conf['with']
+ @through = @list_list_conf['through']
end
def includes
- {@from => {@with => {}} }
+ {@through => {@from => {}} }
end
- end
-
- class ThroughFilterList < FilterList
- def initialize page, page_size, operators, item_name, list_name, conf, manifest
- super
- @through = @list_list_conf['through']
+ def where filter_item
+ w = @model.list_where
+ w += ' and ' unless w.blank?
+ [w + @through + '.' + @filter_key + ' = ?', filter_item.id]
end
+ end
+
+ class ElementFilterList < FilterList
def includes
- {@through => {@from => {}} }
+ {@owner_model.item_name => {}}
end
def where filter_item
w = @model.list_where
w += ' and ' unless w.blank?
- [w + @through + '.' + @filter_key + ' = ?', filter_item.id]
+ [w + @owner_table_name + '.' + @filter_key + ' = ?', filter_item.id]
end
end
@@types = {
- 'public' => PublicList, 'system_resource' => SystemResourceList, 'private' => PrivateList,
- 'has_many' => HasManyList, 'filter' => FilterList, 'with_filter' => WithFilterList,
- 'through_filter' => ThroughFilterList
+ 'public' => PublicList, 'private' => PrivateList,
+ 'has_many' => HasManyList, 'filter' => FilterList,
+ 'through_filter' => ThroughFilterList, 'element_filter' => ElementFilterList
}
def initialize list_manifest
@list_manifest = list_manifest
end
def open list_name, page, page_size, operators
+ raise "undefined list for #{@item_name}::#{list_name}\nconf:#{@list_conf}\n" unless @lists[list_name]
@lists[list_name].new page, page_size, operators, @item_name, list_name, @list_conf, @manifest
end