clear finished downloads link
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package com.muwire.webui;
|
package com.muwire.webui;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@ -57,6 +58,16 @@ public class DownloadManager {
|
|||||||
delay();
|
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() {
|
private static void delay() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
@ -100,6 +100,16 @@ public class DownloadServlet extends HttpServlet {
|
|||||||
|
|
||||||
|
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
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");
|
String infoHashB64 = req.getParameter("infoHash");
|
||||||
if (infoHashB64 == null) {
|
if (infoHashB64 == null) {
|
||||||
resp.sendError(403, "Bad param");
|
resp.sendError(403, "Bad param");
|
||||||
@ -111,11 +121,6 @@ public class DownloadServlet extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
InfoHash infoHash = new InfoHash(h);
|
InfoHash infoHash = new InfoHash(h);
|
||||||
String action = req.getParameter("action");
|
|
||||||
if (action == null) {
|
|
||||||
resp.sendError(403, "Bad param");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (action.equals("start")) {
|
if (action.equals("start")) {
|
||||||
if (core == null) {
|
if (core == null) {
|
||||||
resp.sendError(403, "Not initialized");
|
resp.sendError(403, "Not initialized");
|
||||||
|
@ -32,6 +32,7 @@ public class Util {
|
|||||||
_x("Cancel"),
|
_x("Cancel"),
|
||||||
_x("Certified"),
|
_x("Certified"),
|
||||||
_x("Certify"),
|
_x("Certify"),
|
||||||
|
_x("Clear Finished"),
|
||||||
_x("Comment"),
|
_x("Comment"),
|
||||||
_x("Details for {0}"),
|
_x("Details for {0}"),
|
||||||
_x("Down"),
|
_x("Down"),
|
||||||
|
@ -125,8 +125,16 @@ function refreshDownloader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var downloadsDiv = document.getElementById("downloads");
|
var downloadsDiv = document.getElementById("downloads");
|
||||||
if (downloaders.size > 0)
|
var clearDiv = document.getElementById("clearFinished")
|
||||||
|
if (downloaders.size > 0) {
|
||||||
downloadsDiv.innerHTML = table.render();
|
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)
|
if (downloader != null)
|
||||||
updateDownloader(downloader);
|
updateDownloader(downloader);
|
||||||
}
|
}
|
||||||
@ -136,6 +144,18 @@ function refreshDownloader() {
|
|||||||
xmlhttp.send();
|
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 downloadsSortKey
|
||||||
var downloadsSortOrder
|
var downloadsSortOrder
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
<div id="table-wrapper">
|
<div id="table-wrapper">
|
||||||
<div id="downloads"></div>
|
<div id="downloads"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<center><span id="clearFinished"></span></center>
|
||||||
<hr/>
|
<hr/>
|
||||||
<p><%=Util._t("Download Details")%></p>
|
<p><%=Util._t("Download Details")%></p>
|
||||||
<div id="downloadDetails"><p><%=Util._t("Click on a download to view details")%></p></div>
|
<div id="downloadDetails"><p><%=Util._t("Click on a download to view details")%></p></div>
|
||||||
|
Reference in New Issue
Block a user