mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-22 06:23:01 +00:00
[client/device-graph] Bugfix: Avoid issues when no data can be fetched
This commit is contained in:
parent
f73cf8b1f6
commit
3a166a0563
2 changed files with 22 additions and 13 deletions
10
build
10
build
|
@ -144,9 +144,15 @@ function task_client {
|
|||
|
||||
function task_client-watch {
|
||||
echo -e "Watching for changes.";
|
||||
while inotifywait -qr --event modify --format '%:e %f' client_src; do
|
||||
while :; do # : = infinite loop
|
||||
# Wait for an update
|
||||
# inotifywait's non-0 exit code forces an exit for some reason :-/
|
||||
inotifywait -qr --event modify --format '%:e %f' client_src;
|
||||
|
||||
# Rebuild the client code - spawn a sub-process to avoid the hard exit
|
||||
# This still doesn't work though, which is *really* annoying
|
||||
stage_begin "Rebuilding client code";
|
||||
task_client;
|
||||
./build client;
|
||||
stage_end $?;
|
||||
done
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ class DeviceReadingDisplay {
|
|||
// TODO: Display a nice error message here instead of an alert()
|
||||
alert(error);
|
||||
console.error(error);
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log("[marker/popup/device-graph] Fetched data:", new_data);
|
||||
|
@ -157,21 +157,20 @@ class DeviceReadingDisplay {
|
|||
}
|
||||
|
||||
async switch_graph_type_handler(event) {
|
||||
let old_reading_type = this.reading_type;
|
||||
// Figure out what the new reading type is
|
||||
this.reading_type = this.reading_types.find((type) => type.id == event.target.parentNode.dataset.id);
|
||||
|
||||
console.log("[marker/device-graph] Reading type is now", this.reading_type);
|
||||
|
||||
await this.update_chart();
|
||||
|
||||
// If we get to here, we updated the chart without error
|
||||
|
||||
// Update the button list to highlight the newly-selected reading type
|
||||
// Remove the selected class from the old one
|
||||
event.target.parentNode.parentNode.querySelector(`[data-id=${old_reading_type.id}] button`).classList.remove("selected");
|
||||
// Add the selected class to the new one
|
||||
event.target.classList.add("selected");
|
||||
// Update the button list to highlight the newly-selected reading type, but only if we managed to update the chart successfully
|
||||
if(await this.update_chart()) {
|
||||
// Remove the selected class from the old one(s?)
|
||||
event.target.parentNode.parentNode.querySelectorAll(`button`)
|
||||
.forEach((next_button) => next_button.classList.remove("selected"));
|
||||
|
||||
// Add the selected class to the new one
|
||||
event.target.classList.add("selected");
|
||||
}
|
||||
}
|
||||
|
||||
async update_chart() {
|
||||
|
@ -183,6 +182,8 @@ class DeviceReadingDisplay {
|
|||
data: await this.get_data()
|
||||
};
|
||||
|
||||
if(new_data_obj.data == null) return false;
|
||||
|
||||
// Update the colour & suggested min/max values
|
||||
let def = this.reading_type_defs[this.reading_type.id],
|
||||
y_axis = this.chart.options.scales.yAxes[0];
|
||||
|
@ -210,6 +211,8 @@ class DeviceReadingDisplay {
|
|||
|
||||
// Update the chart
|
||||
this.chart.update();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue