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
- #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
27 28 29 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 27 def outputs @outputs ||= ['list'] end |
Instance Method Details
#add_available_column(name, options = {}) ⇒ Object
134 135 136 137 138 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 134 def add_available_column(name, ={}) @available_columns ||= [] @available_columns << QueryColumn.new(name.to_sym, ) end |
#create_entity_scope(options = {}) ⇒ Object
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 126 127 128 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 93 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
144 145 146 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 144 def default_columns_names default_list_columns end |
#default_find_include ⇒ Object
35 36 37 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 35 def default_find_include [].freeze end |
#default_find_joins ⇒ Object
43 44 45 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 43 def default_find_joins [].freeze end |
#default_find_preload ⇒ Object
39 40 41 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 39 def default_find_preload [].freeze end |
#default_list_columns ⇒ Object
47 48 49 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 47 def default_list_columns [].freeze end |
#entities(options = {}) ⇒ Object
130 131 132 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 130 def entities(={}) create_entity_scope().order([:order]).to_a end |
#entity ⇒ Object
69 70 71 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 69 def entity self.class.queried_class end |
#entity_scope ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 73 def entity_scope if !@entity_scope.nil? @entity_scope elsif entity.respond_to?(:visible) entity.visible else entity end end |
#formatter ⇒ Object
51 52 53 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 51 def formatter @formatter end |
#init_formatter(object) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 55 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
31 32 33 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 31 def output=(output_t) self.outputs = Array.wrap(output_t) end |
#queried_table_name ⇒ Object
148 149 150 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 148 def queried_table_name entity.table_name end |
#set_entity_scope(entity, reference_collection = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 83 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
140 141 142 |
# File 'lib/redmine_extensions/easy_query_adapter.rb', line 140 def to_partial_path 'easy_queries/index' end |