diff options
author | Matt Strapp <matt@mattstrapp.net> | 2022-02-22 18:13:53 -0600 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2022-02-22 18:27:42 -0600 |
commit | 1e776b35bed788ad0c9332ac67b86b2ce4b9b826 (patch) | |
tree | a9b8dc73fced7d2160bd334da271ae04e0751dd5 /src/public | |
parent | Bump @typescript-eslint/eslint-plugin from 5.12.0 to 5.12.1 (#10) (diff) | |
download | ee4511w-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')
-rw-r--r-- | src/public/css/style.css | 4 | ||||
-rw-r--r-- | src/public/js/form.js | 21 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/public/css/style.css b/src/public/css/style.css index b1651df..a106926 100644 --- a/src/public/css/style.css +++ b/src/public/css/style.css @@ -28,7 +28,7 @@ p { /* Used for id=button1 */ -#actuate_but { +#actuate-but { background-color: #0a3f73; border: solid; border-color: #d5d6d2; @@ -45,7 +45,7 @@ p { /* Used for id=button1 - What the button looks like when a user puts one's cursor on it */ -#actuate_but:hover { +#actuate-but:hover { background-color: white; color: maroon; cursor: pointer; 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 |