86 lines
2.7 KiB
JavaScript
86 lines
2.7 KiB
JavaScript
function updateDownloads(downloads) {
|
|
var dls = [];
|
|
var i = 0;
|
|
var tbody = $("<tbody></tbody>").attr("id", "table")
|
|
for (var d of downloads) {
|
|
var row = $("<tr></tr>").addClass("download").attr("index", i)
|
|
|
|
var index = $("<th></th>").attr("scope", "row").text(i)
|
|
var filename = $("<td></td>").text(d.subdir + "/" + d.filename).addClass("lastlog")
|
|
var url = $("<td></td>").text(d.url)
|
|
var status = $("<td></td>").addClass(d.status).css("cursor", "pointer").text(d.status + "\n" + d.error).on("click",{index: i, download: d}, evt => {
|
|
if (d.status != "Queue" || d.status != "Complete") {
|
|
setDownload([{
|
|
index: evt.data("index"),
|
|
status: "Queue",
|
|
priority: evt.data("d").priority
|
|
}])
|
|
}
|
|
})
|
|
|
|
var action = $("<td></td>").addClass("dropdown")
|
|
var button = $("<button>Actions</button>").addClass("btn btn-secondary dropdown-toggle").attr("type", "button").attr("data-toggle", "dropdown")
|
|
var menu = $("<div></div>").addClass("dropdown-menu")
|
|
|
|
var del = $('<a href="#">Delete</a>').addClass("dropdown-item").on("click",{index: i, download: d}, evt => {
|
|
if (confirm("confirm deletion of " + evt.data.download.filename)) {
|
|
deleteDownload([{
|
|
index: evt.data.index
|
|
}])
|
|
}
|
|
})
|
|
var resume = $('<a href="#">Resume</a>').addClass("dropdown-item").on("click",{index: i, download: d}, evt => {
|
|
setDownload([{
|
|
index: evt.data.index,
|
|
status: "Queue",
|
|
priority: evt.data.download.priority
|
|
}])
|
|
})
|
|
var stop = $('<a href="#">Stop</a>').addClass("dropdown-item").on("click",{index: i, download: d}, evt => {
|
|
setDownload([{
|
|
index: evt.data.index,
|
|
status: "Stop",
|
|
priority: evt.data.download.priority
|
|
}])
|
|
})
|
|
var na = $('<a href="#">N/A</a>').addClass("dropdown-item")
|
|
|
|
menu.append(del, resume, stop, na)
|
|
action.append(button, menu)
|
|
|
|
var progress = $("<td></td>").append(
|
|
$("<div></div>").addClass("progress").append(
|
|
$("<div></div>").addClass("progress-bar text-dark").css("width", (d.progress ?? "0") + '%').attr("id", "progress-" + i)
|
|
.text((d.progress ?? "0") + '%')
|
|
),
|
|
)
|
|
|
|
|
|
row.append(
|
|
index,
|
|
filename,
|
|
url,
|
|
status,
|
|
action,
|
|
progress
|
|
)
|
|
tbody.append(row)
|
|
i++;
|
|
}
|
|
$("#table").replaceWith(tbody)
|
|
}
|
|
|
|
function deleteDownload(data){
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("DELETE", "http://gloader.narnian.us:8844/delete");
|
|
xhr.setRequestHeader("Content-Type", "application/javascript");
|
|
xhr.send(JSON.stringify(data));
|
|
}
|
|
|
|
function setDownload(data){
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "http://gloader.narnian.us:8844/set");
|
|
xhr.setRequestHeader("Content-Type", "application/javascript");
|
|
xhr.send(JSON.stringify(data));
|
|
}
|