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-02-04 19:37:46 +01:00
|
|
|
this.graph = 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-01-28 12:51:21 +01:00
|
|
|
if (this.graph === 0) {
|
2020-02-04 19:37:46 +01:00
|
|
|
this.renderGraph()
|
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-02-04 19:37:46 +01:00
|
|
|
DetailsWindow.prototype.updateGraph = function(file) {
|
|
|
|
console.log("updating graph")
|
|
|
|
fetch(file.timeseries_href+"?interval=60?days=14").then(resp => {
|
|
|
|
if (!resp.ok) {return null}
|
|
|
|
return resp.json()
|
2020-01-27 16:56:16 +01:00
|
|
|
}).then(resp => {
|
2020-02-04 19:37:46 +01:00
|
|
|
this.graph.data.labels = resp.labels
|
|
|
|
this.graph.data.datasets[0].data = resp.downloads
|
|
|
|
this.graph.data.datasets[1].data = resp.views
|
|
|
|
this.graph.update()
|
2020-01-27 16:56:16 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-28 12:51:21 +01:00
|
|
|
DetailsWindow.prototype.renderGraph = function() {
|
2020-02-04 19:37:46 +01:00
|
|
|
console.log("rendering graph")
|
|
|
|
Chart.defaults.global.defaultFontColor = "#b3b3b3"
|
|
|
|
Chart.defaults.global.defaultFontSize = 15
|
|
|
|
Chart.defaults.global.defaultFontFamily = "Ubuntu"
|
2020-03-10 17:06:52 +01:00
|
|
|
Chart.defaults.global.maintainAspectRatio = false;
|
2020-02-04 19:37:46 +01:00
|
|
|
Chart.defaults.global.elements.point.radius = 0
|
|
|
|
Chart.defaults.global.tooltips.mode = "index"
|
|
|
|
Chart.defaults.global.tooltips.axis = "x"
|
|
|
|
Chart.defaults.global.tooltips.intersect = false
|
2020-01-28 12:51:21 +01:00
|
|
|
this.graph = new Chart(
|
2020-01-27 16:56:16 +01:00
|
|
|
document.getElementById('bandwidth_chart'),
|
|
|
|
{
|
2020-03-10 21:42:23 +01:00
|
|
|
type: 'line',
|
2020-01-27 16:56:16 +01:00
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{
|
2020-03-10 17:06:52 +01:00
|
|
|
label: "Bandwidth",
|
|
|
|
backgroundColor: "rgba(64, 255, 64, .01)",
|
|
|
|
borderColor: "rgba(96, 255, 96, 1)",
|
|
|
|
borderWidth: 2,
|
|
|
|
lineTension: 0.2,
|
2020-01-27 16:56:16 +01:00
|
|
|
fill: true,
|
2020-03-10 17:06:52 +01:00
|
|
|
yAxisID: "y_bandwidth"
|
2020-01-27 16:56:16 +01:00
|
|
|
}, {
|
|
|
|
label: "Views",
|
2020-03-10 17:06:52 +01:00
|
|
|
backgroundColor: "rgba(64, 64, 255, .01)",
|
|
|
|
borderColor: "rgba(64, 64, 255, 1)",
|
|
|
|
borderWidth: 2,
|
|
|
|
lineTension: 0.2,
|
2020-01-27 16:56:16 +01:00
|
|
|
fill: true,
|
2020-03-10 17:06:52 +01:00
|
|
|
yAxisID: "y_views"
|
2020-01-27 16:56:16 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
yAxes: [
|
2020-01-20 19:55:51 +01:00
|
|
|
{
|
2020-01-27 16:56:16 +01:00
|
|
|
type: "linear",
|
|
|
|
display: true,
|
|
|
|
position: "left",
|
|
|
|
id: "y_bandwidth",
|
|
|
|
scaleLabel: {
|
2020-01-20 19:55:51 +01:00
|
|
|
display: true,
|
2020-01-27 16:56:16 +01:00
|
|
|
labelString: "Downloads"
|
|
|
|
},
|
|
|
|
gridLines: {
|
2020-03-10 17:06:52 +01:00
|
|
|
color: "rgba(100, 255, 100, .05)"
|
2020-01-27 16:56:16 +01:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: "linear",
|
|
|
|
display: true,
|
|
|
|
position: "right",
|
|
|
|
id: "y_views",
|
|
|
|
scaleLabel: {
|
2020-01-20 19:55:51 +01:00
|
|
|
display: true,
|
2020-01-27 16:56:16 +01:00
|
|
|
labelString: "Views"
|
|
|
|
},
|
|
|
|
gridLines: {
|
2020-03-10 17:06:52 +01:00
|
|
|
color: "rgba(128, 128, 255, .05)"
|
2020-01-20 19:55:51 +01:00
|
|
|
}
|
2020-01-27 16:56:16 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
xAxes: [
|
|
|
|
{
|
|
|
|
ticks: {
|
|
|
|
maxRotation: 20
|
|
|
|
},
|
|
|
|
gridLines: {
|
|
|
|
display: false
|
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-01-27 16:56:16 +01:00
|
|
|
}
|
2020-02-04 19:37:46 +01:00
|
|
|
)
|
2020-01-20 19:55:51 +01:00
|
|
|
}
|