Module: HeatLossPathsHelper

Included in:
Controllers::HeatLoss
Defined in:
app/helpers/heat_loss_paths_helper.rb

Overview

Provides subdomain-aware path helpers for heat loss functionality.
These helpers work on both WWW (my_rooms) and CRM (room_configurations).

Usage in views:
heat_loss_path(:complete_heat_loss_info, @room)
heat_loss_path(:exterior_walls_heat_loss_details, @room, exterior_wall_id: @wall)

Constant Summary collapse

HEAT_LOSS_ACTIONS =

Map of action names to their path method suffixes

%w[
  complete_heat_loss_info
  heat_loss_details_summary
  room_heat_loss_details
  complete_room_heat_loss_details
  under_floor_heat_loss_details
  complete_under_floor_heat_loss_details
  ceiling_heat_loss_details
  complete_ceiling_heat_loss_details
  skylights_heat_loss_details
  complete_skylights_heat_loss_details
  dupe_skylight_heat_loss_details
  remove_skylight_heat_loss_details
  exterior_walls_heat_loss_details
  complete_exterior_walls_heat_loss_details
  dupe_exterior_wall_heat_loss_details
  remove_exterior_wall_heat_loss_details
  windows_heat_loss_details
  complete_windows_heat_loss_details
  dupe_window_heat_loss_details
  remove_window_heat_loss_details
  doors_heat_loss_details
  complete_doors_heat_loss_details
  dupe_door_heat_loss_details
  remove_door_heat_loss_details
  update_under_floor_type
  update_ceiling_type
  update_exterior_wall_type
  update_window_type
  update_door_type
].freeze

Instance Method Summary collapse

Instance Method Details

#crm_request?Boolean

Check if we're on the CRM subdomain

Returns:

  • (Boolean)


62
63
64
# File 'app/helpers/heat_loss_paths_helper.rb', line 62

def crm_request?
  request.subdomain =~ /^crm/
end

#enter_heat_loss_info_path_for_room(room) ⇒ Object

Convenience method for enter_heat_loss_info path



76
77
78
79
80
81
82
# File 'app/helpers/heat_loss_paths_helper.rb', line 76

def enter_heat_loss_info_path_for_room(room)
  if crm_request?
    enter_heat_loss_info_room_configuration_path(room)
  else
    enter_heat_loss_info_my_room_path(room)
  end
end

#format_errors_as_list(errors) ⇒ String

Format validation errors as an HTML bullet list for flash messages

Parameters:

  • errors (Array<String>)

    Array of error messages

Returns:

  • (String)

    HTML formatted error list



134
135
136
137
138
139
140
# File 'app/helpers/heat_loss_paths_helper.rb', line 134

def format_errors_as_list(errors)
  return '' if errors.blank?

  tag.ul(class: 'mb-0 ps-3') do
    safe_join(errors.map { |msg| tag.li(msg) })
  end.to_s
end

#heat_loss_path(action, room, options = {}) ⇒ String

Returns the correct path for a heat loss action based on current subdomain

Parameters:

  • action (String, Symbol)

    The action name (e.g., :complete_heat_loss_info)

  • room (RoomConfiguration)

    The room object

  • options (Hash) (defaults to: {})

    Additional path options (e.g., exterior_wall_id: @wall)

Returns:

  • (String)

    The URL path

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/heat_loss_paths_helper.rb', line 50

def heat_loss_path(action, room, options = {})
  action = action.to_s
  raise ArgumentError, "Unknown heat loss action: #{action}" unless HEAT_LOSS_ACTIONS.include?(action)

  if crm_request?
    send("#{action}_room_configuration_path", room, options)
  else
    send("#{action}_my_room_path", room, options)
  end
end

#hl_btn_submit_classObject



127
128
129
# File 'app/helpers/heat_loss_paths_helper.rb', line 127

def hl_btn_submit_class
  crm_request? ? 'btn btn-success' : 'btn btn-success btn-block btn-my-account-card'
end

#hl_card_classObject

CSS class helpers for context-aware styling
Returns appropriate CSS classes for cards based on context



95
96
97
# File 'app/helpers/heat_loss_paths_helper.rb', line 95

def hl_card_class
  crm_request? ? 'card' : 'my-account-card'
end

#hl_card_col_classObject



111
112
113
# File 'app/helpers/heat_loss_paths_helper.rb', line 111

def hl_card_col_class
  crm_request? ? 'col-12' : 'col-12 col-my-account-card'
end

#hl_card_content_classObject



107
108
109
# File 'app/helpers/heat_loss_paths_helper.rb', line 107

def hl_card_content_class
  crm_request? ? 'card-body' : 'my-account-card-content'
end

#hl_card_header_classObject



99
100
101
# File 'app/helpers/heat_loss_paths_helper.rb', line 99

def hl_card_header_class
  crm_request? ? 'card-header' : 'my-account-card-header'
end

#hl_card_title_classObject



103
104
105
# File 'app/helpers/heat_loss_paths_helper.rb', line 103

def hl_card_title_class
  crm_request? ? 'card-title mb-0' : 'my-account-card-title'
end

#hl_field_class(object, field) ⇒ String

Check if a field has errors and return appropriate CSS class

Parameters:

  • object (ActiveRecord::Base)

    The form object

  • field (Symbol)

    The field name

Returns:

  • (String)

    CSS class for invalid state or empty string



159
160
161
# File 'app/helpers/heat_loss_paths_helper.rb', line 159

def hl_field_class(object, field)
  object.errors[field].any? ? 'is-invalid' : ''
end

#hl_field_error(object, field) ⇒ String?

Display inline field errors for a form field
Works with nested attributes by checking both the field and nested associations

Parameters:

  • object (ActiveRecord::Base)

    The form object

  • field (Symbol)

    The field name

Returns:

  • (String, nil)

    HTML error message or nil



147
148
149
150
151
152
153
# File 'app/helpers/heat_loss_paths_helper.rb', line 147

def hl_field_error(object, field)
  return nil unless object.errors[field].any?

  tag.div(class: 'invalid-feedback d-block') do
    object.errors[field].to_sentence
  end
end

#hl_form_control_classObject



119
120
121
# File 'app/helpers/heat_loss_paths_helper.rb', line 119

def hl_form_control_class
  crm_request? ? 'form-control' : 'form-control form-control-my-account'
end

#hl_form_group_classObject



115
116
117
# File 'app/helpers/heat_loss_paths_helper.rb', line 115

def hl_form_group_class
  crm_request? ? 'form-group mb-3' : 'form-group form-group-my-account'
end

#hl_form_select_classObject



123
124
125
# File 'app/helpers/heat_loss_paths_helper.rb', line 123

def hl_form_select_class
  crm_request? ? 'form-select' : 'form-control form-control-my-account form-select'
end

#room_path_for_room(room) ⇒ Object

Convenience method for room path (back to room details)



85
86
87
88
89
90
91
# File 'app/helpers/heat_loss_paths_helper.rb', line 85

def room_path_for_room(room)
  if crm_request?
    room_configuration_path(room)
  else
    my_room_path(room)
  end
end

#show_heat_loss_path_for_room(room) ⇒ Object

Convenience method for show_heat_loss path



67
68
69
70
71
72
73
# File 'app/helpers/heat_loss_paths_helper.rb', line 67

def show_heat_loss_path_for_room(room)
  if crm_request?
    show_heat_loss_room_configuration_path(room)
  else
    show_heat_loss_my_room_path(room)
  end
end