Class: Crm::SiteMapSearchForm
- Inherits:
-
Object
- Object
- Crm::SiteMapSearchForm
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- app/forms/crm/site_map_search_form.rb
Overview
Form object for SiteMap search that combines Ransack predicates with custom UI controls
and action parameters in a single, cohesive object.
Usage in controller:
@search_form = Crm::SiteMapSearchForm.new(params)
@site_maps = @search_form.results
Usage in view:
simple_form_for @search_form, url: ..., method: :get do |f|
f.input :locale_eq, ...
f.input :url_predicate, ...
f.input :auto_purge_action, ...
end
Supports full URL input - when a full URL is pasted (e.g., https://www.warmlyyours.com/en-US/floor-heating),
the form automatically extracts the locale and path for searching.
Constant Summary collapse
- URL_PREDICATE_OPTIONS =
Path predicate options for the filter dropdown
[ ['Path Contains', 'path_cont'], ['Path Starts With', 'path_start'], ['Path Ends With', 'path_end'], ['Path Equals', 'path_eq'] ].freeze
- ALLOWED_URL_PREDICATES =
Allowed url predicates.
URL_PREDICATE_OPTIONS.map(&:second).freeze
- STATUS_FILTER_OPTIONS =
Available status filter options.
[ ['All', ''], ['Not 200 (Failed)', 'not_200'], ['200 (OK)', '200'], ['301 (Redirect)', '301'], ['404 (Not Found)', '404'], ['500 (Server Error)', '500'] ].freeze
- AUTO_PURGE_OPTIONS =
Available auto purge options.
[ ['None', 'none'], ['Page (URLs)', 'page'], ['Tag (Categories)', 'tag'] ].freeze
- VALID_HOSTS =
Valid hosts for URL parsing
%w[ www.warmlyyours.com www.warmlyyours.ca www.warmlyyours.me ].freeze
- OPEN_REC_OPTIONS =
Available open rec options.
[ ['All', ''], ['Has Open Issues', 'yes'], ['No Open Issues', 'no'] ].freeze
- ANALYSIS_FRESHNESS_OPTIONS =
Available analysis freshness options.
[ ['All', ''], ['Stale (recrawled after analysis)', 'stale'], ['Fresh', 'fresh'], ['No analysis', 'none'] ].freeze
Instance Method Summary collapse
-
#auto_purge? ⇒ Boolean
Checks if an auto purge action is requested.
-
#initialize(params = {}) ⇒ SiteMapSearchForm
constructor
Builds the form from controller params, extracting locale and path when
url_valueis a full URL on a valid host. -
#model_name ⇒ ActiveModel::Name
For SimpleForm compatibility - used to determine form field names.
-
#persisted? ⇒ false
Whether the form object is persisted (always false for SimpleForm).
-
#purge_by_page? ⇒ Boolean
Whether the requested purge targets pages (URLs).
-
#purge_by_tag? ⇒ Boolean
Whether the requested purge targets tags (categories).
-
#ransack_search ⇒ Ransack::Search
Builds the Ransack search object with normalized parameters.
-
#results ⇒ ActiveRecord::Relation<SiteMap>
Delegates to ransack for results, with optional keyword and recommendation filtering.
-
#to_key ⇒ nil
For SimpleForm compatibility.
Constructor Details
#initialize(params = {}) ⇒ SiteMapSearchForm
Builds the form from controller params, extracting locale and path when
url_value is a full URL on a valid host.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/forms/crm/site_map_search_form.rb', line 95 def initialize(params = {}) # Handle both ActionController::Parameters and plain Hash q_params = params[:q] || params['q'] || {} q_params = q_params.to_unsafe_h if q_params.respond_to?(:to_unsafe_h) raw_url_value = q_params['url_value'] parsed = parse_url_value(raw_url_value) super( locale_eq: parsed[:locale] || q_params['locale_eq'], category_eq: q_params['category_eq'], last_status_eq: q_params['last_status_eq'], url_predicate: q_params['url_predicate'].presence || 'path_cont', url_value: parsed[:path] || raw_url_value, keyword: q_params['keyword'], has_open_recommendations: q_params['has_open_recommendations'], seo_score_gteq: q_params['seo_score_gteq'], seo_score_lteq: q_params['seo_score_lteq'], analysis_freshness: q_params['analysis_freshness'], s: q_params['s'], auto_purge_action: q_params['auto_purge_action'].presence || 'none' ) end |
Instance Method Details
#auto_purge? ⇒ Boolean
Checks if an auto purge action is requested.
181 182 183 |
# File 'app/forms/crm/site_map_search_form.rb', line 181 def auto_purge? auto_purge_action.present? && auto_purge_action != 'none' end |
#model_name ⇒ ActiveModel::Name
For SimpleForm compatibility - used to determine form field names.
160 161 162 |
# File 'app/forms/crm/site_map_search_form.rb', line 160 def model_name ActiveModel::Name.new(self.class, nil, 'q') end |
#persisted? ⇒ false
Whether the form object is persisted (always false for SimpleForm).
174 175 176 |
# File 'app/forms/crm/site_map_search_form.rb', line 174 def persisted? false end |
#purge_by_page? ⇒ Boolean
Whether the requested purge targets pages (URLs).
188 189 190 |
# File 'app/forms/crm/site_map_search_form.rb', line 188 def purge_by_page? auto_purge_action == 'page' end |
#purge_by_tag? ⇒ Boolean
Whether the requested purge targets tags (categories).
195 196 197 |
# File 'app/forms/crm/site_map_search_form.rb', line 195 def purge_by_tag? auto_purge_action == 'tag' end |
#ransack_search ⇒ Ransack::Search
Builds the Ransack search object with normalized parameters.
122 123 124 |
# File 'app/forms/crm/site_map_search_form.rb', line 122 def ransack_search @ransack_search ||= SiteMap.ransack(ransack_params) end |
#results ⇒ ActiveRecord::Relation<SiteMap>
Delegates to ransack for results, with optional keyword and recommendation filtering.
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/forms/crm/site_map_search_form.rb', line 144 def results scope = ransack_search.result if keyword.present? scope = scope.joins(:seo_page_keywords) .where(seo_page_keywords: { keyword: keyword }) .distinct end scope = apply_recommendation_filter(scope) apply_analysis_freshness_filter(scope) end |
#to_key ⇒ nil
For SimpleForm compatibility.
167 168 169 |
# File 'app/forms/crm/site_map_search_form.rb', line 167 def to_key nil end |