2020-01-28 12:51:21 +01:00
|
|
|
function DetailsWindow(viewer) {
|
2021-09-27 21:01:14 +02:00
|
|
|
this.viewer = viewer
|
2020-02-04 19:37:46 +01:00
|
|
|
this.visible = false
|
2021-09-27 21:01:14 +02:00
|
|
|
this.file = null
|
2020-08-11 19:52:03 +02:00
|
|
|
this.graphsInitialized = false
|
2021-09-27 21:01:14 +02:00
|
|
|
this.graphViews = 0
|
2020-08-11 19:52:03 +02:00
|
|
|
this.graphDownloads = 0
|
2021-09-27 21:01:14 +02:00
|
|
|
this.modal = new Modal(
|
2020-02-18 14:57:27 +01:00
|
|
|
document.getElementById("file_viewer"),
|
|
|
|
() => { this.toggle() },
|
2021-09-27 21:01:14 +02:00
|
|
|
"File Details", "1200px", "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
|
|
|
|
2021-09-27 21:01:14 +02:00
|
|
|
DetailsWindow.prototype.toggle = function () {
|
2020-01-28 12:51:21 +01:00
|
|
|
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
|
|
|
|
2021-09-27 21:01:14 +02:00
|
|
|
DetailsWindow.prototype.setFile = function (file) {
|
2020-02-05 16:52:55 +01:00
|
|
|
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
|
|
|
}
|
2021-09-27 21:01:14 +02:00
|
|
|
this.divFileDetails.innerHTML = `<tr><td>Name<td><td>${escapeHTML(file.name)}</td></tr>
|
|
|
|
<tr><td>URL<td><td><a href="${file.link}">${file.link}</a></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>Size<td><td>${formatDataVolume(file.size, 4)} ( ${formatThousands(file.size)} B )</td></tr>
|
|
|
|
<tr><td>Bandwidth<td><td>${formatDataVolume(file.bandwidth_used, 4)}</td></tr>
|
|
|
|
<tr><td>Upload Date<td><td>${printDate(file.date_created, true, true, true)}</td></tr>
|
|
|
|
<tr><td>Description<td><td>${escapeHTML(desc)}</td></tr>`
|
2020-01-20 19:55:51 +01:00
|
|
|
|
2021-09-27 21:01:14 +02:00
|
|
|
if (this.visible && file.timeseries_href !== "") {
|
2020-02-04 19:37:46 +01:00
|
|
|
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
|
|
|
|
2021-09-27 21:01:14 +02:00
|
|
|
DetailsWindow.prototype.renderGraphs = function () {
|
2020-08-11 19:52:03 +02:00
|
|
|
console.log("rendering graphs")
|
|
|
|
this.graphDownloads = drawGraph(
|
|
|
|
document.getElementById("downloads_chart"), "Downloads", "number",
|
|
|
|
);
|
|
|
|
this.graphViews = drawGraph(
|
|
|
|
document.getElementById("views_chart"), "Views", "number",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-27 21:01:14 +02:00
|
|
|
DetailsWindow.prototype.updateGraph = function (file) {
|
2020-02-04 19:37:46 +01:00
|
|
|
console.log("updating graph")
|
2020-06-08 14:56:58 +02:00
|
|
|
|
|
|
|
let today = new Date()
|
|
|
|
let start = new Date()
|
2021-09-27 21:01:14 +02:00
|
|
|
start.setDate(start.getDate() - 90)
|
2020-06-08 14:56:58 +02:00
|
|
|
|
|
|
|
fetch(
|
2021-09-27 21:01:14 +02:00
|
|
|
file.timeseries_href +
|
|
|
|
"?start=" + start.toISOString() +
|
|
|
|
"&end=" + today.toISOString() +
|
|
|
|
"&interval=" + 60
|
2020-06-08 14:56:58 +02:00
|
|
|
).then(resp => {
|
2021-09-27 21:01:14 +02:00
|
|
|
if (!resp.ok) { return null }
|
2020-02-04 19:37:46 +01:00
|
|
|
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);
|
2021-09-27 21:01:14 +02:00
|
|
|
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
|
2020-08-11 19:52:03 +02:00
|
|
|
});
|
|
|
|
resp.bandwidth.amounts.forEach((val, idx) => {
|
2021-09-27 21:01:14 +02:00
|
|
|
resp.bandwidth.amounts[idx] = Math.round(val / file.size);
|
2020-08-11 19:52:03 +02:00
|
|
|
});
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|