Class: RedmineExtensions::QueryOutput
- Inherits:
-
Object
- Object
- RedmineExtensions::QueryOutput
show all
- Defined in:
- lib/redmine_extensions/query_output.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(query_presenter, outputs = nil) ⇒ QueryOutput
Returns a new instance of QueryOutput.
42
43
44
45
|
# File 'lib/redmine_extensions/query_output.rb', line 42
def initialize(query_presenter, outputs=nil)
@query = query_presenter
@outputs = outputs || query_presenter.outputs
end
|
Instance Attribute Details
Returns the value of attribute query.
4
5
6
|
# File 'lib/redmine_extensions/query_output.rb', line 4
def query
@query
end
|
Class Method Details
.available_for?(query) ⇒ Boolean
Take query and decide if it is possible to render it by this output
38
39
40
|
# File 'lib/redmine_extensions/query_output.rb', line 38
def self.available_for?(query)
query.class > Query
end
|
.available_output_klasses_for(query) ⇒ Object
22
23
24
25
26
|
# File 'lib/redmine_extensions/query_output.rb', line 22
def self.available_output_klasses_for(query)
registered_outputs.select do |name, output|
output.available_for?(query)
end.values
end
|
.available_outputs_for(query) ⇒ Object
16
17
18
19
20
|
# File 'lib/redmine_extensions/query_output.rb', line 16
def self.available_outputs_for(query)
registered_outputs.select do |name, output|
output.available_for?(query)
end.keys
end
|
32
33
34
|
# File 'lib/redmine_extensions/query_output.rb', line 32
def self.key
self.name.split('::').last.sub(/Output$/, '').underscore
end
|
.output_klass_for(output) ⇒ Object
28
29
30
|
# File 'lib/redmine_extensions/query_output.rb', line 28
def self.output_klass_for(output)
registered_outputs[output.to_sym]
end
|
.register_output(klass, options = {}) ⇒ Object
7
8
9
10
|
# File 'lib/redmine_extensions/query_output.rb', line 7
def self.register_output(klass, options={})
register_as = (options[:as] || klass.key).to_sym
registered_outputs[register_as] = klass
end
|
.registered_outputs ⇒ Object
12
13
14
|
# File 'lib/redmine_extensions/query_output.rb', line 12
def self.registered_outputs
@@registered_outputs ||= {}
end
|
Instance Method Details
#data_partial ⇒ Object
47
48
49
|
# File 'lib/redmine_extensions/query_output.rb', line 47
def data_partial
'easy_queries/easy_query_'+key
end
|
104
105
106
|
# File 'lib/redmine_extensions/query_output.rb', line 104
def edit_form
'easy_queries/form_'+key+'_settings'
end
|
#enabled? ⇒ Boolean
67
68
69
|
# File 'lib/redmine_extensions/query_output.rb', line 67
def enabled?
@outputs.output_enabled?(key)
end
|
108
109
110
|
# File 'lib/redmine_extensions/query_output.rb', line 108
def h
@outputs.view_context
end
|
75
76
77
78
|
# File 'lib/redmine_extensions/query_output.rb', line 75
def
content = options["#{key}_header".to_sym]
h.content_tag(:h3, content.html_safe) unless content.blank?
end
|
59
60
61
|
# File 'lib/redmine_extensions/query_output.rb', line 59
def key
self.class.key
end
|
63
64
65
|
# File 'lib/redmine_extensions/query_output.rb', line 63
def label
h.l('label_easy_query_output.'+key, default: key.humanize)
end
|
51
52
53
|
# File 'lib/redmine_extensions/query_output.rb', line 51
def order
10
end
|
#render_data ⇒ Object
55
56
57
|
# File 'lib/redmine_extensions/query_output.rb', line 55
def render_data
h.render partial: data_partial, locals: variables
end
|
#render_edit(action = 'edit') ⇒ Object
94
95
96
97
98
|
# File 'lib/redmine_extensions/query_output.rb', line 94
def render_edit(action='edit')
h.content_tag(:fieldset, class: "easy-query-filters-field #{key}_settings", style: ('display: none;' unless enabled? )) do
h.content_tag(:legend, label) + render_edit_form(action)
end
end
|
#render_edit_box(style = :check_box, options = {}) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/redmine_extensions/query_output.rb', line 80
def render_edit_box(style=:check_box, options={})
raise 'Style of edit box is not allowed' unless [:check_box, :radio_button].include?(style)
box_id = "#{query.modul_uniq_id}output_#{key}"
options[:class] = "#{options[:class]} #{query.modul_uniq_id}output_switch #{query.modul_uniq_id}content_switch"
options[:enabled] = enabled? unless options.key?(:enabled)
r = ''
r << h.send("#{style}_tag" , query.block_name.blank? ? 'outputs[]' : "#{query.block_name}[outputs][]", key, options[:enabled], id: box_id, class: options[:class])
r << h.label_tag(box_id, h.l('label_my_page_issue_output.' + key), :class => 'inline')
r.html_safe
end
|
100
101
102
|
# File 'lib/redmine_extensions/query_output.rb', line 100
def render_edit_form(action='edit')
h.render(self.edit_form, options.reverse_merge(query: query, modul_uniq_id: query.modul_uniq_id, block_name: query.block_name, action: action, page_module: query.page_module))
end
|
#variables ⇒ Object
71
72
73
|
# File 'lib/redmine_extensions/query_output.rb', line 71
def variables
options.reverse_merge(query: @query, output: self)
end
|