aboutsummaryrefslogtreecommitdiffstats
path: root/src/public/js
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2022-02-22 18:13:53 -0600
committerMatt Strapp <matt@mattstrapp.net>2022-02-22 18:27:42 -0600
commit1e776b35bed788ad0c9332ac67b86b2ce4b9b826 (patch)
treea9b8dc73fced7d2160bd334da271ae04e0751dd5 /src/public/js
parentBump @typescript-eslint/eslint-plugin from 5.12.0 to 5.12.1 (#10) (diff)
downloadee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.tar
ee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.tar.gz
ee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.tar.bz2
ee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.tar.lz
ee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.tar.xz
ee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.tar.zst
ee4511w-web-1e776b35bed788ad0c9332ac67b86b2ce4b9b826.zip
Maybe add CSV support
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'src/public/js')
-rw-r--r--src/public/js/form.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/public/js/form.js b/src/public/js/form.js
index 581d5a3..3fbeb50 100644
--- a/src/public/js/form.js
+++ b/src/public/js/form.js
@@ -1,3 +1,5 @@
+// This is split into comments so it doesn't look as gross with the closure tabs
+
window.onload = function () {
document.getElementById('nojs').hidden = true;
document.getElementById('block').hidden = false;
@@ -10,6 +12,7 @@ document.getElementById('upload').onsubmit = function () {
document.getElementById('upload-err').innerText = '';
document.getElementById('actuate-err').innerText = '';
document.getElementById('upload-response').innerText = '';
+ document.getElementById('download-link').innerText = '';
// Make AJAX request
let xhr = new XMLHttpRequest();
xhr.open('POST', '/api/v1/upload');
@@ -43,8 +46,7 @@ function actuate(file) {
let xhr = new XMLHttpRequest();
xhr.open('POST', '/api/v1/actuate');
let data = {
- name: file.name,
- path: file.path,
+ file: file.file
};
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.setRequestHeader('X-CSRF-TOKEN', file.csrf);
@@ -54,6 +56,7 @@ function actuate(file) {
let response = JSON.parse(xhr.responseText);
if (xhr.status === 200) {
console.log(response);
+ createDownload(response.file);
} else {
// Display upload error message to the user
document.getElementById('actuate-err').innerText = response.error;
@@ -61,6 +64,20 @@ function actuate(file) {
if (xhr.status === 500)
console.error(response.error_msg);
}
+ return;
}
};
+}
+
+
+// Creates the download element
+function createDownload(response) {
+ const tempName = response.filename;
+ const downloadName = response.name.split('.')[ 0 ];
+ const downloadLink = document.createElement('a');
+ downloadLink.setAttribute('href', `/api/v1/download/?filename=${tempName}`);
+ downloadLink.setAttribute('download', `${downloadName}.csv`);
+ downloadLink.innerText = 'Download CSV of results here.';
+ document.getElementById('download-link').appendChild(downloadLink);
+ return;
} \ No newline at end of file