From 9743bf890107f14670ac15a9b522e23f06370587 Mon Sep 17 00:00:00 2001 From: lrdossan Date: Wed, 28 Aug 2024 10:48:05 +0200 Subject: [PATCH] UI modifications for optional room_capacity input --- caimira/apps/calculator/static/js/co2_form.js | 37 +++++++++++-------- .../templates/base/calculator.form.html.j2 | 4 ++ .../templates/base/calculator.report.html.j2 | 9 +++-- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/caimira/apps/calculator/static/js/co2_form.js b/caimira/apps/calculator/static/js/co2_form.js index eb019c5b..afcf7638 100644 --- a/caimira/apps/calculator/static/js/co2_form.js +++ b/caimira/apps/calculator/static/js/co2_form.js @@ -154,8 +154,8 @@ function validateFormInputs(obj) { const $referenceNode = $("#DIVCO2_data_dialog"); for (let i = 0; i < CO2_data_form.length; i++) { const $requiredElement = $(`[name=${CO2_data_form[i]}]`).first(); - if ($requiredElement.attr('name') !== "fitting_ventilation_states" && - $requiredElement.attr('name') !== "room_capacity" && + if ($requiredElement.attr('name') !== "fitting_ventilation_states" && + $requiredElement.attr('name') !== "room_capacity" && $requiredElement.val() === "") { insertErrorFor( $referenceNode, @@ -245,7 +245,6 @@ function validateCO2Form() { const roomCapacityVal = roomCapacity.val(); if (roomCapacityVal !== "") { const roomCapacityNumber = Number(roomCapacityVal); - const totalPeopleNumber = Number($("#total_people").val()); if (!Number.isInteger(roomCapacityNumber) || roomCapacityNumber <= 0) { insertErrorFor( $referenceNode, @@ -255,11 +254,7 @@ function validateCO2Form() { } } else { - insertErrorFor( - $referenceNode, - `'${roomCapacity.attr('name')}' must be defined.
` - ); - submit = false; + $fittingToSubmit.find("#warning_room_capacity_null").show(); } } @@ -286,6 +281,10 @@ function displayFittingData(json_response) { // Not needed for the form submission delete json_response["CO2_plot"]; delete json_response["predictive_CO2"]; + // Convert nulls to empty strings in the JSON response + if (json_response["room_capacity"] === null) json_response["room_capacity"] = ''; + if (json_response["ventilation_lsp_values"] === null) json_response["ventilation_lsp_values"] = ''; + // Populate the hidden input $("#CO2_fitting_result").val(JSON.stringify(json_response)); $("#exhalation_rate_fit").html( "Exhalation rate: " + @@ -295,10 +294,14 @@ function displayFittingData(json_response) { let ventilation_table = ` Time (HH:MM) ACH value (h⁻¹) - Flow rate (L/s) - Flow rate (L/s/person) - `; - json_response["ventilation_values"].forEach((CO2_val, index) => { + Flow rate (L/s)`; + // Check if ventilation_lsp_values is not empty + let hasLspValues = json_response['ventilation_lsp_values'] !== ''; + if (hasLspValues) { + ventilation_table += `Flow rate (L/s/person)`; + } + ventilation_table += ``; + json_response["ventilation_values"].forEach((CO2_val, index) => { let transition_times = displayTransitionTimesHourFormat( json_response["transition_times"][index], json_response["transition_times"][index + 1] @@ -307,9 +310,12 @@ function displayFittingData(json_response) { ventilation_table += ` ${transition_times} ${CO2_val.toPrecision(2)} - ${json_response['ventilation_ls_values'][index].toPrecision(2)} - ${json_response['ventilation_lsp_values'][index].toPrecision(2)} - `; + ${json_response['ventilation_ls_values'][index].toPrecision(2)}`; + // Add the L/s/person value if available + if (hasLspValues) { + ventilation_table += `${json_response['ventilation_lsp_values'][index].toPrecision(2)}`; + } + ventilation_table += ``; }); $("#disable_fitting_algorithm").prop("disabled", false); @@ -419,6 +425,7 @@ function clearFittingResultComponent() { $referenceNode.find("#DIVCO2_fitting_result, #CO2_input_data_div").hide(); $referenceNode.find("#DIVCO2_fitting_to_submit").hide(); $referenceNode.find("#CO2_data_plot").attr("src", ""); + $referenceNode.find("#warning_room_capacity_null").hide(); // Update the ventilation scheme components $referenceNode.find("#fitting_ventilation_states, [name=fitting_ventilation_type]").prop( diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index 9c74d295..90fbf6b0 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -370,6 +370,10 @@ ? + diff --git a/caimira/apps/templates/base/calculator.report.html.j2 b/caimira/apps/templates/base/calculator.report.html.j2 index e53fdca8..5f0edad0 100644 --- a/caimira/apps/templates/base/calculator.report.html.j2 +++ b/caimira/apps/templates/base/calculator.report.html.j2 @@ -542,13 +542,16 @@
  • From fitting: {% if form.ventilation_type == "from_fitting" %} Yes

    -
  • + {% if form.CO2_fitting_result['room_capacity'] %} + + {% endif %} + - + {% if form.CO2_fitting_result['room_capacity'] %}{% endif %} {% for ventilation in form.CO2_fitting_result['ventilation_values'] %} {% set transition_time = form.CO2_fitting_result['transition_times'] %} @@ -556,7 +559,7 @@ - + {% if form.CO2_fitting_result['room_capacity'] %}{% endif %} {% endfor %}
    Time (HH:MM) ACH value (h⁻¹) Flow rate (L/s)Flow rate (L/s/person)Flow rate (L/s/person)
    {{ transition_time[loop.index - 1] | hour_format }} - {{ transition_time[loop.index] | hour_format }} {{ ventilation | float_format }} {{ form.CO2_fitting_result['ventilation_ls_values'][loop.index - 1] | float_format }} {{ form.CO2_fitting_result['ventilation_lsp_values'][loop.index - 1] | float_format }} {{ form.CO2_fitting_result['ventilation_lsp_values'][loop.index - 1] | float_format }}