clear finished downloads link
This commit is contained in:
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -32,6 +32,7 @@ public class Util {
|
||||
_x("Cancel"),
|
||||
_x("Certified"),
|
||||
_x("Certify"),
|
||||
_x("Clear Finished"),
|
||||
_x("Comment"),
|
||||
_x("Details for {0}"),
|
||||
_x("Down"),
|
||||
|
@ -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
|
||||
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user