clear finished downloads link

This commit is contained in:
Zlatin Balevsky
2019-12-15 08:29:55 +00:00
parent 8cf4b23762
commit 2b9e722165
5 changed files with 44 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package com.muwire.webui;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
@ -57,6 +58,16 @@ public class DownloadManager {
delay();
}
void clearFinished() {
for(Iterator<Map.Entry<InfoHash, Downloader>> iter = downloaders.entrySet().iterator(); iter.hasNext();) {
Map.Entry<InfoHash, Downloader> entry = iter.next();
Downloader.DownloadState state = entry.getValue().getCurrentState();
if (state == Downloader.DownloadState.CANCELLED ||
state == Downloader.DownloadState.FINISHED)
iter.remove();
}
}
private static void delay() {
try {
Thread.sleep(100);

View File

@ -100,6 +100,16 @@ public class DownloadServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String action = req.getParameter("action");
if (action == null) {
resp.sendError(403, "Bad param");
return;
}
if (action.equals("clear")) {
downloadManager.clearFinished();
return;
}
String infoHashB64 = req.getParameter("infoHash");
if (infoHashB64 == null) {
resp.sendError(403, "Bad param");
@ -111,11 +121,6 @@ public class DownloadServlet extends HttpServlet {
return;
}
InfoHash infoHash = new InfoHash(h);
String action = req.getParameter("action");
if (action == null) {
resp.sendError(403, "Bad param");
return;
}
if (action.equals("start")) {
if (core == null) {
resp.sendError(403, "Not initialized");

View File

@ -32,6 +32,7 @@ public class Util {
_x("Cancel"),
_x("Certified"),
_x("Certify"),
_x("Clear Finished"),
_x("Comment"),
_x("Details for {0}"),
_x("Down"),

View File

@ -125,8 +125,16 @@ function refreshDownloader() {
}
var downloadsDiv = document.getElementById("downloads");
if (downloaders.size > 0)
var clearDiv = document.getElementById("clearFinished")
if (downloaders.size > 0) {
downloadsDiv.innerHTML = table.render();
var clearLink = new Link(_t("Clear Finished"), "clear", ["ignored"])
clearDiv.innerHTML = clearLink.render()
} else {
downloadsDiv.innerHTML = ""
clearDiv.innerHTML = ""
}
if (downloader != null)
updateDownloader(downloader);
}
@ -136,6 +144,18 @@ function refreshDownloader() {
xmlhttp.send();
}
function clear(ignored) {
xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
refreshDownloader()
}
}
xmlhttp.open("POST", "/MuWire/Download", true)
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send(encodeURI("action=clear"));
}
var downloadsSortKey
var downloadsSortOrder

View File

@ -31,6 +31,7 @@
<div id="table-wrapper">
<div id="downloads"></div>
</div>
<center><span id="clearFinished"></span></center>
<hr/>
<p><%=Util._t("Download Details")%></p>
<div id="downloadDetails"><p><%=Util._t("Click on a download to view details")%></p></div>