From 8c6905d0553b88b1257cab13355873d5438704fa Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sun, 14 Apr 2019 17:55:38 +0200
Subject: Added table for file list view
---
src/main/resources/js/files.js | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
(limited to 'src/main/resources/js/files.js')
diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js
index 24140b0..3cdf4fd 100644
--- a/src/main/resources/js/files.js
+++ b/src/main/resources/js/files.js
@@ -22,10 +22,24 @@ drop.addEventListener('drop', e => {
let request = new XMLHttpRequest();
let formData = new FormData();
- drop.insertAdjacentHTML('beforeend', `${files[i].name}
`);
+ // TODO: Consider using current date due to updated lastModified state at upload
+ const date = new Date(files[i].lastModified);
+ const lastModified = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
+
+ const row = document.getElementById("table").insertRow(-1);
+ row.insertCell(0).innerHTML = `${files[i].name}`;
+ row.insertCell(1).innerHTML = `${bytesToSize(files[i].size)}`;
+ row.insertCell(2).innerHTML = `${lastModified}`;
formData.append("file", files[i]);
request.open("POST", "/upload/" + path);
request.send(formData);
}
+
+ function bytesToSize(bytes) {
+ const sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
+ if (bytes === 0) return '0 Byte';
+ const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+ return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
+ }
});
--
cgit v1.2.3