Class: MyRoomsController

Inherits:
BasePortalController show all
Includes:
Controllers::HeatLoss
Defined in:
app/controllers/my_rooms_controller.rb

Constant Summary

Constants included from HeatLossPathsHelper

HeatLossPathsHelper::HEAT_LOSS_ACTIONS

Constants included from Controllers::MasqueradeGuarded

Controllers::MasqueradeGuarded::DEFAULT_BLOCK_MESSAGE

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

Constants included from Www::SeoHelper

Www::SeoHelper::AWARDS, Www::SeoHelper::CA_ADDRESS, Www::SeoHelper::CA_BUSINESS_HOURS, Www::SeoHelper::CA_CONTACT_POINT, Www::SeoHelper::CA_CURRENCIES, Www::SeoHelper::CA_DESCRIPTION, Www::SeoHelper::CA_FOUNDING_DATE, Www::SeoHelper::CA_GLOBAL_LOCATION_NUMBER, Www::SeoHelper::CA_LEGAL_NAME, Www::SeoHelper::CA_LOCAL_BUSINESS, Www::SeoHelper::CA_ONLINE_STORE, Www::SeoHelper::CA_RETURN_POLICY, Www::SeoHelper::CA_SALES_DEPARTMENT, Www::SeoHelper::CA_SERVICE_AREA, Www::SeoHelper::CA_URL, Www::SeoHelper::CA_VAT_ID, Www::SeoHelper::CA_WAREHOUSE_DEPARTMENT, Www::SeoHelper::CA_WAREHOUSE_HOURS, Www::SeoHelper::COMPANY_EMAIL, Www::SeoHelper::COMPANY_LOGO, Www::SeoHelper::COMPANY_NAME, Www::SeoHelper::COMPANY_SLOGAN, Www::SeoHelper::EXPERTISE, Www::SeoHelper::FAX_NUMBER, Www::SeoHelper::GS1_COMPANY_PREFIX, Www::SeoHelper::ISO6523_CODE, Www::SeoHelper::PAYMENT_METHODS, Www::SeoHelper::PHONE_NUMBER, Www::SeoHelper::PRIMARY_NAICS, Www::SeoHelper::REFUND_TYPE, Www::SeoHelper::RETURN_FEES, Www::SeoHelper::RETURN_METHOD, Www::SeoHelper::RETURN_POLICY_CATEGORY, Www::SeoHelper::SECONDARY_NAICS, Www::SeoHelper::SOCIAL_PROFILES, Www::SeoHelper::US_ADDRESS, Www::SeoHelper::US_BUSINESS_HOURS, Www::SeoHelper::US_CONTACT_POINT, Www::SeoHelper::US_CURRENCIES, Www::SeoHelper::US_DESCRIPTION, Www::SeoHelper::US_FOUNDING_DATE, Www::SeoHelper::US_GLOBAL_LOCATION_NUMBER, Www::SeoHelper::US_IMAGE, Www::SeoHelper::US_LEGAL_NAME, Www::SeoHelper::US_LOCAL_BUSINESS, Www::SeoHelper::US_ONLINE_STORE, Www::SeoHelper::US_RETURN_POLICY, Www::SeoHelper::US_SALES_DEPARTMENT, Www::SeoHelper::US_SERVICE_AREA, Www::SeoHelper::US_TAX_ID, Www::SeoHelper::US_URL, Www::SeoHelper::US_WAREHOUSE_DEPARTMENT, Www::SeoHelper::US_WAREHOUSE_HOURS

Constants included from IconHelper

IconHelper::CUSTOM_ICON_MAP, IconHelper::CUSTOM_SVG_DIR, IconHelper::DEFAULT_FAMILY

Instance Method Summary collapse

Methods included from Controllers::HeatLoss

#ceiling_heat_loss_details, #complete_ceiling_heat_loss_details, #complete_doors_heat_loss_details, #complete_exterior_walls_heat_loss_details, #complete_heat_loss_info, #complete_room_heat_loss_details, #complete_skylights_heat_loss_details, #complete_under_floor_heat_loss_details, #complete_windows_heat_loss_details, #doors_heat_loss_details, #dupe_door_heat_loss_details, #dupe_exterior_wall_heat_loss_details, #dupe_skylight_heat_loss_details, #dupe_window_heat_loss_details, #enter_heat_loss_info, #exterior_walls_heat_loss_details, #heat_loss_details_summary, #projects_path_for, #remove_door_heat_loss_details, #remove_exterior_wall_heat_loss_details, #remove_skylight_heat_loss_details, #remove_window_heat_loss_details, #room_heat_loss_details, #set_ceiling_variables, #set_doors_variables, #set_exterior_walls_variables, #set_skylights_variables, #set_under_floor_variables, #set_windows_variables, #show_heat_loss, #show_heat_loss_path_for, #skylights_heat_loss_details, #under_floor_heat_loss_details, #update_ceiling_type, #update_door_type, #update_exterior_wall_type, #update_under_floor_type, #update_window_type, #windows_heat_loss_details

Methods included from HeatLossPathsHelper

#crm_request?, #enter_heat_loss_info_path_for_room, #format_errors_as_list, #heat_loss_path, #hl_btn_submit_class, #hl_card_class, #hl_card_col_class, #hl_card_content_class, #hl_card_header_class, #hl_card_title_class, #hl_field_class, #hl_field_error, #hl_form_control_class, #hl_form_group_class, #hl_form_select_class, #room_path_for_room, #show_heat_loss_path_for_room

Methods inherited from BasePortalController

#current_ability, #portal_party, #set_catalog, #set_webpack

Methods included from Controllers::MasqueradeGuarded

block_while_masquerading, #masquerade_blocks?

Methods inherited from ApplicationController

#account_impersonated?, #add_to_flash, #append_token, #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, #should_render_layout?, #stamp_impersonation_context, #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, #track_event

Methods included from Controllers::DeviceDetection

#device_detector, #is_ie?

Methods included from Controllers::SubdomainDetection

#is_crm_request?, #is_www_request?, #json_request?

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, #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_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!, #authenticate_account_from_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 ApplicationHelper

#better_number_to_currency, #check_force_logout, #check_or_cross, #check_or_times, #error_messages, #general_disclaimer_on_product_installation_and_local_codes, #gridjs_from_html_table, #gridjs_table, #is_wy_ip, #line_break, #parent_layout, #pass_or_fail, #render_error_messages_list, #render_video_card, #resolved_auth_form_turbo_frame, #return_path_or, #safe_css_color, #set_return_path_if_present, #set_section_if_present, #tab_frame_id, #to_underscore, #track_page?, #turbo_section_wrapper, #turbo_tabs_request?, #url_on_same_domain_as_request, #widget_index_daily_focus_index_path, #working_hours?, #yes_or_no, #yes_or_no_highlighted, #yes_or_no_with_check_or_cross, #youtube_video

Methods included from UppyUploaderHelper

#file_uploader, #image_uploader, #large_file_uploader_s3, #lead_sketch_uploader, #rma_image_uploader, #rma_image_uploader_s3, #uppy_uploader, #video_uploader

Methods included from Www::ImagesHelper

#image_asset_tag, #image_asset_url

Methods included from Www::SeoHelper

#add_page_schema, #canada?, #company_social_links, #ensure_context_json, #json_ld_script_tag, #local_business_schema, #online_store_id, #online_store_schema, #page_main_entity, #page_main_entity_json, #render_auto_collection_page_schema, #render_collection_page_schema, #render_local_business_schema, #render_online_store_schema, #render_page_schemas, #render_page_video_schemas, #render_webpage_schema, #render_webpage_schema_with_collections, #usa?

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?

Methods included from IconHelper

#account_nav_icon, #fa_icon, #star_rating_html

Instance Method Details

#add_to_cartObject



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'app/controllers/my_rooms_controller.rb', line 352

def add_to_cart
  @cart = @context_user.cart
  if @cart.room_configuration_ids.include? @room.id
    flash[:warning] = 'This room/heated space is already in your cart.'
    redirect_to_return_path_or_default my_cart_path
  elsif @room.in_design?
    flash[:warning] =
      "This room/heated space is in design and can't be added to your cart. To buy the room/heated space please cancel the design request and then add it to you cart. All orders with room/heated space layouts will ship with a free installation plan."
    redirect_to_return_path_or_default my_room_path(@room)
  elsif !@room.can_add_to_cart?
    flash[:warning] = "This room can't be added to your cart yet. It must have items and not be pending measurement or being designed."
    redirect_to_return_path_or_default my_room_path(@room)
  else
    track_event('Cart - Product Added', {
      quoteId: @room.id,
      roomType: @room.reception_type,
      value: @room.total
    })
    quote = @room.quotes.completed_quotes.last || @room.quotes.pending.last
    quote ||= Quote.auto_quote_from_room(@room, force_single_origin: true)
    notice = "Your room/heated space #{@room.name} has been added to your cart. "
    flash[:info] = notice
    redirect_to add_to_cart_my_quote_path(quote, room_id: @room.id)
  end
end

#apply_customer_pricing_on_loginObject



459
460
461
462
463
464
465
# File 'app/controllers/my_rooms_controller.rb', line 459

def 
  if @room && (q = @room.quotes.first)
    q.reset_discount
    flash[:info] = 'Quote and room/heated space were saved.'
  end
  redirect_to my_room_path(@room)
end

#cancelObject



389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'app/controllers/my_rooms_controller.rb', line 389

def cancel
  if @room.ok_to_delete?
    @room.destroy
    flash[:info] = "Room/heated space #{@room.name} was deleted"
    redirect_to_return_path_or_default my_project_path(@project)
  elsif @room.ok_to_customer_cancel?
    @room.cancel
    flash[:info] = "Room/heated space #{@room.name} was cancelled"
    redirect_to_return_path_or_default my_project_path(@project)
  else
    flash[:error] = "Room/heated space #{@room.name} is not in a state where it can be cancelled"
    redirect_to_return_path_or_default my_room_path(@room)
  end
end

#cancel_designObject



235
236
237
238
239
240
241
242
243
# File 'app/controllers/my_rooms_controller.rb', line 235

def cancel_design
  if @room.in_design?
    flash[:info] = 'Your room/heated space was pulled out of design.'
    @room.more_information_required
  elsif !@room.draft? # already there
    flash[:error] = 'Your room/heated space cannot be pulled out of design in this state.'
  end
  redirect_to my_room_path(@room)
end

#capture_measurementsObject



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'app/controllers/my_rooms_controller.rb', line 245

def capture_measurements
  @room ||= @project.room_configurations.find(params[:id])
  @room.reception_type ||= 'DesignTool'
  redirect_path = case @room.reception_type
                  when 'DesignTool2'
                    if @room.room_plan
                      edit_room_plan_path(@room.room_plan, room_configuration_id: @room.id)
                    else
                      new_room_plan_path(room_configuration_id: @room.id)
                    end
                  when 'QuickEstimator'
                  when 'Fax'
                  when 'Upload'
                    upload_my_room_path(@room)
                  when 'HeatLossCalculator'
                    enter_heat_loss_info_my_room_path(@room)
                  else
                    my_room_path(@room)
                  end
  redirect_to redirect_path
end

#complete_redesignObject



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'app/controllers/my_rooms_controller.rb', line 406

def complete_redesign
  @room.attributes = params[:room]
  new_note = @room.new_note
  @room.errors.add(:new_note, 'To ensure the best service possible, please provide a note explaining your redesign request.') if new_note.blank?
  if @room.errors.empty?
    copy_specs = @room.reception_type == 'Unspecified'
    @room = @room.create_revision(false, copy_specs, false)
    @room.new_note = new_note
    if @room.reception_type == 'Unspecified'
      # Automatic redesign
      if @room.send_to_engineering_and_create_crm_quote
        flash[:info] = "Room/heated space #{@room.name} with installation plan number: #{@room.reference_number} was submitted to our engineering team for design"
      else
        flash[:error] = "Could not request plan: #{@room.errors_to_s}, #{@room.quotes.last&.errors_to_s}"
      end
      redirect_to my_project_path(@project)
    else
      capture_measurements
    end
  else
    render :redesign, status: :unprocessable_entity
  end
end

#complete_room_plan_toolObject



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'app/controllers/my_rooms_controller.rb', line 303

def complete_room_plan_tool
  if @room.draft?
    if @room.room_plan
      # DesignTool2 will destroy the room's floorplan and line items
      @room.floorplan_xml = nil
      @room.reception_type = 'DesignTool2'
      @room.reception_date = Time.current
      insulation_sqft = @room.room_plan.room_area&.round(2)
      @room.insulation_surface = insulation_sqft if insulation_sqft
      # put nominal value here until we can calculate heated areas. This prevents weird validation issues of last square footage being larger than current insulation_surface
      @room.square_footage = @room.insulation_surface * 0.9 if @room.insulation_surface
      sqft = @room.room_plan.heated_sq_ft&.round(2)
      @room.square_footage = sqft if sqft && (sqft > 0)
      # DesignTool2 will destroy the room's floorplan and line items
      @room.floorplan_xml = nil
      if @room.save
        @room.generate_bill_of_materials
        finish_measurement
      else
        flash.now[:error] = "There was an error saving room/heated space! #{@room.errors.full_messages&.join(', ')}"
        render :show, status: :unprocessable_entity
      end
    else
      redirect_to(my_room_path(@room), flash: { error: 'Room/heated space layout not found' })
    end
  else
    redirect_to(my_room_path(@room), flash: { error: 'Room/heated space cannot receive a new layout in this state' })
  end
end

#complete_uploadObject



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'app/controllers/my_rooms_controller.rb', line 275

def complete_upload
  if @room.draft?
    @room.attributes = params[:room]
    @room.reception_type = 'Upload'
    @room.reception_date = Time.current
    # uploading will destroy the room's floorplan and line items
    @room.floorplan_xml = nil
    if @room.save
      finish_measurement
    else
      render :upload, status: :unprocessable_entity
    end
  else
    redirect_to(my_room_path(@room), flash: { error: 'Room/heated space cannot receive a new layout in this state' })
  end
end

#createObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/controllers/my_rooms_controller.rb', line 153

def create
  @project.update(params[:opportunity]) if params[:opportunity].present?
  @room = @project.room_configurations.new(params[:room])
  @room.currency = @context_user.customer.catalog.currency
  @room.reception_type ||= 'DesignTool'
  @room.name = @project.next_room_name(room_base_name: @room.name, room_type: @room.room_type, heating_system_product_line: @room.heating_system_product_line)
  if @room.save
    capture_measurements
  else
    @move_to_project_options = (@context_user || @party).opportunities.not_cancelled.to_a.concat([@project]).uniq.map { |p| [p.name, p.id] }
    fetch_room_options
    render action: :new, status: :unprocessable_entity
  end
end

#download_electrical_planObject



131
132
133
134
135
136
137
138
# File 'app/controllers/my_rooms_controller.rb', line 131

def download_electrical_plan
  ep = @room.electrical_plan_pdf
  if ep.present?
    send_upload_accelerated ep
  else
    render plain: 'File is missing', status: :not_found
  end
end

#download_layoutObject



83
84
85
86
87
88
89
90
91
# File 'app/controllers/my_rooms_controller.rb', line 83

def download_layout
  rf = @room.room_layout_image
  if rf.present?
    file_path = rf.attachment.path
    send_file_accelerated file_path, mime_type: rf.mime_type
  else
    render plain: 'File is missing', status: :not_found
  end
end

#download_planObject



112
113
114
115
116
117
118
119
# File 'app/controllers/my_rooms_controller.rb', line 112

def download_plan
  ip = @room.installation_plan_pdf
  if ip.present?
    send_upload_accelerated ip
  else
    render plain: 'File is missing', status: :not_found
  end
end

#duplicateObject



430
431
432
433
# File 'app/controllers/my_rooms_controller.rb', line 430

def duplicate
  @room = @room.create_revision(false, true, false)
  capture_measurements
end

#editObject



147
148
149
150
151
# File 'app/controllers/my_rooms_controller.rb', line 147

def edit
  fetch_room_options
  @force_hlc = true if params[:force_hlc].to_s.downcase.index('t').present?
  @move_to_project_options = (@context_user || @party).opportunities.not_cancelled.order('opportunities.created_at DESC').to_a.concat([@project]).uniq.map { |p| [p.name, p.id] }
end

#electrical_plan_thumbnailObject



121
122
123
124
125
126
127
128
129
# File 'app/controllers/my_rooms_controller.rb', line 121

def electrical_plan_thumbnail
  plan = @room.electrical_plan_pdf
  if plan.present?
    expires_in 1.day
    redirect_to plan.pdf_thumbnail_url('x304>')
  else
    render plain: 'File is missing', status: :not_found
  end
end

#fetch_room_optionsObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'app/controllers/my_rooms_controller.rb', line 208

def fetch_room_options
  @new_room = params[:id].nil?
  update_room_name = true
  update_room_name = false if params[:room_name_touched].present? || !@new_room
  result = GetRoomOptions.new.process(@context_user.customer.store.id, @room, room_params: params[:room], update_room_name: update_room_name, public: true, installation_postal_code: @installation_postal_code, room_quoting_method: params[:room_quoting_method] || 'engineering') # here we 'force' engineering as default since the instant quoting process is not via my_room form
  @room_type = result.room_type
  @environment = result.environment
  @sub_floor_type_options = result.sub_floor_type_options
  @sub_floor_type = result.sub_floor_type
  @sub_floor_type_id = result.sub_floor_type_id
  @floor_type_options = result.floor_type_options
  @floor_type = result.floor_type
  @floor_type_id = result.floor_type_id
  @heating_system_product_line_options = result.heating_system_product_line_options
  @heating_system_product_line = result.heating_system_product_line
  @heating_system_product_line_id = result.heating_system_product_line_id
  @voltages = result.voltage_options
  @voltage_id = result.voltage_id
  @require_cable_spacing = result.require_cable_spacing
  @cable_spacing = result.cable_spacing
  @default_cable_spacings = HeatingElementProductLineOption.default_cable_spacings
  @recommended_cable_spacings = HeatingElementProductLineOption.default_cable_spacings(@installation_postal_code, @sub_floor_type, @floor_type)
  @coverage_state = result.coverage_state
  @room_name = result.room_name
  logger.debug "fetch_room_options, result.inspect: #{result.inspect}"
end

#finish_measurementObject



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'app/controllers/my_rooms_controller.rb', line 333

def finish_measurement
  # remove BOM line items if EV Easy Mat and not ev2help
  @room.new_note = 'Customer requested EV2 help' if (@room.heating_system_type_name == 'Environ Easy Mat') && (params[:ev2help] == 'true')
  if 
    # if (@room.draft? and current_account and @room.reception_type != "DesignTool") or (@room.reception_type == "DesignTool" and (!@room.heated_areas_calculated? or params[:ev2help] == "true" or @room.heating_system_type_name == "Environ Easy Mat"))
    if @room.send_to_engineering_and_create_crm_quote
      flash[:info] = "Your room/heated space #{@room.name} with installation plan number: #{@room.reference_number} was submitted to our design team for an installation plan."
    else
      flash[:error] = "Your room/heated space #{@room.name} is not ready to send to our design team for an installation plan. #{@room.errors_to_s} #{@room.quotes.last&.errors_to_s}"
    end
  end
  if 
    redirect_to my_room_path(@room)
  else
    # puts "finish_measurement, request.fullpath: #{request.fullpath}, request.referer: #{request.referer}"
    (after_authenticate_path: (@room))
  end
end

#finish_moveObject



439
440
441
442
443
444
445
446
447
448
# File 'app/controllers/my_rooms_controller.rb', line 439

def finish_move
  if @room.update(params[:room])
    flash[:info] = "Room/heated space was moved to #{@room.opportunity.name}."
    redirect_to_return_path_or_default my_room_path(@room)
  else
    flash.now[:error] = "Unable to move room/heated space. #{@room.errors_to_s}"
    @move_to_project_options = (@context_user || @party).opportunities.not_cancelled.to_a.concat([@project]).uniq.map { |p| [p.name, p.id] }
    render :move, status: :unprocessable_entity
  end
end

#instant_quotesObject

Legacy IQ actions - redirect to Quote Builder (deprecated in 2018)



451
452
453
# File 'app/controllers/my_rooms_controller.rb', line 451

def instant_quotes
  redirect_to quote_builder_path, allow_other_host: true
end

#layout_small_thumbnailObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/my_rooms_controller.rb', line 65

def layout_small_thumbnail
  rf = @room.room_layout_image
  if rf.present? && rf.attachment.present?
    expires_in 1.day
    if rf.is_image?
      file_path = rf.attachment.thumb('92x61>', frame: '0', format: 'png').path
      send_file_accelerated file_path, file_name: "layout_small_thumbnail_#{@room.id}.png", mime_type: 'image/png'
    elsif rf.is_pdf?
      redirect_to rf.pdf_thumbnail_url('92x61>')
    else
      file_path = Rails.public_path.join('images/no-thumb-250.jpg')
      send_file_accelerated file_path, mime_type: 'image/jpeg'
    end
  else
    render plain: 'File is missing', status: :not_found
  end
end

#layout_thumbnailObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/my_rooms_controller.rb', line 48

def layout_thumbnail
  rf = @room.room_layout_image
  if rf.present? && rf.attachment.present?
    if rf.is_image?
      file_path = rf.attachment.thumb('x304>', frame: '0', format: 'png').path
      send_file_accelerated(file_path, mime_type: 'image/png')
    elsif rf.is_pdf?
      redirect_to rf.pdf_thumbnail_url('x304>')
    else
      file_path = Rails.public_path.join('images/no-thumb-250.jpg')
      send_file_accelerated(file_path, mime_type: 'image/jpeg')
    end
  else
    render plain: 'File is missing', status: :not_found
  end
end

#mark_ready_for_design_on_loginObject



292
293
294
295
296
297
298
299
300
301
# File 'app/controllers/my_rooms_controller.rb', line 292

def 
  if @room&.draft? &&  && (@room.reception_type != 'DesignTool')
    if @room.send_to_engineering_and_create_crm_quote
      flash[:info] = "Your room/heated space #{@room.name} with installation plan reference number: #{@room.reference_number} was submitted to our design team for an installation plan."
    else
      flash[:error] = "Your room/heated space #{@room.name} is not ready to send to our design team for an installation plan. #{@room.errors_to_s} #{@room.quotes.last&.errors_to_s}"
    end
  end
  redirect_to my_room_path(@room)
end

#moveObject



435
436
437
# File 'app/controllers/my_rooms_controller.rb', line 435

def move
  @move_to_project_options = (@context_user || @party).opportunities.not_cancelled.to_a.concat([@project]).uniq.map { |p| [p.name, p.id] }
end

#newObject



140
141
142
143
144
145
# File 'app/controllers/my_rooms_controller.rb', line 140

def new
  @room = @project.room_configurations.new(RoomConfiguration.default_attributes(@project.customer.store.id).merge(name: 'My Room', reception_type: params[:reception_type] || 'DesignTool'))
  @move_to_project_options = (@context_user || @party).opportunities.not_cancelled.to_a.concat([@project]).uniq.map { |p| [p.name, p.id] }
  fetch_room_options
  @room.name = @room_name
end

#plan_small_thumbnailObject



102
103
104
105
106
107
108
109
110
# File 'app/controllers/my_rooms_controller.rb', line 102

def plan_small_thumbnail
  plan = @room.installation_plan_pdf
  if plan.present?
    expires_in 1.day
    redirect_to plan.pdf_thumbnail_url('92x61>')
  else
    render plain: 'File is missing', status: :not_found
  end
end

#plan_thumbnailObject



93
94
95
96
97
98
99
100
# File 'app/controllers/my_rooms_controller.rb', line 93

def plan_thumbnail
  plan = @room.installation_plan_pdf
  if plan.present?
    redirect_to plan.pdf_thumbnail_url('x304>')
  else
    render plain: 'File is missing', status: :not_found
  end
end

#redesignObject



404
# File 'app/controllers/my_rooms_controller.rb', line 404

def redesign; end

#remove_from_cartObject



378
379
380
381
382
383
384
385
386
387
# File 'app/controllers/my_rooms_controller.rb', line 378

def remove_from_cart
  @cart = @context_user.cart
  res_hash = @cart.remove_room_configuration(@room)
  if res_hash[:status]
    flash[:info] = res_hash[:message]
  else
    flash[:error] = res_hash[:message]
  end
  redirect_to_return_path_or_default my_room_path(@room)
end

#request_designObject



168
169
170
171
172
173
174
175
176
# File 'app/controllers/my_rooms_controller.rb', line 168

def request_design
  @room.attributes = params[:room]
  if @room.send_to_engineering_and_create_crm_quote
    flash[:info] = "Your room/heated space #{@room.name} with installation plan number: #{@room.reference_number} was submitted to our design team for an installation plan and bill of materials."
  else
    flash[:error] = "Your room/heated space #{@room.name} is not ready to send to our design team for an installation plan. #{@room.errors_to_s} #{@room.quotes.last&.errors_to_s}"
  end
  redirect_to_return_path_or_default my_room_path(@room)
end

#select_project_detailsObject



455
456
457
# File 'app/controllers/my_rooms_controller.rb', line 455

def select_project_details
  redirect_to quote_builder_path, allow_other_host: true
end

#set_report_errors_forObject (protected)

This controller instance set the model to use for detecting errors in the application_controller#write_flash_to_cookie method.



470
471
472
473
# File 'app/controllers/my_rooms_controller.rb', line 470

def set_report_errors_for
  @report_errors_for ||= []
  @report_errors_for << @room
end

#set_variablesObject (protected)



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'app/controllers/my_rooms_controller.rb', line 475

def set_variables
  if params[:id].present?
    @room = begin
      RoomConfiguration.find(params[:id])
    rescue StandardError
      nil
    end
    # @room = @context_user.customer.room_configurations.find(params[:id]) rescue nil
    @project = @room.opportunity if @room
  elsif params[:my_project_id].present?
    @project = begin
      @context_user.customer.opportunities.find(params[:my_project_id])
    rescue StandardError
      nil
    end
  end
  @installation_postal_code = @project&.installation_postal_code
  return if @room || @project

  flash[:error] = 'Room/heated space or Project not found or not authorized'
  authenticate_account! # this should never happen...
end

#showObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/my_rooms_controller.rb', line 14

def show
  if @room
    track_event('My Account - Quote Viewed', { quoteId: @room.id, roomType: @room.reception_type }) unless @room.first_view_date
    @first_view = @room.first_view_date.nil?
    @room.update_attribute(:first_view_date, Time.current) if @first_view
    @room_configuration = @room
    if params[:update_discount_for_quote_id].present?
      q = begin
        @room.quotes.find(params[:update_discount_for_quote_id])
      rescue StandardError
        nil
      end
      q&.reset_discount
    end
    respond_to do |format|
      format.html
      format.json do
        render json: @room_configuration
      end
    end
  else
    redirect_to(my_projects_path, flash: { error: 'Sorry, we cannot find this room/heated space' })
  end
end

#show_room_planObject



39
40
41
42
43
44
45
46
# File 'app/controllers/my_rooms_controller.rb', line 39

def show_room_plan
  @room_plan = @room.room_plan if @room
  if @room_plan.present?
    render layout: 'www/design_tool'
  else
    render plain: 'Plan is missing', status: :not_found
  end
end

#updateObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/controllers/my_rooms_controller.rb', line 178

def update
  @room.room_type_id
  @room.floor_type_id
  @room.heating_system_product_line_id
  nil
  edit_fp = nil
  params[:room][:name] = @project.next_room_name(room_base_name: params[:room][:name])

  # puts "my_rooms/update: OLD room_type: #{old_room_type_id}, floor_type: #{old_floor_type_id}"
  if @room.update(params[:room]) && (params[:opportunity].blank? || @project.update(params[:opportunity]))
    redirect_to capture_measurements_my_room_path(@room, edit_fp: edit_fp)
  else
    flash[:error] = "There was a problem updating your room/heated space. #{@room.errors_to_s} #{@project.errors_to_s}"
    @move_to_project_options = (@context_user || @party).opportunities.not_cancelled.to_a.concat([@project]).uniq.map { |p| [p.name, p.id] }
    fetch_room_options
    render action: :edit, status: :unprocessable_entity
  end
end

#update_room_optionsObject



197
198
199
200
201
202
203
204
205
206
# File 'app/controllers/my_rooms_controller.rb', line 197

def update_room_options
  fetch_room_options
  respond_to do |format|
    format.html do
      # the only way this happens is if the session ends while editing the room, and they sign in again, so go back to editing the room
      redirect_to edit_my_room_path(@room)
    end
    format.turbo_stream
  end
end

#uploadObject



267
268
269
270
271
272
273
# File 'app/controllers/my_rooms_controller.rb', line 267

def upload
  if @room
    redirect_to(my_room_path(@room), flash: { error: 'Room/heated space cannot receive a new layout in this state' }) unless @room.draft?
  else
    redirect_to(my_projects_path, flash: { error: 'Sorry we cannot find this room/heated space' })
  end
end