Module: Controllers::HeatLoss
Overview
ActiveSupport::Concern mixin: heat loss.
Constant Summary
HeatLossPathsHelper::HEAT_LOSS_ACTIONS
Instance Method Summary
collapse
#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, #room_path_for_room, #show_heat_loss_path_for_room
Instance Method Details
#ceiling_heat_loss_details ⇒ Object
185
186
187
188
189
190
191
|
# File 'app/concerns/controllers/heat_loss.rb', line 185
def ceiling_heat_loss_details
set_ceiling_variables
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#complete_ceiling_heat_loss_details ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'app/concerns/controllers/heat_loss.rb', line 193
def complete_ceiling_heat_loss_details
if @room.update(params[:room])
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_ceiling_variables
set_validation_errors_flash(@room)
respond_to do |format|
format.turbo_stream { render action: :ceiling_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#complete_doors_heat_loss_details ⇒ Object
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
# File 'app/concerns/controllers/heat_loss.rb', line 387
def complete_doors_heat_loss_details
if @room.update(params[:room])
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_doors_variables
@exterior_wall = @room.exterior_walls.to_a[@exterior_wall_child_index.to_i]
if @door.nil?
@door = @exterior_wall.doors.to_a[@child_index.to_i]
@child_index = nil
end
set_validation_errors_flash(@room)
respond_to do |format|
format.turbo_stream { render action: :doors_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#complete_exterior_walls_heat_loss_details ⇒ Object
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
# File 'app/concerns/controllers/heat_loss.rb', line 276
def complete_exterior_walls_heat_loss_details
if @room.update(params[:room])
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_exterior_walls_variables
if @exterior_wall.nil?
@exterior_wall = @room.exterior_walls.to_a[@child_index.to_i]
@child_index = nil
end
set_validation_errors_flash(@room)
respond_to do |format|
format.turbo_stream { render action: :exterior_walls_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#complete_heat_loss_info ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/concerns/controllers/heat_loss.rb', line 61
def complete_heat_loss_info
if @room.floor_type&.is_indoors?
res = @room.can_calculate_heat_loss?
if res[:status] == :ok
@heat_loss = @room.calculate_heat_loss
redirect_to(show_heat_loss_path_for(@room, request.subdomain), flash: { notice: "Room's heat loss was calculated." })
else
flash[:error] = "Can't calculate heat loss yet: #{res[:errors].join(', ')}."
@room.enter_heat_loss_info = true
render action: :enter_heat_loss_info
end
else
flash[:error] = 'Heat Loss Calculation is only for indoor rooms.'
render action: :show
end
end
|
#complete_room_heat_loss_details ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/concerns/controllers/heat_loss.rb', line 130
def complete_room_heat_loss_details
@room.enter_heat_loss_info = true
if @room.update(params[:room])
set_under_floor_variables
respond_to do |format|
format.turbo_stream { render action: :under_floor_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_validation_errors_flash(@room)
respond_to do |format|
format.turbo_stream { render action: :room_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#complete_skylights_heat_loss_details ⇒ Object
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'app/concerns/controllers/heat_loss.rb', line 223
def complete_skylights_heat_loss_details
if @room.update(params[:room])
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_skylights_variables
if @skylight.nil?
@skylight = @room.ceiling.skylights.to_a[@child_index.to_i]
@child_index = nil
end
set_validation_errors_flash(@room)
respond_to do |format|
format.turbo_stream { render action: :skylights_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#complete_under_floor_heat_loss_details ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'app/concerns/controllers/heat_loss.rb', line 161
def complete_under_floor_heat_loss_details
if @room.update(params[:room])
set_ceiling_variables
respond_to do |format|
format.turbo_stream { render action: :ceiling_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_under_floor_variables
set_validation_errors_flash(@room)
flash.now[:error] ||= 'Could not save...'
respond_to do |format|
format.turbo_stream { render action: :under_floor_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#complete_windows_heat_loss_details ⇒ Object
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# File 'app/concerns/controllers/heat_loss.rb', line 331
def complete_windows_heat_loss_details
if @room.update(params[:room])
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
else
set_windows_variables
@exterior_wall = @room.exterior_walls.to_a[@exterior_wall_child_index.to_i]
if @window.nil?
@window = @exterior_wall.windows.to_a[@child_index.to_i]
@child_index = nil
end
set_validation_errors_flash(@room)
respond_to do |format|
format.turbo_stream { render action: :windows_heat_loss_details }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
end
|
#doors_heat_loss_details ⇒ Object
378
379
380
381
382
383
384
385
|
# File 'app/concerns/controllers/heat_loss.rb', line 378
def doors_heat_loss_details
set_doors_variables
@door ||= @exterior_wall.doors.new
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#dupe_door_heat_loss_details ⇒ Object
408
409
410
411
412
413
414
415
416
|
# File 'app/concerns/controllers/heat_loss.rb', line 408
def dupe_door_heat_loss_details
set_doors_variables
new_door = @door.dup
flash[:error] = "Door could not be duplicated: #{new_door.errors_to_s}" unless new_door.save
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#dupe_exterior_wall_heat_loss_details ⇒ Object
296
297
298
299
300
301
302
303
304
|
# File 'app/concerns/controllers/heat_loss.rb', line 296
def dupe_exterior_wall_heat_loss_details
set_exterior_walls_variables
new_exterior_wall = @exterior_wall.dup
flash[:error] = "Ext. Wall could not be duplicated: #{new_exterior_wall.errors_to_s}" unless new_exterior_wall.save
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#dupe_skylight_heat_loss_details ⇒ Object
243
244
245
246
247
248
249
250
251
|
# File 'app/concerns/controllers/heat_loss.rb', line 243
def dupe_skylight_heat_loss_details
set_skylights_variables
new_skylight = @skylight.dup
flash[:error] = "Skylight could not be duplicated: #{new_skylight.errors_to_s}" unless new_skylight.save
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#dupe_window_heat_loss_details ⇒ Object
352
353
354
355
356
357
358
359
360
|
# File 'app/concerns/controllers/heat_loss.rb', line 352
def dupe_window_heat_loss_details
set_windows_variables
new_window = @window.dup
flash[:error] = "Window could not be duplicated: #{new_window.errors_to_s}" unless new_window.save
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#enter_heat_loss_info ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/concerns/controllers/heat_loss.rb', line 48
def enter_heat_loss_info
if @room.present?
if @room.floor_type&.is_indoors?
@room.enter_heat_loss_info = true
else
flash[:error] = 'Heat Loss Calculation is only for indoor rooms.'
render action: :show
end
else
redirect_to(projects_path_for(@room, request.subdomain), flash: { error: 'Sorry we cannot find this room' })
end
end
|
#exterior_walls_heat_loss_details ⇒ Object
267
268
269
270
271
272
273
274
|
# File 'app/concerns/controllers/heat_loss.rb', line 267
def exterior_walls_heat_loss_details
set_exterior_walls_variables
@exterior_wall ||= @room.exterior_walls.new
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#heat_loss_details_summary ⇒ Object
115
116
117
118
119
120
|
# File 'app/concerns/controllers/heat_loss.rb', line 115
def heat_loss_details_summary
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#projects_path_for(room, subdomain) ⇒ Object
511
512
513
514
515
516
517
518
|
# File 'app/concerns/controllers/heat_loss.rb', line 511
def projects_path_for(room, subdomain)
case subdomain
when 'crm'
customer_opportunities_path(room.customer)
else
my_projects_path
end
end
|
#remove_door_heat_loss_details ⇒ Object
418
419
420
421
422
423
424
425
|
# File 'app/concerns/controllers/heat_loss.rb', line 418
def remove_door_heat_loss_details
set_doors_variables
@door.destroy
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#remove_exterior_wall_heat_loss_details ⇒ Object
306
307
308
309
310
311
312
313
|
# File 'app/concerns/controllers/heat_loss.rb', line 306
def remove_exterior_wall_heat_loss_details
set_exterior_walls_variables
@exterior_wall.destroy
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#remove_skylight_heat_loss_details ⇒ Object
253
254
255
256
257
258
259
260
|
# File 'app/concerns/controllers/heat_loss.rb', line 253
def remove_skylight_heat_loss_details
set_skylights_variables
@skylight.destroy
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#remove_window_heat_loss_details ⇒ Object
362
363
364
365
366
367
368
369
|
# File 'app/concerns/controllers/heat_loss.rb', line 362
def remove_window_heat_loss_details
set_windows_variables
@window.destroy
respond_to do |format|
format.turbo_stream { render action: :heat_loss_details_summary }
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#room_heat_loss_details ⇒ Object
122
123
124
125
126
127
128
|
# File 'app/concerns/controllers/heat_loss.rb', line 122
def room_heat_loss_details
@room.insulation_surface ||= @room.area
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#set_ceiling_variables ⇒ Object
179
180
181
182
183
|
# File 'app/concerns/controllers/heat_loss.rb', line 179
def set_ceiling_variables
@room.build_ceiling(area: @room.area, height: 9.0) if @room.ceiling.blank?
@ceiling_insulation_type_options = CeilingInsulationType.options_for_select(@room.ceiling.ceiling_type_id, @room)
@ceiling_insulation_type_id = @room.ceiling.ceiling_insulation_type_id if @room.ceiling.present?
end
|
#set_doors_variables ⇒ Object
371
372
373
374
375
376
|
# File 'app/concerns/controllers/heat_loss.rb', line 371
def set_doors_variables
@exterior_wall = @room.exterior_walls.find(params[:exterior_wall_id])
@exterior_wall_child_index = params[:exterior_wall_child_index]
@door = @exterior_wall.doors.find(params[:door_id]) if params[:door_id].present?
@child_index = params[:child_index]
end
|
#set_exterior_walls_variables ⇒ Object
262
263
264
265
|
# File 'app/concerns/controllers/heat_loss.rb', line 262
def set_exterior_walls_variables
@exterior_wall = @room.exterior_walls.find_by(id: params[:exterior_wall_id]) if params[:exterior_wall_id].present?
@child_index = params[:child_index]
end
|
#set_skylights_variables ⇒ Object
209
210
211
212
|
# File 'app/concerns/controllers/heat_loss.rb', line 209
def set_skylights_variables
@skylight = @room.ceiling.skylights.find(params[:skylight_id]) if params[:skylight_id].present?
@child_index = params[:child_index]
end
|
#set_under_floor_variables ⇒ Object
147
148
149
150
151
|
# File 'app/concerns/controllers/heat_loss.rb', line 147
def set_under_floor_variables
@room.build_under_floor(area: @room.area, under_floor_type_id: @room.guess_under_floor_type_id) if @room.under_floor.blank?
@under_floor_insulation_type_options = UnderFloorInsulationType.options_for_select(@room.under_floor.under_floor_type_id, @room)
@under_floor_insulation_type_id = @room.under_floor.under_floor_insulation_type_id if @room.under_floor.present?
end
|
#set_windows_variables ⇒ Object
315
316
317
318
319
320
|
# File 'app/concerns/controllers/heat_loss.rb', line 315
def set_windows_variables
@exterior_wall = @room.exterior_walls.find(params[:exterior_wall_id])
@exterior_wall_child_index = params[:exterior_wall_child_index]
@window = @exterior_wall.windows.find(params[:window_id]) if params[:window_id].present?
@child_index = params[:child_index]
end
|
#show_heat_loss ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'app/concerns/controllers/heat_loss.rb', line 78
def show_heat_loss
if @room.present?
if @room.floor_type&.is_indoors?
res = @room.can_calculate_heat_loss?
@heat_loss = @room.last_heat_loss.presence || @room.calculate_heat_loss if res[:status] == :ok
if @heat_loss && @heat_loss['hlc_by_object']&.any?
respond_to do |format|
format.html format.pdf do
result = Pdf::Document::HeatLossReport.call(@room)
if params[:save_to_room].to_b
@room.uploads.where(category: 'heat_loss_report').find_each(&:destroy) Upload.uploadify_from_data(file_name: result.file_name, data: result.pdf, category: 'heat_loss_report', resource: @room)
flash[:info] = 'The Heat Loss report was saved and can be found in the attachments for this room'
redirect_to room_configuration_path(@room, anchor: "attachments")
else
send_data result.pdf,
filename: result.file_name,
type: 'application/pdf',
disposition: 'inline'
end
end
end
else
flash[:error] = "Can't calculate heat loss yet: #{res[:errors].join(', ')}."
@room.enter_heat_loss_info = true
redirect_to enter_heat_loss_info_path_for_room(@room)
end
else
flash[:error] = 'Heat Loss Calculation is only for indoor rooms.'
render action: :show
end
else
redirect_to(projects_path_for(@room, request.subdomain), flash: { error: 'Sorry we cannot find this room' })
end
end
|
#show_heat_loss_path_for(room, subdomain) ⇒ Object
502
503
504
505
506
507
508
509
|
# File 'app/concerns/controllers/heat_loss.rb', line 502
def show_heat_loss_path_for(room, subdomain)
case subdomain
when 'crm'
show_heat_loss_room_configuration_path(room)
else
show_heat_loss_my_room_path(room)
end
end
|
#skylights_heat_loss_details ⇒ Object
214
215
216
217
218
219
220
221
|
# File 'app/concerns/controllers/heat_loss.rb', line 214
def skylights_heat_loss_details
set_skylights_variables
@skylight ||= @room.ceiling.skylights.new
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#under_floor_heat_loss_details ⇒ Object
153
154
155
156
157
158
159
|
# File 'app/concerns/controllers/heat_loss.rb', line 153
def under_floor_heat_loss_details
set_under_floor_variables
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#update_ceiling_type ⇒ Object
437
438
439
440
441
442
443
444
445
|
# File 'app/concerns/controllers/heat_loss.rb', line 437
def update_ceiling_type
ceiling_type_id = params[:room].try(:[], :ceiling_attributes).try(:[], :ceiling_type_id).try(:to_i)
@ceiling_insulation_type_options = CeilingInsulationType.options_for_select(ceiling_type_id, @room)
@ceiling_insulation_type_id = @room.ceiling.try(:ceiling_insulation_type_id)
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#update_door_type ⇒ Object
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
# File 'app/concerns/controllers/heat_loss.rb', line 482
def update_door_type
@door_child_index = params[:child_index].to_i unless params[:child_index].nil?
@exterior_wall_child_index = params[:exterior_wall_child_index].to_i
if (door_attributes = params[:room].try(:[], :exterior_walls_attributes).try(:[], @exterior_wall_child_index.to_s).try(:[], :doors_attributes).try(:[], @door_child_index.to_s))
@door_type_id = door_attributes[:door_type_id].to_i
@door_core_type_id = door_attributes[:door_core_type_id].to_i
@door_frame_type_id = door_attributes[:door_frame_type_id].to_i
end
if (door = @room.exterior_walls.try(:[], @exterior_wall_child_index).try(:doors).try(:[], @door_child_index))
@door_type_id ||= door.door_type_id
@door_core_type_id ||= door.door_core_type_id
@door_frame_type_id ||= door.door_frame_type_id
end
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#update_exterior_wall_type ⇒ Object
447
448
449
450
451
452
453
454
455
456
457
458
|
# File 'app/concerns/controllers/heat_loss.rb', line 447
def update_exterior_wall_type
@exterior_wall_child_index = params[:child_index].try(:to_i)
@exterior_wall_type_id = params[:room].try(:[], :exterior_walls_attributes).try(:[], @exterior_wall_child_index.to_s).try(:[], :exterior_wall_type_id).try(:to_i)
@exterior_wall_type_id ||= @room.try(:exterior_walls).try(:[], @exterior_wall_child_index).try(:exterior_wall_type_id)
@exterior_wall_insulation_type_options = ExteriorWallInsulationType.options_for_select(@exterior_wall_type_id, @room)
@exterior_wall_insulation_type_id = @room.exterior_walls.try(:[], @exterior_wall_child_index).try(:exterior_wall_insulation_type_id)
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#update_under_floor_type ⇒ Object
427
428
429
430
431
432
433
434
435
|
# File 'app/concerns/controllers/heat_loss.rb', line 427
def update_under_floor_type
under_floor_type_id = params.dig(:room, :under_floor_attributes, :under_floor_type_id)&.to_i
@under_floor_insulation_type_options = UnderFloorInsulationType.options_for_select(under_floor_type_id, @room)
@under_floor_insulation_type_id = @room.try(:under_floor).try(:under_floor_insulation_type_id)
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#update_window_type ⇒ Object
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'app/concerns/controllers/heat_loss.rb', line 460
def update_window_type
@window_child_index = params[:child_index].try(:to_i)
@exterior_wall_child_index = params[:exterior_wall_child_index].to_i
if (window_attributes = params[:room].try(:[], :exterior_walls_attributes).try(:[], @exterior_wall_child_index.to_s).try(:[], :windows_attributes).try(:[], @window_child_index.to_s))
@window_type_id = window_attributes[:window_type_id].to_i
@window_glass_type_id = window_attributes[:window_glass_type_id].to_i
@window_frame_type_id = window_attributes[:window_frame_type_id].to_i
end
if (window = @room.exterior_walls.try(:[], @exterior_wall_child_index).try(:windows).try(:[], @window_child_index))
@window_type_id ||= window.window_type_id
@window_glass_type_id ||= window.window_glass_type_id
@window_frame_type_id ||= window.window_frame_type_id
end
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|
#windows_heat_loss_details ⇒ Object
322
323
324
325
326
327
328
329
|
# File 'app/concerns/controllers/heat_loss.rb', line 322
def windows_heat_loss_details
set_windows_variables
@window ||= @exterior_wall.windows.new
respond_to do |format|
format.turbo_stream
format.html { redirect_to enter_heat_loss_info_path_for_room(@room) }
end
end
|