automatically update active browse if the revision has changed
This commit is contained in:
@ -27,6 +27,7 @@ public class BrowseManager {
|
||||
if (browse == null)
|
||||
return; // hmm
|
||||
browse.status = e.getStatus();
|
||||
browse.revision++;
|
||||
if (browse.status == BrowseStatus.FETCHING)
|
||||
browse.totalResults = e.getTotalResults();
|
||||
}
|
||||
@ -36,6 +37,7 @@ public class BrowseManager {
|
||||
if (browse == null)
|
||||
return;
|
||||
browse.results.add(e);
|
||||
browse.revision++;
|
||||
}
|
||||
|
||||
void browse(Persona p) {
|
||||
@ -62,6 +64,7 @@ public class BrowseManager {
|
||||
private final Persona persona;
|
||||
private volatile BrowseStatus status;
|
||||
private volatile int totalResults;
|
||||
private volatile long revision;
|
||||
private final List<UIResultEvent> results = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
Browse(Persona persona) {
|
||||
@ -79,5 +82,9 @@ public class BrowseManager {
|
||||
public List<UIResultEvent> getResults() {
|
||||
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("<TotalResults>").append(browse.getTotalResults()).append("</TotalResults>");
|
||||
sb.append("<ResultsCount>").append(browse.getResults().size()).append("</ResultsCount>");
|
||||
sb.append("<Revision>").append(browse.getRevision()).append("</Revision>");
|
||||
sb.append("</Browse>");
|
||||
});
|
||||
sb.append("</Status>");
|
||||
|
@ -9,12 +9,13 @@ class Result {
|
||||
}
|
||||
|
||||
class Browse {
|
||||
constructor(host, hostB64, status, totalResults, receivedResults) {
|
||||
constructor(host, hostB64, status, totalResults, receivedResults, revision) {
|
||||
this.host = host
|
||||
this.hostB64 = hostB64
|
||||
this.totalResults = totalResults
|
||||
this.receivedResults = receivedResults
|
||||
this.status = status
|
||||
this.revision = revision
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +32,11 @@ function refreshActive() {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
|
||||
var currentBrowse = null
|
||||
if (currentHost != null)
|
||||
currentBrowse = browsesByHost.get(currentHost)
|
||||
|
||||
var xmlDoc = this.responseXML
|
||||
var browses = xmlDoc.getElementsByTagName("Browse")
|
||||
var i
|
||||
@ -40,8 +46,9 @@ function refreshActive() {
|
||||
var status = browses[i].getElementsByTagName("BrowseStatus")[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 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)
|
||||
}
|
||||
|
||||
@ -62,6 +69,12 @@ function refreshActive() {
|
||||
|
||||
var tableDiv = document.getElementById("activeBrowses")
|
||||
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)
|
||||
@ -74,10 +87,6 @@ function getBrowseLink(host, text) {
|
||||
|
||||
function showResults(host) {
|
||||
|
||||
var refreshLink = getBrowseLink(host, "Refresh")
|
||||
var linkDiv = document.getElementById("refresh-link")
|
||||
linkDiv.innerHTML = refreshLink
|
||||
|
||||
var browse = browsesByHost.get(host)
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
|
@ -37,7 +37,6 @@ String pagetitle="Browse Host";
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div id="refresh-link"></div>
|
||||
<div id="table-wrapper">
|
||||
<div id="table-scroll">
|
||||
<div id="resultsTable"></div>
|
||||
|
Reference in New Issue
Block a user