aboutsummaryrefslogtreecommitdiffstats
path: root/snag/static/interactive.js
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2023-09-04 15:36:33 -0400
committerMatt Kohls <mattkohls13@gmail.com>2023-09-04 15:36:33 -0400
commitc8ef8843aaaf28bc38b544ae8ac72accf233aead (patch)
tree53e846d7480814040bbebe11dd6e290f5d366589 /snag/static/interactive.js
downloadsensor-aggregator-c8ef8843aaaf28bc38b544ae8ac72accf233aead.tar.gz
sensor-aggregator-c8ef8843aaaf28bc38b544ae8ac72accf233aead.tar.bz2
sensor-aggregator-c8ef8843aaaf28bc38b544ae8ac72accf233aead.zip
Revamped project init
New repo for larger structural changes from Sensor-Server. Currently doing most all the same stuff but hopefully better. Still have to clean out some of the older templates for the new interface
Diffstat (limited to 'snag/static/interactive.js')
-rw-r--r--snag/static/interactive.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/snag/static/interactive.js b/snag/static/interactive.js
new file mode 100644
index 0000000..de44670
--- /dev/null
+++ b/snag/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);
+})
+