2020-01-28 12:51:21 +01:00
|
|
|
function DetailsWindow(viewer) {
|
2020-02-04 19:37:46 +01:00
|
|
|
this.viewer = viewer
|
|
|
|
this.visible = false
|
2020-02-05 16:52:55 +01:00
|
|
|
this.file = null
|
2020-08-11 19:52:03 +02:00
|
|
|
this.graphsInitialized = false
|
|
|
|
this.graphViews = 0
|
|
|
|
this.graphDownloads = 0
|
2020-02-18 14:57:27 +01:00
|
|
|
this.modal = new Modal(
|
|
|
|
document.getElementById("file_viewer"),
|
|
|
|
() => { this.toggle() },
|
2020-02-18 21:37:22 +01:00
|
|
|
"File Details", "1500px", "1000px",
|
2020-02-18 14:57:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
let clone = document.getElementById("tpl_details_popup").content.cloneNode(true)
|
|
|
|
this.divFileDetails = clone.querySelector(".info_file_details")
|
|
|
|
this.modal.setBody(clone)
|
|
|
|
|
|
|
|
this.btnDetails = document.getElementById("btn_details")
|
|
|
|
this.btnDetails.addEventListener("click", () => { this.toggle() })
|
2020-01-27 16:56:16 +01:00
|
|
|
}
|
2020-01-20 19:55:51 +01:00
|
|
|
|
2020-01-28 12:51:21 +01:00
|
|
|
DetailsWindow.prototype.toggle = function() {
|
|
|
|
if (this.visible) {
|
2020-02-18 14:57:27 +01:00
|
|
|
this.modal.close()
|
2020-02-04 19:37:46 +01:00
|
|
|
this.btnDetails.classList.remove("button_highlight")
|
|
|
|
this.visible = false
|
2020-01-27 16:56:16 +01:00
|
|
|
} else {
|
2020-02-18 14:57:27 +01:00
|
|
|
this.modal.open()
|
2020-02-04 19:37:46 +01:00
|
|
|
this.btnDetails.classList.add("button_highlight")
|
|
|
|
this.visible = true
|
2020-01-20 19:55:51 +01:00
|
|
|
|
2020-08-11 19:52:03 +02:00
|
|
|
if (!this.graphsInitialized) {
|
|
|
|
this.renderGraphs()
|
|
|
|
this.graphsInitialized = true
|
2020-01-20 19:55:51 +01:00
|
|
|
}
|
2020-02-05 16:45:31 +01:00
|
|
|
this.updateGraph(this.file)
|
2020-01-20 19:55:51 +01:00
|
|
|
}
|
2020-01-27 16:56:16 +01:00
|
|
|
}
|
2020-01-20 19:55:51 +01:00
|
|
|
|
2020-02-05 16:52:55 +01:00
|
|
|
DetailsWindow.prototype.setFile = function(file) {
|
|
|
|
this.file = file
|
2020-02-04 19:37:46 +01:00
|
|
|
let desc = ""
|
2020-01-28 12:51:21 +01:00
|
|
|
if (this.viewer.isList) {
|
2020-02-04 19:37:46 +01:00
|
|
|
desc = file.description
|
2020-01-20 19:55:51 +01:00
|
|
|
}
|
2020-02-18 14:57:27 +01:00
|
|
|
this.divFileDetails.innerHTML = "<tr><td>Name<td><td>" + escapeHTML(file.name) + "</td></tr>"
|
2020-02-04 19:37:46 +01:00
|
|
|
+ "<tr><td>URL<td><td><a href=\""+file.link+"\">"+file.link+"</a></td></tr>"
|
2020-01-27 16:56:16 +01:00
|
|
|
+ "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>"
|
|
|
|
+ "<tr><td>ID<td><td>" + file.id + "</td></tr>"
|
|
|
|
+ "<tr><td>Size<td><td>" + formatDataVolume(file.size, 4) + "</td></tr>"
|
|
|
|
+ "<tr><td>Bandwidth<td><td>" + formatDataVolume(file.bandwidth_used, 4) + "</td></tr>"
|
2020-02-04 19:37:46 +01:00
|
|
|
+ "<tr><td>Upload Date<td><td>" + printDate(file.date_created, true, true, true) + "</td></tr>"
|
2020-01-27 16:56:16 +01:00
|
|
|
+ "<tr><td>Description<td><td>" + escapeHTML(desc) + "</td></tr>"
|
2020-01-20 19:55:51 +01:00
|
|
|
|
2020-02-04 19:37:46 +01:00
|
|
|
if(this.visible && file.timeseries_href !== "") {
|
|
|
|
this.updateGraph(file)
|
2020-01-20 19:55:51 +01:00
|
|
|
}
|
2020-01-27 16:56:16 +01:00
|
|
|
}
|
2020-01-20 19:55:51 +01:00
|
|
|
|
2020-08-11 19:52:03 +02:00
|
|
|
DetailsWindow.prototype.renderGraphs = function() {
|
|
|
|
console.log("rendering graphs")
|
|
|
|
this.graphDownloads = drawGraph(
|
|
|
|
document.getElementById("downloads_chart"), "Downloads", "number",
|
|
|
|
);
|
|
|
|
this.graphViews = drawGraph(
|
|
|
|
document.getElementById("views_chart"), "Views", "number",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-04 19:37:46 +01:00
|
|
|
DetailsWindow.prototype.updateGraph = function(file) {
|
|
|
|
console.log("updating graph")
|
2020-06-08 14:56:58 +02:00
|
|
|
|
|
|
|
let today = new Date()
|
|
|
|
let start = new Date()
|
2020-08-11 19:52:03 +02:00
|
|
|
start.setDate(start.getDate()-90)
|
2020-06-08 14:56:58 +02:00
|
|
|
|
|
|
|
fetch(
|
|
|
|
file.timeseries_href+
|
|
|
|
"?start="+start.toISOString() +
|
|
|
|
"&end="+today.toISOString() +
|
|
|
|
"&interval="+60
|
|
|
|
).then(resp => {
|
2020-02-04 19:37:46 +01:00
|
|
|
if (!resp.ok) {return null}
|
|
|
|
return resp.json()
|
2020-01-27 16:56:16 +01:00
|
|
|
}).then(resp => {
|
2020-08-11 19:52:03 +02:00
|
|
|
resp.views.timestamps.forEach((val, idx) => {
|
|
|
|
let date = new Date(val);
|
|
|
|
let dateStr = ("00"+(date.getMonth()+1)).slice(-2);
|
|
|
|
dateStr += "-"+("00"+date.getDate()).slice(-2);
|
|
|
|
dateStr += " "+("00"+date.getHours()).slice(-2)+"h";
|
|
|
|
resp.views.timestamps[idx] = " "+dateStr+" "; // Poor man's padding
|
|
|
|
});
|
|
|
|
resp.bandwidth.amounts.forEach((val, idx) => {
|
|
|
|
resp.bandwidth.amounts[idx] = Math.round(val/file.size);
|
|
|
|
});
|
|
|
|
this.graphDownloads.data.labels = resp.views.timestamps
|
|
|
|
this.graphViews.data.labels = resp.views.timestamps
|
|
|
|
this.graphDownloads.data.datasets[0].data = resp.bandwidth.amounts
|
|
|
|
this.graphViews.data.datasets[0].data = resp.views.amounts
|
|
|
|
this.graphDownloads.update()
|
|
|
|
this.graphViews.update()
|
2020-01-27 16:56:16 +01:00
|
|
|
})
|
|
|
|
}
|