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 ⇒ Hash
- #result_set ⇒ Array
- #result_set_length ⇒ Integer?
- #selected_columns ⇒ Array
- #show_count? ⇒ Boolean
- #title ⇒ String?
-
#to_params(options = {}) ⇒ Hash
Flattened, blank-compacted params.
Constructor Details
#initialize(klass, options) ⇒ QueryTemplate
Returns a new instance of QueryTemplate.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/query_template.rb', line 24 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
55 56 57 |
# File 'app/models/query_template.rb', line 55 def auto_pin? @options[:auto_pin] end |
#query_params ⇒ Hash
65 66 67 |
# File 'app/models/query_template.rb', line 65 def query_params @options[:query_params] end |
#result_set ⇒ Array
84 85 86 |
# File 'app/models/query_template.rb', line 84 def result_set @search.perform(nil, nil, nil, nil, nil, false, true) end |
#result_set_length ⇒ Integer?
75 76 77 78 79 80 81 |
# File 'app/models/query_template.rb', line 75 def result_set_length begin result_set.size rescue StandardError nil end || result_set.size end |
#selected_columns ⇒ Array
70 71 72 |
# File 'app/models/query_template.rb', line 70 def selected_columns @options[:selected_columns] end |
#show_count? ⇒ Boolean
60 61 62 |
# File 'app/models/query_template.rb', line 60 def show_count? @options[:auto_count] end |
#title ⇒ String?
50 51 52 |
# File 'app/models/query_template.rb', line 50 def title @options[:title] end |
#to_params(options = {}) ⇒ Hash
Returns flattened, blank-compacted params.
40 41 42 43 44 45 46 47 |
# File 'app/models/query_template.rb', line 40 def to_params( = {}) hsh = { type: @search_class.name, search: @search.attributes } hsh.deep_merge() Hash[*hsh.compact_blank.flatten] # Only non nil end |