mirror of https://github.com/zlatinb/muwire
automatically update active browse if the revision has changed
parent
f9c428cfcd
commit
eacaedaf3d
|
@ -27,6 +27,7 @@ public class BrowseManager {
|
||||||
if (browse == null)
|
if (browse == null)
|
||||||
return; // hmm
|
return; // hmm
|
||||||
browse.status = e.getStatus();
|
browse.status = e.getStatus();
|
||||||
|
browse.revision++;
|
||||||
if (browse.status == BrowseStatus.FETCHING)
|
if (browse.status == BrowseStatus.FETCHING)
|
||||||
browse.totalResults = e.getTotalResults();
|
browse.totalResults = e.getTotalResults();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +37,7 @@ public class BrowseManager {
|
||||||
if (browse == null)
|
if (browse == null)
|
||||||
return;
|
return;
|
||||||
browse.results.add(e);
|
browse.results.add(e);
|
||||||
|
browse.revision++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void browse(Persona p) {
|
void browse(Persona p) {
|
||||||
|
@ -62,6 +64,7 @@ public class BrowseManager {
|
||||||
private final Persona persona;
|
private final Persona persona;
|
||||||
private volatile BrowseStatus status;
|
private volatile BrowseStatus status;
|
||||||
private volatile int totalResults;
|
private volatile int totalResults;
|
||||||
|
private volatile long revision;
|
||||||
private final List<UIResultEvent> results = Collections.synchronizedList(new ArrayList<>());
|
private final List<UIResultEvent> results = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
Browse(Persona persona) {
|
Browse(Persona persona) {
|
||||||
|
@ -79,5 +82,9 @@ public class BrowseManager {
|
||||||
public List<UIResultEvent> getResults() {
|
public List<UIResultEvent> getResults() {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getRevision() {
|
||||||
|
return revision;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class BrowseServlet extends HttpServlet {
|
||||||
sb.append("<BrowseStatus>").append(browse.getStatus()).append("</BrowseStatus>");
|
sb.append("<BrowseStatus>").append(browse.getStatus()).append("</BrowseStatus>");
|
||||||
sb.append("<TotalResults>").append(browse.getTotalResults()).append("</TotalResults>");
|
sb.append("<TotalResults>").append(browse.getTotalResults()).append("</TotalResults>");
|
||||||
sb.append("<ResultsCount>").append(browse.getResults().size()).append("</ResultsCount>");
|
sb.append("<ResultsCount>").append(browse.getResults().size()).append("</ResultsCount>");
|
||||||
|
sb.append("<Revision>").append(browse.getRevision()).append("</Revision>");
|
||||||
sb.append("</Browse>");
|
sb.append("</Browse>");
|
||||||
});
|
});
|
||||||
sb.append("</Status>");
|
sb.append("</Status>");
|
||||||
|
|
|
@ -9,12 +9,13 @@ class Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Browse {
|
class Browse {
|
||||||
constructor(host, hostB64, status, totalResults, receivedResults) {
|
constructor(host, hostB64, status, totalResults, receivedResults, revision) {
|
||||||
this.host = host
|
this.host = host
|
||||||
this.hostB64 = hostB64
|
this.hostB64 = hostB64
|
||||||
this.totalResults = totalResults
|
this.totalResults = totalResults
|
||||||
this.receivedResults = receivedResults
|
this.receivedResults = receivedResults
|
||||||
this.status = status
|
this.status = status
|
||||||
|
this.revision = revision
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +32,11 @@ function refreshActive() {
|
||||||
var xmlhttp = new XMLHttpRequest()
|
var xmlhttp = new XMLHttpRequest()
|
||||||
xmlhttp.onreadystatechange = function() {
|
xmlhttp.onreadystatechange = function() {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
|
||||||
|
var currentBrowse = null
|
||||||
|
if (currentHost != null)
|
||||||
|
currentBrowse = browsesByHost.get(currentHost)
|
||||||
|
|
||||||
var xmlDoc = this.responseXML
|
var xmlDoc = this.responseXML
|
||||||
var browses = xmlDoc.getElementsByTagName("Browse")
|
var browses = xmlDoc.getElementsByTagName("Browse")
|
||||||
var i
|
var i
|
||||||
|
@ -40,8 +46,9 @@ function refreshActive() {
|
||||||
var status = browses[i].getElementsByTagName("BrowseStatus")[0].childNodes[0].nodeValue;
|
var status = browses[i].getElementsByTagName("BrowseStatus")[0].childNodes[0].nodeValue;
|
||||||
var totalResults = browses[i].getElementsByTagName("TotalResults")[0].childNodes[0].nodeValue;
|
var totalResults = browses[i].getElementsByTagName("TotalResults")[0].childNodes[0].nodeValue;
|
||||||
var count = browses[i].getElementsByTagName("ResultsCount")[0].childNodes[0].nodeValue;
|
var count = browses[i].getElementsByTagName("ResultsCount")[0].childNodes[0].nodeValue;
|
||||||
|
var revision = browses[i].getElementsByTagName("Revision")[0].childNodes[0].nodeValue;
|
||||||
|
|
||||||
var browse = new Browse(host, hostB64, status, totalResults, count)
|
var browse = new Browse(host, hostB64, status, totalResults, count, revision)
|
||||||
browsesByHost.set(host, browse)
|
browsesByHost.set(host, browse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +69,12 @@ function refreshActive() {
|
||||||
|
|
||||||
var tableDiv = document.getElementById("activeBrowses")
|
var tableDiv = document.getElementById("activeBrowses")
|
||||||
tableDiv.innerHTML = tableHtml
|
tableDiv.innerHTML = tableHtml
|
||||||
|
|
||||||
|
if (currentBrowse != null) {
|
||||||
|
var newBrowse = browsesByHost.get(currentHost)
|
||||||
|
if (currentBrowse.revision < newBrowse.revision)
|
||||||
|
showResults(currentHost)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlhttp.open("GET", "/MuWire/Browse?section=status", true)
|
xmlhttp.open("GET", "/MuWire/Browse?section=status", true)
|
||||||
|
@ -74,10 +87,6 @@ function getBrowseLink(host, text) {
|
||||||
|
|
||||||
function showResults(host) {
|
function showResults(host) {
|
||||||
|
|
||||||
var refreshLink = getBrowseLink(host, "Refresh")
|
|
||||||
var linkDiv = document.getElementById("refresh-link")
|
|
||||||
linkDiv.innerHTML = refreshLink
|
|
||||||
|
|
||||||
var browse = browsesByHost.get(host)
|
var browse = browsesByHost.get(host)
|
||||||
var xmlhttp = new XMLHttpRequest()
|
var xmlhttp = new XMLHttpRequest()
|
||||||
xmlhttp.onreadystatechange = function() {
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
|
|
@ -37,7 +37,6 @@ String pagetitle="Browse Host";
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
<div id="refresh-link"></div>
|
|
||||||
<div id="table-wrapper">
|
<div id="table-wrapper">
|
||||||
<div id="table-scroll">
|
<div id="table-scroll">
|
||||||
<div id="resultsTable"></div>
|
<div id="resultsTable"></div>
|
||||||
|
|
Loading…
Reference in New Issue