Class: QueryTemplate
- Inherits:
-
Object
- Object
- QueryTemplate
- Defined in:
- app/models/query_template.rb
Overview
Pre-canned saved-query template — a named bundle of query params,
selected columns, sort, and limit — used by the CRM's "Saved
Queries" surface to spin up consistent reports without rebuilding
the search form each time. Wraps an arbitrary Search subclass.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Instance Method Summary collapse
- #auto_pin? ⇒ Boolean
-
#initialize(klass, options) ⇒ QueryTemplate
constructor
A new instance of QueryTemplate.
- #query_params ⇒ Object
- #result_set ⇒ Object
- #result_set_length ⇒ Object
- #selected_columns ⇒ Object
- #show_count? ⇒ Boolean
- #title ⇒ Object
- #to_params(options = {}) ⇒ Object
Constructor Details
#initialize(klass, options) ⇒ QueryTemplate
Returns a new instance of QueryTemplate.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/query_template.rb', line 9 def initialize(klass, ) @search_class = klass @options = .dup || {} @options[:auto_count] = true if @options[:auto_count].nil? @search = klass.new(query_params: @options[:query_params], selected_columns: @options[:selected_columns], sort_columns: @options[:sort_columns].presence || [], sort_direction: @options[:sort_direction], set_limit: @options[:set_limit], pinned: @options[:pinned] || false) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'app/models/query_template.rb', line 7 def @options end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
7 8 9 |
# File 'app/models/query_template.rb', line 7 def search @search end |
Instance Method Details
#auto_pin? ⇒ Boolean
34 35 36 |
# File 'app/models/query_template.rb', line 34 def auto_pin? @options[:auto_pin] end |
#query_params ⇒ Object
42 43 44 |
# File 'app/models/query_template.rb', line 42 def query_params @options[:query_params] end |
#result_set ⇒ Object
58 59 60 |
# File 'app/models/query_template.rb', line 58 def result_set @search.perform(nil, nil, nil, nil, nil, false, true) end |
#result_set_length ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/models/query_template.rb', line 50 def result_set_length begin result_set.size rescue StandardError nil end || result_set.size end |
#selected_columns ⇒ Object
46 47 48 |
# File 'app/models/query_template.rb', line 46 def selected_columns @options[:selected_columns] end |
#show_count? ⇒ Boolean
38 39 40 |
# File 'app/models/query_template.rb', line 38 def show_count? @options[:auto_count] end |
#title ⇒ Object
30 31 32 |
# File 'app/models/query_template.rb', line 30 def title @options[:title] end |
#to_params(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/models/query_template.rb', line 21 def to_params( = {}) hsh = { type: @search_class.name, search: @search.attributes } hsh.deep_merge() Hash[*hsh.compact_blank.flatten] # Only non nil end |