Class: ProductLinesController
- Inherits:
-
CrmController
- Object
- ActionController::Base
- ApplicationController
- CrmController
- ProductLinesController
- Defined in:
- app/controllers/product_lines_controller.rb
Overview
Controller: product lines.
Constant Summary collapse
- TAB_ACTIONS =
Lazy-loaded tab fragments on the show page (see CrmHelper#tab_panel).
%i[tab_main_attributes tab_descriptions tab_seo tab_specifications tab_items tab_publications tab_digital_assets].freeze
Constants included from Controllers::ReferenceFindable
Controllers::ReferenceFindable::ID_EMBEDDED_PATTERNS
Constants included from Controllers::AnalyticsEvents
Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY
Constants included from Controllers::ErrorRendering
Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES
Instance Method Summary collapse
-
#create ⇒ void
Creates a product line from submitted params.
-
#destroy ⇒ void
Deletes the loaded product line, reparenting the redirect to its parent's lineage tab (or the index if it was top-level).
-
#edit ⇒ void
Loads a product line (via
load_product_line) and its image list for editing. -
#features ⇒ void
Lists product lines that have at least one feature configured.
-
#index ⇒ void
Lists product lines, sorted by their tree position.
-
#new ⇒ void
Builds a new, unsaved product line under the given parent.
-
#prioritize ⇒ void
Lists product lines ordered by priority, for drag-and-drop reordering.
-
#refresh_cache ⇒ void
Touches the product line's descendants and purges its edge cache.
-
#refresh_rendered_product_specifications ⇒ void
Re-renders each active, non-publication item's rendered product specifications.
-
#show ⇒ void
Displays a single product line (loaded by
load_product_line). -
#sort ⇒ void
Persists a new priority ordering submitted by the
prioritizedrag-and-drop UI. -
#tab_descriptions ⇒ void
Renders the descriptions tab fragment.
-
#tab_digital_assets ⇒ void
Renders the digital assets tab fragment.
-
#tab_items ⇒ void
Renders the items tab fragment, applying the ransack filters in
params[:q]. -
#tab_main_attributes ⇒ void
Renders the main attributes tab fragment.
-
#tab_publications ⇒ void
Renders the publications tab fragment.
-
#tab_seo ⇒ void
Renders the SEO tab fragment.
-
#tab_specifications ⇒ void
Renders the specifications tab fragment.
-
#update ⇒ void
Updates the loaded product line from submitted params.
Methods included from Controllers::RequireTurboFrame
require_in_pane_tab_frames, require_turbo_frame
Methods included from Controllers::ContentLocalizable
#allow_content_locale_switch, #default_url_options, #set_content_locale
Methods inherited from CrmController
#access_denied, #context_id, #context_object, #crm_home_path, #current_ability, #default_url_options, #download_temp, #get_tempfile_path_for_download, #init_status_job_collector, #initialize_crm_lazy_chunks, #persist_enqueued_status_jobs, #record_not_found, #redirect_to_job_or_fallback, #render_edit_action, #set_context, #set_download_path, #stash_file_for_temp_download, #sync_admin_presence_cookie, #touch_employee_last_seen
Methods inherited from ApplicationController
#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #set_report_errors_for, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y
Methods included from Controllers::ReturnPathHandling
#check_for_return_path, #redirect_to_return_path_or_default
Methods included from Controllers::AnalyticsEvents
#consume_queued_analytics_events, #registration_lead_type, #track_event
Methods included from Controllers::DeviceDetection
Methods included from Controllers::SubdomainDetection
#is_crm_request?, #is_www_request?, #json_request?
Methods included from Controllers::TurboSafeRedirect
Methods included from Controllers::TrackingDetection
#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?
Methods included from Controllers::AcceleratedFileSending
#send_file_accelerated, #send_upload_accelerated
Methods included from Controllers::ErrorRendering
#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback
Methods included from Controllers::TurnstileVerification
#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!
Methods included from Controllers::CloudflareCaching
edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session
Methods included from Controllers::Webpackable
#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?
Methods included from Controllers::Localizable
#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale
Methods included from Controllers::Authenticable
#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak
Methods included from UrlsHelper
#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?
Instance Method Details
#create ⇒ void
This method returns an undefined value.
Creates a product line from submitted params.
59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/product_lines_controller.rb', line 59 def create :create, ProductLine @product_line = ProductLine.new(params[:product_line]) if @product_line.save redirect_to_return_path_or_default product_line_path(@product_line) else set_image_ransack render :new, status: :unprocessable_content end end |
#destroy ⇒ void
This method returns an undefined value.
Deletes the loaded product line, reparenting the redirect to its parent's
lineage tab (or the index if it was top-level).
112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/product_lines_controller.rb', line 112 def destroy :destroy, ProductLine parent = @product_line.parent if @product_line.destroy redirect_path = parent ? product_line_path(parent, tab: "lineage") : product_lines_path redirect_to redirect_path, flash: { notice: "Product Line id #{@product_line.id} deleted" } else redirect_back_or_to root_path, flash: { error: "Could not delete product product line. #{@product_line.errors..inspect}" } end end |
#edit ⇒ void
This method returns an undefined value.
Loads a product line (via load_product_line) and its image list for editing.
51 52 53 54 |
# File 'app/controllers/product_lines_controller.rb', line 51 def edit :update, ProductLine set_image_ransack end |
#features ⇒ void
This method returns an undefined value.
Lists product lines that have at least one feature configured.
239 240 241 242 243 |
# File 'app/controllers/product_lines_controller.rb', line 239 def features @q = ProductLine.with_features.ransack(params[:q]) @q.sorts = 'slug_ltree' if @q.sorts.blank? @product_lines = @q.result end |
#index ⇒ void
This method returns an undefined value.
Lists product lines, sorted by their tree position.
22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/product_lines_controller.rb', line 22 def index :read, ProductLine @q = ProductLine.ransack(params[:q]) @q.sorts = 'slug_ltree asc' # This is always the sort order or the tree will be messed up @product_lines = @q.result # We have to pull only product line at the same level because the tree will render based on children # selected_product_line_ids = @product_lines.map(&:self_and_ancestors_ids).flatten.uniq end |
#new ⇒ void
This method returns an undefined value.
Builds a new, unsaved product line under the given parent.
42 43 44 45 46 |
# File 'app/controllers/product_lines_controller.rb', line 42 def new :create, ProductLine @product_line = ProductLine.new(parent_id: params[:parent_id]) set_image_ransack end |
#prioritize ⇒ void
This method returns an undefined value.
Lists product lines ordered by priority, for drag-and-drop reordering.
126 127 128 129 130 131 |
# File 'app/controllers/product_lines_controller.rb', line 126 def prioritize (:manage, ProductLine) @q = ProductLine.ransack(params[:q]) @q.sorts = 'priority asc' @product_lines = @q.result.for_index end |
#refresh_cache ⇒ void
This method returns an undefined value.
Touches the product line's descendants and purges its edge cache.
248 249 250 251 252 253 254 |
# File 'app/controllers/product_lines_controller.rb', line 248 def refresh_cache (:manage, ProductLine) @product_line.self_and_descendants.update_all(updated_at: Time.current) @product_line.purge_edge_cache flash[:info] = 'Cache refreshed for this product line' redirect_to_return_path_or_default url_for(action: :show, tab: "items") end |
#refresh_rendered_product_specifications ⇒ void
This method returns an undefined value.
Re-renders each active, non-publication item's rendered product specifications.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/product_lines_controller.rb', line 92 def refresh_rendered_product_specifications :update, ProductLine @product_line.touch # Clears cache items = @product_line.all_my_items.non_publications.active items = items.where(product_category_id: params[:product_category_id]) if params[:product_category_id].present? items.find_each do |item| if Rails.env.development? item.update_rendered_product_specifications else item.async_update_rendered_product_specifications end end flash[:info] = 'Specs queued for refresh on all items' redirect_to_return_path_or_default url_for(action: :show, tab: "items") end |
#show ⇒ void
This method returns an undefined value.
Displays a single product line (loaded by load_product_line).
35 36 37 |
# File 'app/controllers/product_lines_controller.rb', line 35 def show :read, ProductLine end |
#sort ⇒ void
This method returns an undefined value.
Persists a new priority ordering submitted by the prioritize drag-and-drop UI.
136 137 138 139 140 141 142 |
# File 'app/controllers/product_lines_controller.rb', line 136 def sort (:manage, ProductLine) (params[:product_line] || {}).each_with_index do |id, index| ProductLine.where(id:).update_all(priority: index + 1, updated_at: Time.current) end head :ok end |
#tab_descriptions ⇒ void
This method returns an undefined value.
Renders the descriptions tab fragment.
160 161 162 163 164 165 166 |
# File 'app/controllers/product_lines_controller.rb', line 160 def tab_descriptions (:read, @product_line) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_digital_assets ⇒ void
This method returns an undefined value.
Renders the digital assets tab fragment.
228 229 230 231 232 233 234 |
# File 'app/controllers/product_lines_controller.rb', line 228 def tab_digital_assets (:read, @product_line) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_items ⇒ void
This method returns an undefined value.
Renders the items tab fragment, applying the ransack filters in params[:q].
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'app/controllers/product_lines_controller.rb', line 193 def tab_items (:read, @product_line) filter_params = params.fetch(:q, {}).to_h filter_params[:show_all_product_lines] = true if filter_params[:show_all_product_lines].nil? @all_items = if filter_params[:show_all_product_lines].to_b @product_line.all_my_items_all_product_lines else @product_line.all_my_items end @all_items = @all_items.non_publications .joins(:product_category) .includes(:primary_product_line, :product_category, :product_lines, :primary_image, :orderable_view_product_catalogs) .order(ProductCategory[:lineage_expanded], :sku) @all_items = @all_items.condition_new unless filter_params[:show_refurbished].to_b @all_items = @all_items.active unless filter_params[:show_inactive].to_b respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_main_attributes ⇒ void
This method returns an undefined value.
Renders the main attributes tab fragment.
149 150 151 152 153 154 155 |
# File 'app/controllers/product_lines_controller.rb', line 149 def tab_main_attributes (:read, @product_line) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_publications ⇒ void
This method returns an undefined value.
Renders the publications tab fragment.
217 218 219 220 221 222 223 |
# File 'app/controllers/product_lines_controller.rb', line 217 def tab_publications (:read, @product_line) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_seo ⇒ void
This method returns an undefined value.
Renders the SEO tab fragment.
171 172 173 174 175 176 177 |
# File 'app/controllers/product_lines_controller.rb', line 171 def tab_seo (:read, @product_line) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_specifications ⇒ void
This method returns an undefined value.
Renders the specifications tab fragment.
182 183 184 185 186 187 188 |
# File 'app/controllers/product_lines_controller.rb', line 182 def tab_specifications (:read, @product_line) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#update ⇒ void
This method returns an undefined value.
Updates the loaded product line from submitted params.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/product_lines_controller.rb', line 73 def update :update, ProductLine respond_to do |format| if @product_line.update(params[:product_line]) format.html { redirect_to_return_path_or_default product_line_path(@product_line) } format.json { respond_with_bip(@product_line) } else format.html do set_image_ransack render :edit, status: :unprocessable_content end format.json { respond_with_bip(@product_line) } end end end |