Class: EasyQueryAdapter
- Defined in:
- lib/redmine_extensions/easy_query_adapter.rb
Instance Method Summary collapse
- #add_available_column(name, options = {}) ⇒ Object
- #after_initialize ⇒ Object
- #create_entity_scope(options = {}) ⇒ Object
- #default_columns_names ⇒ Object
- #default_find_include ⇒ Object
- #default_find_joins ⇒ Object
- #default_find_preload ⇒ Object
- #default_list_columns ⇒ Object
- #entities(options = {}) ⇒ Object
- #entity ⇒ Object
- #entity_scope ⇒ Object
- #formatter ⇒ Object
- #init_formatter(object) ⇒ Object
- #queried_table_name ⇒ Object
- #set_entity_scope(entity, reference_collection = nil) ⇒ Object
- #to_partial_path ⇒ Object
Instance Method Details
#add_available_column(name, options = {}) ⇒ Object
131 132 133 134 135 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 131 def add_available_column(name, ={}) @available_columns ||= [] @available_columns << QueryColumn.new(name.to_sym, ) end |
#after_initialize ⇒ Object
28 29 30 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 28 def after_initialize self.filters ||= {} end |
#create_entity_scope(options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 90 def create_entity_scope(={}) scope = entity_scope.where(statement) includes = default_find_include.dup includes.concat(Array.wrap([:includes])) preload = default_find_preload.dup preload.concat(Array.wrap([:preload])) joins = default_find_joins.dup joins.concat(Array.wrap([:joins])) filters.keys.each do |filter| f = available_filters[filter] next if f.blank? includes.concat(Array.wrap(f[:includes])) if f[:includes] joins.concat(Array.wrap(f[:joins])) if f[:joins] end if filters columns.each do |c| includes.concat(Array.wrap(c.includes)) if c.includes joins.concat(Array.wrap(c.joins)) if c.joins preload.concat(Array.wrap(c.preload)) if c.preload end if project includes << :project end includes.uniq! joins.uniq! preload.uniq! scope.includes(includes).references(includes).joins(joins).preload(preload) end |
#default_columns_names ⇒ Object
141 142 143 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 141 def default_columns_names default_list_columns end |
#default_find_include ⇒ Object
32 33 34 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 32 def default_find_include [].freeze end |
#default_find_joins ⇒ Object
40 41 42 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 40 def default_find_joins [].freeze end |
#default_find_preload ⇒ Object
36 37 38 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 36 def default_find_preload [].freeze end |
#default_list_columns ⇒ Object
44 45 46 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 44 def default_list_columns [].freeze end |
#entities(options = {}) ⇒ Object
127 128 129 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 127 def entities(={}) create_entity_scope().order([:order]).to_a end |
#entity ⇒ Object
66 67 68 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 66 def entity self.class.queried_class end |
#entity_scope ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 70 def entity_scope if !@entity_scope.nil? @entity_scope elsif entity.respond_to?(:visible) entity.visible else entity end end |
#formatter ⇒ Object
48 49 50 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 48 def formatter @formatter end |
#init_formatter(object) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 52 def init_formatter(object) return @formatter if @formatter if entity begin formatter_klass = "#{entity}Formatter".constantize rescue NameError end end formatter_klass ||= EasyEntityFormatter @formatter = formatter_klass.new(object) end |
#queried_table_name ⇒ Object
145 146 147 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 145 def queried_table_name entity.table_name end |
#set_entity_scope(entity, reference_collection = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 80 def set_entity_scope(entity, reference_collection = nil) return nil if entity.nil? || reference_collection.nil? @entity_scope = entity.send(reference_collection.to_sym) self.filters = {} @entity_scope end |
#to_partial_path ⇒ Object
137 138 139 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 137 def to_partial_path 'easy_queries/index' end |