Size in toolbar

This commit is contained in:
2020-01-21 17:01:26 +01:00
parent ef063bbe26
commit 8bff81ce6c
7 changed files with 31 additions and 29 deletions

View File

@@ -90,3 +90,17 @@ function domainURL() {
} }
return url; return url;
} }
function formatDataVolume(amt = 0, precision = 3) {
if (precision < 3) { precision = 3; }
if (amt >= 1e12) {
return (amt/1e12).toPrecision(precision) + " TB";
} else if (amt >= 1e9) {
return (amt/1e9).toPrecision(precision) + " GB";
} else if (amt >= 1e6) {
return (amt/1e6).toPrecision(precision) + " MB";
} else if (amt >= 1e3) {
return (amt/1e3).toPrecision(precision) + " kB";
}
return amt + " B"
}

View File

@@ -56,13 +56,12 @@ class DetailsWindow {
+ "<tr><td>URL<td><td><a href=\"/u/" + file.id + "\">"+domainURL()+"/u/" + file.id + "</a></td></tr>" + "<tr><td>URL<td><td><a href=\"/u/" + file.id + "\">"+domainURL()+"/u/" + file.id + "</a></td></tr>"
+ "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>" + "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>"
+ "<tr><td>ID<td><td>" + file.id + "</td></tr>" + "<tr><td>ID<td><td>" + file.id + "</td></tr>"
+ "<tr><td>Size<td><td>" + formatDataVolume(file.size) + "</td></tr>" + "<tr><td>Size<td><td>" + formatDataVolume(file.size, 4) + "</td></tr>"
+ "<tr><td>Bandwidth<td><td>" + formatDataVolume(file.bandwidth_used) + "</td></tr>" + "<tr><td>Bandwidth<td><td>" + formatDataVolume(file.bandwidth_used, 4) + "</td></tr>"
+ "<tr><td>Upload Date<td><td>" + file.date_upload + "</td></tr>" + "<tr><td>Upload Date<td><td>" + file.date_upload + "</td></tr>"
+ "<tr><td>Description<td><td>" + escapeHTML(desc) + "</td></tr>" + "<tr><td>Description<td><td>" + escapeHTML(desc) + "</td></tr>"
+ "</table>"; + "</table>";
dw.viewer.toolbar.setStats(file.views, file.bandwidth_used/file.size);
if(dw.visible) { if(dw.visible) {
dw.updateGraph(file.id); dw.updateGraph(file.id);
} }

View File

@@ -7,10 +7,11 @@ class Toolbar {
// Elements // Elements
divToolbar = null; divToolbar = null;
divFilePreview = null; divFilePreview = null;
downloadFrame = null downloadFrame = null;
spanViews = null; spanViews = null;
spanDownloads = null; spanDownloads = null;
spanSize = null;
btnToggleToolbar = null; btnToggleToolbar = null;
btnDownload = null; btnDownload = null;
@@ -27,6 +28,7 @@ class Toolbar {
t.downloadFrame = document.getElementById("download_frame"); t.downloadFrame = document.getElementById("download_frame");
t.spanViews = document.getElementById("stat_views"); t.spanViews = document.getElementById("stat_views");
t.spanDownloads = document.getElementById("stat_downloads"); t.spanDownloads = document.getElementById("stat_downloads");
t.spanSize = document.getElementById("stat_size");
t.btnToggleToolbar = document.getElementById("btn_toggle_toolbar"); t.btnToggleToolbar = document.getElementById("btn_toggle_toolbar");
t.btnDownload = document.getElementById("btn_download"); t.btnDownload = document.getElementById("btn_download");
@@ -148,9 +150,10 @@ class Toolbar {
}, 60000); }, 60000);
} }
setStats(views, downloads) {let t = this; setStats(file) {let t = this;
t.spanViews.innerText = views t.spanViews.innerText = file.views
t.spanDownloads.innerText = Math.round(downloads*10)/10; t.spanDownloads.innerText = Math.round((file.bandwidth_used/file.size)*10)/10;
t.spanSize.innerText = formatDataVolume(file.size, 3);
} }
} }
@@ -171,16 +174,3 @@ function loadCaptcha(){
} }
}); });
} }
function formatDataVolume(amt) {
if (amt > 1e12) {
return Math.round(amt/1e9)/1e3 + " TB";
} else if (amt > 1e9) {
return Math.round(amt/1e6)/1e3 + " GB";
} else if (amt > 1e6) {
return Math.round(amt/1e3)/1e3 + " MB";
} else if (amt > 1e3) {
return Math.round(amt)/1e3 + " kB";
}
return amt + " B"
}

View File

@@ -73,6 +73,7 @@ class Viewer {
// Update the file details // Update the file details
v.detailsWindow.setDetails(file); v.detailsWindow.setDetails(file);
v.toolbar.setStats(file);
// Register a new view. We don't care what this returns becasue we can't // Register a new view. We don't care what this returns becasue we can't
// do anything about it anyway // do anything about it anyway

View File

@@ -275,7 +275,8 @@ table:not(.form) {border-collapse: collapse; width: 100%;}
tr:not(.form) {border-bottom: 1px var(--layer_2_color_border) solid;} tr:not(.form) {border-bottom: 1px var(--layer_2_color_border) solid;}
tr > td {padding: 0.3em;} tr > td {padding: 0.3em;}
@media(max-width: 30em) { @media(max-width: 30em) {
tr > td { /* Forms will be stacked on small screens */
tr.form > td {
box-sizing: border-box; box-sizing: border-box;
float: left; float: left;
width: 100%; width: 100%;

View File

@@ -29,6 +29,8 @@
<script> <script>
var apiEndpoint = '{{.APIEndpoint}}'; var apiEndpoint = '{{.APIEndpoint}}';
{{template `util.js`}}
Chart.defaults.global.defaultFontColor = "#b3b3b3"; Chart.defaults.global.defaultFontColor = "#b3b3b3";
Chart.defaults.global.defaultFontSize = 15; Chart.defaults.global.defaultFontSize = 15;
Chart.defaults.global.defaultFontFamily = "Ubuntu"; Chart.defaults.global.defaultFontFamily = "Ubuntu";
@@ -79,14 +81,7 @@
}, },
ticks: { ticks: {
callback: function(value, index, values) { callback: function(value, index, values) {
if (value >= 1e12) { return formatDataVolume(value, 3);
return Math.round(value/1e9)/1e3 + " TB";
} else if (value >= 1e9) {
return Math.round(value/1e6)/1e3 + " GB";
} else if (value >= 1e6) {
return Math.round(value/1e3)/1e3 + " MB";
}
return value/1e3 + " kB";
} }
}, },
gridLines: { gridLines: {

View File

@@ -41,6 +41,8 @@
<div id="stat_views" style="text-align: center;">N/A</div> <div id="stat_views" style="text-align: center;">N/A</div>
<div id="stat_downloads_label" class="toolbar_label">Downloads</div> <div id="stat_downloads_label" class="toolbar_label">Downloads</div>
<div id="stat_downloads" style="text-align: center;">N/A</div> <div id="stat_downloads" style="text-align: center;">N/A</div>
<div id="stat_size_label" class="toolbar_label">Size</div>
<div id="stat_size" style="text-align: center;">N/A</div>
<button id="btn_download" class="toolbar_button button_full_width"> <button id="btn_download" class="toolbar_button button_full_width">
{{template `save.svg` .}} {{template `save.svg` .}}