Class: RedmineExtensions::EasyQueryPresenter
Defined Under Namespace
Classes: Outputs
Instance Attribute Summary collapse
#model, #options
Instance Method Summary
collapse
#class, #h, present, presenter_for, register, registered_presenters, #update_options
Constructor Details
7
8
9
10
11
12
13
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 7
def initialize(*attrs)
super
@export_formats = ActiveSupport::OrderedHash.new
@export_formats[:csv] = {}
@export_formats[:pdf] = {}
@export_formats[:xlsx] = {}
end
|
Instance Attribute Details
5
6
7
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 5
def export_formats
@export_formats
end
|
#loading_group ⇒ Object
5
6
7
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 5
def loading_group
@loading_group
end
|
#page_module ⇒ Object
5
6
7
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 5
def page_module
@page_module
end
|
#row_limit ⇒ Object
5
6
7
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 5
def row_limit
@row_limit
end
|
Instance Method Details
Returns a additional fast-icons buttons
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 132
def additional_beginning_buttons(entity, options={})
return ''.html_safe if model.nil? || entity.nil?
easy_query_additional_buttons_method = "#{model.class.name.underscore}_additional_beginning_buttons".to_sym
additional_buttons = ''
if h.respond_to?(easy_query_additional_buttons_method)
additional_buttons = h.send(easy_query_additional_buttons_method, entity, options)
end
return additional_buttons.html_safe
end
|
144
145
146
147
148
149
150
151
152
153
154
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 144
def additional_ending_buttons(entity, options={})
return ''.html_safe if model.nil? || entity.nil?
easy_query_additional_buttons_method = "#{model.class.name.underscore}_additional_ending_buttons".to_sym
additional_buttons = ''
if h.respond_to?(easy_query_additional_buttons_method)
additional_buttons = h.send(easy_query_additional_buttons_method, entity, options)
end
return additional_buttons.html_safe
end
|
#available_columns_for_select ⇒ Object
194
195
196
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 194
def available_columns_for_select
h.options_for_select (model.available_columns - model.columns).reject(&:frozen?).collect {|column| [column.caption(true), column.name]}
end
|
#available_outputs ⇒ Object
26
27
28
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 26
def available_outputs
outputs.available_outputs
end
|
#block_name ⇒ Object
89
90
91
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 89
def block_name
options[:block_name] || ( page_module ? page_module.page_zone_module.module_name : nil )
end
|
#column_header(column, options = {}) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 157
def column_header(column, options={})
if !options[:disable_sort] && column.sortable
if page_module
h.(page_module, model, column.name.to_s, {:class => column.css_classes, :caption => column.caption, :default_order => column.default_order})
else
h.(column.name.to_s, {:class => column.css_classes, :caption => column.caption, :default_order => column.default_order})
end
else
h.content_tag(:th, column.caption, {:class => column.css_classes})
end
end
|
#default_name ⇒ Object
41
42
43
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 41
def default_name
h.l(self.class.name.underscore, :scope => [:easy_query, :name])
end
|
#display_columns_select?(action = 'edit') ⇒ Boolean
57
58
59
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 57
def display_columns_select?(action='edit')
true
end
|
#display_group_by_select?(action = 'edit') ⇒ Boolean
63
64
65
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 63
def display_group_by_select?(action='edit')
true
end
|
34
35
36
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 34
def display_save_button
true
end
|
#display_settings?(action) ⇒ Boolean
66
67
68
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 66
def display_settings?(action)
true
end
|
#display_sort_options?(action = 'edit') ⇒ Boolean
60
61
62
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 60
def display_sort_options?(action='edit')
true
end
|
#entities(options = {}) ⇒ Object
15
16
17
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 15
def entities(options={})
@entities ||= @options[:entities] || h.instance_variable_get(:@entities) || model.entities(options)
end
|
#entities_for_export(options = {}) ⇒ Object
Also known as:
prepare_export_result
226
227
228
229
230
231
232
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 226
def entities_for_export(options={})
if model.grouped?
return model.groups(options.merge(:include_entities => true))
else
return {nil => {:entities => model.entities(options), :sums => model.send(:summarize_entities, entities)}}
end
end
|
#entities_for_html(options = {}) ⇒ Object
Also known as:
prepare_html_result
214
215
216
217
218
219
220
221
222
223
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 214
def entities_for_html(options={})
options[:limit] ||= row_limit
return model.entities_for_group(loading_group, options) if loading_group
if model.grouped?
return model.groups(options)
else
return model.entities(options)
end
end
|
#entity_count(options = {}) ⇒ Object
19
20
21
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 19
def entity_count(options={})
@entity_count ||= h.instance_variable_get(:@entity_count) || model.entity_count(options)
end
|
#entity_count_for_list(options = {}) ⇒ Object
Returns count of entities on the list action returns groups_count if query is grouped and entity_count otherwise
206
207
208
209
210
211
212
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 206
def entity_count_for_list(options={})
if model.grouped?
return model.groups_count(options)
else
return model.entity_count(options)
end
end
|
#entity_css_classes(entity, options = {}) ⇒ Object
122
123
124
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 122
def entity_css_classes(entity, options={})
entity.css_classes if entity.respond_to?(:css_classes)
end
|
#entity_easy_query_path(options = {}) ⇒ Object
259
260
261
262
263
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 259
def entity_easy_query_path(options = {})
options = options.dup
h.polymorphic_path([(options.delete(:project) || self.project), self.entity], options)
end
|
#entity_list(entities = self.entities) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 110
def entity_list(entities=self.entities)
if model.entity.class.respond_to?(:each_with_easy_level)
model.entity.class.each_with_easy_level(entities) do |entity, level|
yield entity, level
end
else
entities.each do |entity|
yield entity, nil
end
end
end
|
#entity_pages ⇒ Object
22
23
24
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 22
def entity_pages
h.instance_variable_get(:@entity_pages)
end
|
#filters_active? ⇒ Boolean
235
236
237
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 235
def filters_active?
model.filters.any?
end
|
#filters_for_select ⇒ Object
Get values from Proc, select only valid filters, sort and cache list of filters. Return array of arrays
171
172
173
174
175
176
177
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 171
def filters_for_select
@filters_for_select ||= model.available_filters.select do |name, filter|
filter.valid?
end.sort { |a, b| a[1] <=> b[1] }
return @filters_for_select
end
|
#from_params(params) ⇒ Object
—– SERIALIZATION HELPERS ——
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 268
def from_params(params)
return if params.nil?
if params['set_filter'] == '1'
model.filters = {}
model.group_by = ''
else
model.filters = model.default_filter
model.group_by = model.default_group_by
end
if params['fields'] && params['fields'].is_a?(Array)
params['values'] ||= {}
params['fields'].each do |field|
model.add_filter(field, params['operators'][field], params['values'][field])
end
else
model.available_filters.keys.each do |field|
model.add_short_filter(field, params[field]) if params[field]
end
end
model.group_by = params['group_by'] if params['group_by'].present?
model.show_sum_row = params['show_sum_row'].try(:to_boolean) if params['show_sum_row'].present?
model.load_groups_opened = params['load_groups_opened'].try(:to_boolean) if params['load_groups_opened'].present?
self.outputs_from_params(params)
if params['easy_query'] && params['easy_query']['columns_to_export'] == 'all'
model.column_names = available_columns.collect { |col| col.name.to_s }
elsif params['column_names'] && params['column_names'].is_a?(Array)
if params['column_names'].first && params['column_names'].first.include?(',')
model.column_names = params['column_names'].first.split(',')
else
model.column_names = params['column_names']
end
end
if params['settings'] && params['settings'].is_a?(Hash)
if model.settings.is_a?(Hash)
model.settings.merge!(params['settings'])
else
model.settings = params['settings'].dup
end
end
self.set_additional_params(params)
model.sort_criteria = params['sort_criteria'] if params['sort_criteria']
@sort_helper = SortHelper::SortCriteria.new
if params['sort'].present?
@sort_helper.available_criteria = sortable_columns
@sort_helper.from_param(params['sort'])
@sort_helper.criteria = model.sort_criteria_init if @sort_helper.empty?
model.sort_criteria = @sort_helper.to_a
end
if params['easy_query_q']
model.use_free_search = true
model.free_search_question = params['easy_query_q']
model.free_search_question.strip!
model.free_search_tokens = model.free_search_question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect { |m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '') }
model.free_search_tokens = model.free_search_tokens.uniq.select { |w| w.length > 1 }
model.free_search_tokens.slice! 5..-1 if model.free_search_tokens.size > 5
end
end
|
#has_default_filter? ⇒ Boolean
69
70
71
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 69
def has_default_filter?
model.filters == model.default_filter
end
|
#model_name ⇒ Object
81
82
83
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 81
def model_name
EasyQuery.model_name
end
|
#modul_uniq_id ⇒ Object
92
93
94
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 92
def modul_uniq_id
options[:modul_uniq_id] || ''
end
|
45
46
47
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 45
def name
model.new_record? ? default_name : model.name
end
|
#operators_for_select(filter_type) ⇒ Object
179
180
181
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 179
def operators_for_select(filter_type)
EasyQueryFilter.operators_by_filter_type[filter_type].collect { |o| [l(EasyQueryFilter.operators[o]), o] }
end
|
183
184
185
186
187
188
189
190
191
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 183
def other_formats_links(options={})
if options[:no_container]
yield RedmineExtensions::Export::EasyOtherFormatsBuilder.new(h)
else
h.concat('<div class="other-formats">'.html_safe)
yield RedmineExtensions::Export::EasyOtherFormatsBuilder.new(h)
h.concat('</div>'.html_safe)
end
end
|
30
31
32
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 30
def outputs
@outputs ||= Outputs.new(self)
end
|
#outputs_from_params(params) ⇒ Object
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 342
def outputs_from_params(params)
if params['outputs'].is_a?(Array)
model.outputs = params['outputs'] & available_outputs.collect(&:to_s)
else
model.outputs = available_outputs.select do |output|
if params[output.to_s].present?
true
elsif !params['output'].blank?
params['output'] == output
end
end
end
model.outputs = ['table'] if model.outputs.empty?
end
|
#path(params = {}) ⇒ Object
251
252
253
254
255
256
257
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 251
def path(params={})
if self.new_record?
entity_easy_query_path(self.to_params.merge(params))
else
entity_easy_query_path({:query_id => model}.merge(params))
end
end
|
#prepare_table_render ⇒ Object
106
107
108
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 106
def prepare_table_render
end
|
#render_exports? ⇒ Boolean
53
54
55
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 53
def render_exports?
outputs.table?
end
|
#render_zoom_links ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 96
def render_zoom_links
return unless render_zoom_links?
if self.page_module
h.render(:partial => 'easy_queries/zoom_links', :locals => {:query => self, :base_url => {}, :block_name => self.page_module.page_zone_module.module_name})
else
h.render(:partial => 'easy_queries/zoom_links', :locals => {:query => self})
end
end
|
#render_zoom_links? ⇒ Boolean
73
74
75
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 73
def render_zoom_links?
false
end
|
#selected_columns_for_select ⇒ Object
198
199
200
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 198
def selected_columns_for_select
h.options_for_select (model.columns & model.available_columns).reject(&:frozen?).collect {|column| [column.caption(true), column.name]}
end
|
#set_additional_params(params) ⇒ Object
357
358
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 357
def set_additional_params(params)
end
|
#show_free_search? ⇒ Boolean
49
50
51
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 49
def show_free_search?
options.key?(:show_free_search) ? options[:show_free_search] : options[:page_module].nil? && model.searchable_columns.any?
end
|
77
78
79
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 77
def to_model
self
end
|
#to_params ⇒ Object
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 360
def to_params
easy_query_params = {:set_filter => '1', :type => model.class.name, :fields => [], :operators => {}, :values => {}}
model.filters.each do |f, o|
easy_query_params[:fields] << f
easy_query_params[:operators][f] = o[:operator]
easy_query_params[:values][f] = o[:values]
end
easy_query_params[:group_by] = model.group_by
easy_query_params[:column_names] = (model.column_names || []).collect(&:to_s)
easy_query_params[:load_groups_opened] = model.load_groups_opened ? '1' : '0'
easy_query_params[:show_sum_row] = model.show_sum_row ? '1' : '0'
easy_query_params[:show_avatars] = model.show_avatars ? '1' : '0'
easy_query_params
end
|
#to_partial_path ⇒ Object
85
86
87
|
# File 'app/presenters/redmine_extensions/easy_query_presenter.rb', line 85
def to_partial_path
'easy_queries/easy_query'
end
|