Module: HeatlossCalculationsHelper
- Defined in:
- app/helpers/heatloss_calculations_helper.rb
Overview
View helper: heatloss calculations.
Instance Method Summary collapse
- #ceiling_heat_loss_edit_link ⇒ Object
- #ceiling_heat_loss_header ⇒ Object
-
#ceiling_heat_loss_present? ⇒ Boolean
BEGIN CEILING.
-
#check_mark_hlc(done) ⇒ Object
BEGIN COMMON HELPER.
- #edit_icon_hlc(done) ⇒ Object
-
#heat_loss_charts_data(room, heat_loss) ⇒ Hash
Generates data for heat loss charts Stimulus controller.
- #report_hlc_room_error_js(objects = [@room]) ⇒ Object
-
#room_heat_loss_details_header ⇒ Object
BEGIN ROOM GENERAL.
- #under_floor_heat_loss_edit_link ⇒ Object
- #under_floor_heat_loss_header ⇒ Object
-
#under_floor_heat_loss_present? ⇒ Boolean
BEGIN UNDERFLOOR.
Instance Method Details
#ceiling_heat_loss_edit_link ⇒ Object
58 59 60 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 58 def ceiling_heat_loss_edit_link link_to edit_icon_hlc(ceiling_heat_loss_present?), ceiling_heat_loss_details_my_room_path(@room), data: { controller: 'ui-blocker', turbo: true, turbo_stream: true }, class: "btn btn-my-account-card transparent border-0 p-0" end |
#ceiling_heat_loss_header ⇒ Object
54 55 56 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 54 def ceiling_heat_loss_header "#{check_mark_hlc(ceiling_heat_loss_present?)} <span class='step-number'>Step 3:</span> Ceiling".html_safe end |
#ceiling_heat_loss_present? ⇒ Boolean
BEGIN CEILING
50 51 52 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 50 def ceiling_heat_loss_present? @room.ceiling.present? and !@room.ceiling.new_record? end |
#check_mark_hlc(done) ⇒ Object
BEGIN COMMON HELPER
19 20 21 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 19 def check_mark_hlc(done) fa_icon('circle-check', style: "").html_safe if done end |
#edit_icon_hlc(done) ⇒ Object
23 24 25 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 23 def edit_icon_hlc(done) done ? fa_icon('pen-to-square', text: "Edit") : fa_icon('plus', text: "Add") end |
#heat_loss_charts_data(room, heat_loss) ⇒ Hash
Generates data for heat loss charts Stimulus controller
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 66 def heat_loss_charts_data(room, heat_loss) # Build highlight months (months where loss exceeds heat supply) highlight_months = heat_loss['loss_exceeds_heat_supply'] .each_with_index .select { |o, _i| o['exceeds'] } .map { |_o, i| i } # Pie chart data pie_data = heat_loss['hlc_by_object'].map do |o| { name: o['name'], y: o['heat_loss'].round, color: o['color'] } end { pie_data: pie_data, hl_averages: heat_loss['hlc_averages'].map { |o| o['heat_loss'].round }, hl_ranges: heat_loss['hlc_ranges'].map { |o| [o['range'][0].round, o['range'][1].round] }, heat_supplied: heat_loss['heat_supplied'].map { |o| o['heat_supplied'].round }, heat_supply_ranges: heat_loss['heat_supplied'].map { |o| [(o['heat_supplied'] * 0.875).round, (o['heat_supplied'] * 1.125).round] }, highlight_months: highlight_months, desired_temps: heat_loss['avg_temperatures'].map { |_o| room.desired_temperature.round }, ambient_temps: heat_loss['ambient_temperatures'].map { |o| o['temperature'].round }, ambient_temp_ranges: heat_loss['ambient_temperature_ranges'].map { |o| [o['range'][0].round, o['range'][1].round] }, avg_temps: heat_loss['avg_temperatures'].map { |o| o['temperature'].round }, avg_temp_ranges: heat_loss['avg_temperature_ranges'].map { |o| [o['range'][0].round, o['range'][1].round] } } end |
#report_hlc_room_error_js(objects = [@room]) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 4 def report_hlc_room_error_js(objects = [@room]) errors = [] if flash[:error].present? errors << flash[:error] flash[:error] = nil end objects.select { |record| record.errors.any? }.each do |record| errors += record.errors. record.errors.clear end errors.compact.uniq end |
#room_heat_loss_details_header ⇒ Object
BEGIN ROOM GENERAL
29 30 31 32 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 29 def room_heat_loss_details_header done = @room.installation_postal_code.present? and @room.area > 0.0 "#{check_mark_hlc(done)} <span class='step-number'>Step 1:</span> Room/Area".html_safe end |
#under_floor_heat_loss_edit_link ⇒ Object
44 45 46 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 44 def under_floor_heat_loss_edit_link link_to edit_icon_hlc(under_floor_heat_loss_present?), under_floor_heat_loss_details_my_room_path(@room), data: { controller: 'ui-blocker', turbo: true, turbo_stream: true }, class: "btn btn-my-account-card transparent border-0 p-0" end |
#under_floor_heat_loss_header ⇒ Object
40 41 42 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 40 def under_floor_heat_loss_header "#{check_mark_hlc(under_floor_heat_loss_present?)} <span class='step-number'>Step 2:</span> Under Floor".html_safe end |
#under_floor_heat_loss_present? ⇒ Boolean
BEGIN UNDERFLOOR
36 37 38 |
# File 'app/helpers/heatloss_calculations_helper.rb', line 36 def under_floor_heat_loss_present? @room.under_floor.present? and !@room.under_floor.new_record? end |