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
Class Method Summary collapse
-
.keywords_for_select ⇒ Object
Get all keywords that have rankings for the dropdown.
Instance Method Summary collapse
-
#auto_purge? ⇒ Boolean
Check if an auto purge action is requested.
-
#initialize(params = {}) ⇒ SiteMapSearchForm
constructor
A new instance of SiteMapSearchForm.
-
#model_name ⇒ Object
For SimpleForm compatibility - used to determine form field names.
- #persisted? ⇒ Boolean
- #purge_by_page? ⇒ Boolean
- #purge_by_tag? ⇒ Boolean
-
#ransack_search ⇒ Object
Build the Ransack search object with normalized parameters.
-
#results ⇒ Object
Delegate to ransack for results, with optional keyword and recommendation filtering.
-
#to_key ⇒ Object
For SimpleForm compatibility.
Constructor Details
#initialize(params = {}) ⇒ SiteMapSearchForm
Returns a new instance of SiteMapSearchForm.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/forms/crm/site_map_search_form.rb', line 90 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 |
Class Method Details
.keywords_for_select ⇒ Object
Get all keywords that have rankings for the dropdown
149 150 151 152 153 154 155 |
# File 'app/forms/crm/site_map_search_form.rb', line 149 def self.keywords_for_select SeoPageKeyword .ranking .distinct .order(:keyword) .pluck(:keyword) end |
Instance Method Details
#auto_purge? ⇒ Boolean
Check if an auto purge action is requested
172 173 174 |
# File 'app/forms/crm/site_map_search_form.rb', line 172 def auto_purge? auto_purge_action.present? && auto_purge_action != 'none' end |
#model_name ⇒ Object
For SimpleForm compatibility - used to determine form field names
158 159 160 |
# File 'app/forms/crm/site_map_search_form.rb', line 158 def model_name ActiveModel::Name.new(self.class, nil, 'q') end |
#persisted? ⇒ Boolean
167 168 169 |
# File 'app/forms/crm/site_map_search_form.rb', line 167 def persisted? false end |
#purge_by_page? ⇒ Boolean
176 177 178 |
# File 'app/forms/crm/site_map_search_form.rb', line 176 def purge_by_page? auto_purge_action == 'page' end |
#purge_by_tag? ⇒ Boolean
180 181 182 |
# File 'app/forms/crm/site_map_search_form.rb', line 180 def purge_by_tag? auto_purge_action == 'tag' end |
#ransack_search ⇒ Object
Build the Ransack search object with normalized parameters
115 116 117 |
# File 'app/forms/crm/site_map_search_form.rb', line 115 def ransack_search @ransack_search ||= SiteMap.ransack(ransack_params) end |
#results ⇒ Object
Delegate to ransack for results, with optional keyword and recommendation filtering
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/forms/crm/site_map_search_form.rb', line 135 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 ⇒ Object
For SimpleForm compatibility
163 164 165 |
# File 'app/forms/crm/site_map_search_form.rb', line 163 def to_key nil end |