Files
fnx_web/res/include/script/file_viewer/DetailsWindow.js

153 lines
4.1 KiB
JavaScript
Raw Normal View History

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-01-20 19:55:51 +01:00
2020-02-04 19:37:46 +01:00
this.divPopup = document.getElementById("details_popup")
this.btnDetails = document.getElementById("btn_details")
this.btnCloseDetails = document.getElementById("btn_close_details")
this.divFileDetails = document.getElementById("info_file_details")
2020-01-20 19:55:51 +01:00
2020-02-04 19:37:46 +01:00
this.btnDetails.addEventListener("click", () => { this.toggle() })
this.btnCloseDetails.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-04 19:37:46 +01:00
this.divPopup.style.opacity = "0"
this.divPopup.style.visibility = "hidden"
this.btnDetails.classList.remove("button_highlight")
this.visible = false
2020-01-27 16:56:16 +01:00
} else {
2020-02-04 19:37:46 +01:00
this.divPopup.style.opacity = "1"
this.divPopup.style.visibility = "visible"
this.btnDetails.classList.add("button_highlight")
this.visible = true
2020-01-20 19:55:51 +01:00
2020-01-27 16:56:16 +01:00
// This is a workaround for a chrome bug which makes it so hidden
// windows can't be scrolled after they are shown
2020-02-04 19:37:46 +01:00
this.divPopup.focus()
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-01-28 12:51:21 +01:00
this.divFileDetails.innerHTML = "<table>"
2020-01-27 16:56:16 +01:00
+ "<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-02-04 19:37:46 +01:00
+ "</table>"
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"
Chart.defaults.global.aspectRatio = 2.5
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'),
{
type: 'line',
data: {
datasets: [
{
label: "Downloads",
backgroundColor: "rgba(64, 255, 64, .05)",
borderColor: "rgba(128, 255, 128, 1)",
borderWidth: 1.5,
lineTension: 0.1,
fill: true,
yAxisID: "y_bandwidth",
}, {
label: "Views",
backgroundColor: "rgba(64, 64, 255, .1)",
borderColor: "rgba(128, 128, 255, 1)",
borderWidth: 1.5,
lineTension: 0.1,
fill: true,
yAxisID: "y_views",
}
]
},
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: {
color: "rgba(100, 255, 100, .1)"
}
}, {
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: {
color: "rgba(128, 128, 255, .2)"
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
}