Module: RedmineExtensions::QueryAdapter
- Defined in:
- lib/redmine_extensions/easy_query_adapter.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #add_available_column(name, options = {}) ⇒ 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
- #filters ⇒ Object
- #formatter ⇒ Object
- #init_formatter(object) ⇒ Object
- #output=(output_t) ⇒ Object
- #queried_table_name ⇒ Object
- #set_entity_scope(entity, reference_collection = nil) ⇒ Object
- #to_partial_path ⇒ Object
Instance Attribute Details
#outputs ⇒ Object
33 34 35 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 33 def outputs @outputs ||= ['list'] end |
Instance Method Details
#add_available_column(name, options = {}) ⇒ Object
144 145 146 147 148 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 144 def add_available_column(name, ={}) @available_columns ||= [] @available_columns << QueryColumn.new(name.to_sym, ) end |
#create_entity_scope(options = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 103 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
154 155 156 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 154 def default_columns_names default_list_columns end |
#default_find_include ⇒ Object
45 46 47 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 45 def default_find_include [].freeze end |
#default_find_joins ⇒ Object
53 54 55 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 53 def default_find_joins [].freeze end |
#default_find_preload ⇒ Object
49 50 51 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 49 def default_find_preload [].freeze end |
#default_list_columns ⇒ Object
57 58 59 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 57 def default_list_columns [].freeze end |
#entities(options = {}) ⇒ Object
140 141 142 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 140 def entities(={}) create_entity_scope().order([:order]).to_a end |
#entity ⇒ Object
79 80 81 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 79 def entity self.class.queried_class end |
#entity_scope ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 83 def entity_scope if !@entity_scope.nil? @entity_scope elsif entity.respond_to?(:visible) entity.visible else entity end end |
#filters ⇒ Object
41 42 43 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 41 def filters super || {} end |
#formatter ⇒ Object
61 62 63 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 61 def formatter @formatter end |
#init_formatter(object) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 65 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 |
#output=(output_t) ⇒ Object
37 38 39 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 37 def output=(output_t) self.outputs = Array.wrap(output_t) end |
#queried_table_name ⇒ Object
158 159 160 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 158 def queried_table_name entity.table_name end |
#set_entity_scope(entity, reference_collection = nil) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 93 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
150 151 152 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 150 def to_partial_path 'easy_queries/index' end |