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/css/files.css | 16 +++++++++++++++ src/main/resources/js/files.js | 16 ++++++++++++++- src/main/resources/views/files.rocker.html | 32 +++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 8 deletions(-) (limited to 'src/main/resources') diff --git a/src/main/resources/css/files.css b/src/main/resources/css/files.css index 798e3ec..3ca6792 100644 --- a/src/main/resources/css/files.css +++ b/src/main/resources/css/files.css @@ -1,3 +1,19 @@ +table { + width: 100%; +} + +table, td, th { + vertical-align: middle; + border-spacing: 0; + white-space: nowrap; +} + +table th, table td { + padding: 10px; + border-bottom: 1px solid gray; + text-align: center; +} + a.filename { color: black; text-decoration: none; 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]; + } }); diff --git a/src/main/resources/views/files.rocker.html b/src/main/resources/views/files.rocker.html index f9852f8..2c4a7ff 100644 --- a/src/main/resources/views/files.rocker.html +++ b/src/main/resources/views/files.rocker.html @@ -12,12 +12,30 @@ @layout.template(files.size() + " Files", css, js) -> {
-

/@path

- ../
-
- @for (String file : files) { - @file
-
- } +

/@path

+ + + + + + + + + + + + + + + + @for (String[] fileArray : files) { + + + + + + } + +
NameSizeLast modified
../
@fileArray[0]@fileArray[1]@fileArray[2]
} -- cgit v1.2.3