diff options
author | Matt Kohls <mattkohls13@gmail.com> | 2021-04-23 23:42:42 -0400 |
---|---|---|
committer | Matt Kohls <mattkohls13@gmail.com> | 2021-04-23 23:42:42 -0400 |
commit | 437c1179b545927197637c26bb2d87d20401e5f2 (patch) | |
tree | 590e57b5dd6f0d707d8e95a7a5242bd1e892053f /static/interactive.js | |
parent | 352c56375b4ec2af8f0b593b450069271bcd65e2 (diff) | |
download | Sensor-Server-master.tar.gz Sensor-Server-master.tar.bz2 Sensor-Server-master.zip |
Many changes, mostly to make landing page more readable
Oh and a file to read a sensor attached via i2c on a Raspberry Pi and
add that to the db
Diffstat (limited to 'static/interactive.js')
-rw-r--r-- | static/interactive.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/static/interactive.js b/static/interactive.js new file mode 100644 index 0000000..de44670 --- /dev/null +++ b/static/interactive.js @@ -0,0 +1,64 @@ +/** + * Script to change the shown graph + * + * Matt Kohls + * 2021 + */ + +const form = document.getElementById('query'); +const submitButton = document.getElementById('submit'); +const figure = document.getElementById('figure'); + +function sendRequest(data) { + let url = "/", + urlEncoded = "", + urlEncodedPairs = [], + name, + startDate, + startTime, + endDate, + endTime; + + for (name of data) { + switch (name[0]) { + case 'graph': + url = url.concat(name[1]); + break; + case 'sd': + startDate = name[1].replace(/-/g, ''); + break; + case 'st': + startTime = name[1].replace(/:/g, '').concat('00'); + case 'ed': + endDate = name[1].replace(/-/g, ''); + break; + case 'et': + endTime = name[1].replace(/:/g, '').concat('00'); + break; + case 'deviceId': + default: + urlEncodedPairs.push(name[0] + '=' + name[1]); + } + } + if (startDate !== "") { + if (startTime === "00") { + startTime = "000000"; + } + urlEncodedPairs.push('start=' + startDate + startTime); + } + if (endDate !== "") { + if (endTime === "00") { + endTime = "000000"; + } + urlEncodedPairs.push('end=' + endDate + endTime); + } + + urlEncoded = urlEncodedPairs.join('&'); + figure.setAttribute('src', url + '?' + urlEncoded); +} + +submitButton.addEventListener('click', function() { + const formData = new FormData(form); + sendRequest(formData); +}) + |