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 =
URL_PREDICATE_OPTIONS.map(&:second).freeze
- 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 =
[ ['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 =
[ ['All', ''], ['Has Open Issues', 'yes'], ['No Open Issues', 'no'] ].freeze
- 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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/forms/crm/site_map_search_form.rb', line 87 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
146 147 148 149 150 151 152 |
# File 'app/forms/crm/site_map_search_form.rb', line 146 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
169 170 171 |
# File 'app/forms/crm/site_map_search_form.rb', line 169 def auto_purge? auto_purge_action.present? && auto_purge_action != 'none' end |
#model_name ⇒ Object
For SimpleForm compatibility - used to determine form field names
155 156 157 |
# File 'app/forms/crm/site_map_search_form.rb', line 155 def model_name ActiveModel::Name.new(self.class, nil, 'q') end |
#persisted? ⇒ Boolean
164 165 166 |
# File 'app/forms/crm/site_map_search_form.rb', line 164 def persisted? false end |
#purge_by_page? ⇒ Boolean
173 174 175 |
# File 'app/forms/crm/site_map_search_form.rb', line 173 def purge_by_page? auto_purge_action == 'page' end |
#purge_by_tag? ⇒ Boolean
177 178 179 |
# File 'app/forms/crm/site_map_search_form.rb', line 177 def purge_by_tag? auto_purge_action == 'tag' end |
#ransack_search ⇒ Object
Build the Ransack search object with normalized parameters
112 113 114 |
# File 'app/forms/crm/site_map_search_form.rb', line 112 def ransack_search @ransack_search ||= SiteMap.ransack(ransack_params) end |
#results ⇒ Object
Delegate to ransack for results, with optional keyword and recommendation filtering
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/forms/crm/site_map_search_form.rb', line 130 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) scope = apply_analysis_freshness_filter(scope) scope end |
#to_key ⇒ Object
For SimpleForm compatibility
160 161 162 |
# File 'app/forms/crm/site_map_search_form.rb', line 160 def to_key nil end |