Class: RedmineExtensions::QueryOutput
- Inherits:
-
Object
- Object
- RedmineExtensions::QueryOutput
- Defined in:
- lib/redmine_extensions/query_output.rb
Direct Known Subclasses
RedmineExtensions::QueryOutputs::ListOutput, RedmineExtensions::QueryOutputs::TilesOutput
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
Class Method Summary collapse
-
.available_for?(query) ⇒ Boolean
Take query and decide if it is possible to render it by this output.
- .available_output_klasses_for(query) ⇒ Object
- .available_outputs_for(query) ⇒ Object
- .filter_registered_for(query, whitelist = []) ⇒ Object
- .key ⇒ Object
- .output_available?(query, output) ⇒ Boolean
- .output_klass_for(output, query = nil) ⇒ Object
- .register_output(klass, options = {}) ⇒ Object
- .register_output_for_query(klass, query_class_names, **options) ⇒ Object
- .registered_outputs ⇒ Object
- .registered_per_query ⇒ Object
- .registered_whitelists ⇒ Object
- .whitelist_outputs_for_query(query_class_names, outputs) ⇒ Object
Instance Method Summary collapse
- #data_partial ⇒ Object
- #edit_form ⇒ Object
- #enabled? ⇒ Boolean
- #h ⇒ Object
- #header ⇒ Object
-
#initialize(query_presenter, outputs = nil) ⇒ QueryOutput
constructor
A new instance of QueryOutput.
- #key ⇒ Object
- #label ⇒ Object
- #order ⇒ Object
- #render_data ⇒ Object
- #render_edit(action = 'edit') ⇒ Object
- #render_edit_box(style = :check_box, options = {}) ⇒ Object
- #render_edit_form(action = 'edit') ⇒ Object
- #variables ⇒ Object
Constructor Details
#initialize(query_presenter, outputs = nil) ⇒ QueryOutput
Returns a new instance of QueryOutput.
76 77 78 79 |
# File 'lib/redmine_extensions/query_output.rb', line 76 def initialize(query_presenter, outputs=nil) @query = query_presenter @outputs = outputs || query_presenter.outputs end |
Instance Attribute Details
#query ⇒ Object
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
72 73 74 |
# File 'lib/redmine_extensions/query_output.rb', line 72 def self.available_for?(query) query.is_a? Query end |
.available_output_klasses_for(query) ⇒ Object
57 58 59 |
# File 'lib/redmine_extensions/query_output.rb', line 57 def self.available_output_klasses_for(query) filter_registered_for(query).values end |
.available_outputs_for(query) ⇒ Object
53 54 55 |
# File 'lib/redmine_extensions/query_output.rb', line 53 def self.available_outputs_for(query) filter_registered_for(query).keys end |
.filter_registered_for(query, whitelist = []) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/redmine_extensions/query_output.rb', line 39 def self.filter_registered_for(query, whitelist = []) whitelist += (registered_whitelists[query.type] || []) res = registered_outputs res = res.slice(*whitelist.map(&:to_sym)) if whitelist.any? res = res.select do |_name, output| output.available_for?(query) end res.merge(registered_per_query[query.type] || {}) end |
.key ⇒ Object
66 67 68 |
# File 'lib/redmine_extensions/query_output.rb', line 66 def self.key self.name.split('::').last.sub(/Output$/, '').underscore end |
.output_available?(query, output) ⇒ Boolean
49 50 51 |
# File 'lib/redmine_extensions/query_output.rb', line 49 def self.output_available?(query, output) self.filter_registered_for(query, [output]).any? end |
.output_klass_for(output, query = nil) ⇒ Object
61 62 63 64 |
# File 'lib/redmine_extensions/query_output.rb', line 61 def self.output_klass_for(output, query=nil) filtered = query.nil? ? registered_outputs : filter_registered_for(query) filtered[output.to_sym] end |
.register_output(klass, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/redmine_extensions/query_output.rb', line 19 def self.register_output(klass, ={}) register_as = ([:as] || klass.key).to_sym registered_outputs[register_as] = klass end |
.register_output_for_query(klass, query_class_names, **options) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/redmine_extensions/query_output.rb', line 24 def self.register_output_for_query(klass, query_class_names, **) register_as ||= ([:as] || klass.key).to_sym Array.wrap(query_class_names).each do |query_class_name| registered_per_query[query_class_name] ||= {} registered_per_query[query_class_name][register_as] = klass end end |
.registered_outputs ⇒ Object
7 8 9 |
# File 'lib/redmine_extensions/query_output.rb', line 7 def self.registered_outputs @@registered_outputs ||= {} end |
.registered_per_query ⇒ Object
11 12 13 |
# File 'lib/redmine_extensions/query_output.rb', line 11 def self.registered_per_query @@registered_per_query ||= {} end |
.registered_whitelists ⇒ Object
15 16 17 |
# File 'lib/redmine_extensions/query_output.rb', line 15 def self.registered_whitelists @@registered_whitelists ||= {} end |
.whitelist_outputs_for_query(query_class_names, outputs) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/redmine_extensions/query_output.rb', line 32 def self.whitelist_outputs_for_query(query_class_names, outputs) Array.wrap(query_class_names).each do |query_class_name| registered_whitelists[query_class_name] ||= [] registered_whitelists[query_class_name].concat( Array.wrap(outputs).map(&:to_s) ).uniq! end end |
Instance Method Details
#data_partial ⇒ Object
81 82 83 |
# File 'lib/redmine_extensions/query_output.rb', line 81 def data_partial 'easy_queries/easy_query_'+key end |
#edit_form ⇒ Object
143 144 145 |
# File 'lib/redmine_extensions/query_output.rb', line 143 def edit_form 'easy_queries/form_'+key+'_settings' end |
#enabled? ⇒ Boolean
101 102 103 |
# File 'lib/redmine_extensions/query_output.rb', line 101 def enabled? @outputs.output_enabled?(key) end |
#h ⇒ Object
147 148 149 |
# File 'lib/redmine_extensions/query_output.rb', line 147 def h @outputs.view_context end |
#header ⇒ Object
109 110 111 112 |
# File 'lib/redmine_extensions/query_output.rb', line 109 def header content = ["#{key}_header".to_sym] h.content_tag(:h3, content.html_safe) unless content.blank? end |
#key ⇒ Object
93 94 95 |
# File 'lib/redmine_extensions/query_output.rb', line 93 def key self.class.key end |
#label ⇒ Object
97 98 99 |
# File 'lib/redmine_extensions/query_output.rb', line 97 def label h.l('label_easy_query_output.'+key, default: key.humanize) end |
#order ⇒ Object
85 86 87 |
# File 'lib/redmine_extensions/query_output.rb', line 85 def order 10 end |
#render_data ⇒ Object
89 90 91 |
# File 'lib/redmine_extensions/query_output.rb', line 89 def render_data h.render partial: data_partial, locals: variables end |
#render_edit(action = 'edit') ⇒ Object
133 134 135 136 137 |
# File 'lib/redmine_extensions/query_output.rb', line 133 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
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/redmine_extensions/query_output.rb', line 114 def render_edit_box(style=:check_box, ={}) box_id = "#{query.modul_uniq_id}output_#{key}" [:class] = "#{[:class]} #{query.modul_uniq_id}output_switch #{query.modul_uniq_id}content_switch" [:enabled] = enabled? unless .key?(:enabled) r = '' case style when :hidden_field r << h.hidden_field_tag(query.block_name.blank? ? 'outputs[]' : "#{query.block_name}[outputs][]", key, id: box_id, class: [:class]) when :check_box, :radio_button r << h.send("#{style}_tag" , query.block_name.blank? ? 'outputs[]' : "#{query.block_name}[outputs][]", key, [:enabled], id: box_id, class: [:class]) r << h.label_tag(box_id, h.l('label_my_page_issue_output.' + key), :class => 'inline') else raise 'Style of edit box is not allowed' end r.html_safe end |
#render_edit_form(action = 'edit') ⇒ Object
139 140 141 |
# File 'lib/redmine_extensions/query_output.rb', line 139 def render_edit_form(action='edit') h.render(self.edit_form, .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
105 106 107 |
# File 'lib/redmine_extensions/query_output.rb', line 105 def variables .reverse_merge(query: @query, output: self) end |