Class: ActivitySearch
- Inherits:
-
Search
- Object
- ActiveRecord::Base
- ApplicationRecord
- Search
- ActivitySearch
- Includes:
- Models::SearchAddressable
- Defined in:
- app/models/activity_search.rb
Overview
== Schema Information
Table name: searches
Database name: primary
id :integer not null, primary key
name :string(255)
persist :boolean default(FALSE)
pinned :boolean default(FALSE), not null
query_params :jsonb
result_set_size :integer default(0)
selected_columns :string is an Array
set_limit :integer default(25)
sort_column :string(255)
sort_columns :string default([]), not null, is an Array
sort_direction :string(255) default("ASC")
type :string(255) not null
created_at :datetime
updated_at :datetime
employee_id :integer
Indexes
employee_id_pinned (employee_id,pinned)
employee_id_type (employee_id,type)
Constant Summary
Constants inherited from Search
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary
Attributes inherited from Search
#composite_columns, #pagy_count, #pagy_limit, #pagy_page, #sql_select_columns
Class Method Summary collapse
Instance Method Summary collapse
- #address_id_fields ⇒ void
- #apply_custom_criteria(results) ⇒ void
- #mass_assign_campaign(params, cur_user = nil) ⇒ void
- #mass_spread(params, cur_user = nil) ⇒ void
-
#mass_update(params, cur_user = nil) ⇒ void
Mass actions section #.
-
#normalize_for_mass_update(resource, params) ⇒ void
Called by SearchResourceUpdateWorker for each activity before saving.
- #pinned_query ⇒ void
Methods included from Models::SearchAddressable
Methods inherited from Search
#all_composite_columns, allowed_role_ids, #append_custom_column, #append_ouput_column, #append_to_sql_select_columns, #applicable_sort_terms, #apply_array_match, #apply_criteria, #apply_customer_cross_reference, #apply_distance_search, #apply_select, #apply_sort, #available_events, #available_output_columns, available_output_columns, base_search_class_name, #cleanup_search_results, composite_column, #composite_column, database_columns, default_columns, default_sort, #discard_excess, #effective_name, #effective_short_name, #employee, #enqueue_navbar_pinned_refresh, #fast_count, favorites, friendly_column_name, #get_pinned_results, #get_sort_term, global_favorite, has_role_for_search?, #human_query_params, instantiate_query_template, #instantiate_resource_updater, #limit_options, main_resource_class, main_resource_table, mass_actions_for_select, #mass_export, maximum_unpersisted_queries, options, options_classes, #output_columns_for_select, #pagy_from_search, #perform, #perform_selected, #prepend_custom_column, #prepend_output_column, query_favorites_templates, #ransack_probe_params, recent_searches_for_employee_id, #record_list, #refresh_pinned_results, #remove_other_pins, #search_name, search_name, #search_results, search_type, search_type_humanized, #select_sort_columns, select_sort_columns, #select_statement, #set_defaults, #set_sort_term, #sort_column1, #sort_column1=, #sort_column2, #sort_column2=, #sort_column3, #sort_column3=, #sort_columns_for_select, #sort_columns_to_hash, #sortable_column?, #target_geocoding, unpersisted_queries_quote_reached?, #unrecord_list, #validated_selected_columns, view_resource_class, view_resource_klass, #view_resource_klass, view_resource_table, visible?, with_search_results
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.custom_criteria_keys ⇒ void
This method returns an undefined value.
93 94 95 |
# File 'app/models/activity_search.rb', line 93 def self.custom_criteria_keys %w[activity_type_id activity_result_type_id assigned_resource_id] end |
Instance Method Details
#address_id_fields ⇒ void
This method returns an undefined value.
88 89 90 |
# File 'app/models/activity_search.rb', line 88 def address_id_fields [['Primary Address', 'primary_address_id']] end |
#apply_custom_criteria(results) ⇒ void
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/activity_search.rb', line 101 def apply_custom_criteria(results) results = apply_customer_cross_reference(results, :party_id) results = apply_array_match(results, :activity_type_id, nil, 'Note', 'Any') do |values| values += ActivityType.sales_activities.ids if values.delete('AnySales') values end results = apply_array_match(results, :activity_result_type_id, nil, 'Open', 'Any') do |values| values += ActivityResultType.completed.ids if values.delete('AnyCompletion') values end apply_array_match(results, :assigned_resource_id, nil, 'unassigned', 'anybody') end |
#mass_assign_campaign(params, cur_user = nil) ⇒ void
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/activity_search.rb', line 69 def mass_assign_campaign(params, cur_user = nil) campaign_id = params.dig(:campaign, :campaign_id) return { status: :error, message: 'Campaign not selected' } if campaign_id.blank? jid = ::SearchResourceUpdateWorker.perform_async( 'search_id' => id, 'action_params' => { 'resource_params' => { 'campaign_id' => campaign_id } }, 'user_id' => cur_user&.id, 'locale' => I18n.locale.to_s ) { status: :ok, job_id: jid } end |
#mass_spread(params, cur_user = nil) ⇒ void
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/models/activity_search.rb', line 162 def mass_spread(params, cur_user = nil) return { status: :error, message: 'Please specify a start date and number of activities per day to schedule' } \ unless params[:start_date].present? && params[:max_per_day].to_i > 0 jid = MassSearch::ActivitySpreadWorker.perform_async( 'search_id' => id, 'action_params' => { 'start_date' => params[:start_date], 'max_per_day' => params[:max_per_day] }, 'user_id' => cur_user&.id, 'locale' => I18n.locale.to_s ) { status: :ok, job_id: jid } end |
#mass_update(params, cur_user = nil) ⇒ void
This method returns an undefined value.
Mass actions section #
123 124 125 126 127 128 129 130 131 |
# File 'app/models/activity_search.rb', line 123 def mass_update(params, cur_user = nil) jid = ::SearchResourceUpdateWorker.perform_async( 'search_id' => id, 'action_params' => { 'resource_params' => (params[:resource] || {}).to_h }, 'user_id' => cur_user&.id, 'locale' => I18n.locale.to_s ) { status: :ok, job_id: jid } end |
#normalize_for_mass_update(resource, params) ⇒ void
This method returns an undefined value.
Called by SearchResourceUpdateWorker for each activity before saving.
Normalises result type sentinel values, resolves "assign to primary rep"
shorthand, and defers ChainRunner to the async handler.
Returns false to skip the record and count it as an error.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/models/activity_search.rb', line 140 def normalize_for_mass_update(resource, params) resource.activity_result_type_id = nil if resource.activity_result_type_id.to_i < 0 if params[:assigned_resource_id].to_s == '0' rep = resource.try(:party).try(:customer).try(:primary_sales_rep) unless rep Rails.logger.warn "normalize_for_mass_update: no primary rep for activity #{resource.id} party #{resource.try(:party_id)}" return false end resource.assigned_resource_id = rep.id end resource.halt_chain = true true end |
#pinned_query ⇒ void
This method returns an undefined value.
83 84 85 |
# File 'app/models/activity_search.rb', line 83 def pinned_query search_results.joins('left join activities on activities.id = search_results.resource_id').includes(resource: %i[activity_type party]) end |