Individual feed configuration ability

This commit is contained in:
Zlatin Balevsky
2020-03-13 06:48:58 +00:00
parent b339784826
commit 05b70a4573
6 changed files with 115 additions and 3 deletions

View File

@@ -196,6 +196,20 @@ div#downloadDetails table td {
padding-bottom: 5px;
}
div#feedConfig table * {
background: #bcd1e5 !important;
}
div#feedConfig table {
border-collapse: collapse;
width: auto;
}
div#feedConfig table td {
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
}
div#uploads table thead th:nth-child(2) {
width: 120px;
}

View File

@@ -90,6 +90,21 @@ public class FeedManager {
core.getEventBus().publish(event);
}
void configure(Persona publisher, boolean autoDownload, boolean sequential,
int updateInterval, int itemsToKeep) {
RemoteFeed rf = remoteFeeds.get(publisher);
if (rf == null)
return;
Feed feed = rf.getFeed();
feed.setAutoDownload(autoDownload);
feed.setSequential(sequential);
feed.setUpdateInterval(updateInterval);
feed.setItemsToKeep(itemsToKeep);
UIFeedConfigurationEvent event = new UIFeedConfigurationEvent();
event.setFeed(feed);
core.getEventBus().publish(event);
}
static class RemoteFeed {
private final Feed feed;
private volatile long revision;

View File

@@ -202,6 +202,27 @@ public class FeedServlet extends HttpServlet {
feedManager.update(host);
Util.pause();
} else if (action.equals("configure")) {
String personaB64 = req.getParameter("host");
if (personaB64 == null) {
resp.sendError(403,"Bad param");
return;
}
Persona host;
try {
host = new Persona(new ByteArrayInputStream(Base64.decode(personaB64)));
} catch (Exception bad) {
resp.sendError(403,"Bad param");
return;
}
boolean autoDownload = Boolean.valueOf(req.getParameter("autoDownload"));
boolean sequential = Boolean.valueOf(req.getParameter("sequential"));
int updateInterval = Integer.valueOf(req.getParameter("updateInterval")) * 60000;
int itemsToKeep = Integer.valueOf(req.getParameter("itemsToKeep"));
feedManager.configure(host, autoDownload, sequential, updateInterval, itemsToKeep);
Util.pause();
resp.sendRedirect("/MuWire/Feeds");
}
}
@@ -300,6 +321,10 @@ public class FeedServlet extends HttpServlet {
sb.append("<Status>").append(feed.getStatus().toString()).append("</Status>");
sb.append("<Active>").append(feed.getStatus().isActive()).append("</Active>");
sb.append("<LastUpdated>").append(DataHelper.formatTime(feed.getLastUpdated())).append("</LastUpdated>");
sb.append("<UpdateInterval>").append(feed.getUpdateInterval() / 60000).append("</UpdateInterval>");
sb.append("<ItemsToKeep>").append(feed.getItemsToKeep()).append("</ItemsToKeep>");
sb.append("<AutoDownload>").append(feed.isAutoDownload()).append("</AutoDownload>");
sb.append("<Sequential>").append(feed.isSequential()).append("</Sequential>");
sb.append("</Feed>");
}
}

View File

@@ -44,13 +44,17 @@ public class Util {
_x("Distrusted User"),
_x("Down"),
_x("Download"),
_x("Download each file sequentially"),
_x("Download Location"),
_x("Download published files automatically"),
_x("Downloaded"),
_x("Downloaded Pieces"),
_x("Downloader"),
_x("Downloading"),
_x("Enter Reason (Optional)"),
_x("ETA"),
_x("Feed configuration for {0}"),
_x("Feed update frequency (minutes)"),
_x("Feeds"),
_x("Fetching Certificates"),
_x("Feed"),
@@ -68,6 +72,7 @@ public class Util {
_x("Mark Neutral"),
_x("Mark Trusted"),
_x("Name"),
_x("Number of items to keep on disk (-1 means unlimited)"),
// verb
_x("Pause"),
_x("Piece Size"),

View File

@@ -7,6 +7,10 @@ class Feed {
this.status = xmlNode.getElementsByTagName("Status")[0].childNodes[0].nodeValue
this.active = xmlNode.getElementsByTagName("Active")[0].childNodes[0].nodeValue
this.lastUpdated = xmlNode.getElementsByTagName("LastUpdated")[0].childNodes[0].nodeValue
this.autoDownload = xmlNode.getElementsByTagName("AutoDownload")[0].childNodes[0].nodeValue
this.sequential = xmlNode.getElementsByTagName("Sequential")[0].childNodes[0].nodeValue
this.itemsToKeep = xmlNode.getElementsByTagName("ItemsToKeep")[0].childNodes[0].nodeValue
this.updateInterval = xmlNode.getElementsByTagName("UpdateInterval")[0].childNodes[0].nodeValue
}
getMapping() {
@@ -18,7 +22,7 @@ class Feed {
updateHTML = updateLink.render()
}
var unsubscribeLink = new Link(_t("Unsubscribe"), "unsubscribe", [this.publisherB64])
var configureLink = new Link(_t("Configure"), "configure", [this.publisherB64])
var configureLink = new Link(_t("Configure"), "configure", [this.publisher])
var publisherHTML = publisherLink.render() + "<span class='right'>" + updateHTML + " " +
unsubscribeLink.render() + " " +
@@ -153,6 +157,7 @@ function refreshFeeds() {
if (updatedFeed == null) {
currentFeed = null
document.getElementById("itemsTable").innerHTML = ""
cancelConfig()
} else if (updatedFeed.revision > currentFeed.revision)
displayFeed(currentFeed)
} else
@@ -240,8 +245,55 @@ function unsubscribe(b64) {
xmlhttp.send("action=unsubscribe&host=" + b64)
}
function configure(b64) {
// TODO: implement
function configure(publisher) {
var feed = feeds.get(publisher)
var html = "<form action='/MuWire/Feed' method='post'>"
html += "<h3>"+ _t("Feed configuration for {0}", publisher) + "</h3>"
html += "<table>"
html += "<tr>"
html += "<td>" + _t("Download published files automatically") + "</td>"
html += "<td><p align='right'><input type='checkbox' name='autoDownload' value='true'"
if (feed.autoDownload == "true")
html += " checked "
html += "></p></td>"
html += "</tr>"
html += "<tr>"
html += "<td>" + _t("Download each file sequentially") + "</td>"
html += "<td><p align='right'><input type='checkbox' name='sequential' value='true'"
if (feed.sequential == "true")
html += " checked "
html += "></p></td>"
html += "</tr>"
html += "<tr>"
html += "<td>" + _t("Feed update frequency (minutes)") + "</td>"
html += "<td><p align='right'><input type='text' size='2' name='updateInterval' value='" + feed.updateInterval + "'></p></td>"
html += "</tr>"
html += "<tr>"
html += "<td>" + _t("Number of items to keep on disk (-1 means unlimited)") + "</td>"
html += "<td><p align='right'><input type='text' size='3' name='itemsToKeep' value='" + feed.itemsToKeep + "'></p></td>"
html += "</tr>"
html += "</table>"
html += "<input type='hidden' name='host' value='" + feed.publisherB64 + "'>"
html += "<input type='hidden' name='action' value='configure'>"
html += "<input type='submit' value='" + _t("Save") + "'>"
html += "<a href='#' onclick='window.cancelConfig();return false;'>" + _t("Cancel") + "</a>"
html += "</form>"
var tableDiv = document.getElementById("feedConfig")
tableDiv.innerHTML = html
}
function cancelConfig() {
var tableDiv = document.getElementById("feedConfig")
tableDiv.innerHTML = ""
}
function showComment(infoHash) {

View File

@@ -42,6 +42,7 @@ String pagetitle=Util._t("Feeds");
<div id="feedsTable"></div>
</div>
</div>
<div id="feedConfig"></div>
<hr/>
<div id="table-wrapper">
<div id="table-scroll">