Skip to content

Commit

Permalink
UI modifications for optional room_capacity input
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Aug 28, 2024
1 parent 4f984b2 commit 0355331
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
37 changes: 22 additions & 15 deletions caimira/apps/calculator/static/js/co2_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -255,11 +254,7 @@ function validateCO2Form() {
}
}
else {
insertErrorFor(
$referenceNode,
`'${roomCapacity.attr('name')}' must be defined.</br>`
);
submit = false;
$fittingToSubmit.find("#warning_room_capacity_null").show();
}
}

Expand All @@ -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: " +
Expand All @@ -295,10 +294,14 @@ function displayFittingData(json_response) {
let ventilation_table = `<tr>
<th>Time (HH:MM)</th>
<th>ACH value (h⁻¹)</th>
<th>Flow rate (L/s)</th>
<th>Flow rate (L/s/person)</th>
</tr>`;
json_response["ventilation_values"].forEach((CO2_val, index) => {
<th>Flow rate (L/s)</th>`;
// Check if ventilation_lsp_values is not empty
let hasLspValues = json_response['ventilation_lsp_values'] !== '';
if (hasLspValues) {
ventilation_table += `<th>Flow rate (L/s/person)</th>`;
}
ventilation_table += `</tr>`;
json_response["ventilation_values"].forEach((CO2_val, index) => {
let transition_times = displayTransitionTimesHourFormat(
json_response["transition_times"][index],
json_response["transition_times"][index + 1]
Expand All @@ -307,9 +310,12 @@ function displayFittingData(json_response) {
ventilation_table += `<tr>
<td>${transition_times}</td>
<td>${CO2_val.toPrecision(2)}</td>
<td>${json_response['ventilation_ls_values'][index].toPrecision(2)}</td>
<td>${json_response['ventilation_lsp_values'][index].toPrecision(2)}</td>
</tr>`;
<td>${json_response['ventilation_ls_values'][index].toPrecision(2)}</td>`;
// Add the L/s/person value if available
if (hasLspValues) {
ventilation_table += `<td>${json_response['ventilation_lsp_values'][index].toPrecision(2)}</td>`;
}
ventilation_table += `</tr>`;
});

$("#disable_fitting_algorithm").prop("disabled", false);
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion caimira/apps/templates/base/calculator.form.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
<!-- Formatted excel data -->
<input id="CO2_data" type="text" name="CO2_data" form="not-submitted" class="form-control d-none" placeholder='{"times": [...], "concentrations": [...]}' value="{}"><br>
<div id="CO2_input_data_div" style="display: none"></div>
<input type="text" class="form-control d-none" name="CO2_fitting_result" id="CO2_fitting_result">
<input type="text" class="form-control" name="CO2_fitting_result" id="CO2_fitting_result">

<div id="DIVCO2_fitting_to_submit" style="display: none">
<img id="CO2_data_plot"/><br>
Expand Down Expand Up @@ -370,6 +370,10 @@
<span class="tooltip_text">?</span>
</div>
<input type="number" id="room_capacity" class="form-control col-sm-7" name="room_capacity" placeholder="Number" min=1 form="not-submitted">
<p id="warning_room_capacity_null" class="mt-2" style="display: none">
<strong>Note:</strong> The maximum occupation - design limit was not defined. <br>
Therefore the flow rate in liters per second per person will not be calculated.
</p>
</div>
</div>

Expand Down
9 changes: 6 additions & 3 deletions caimira/apps/templates/base/calculator.report.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -542,21 +542,24 @@
<li><p class="data_text">From fitting:
{% if form.ventilation_type == "from_fitting" %}
Yes</p>
<ul><li><p class="data_text">Room capacity: {{ form.CO2_fitting_result['room_capacity'] | int_format }}</p></li></ul></li>
{% if form.CO2_fitting_result['room_capacity'] %}
<ul><li><p class="data_text">Room capacity: {{ form.CO2_fitting_result['room_capacity'] | int_format }}</p></li></ul>
{% endif %}
</li>
<table class="w-50 mt-3 ml-4" border="1">
<tr>
<th> Time (HH:MM)</th>
<th>ACH value (h⁻¹)</th>
<th>Flow rate (L/s)</th>
<th>Flow rate (L/s/person)</th>
{% if form.CO2_fitting_result['room_capacity'] %}<th>Flow rate (L/s/person)</th>{% endif %}
</tr>
{% for ventilation in form.CO2_fitting_result['ventilation_values'] %}
{% set transition_time = form.CO2_fitting_result['transition_times'] %}
<tr>
<td>{{ transition_time[loop.index - 1] | hour_format }} - {{ transition_time[loop.index] | hour_format }}</td>
<td>{{ ventilation | float_format }} </td>
<td>{{ form.CO2_fitting_result['ventilation_ls_values'][loop.index - 1] | float_format }} </td>
<td>{{ form.CO2_fitting_result['ventilation_lsp_values'][loop.index - 1] | float_format }} </td>
{% if form.CO2_fitting_result['room_capacity'] %}<td>{{ form.CO2_fitting_result['ventilation_lsp_values'][loop.index - 1] | float_format }} </td>{% endif %}
</tr>
{% endfor %}
</table>
Expand Down

0 comments on commit 0355331

Please sign in to comment.