summaryrefslogtreecommitdiff
path: root/htroot/js/yacysearch.js
diff options
context:
space:
mode:
authorluccioman <luccioman@users.noreply.github.com>2016-12-20 14:52:33 +0100
committerluccioman <luccioman@users.noreply.github.com>2016-12-20 14:52:33 +0100
commitc25e48e969f180dcc3c73863acbfcc383a182c8f (patch)
tree9ca47859b223d33cf1f471932d5246affd432614 /htroot/js/yacysearch.js
parenta3886c6adb771d1d2b8ed4a07aeb5f4d249c8c52 (diff)
Enabled displaying results after 14th page for local search queries.
Fixes issue #90 for local queries only: Stealth mode, Portal mode or Intranet mode. For P2p mode, the issue would probably be difficult to solve with reasonable performance. This is still to dig. Also switched some InterreputedException catch log messages to warn level as this is normal behavior when shutting down a peer. Fixed yacysearch buttons navbar behavior to deal correctly with total results count or offset over 1000. Also improved the buttons navbar to be able to navigate over 10th page for local queries.
Diffstat (limited to 'htroot/js/yacysearch.js')
-rw-r--r--htroot/js/yacysearch.js108
1 files changed, 70 insertions, 38 deletions
diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js
index 2c7366081..0b754d23a 100644
--- a/htroot/js/yacysearch.js
+++ b/htroot/js/yacysearch.js
@@ -39,11 +39,72 @@ function fadeOutBar() {
document.getElementById("progressbar").setAttribute('style',"transition:transform 0s;-webkit-transition:-webkit-transform 0s;backgroundColor:transparent;");
}
-function statistics(offset, itemscount, itemsperpage, totalcount, localResourceSize, remoteResourceSize, remoteIndexCount, remotePeerCount, navurlbase) {
- if (totalcount == 0) return;
- if (offset >= 0) document.getElementById("offset").innerHTML = offset;
- if (offset >= 0) document.getElementById("startRecord").setAttribute('value', offset - 1);
- if (itemscount >= 0) document.getElementById("itemscount").firstChild.nodeValue = itemscount;
+/**
+ * @returns pagination buttons
+ */
+function renderPaginationButtons(offset, itemscount, itemsperpage, totalcount, localResourceSize, remoteResourceSize, remoteIndexCount, remotePeerCount, navurlbase, localQuery) {
+ var resnav = "<ul class=\"pagination\">";
+ var thispage = Math.floor(offset / itemsperpage);
+ var firstPage = thispage - (thispage % 10);
+ if (thispage == 0) {
+ resnav += "<li class=\"disabled\"><a href=\"#\">&laquo;</a></li>";
+ } else {
+ resnav += "<li><a id=\"prevpage\" href=\"";
+ resnav += (navurlbase + "&amp;startRecord=" + ((thispage - 1) * itemsperpage));
+ resnav += "\">&laquo;</a></li>";
+ }
+
+ var totalPagesNb = Math.floor(1 + ((totalcount - 1) / itemsperpage));
+ var numberofpages = Math.min(10, totalPagesNb - firstPage);
+ if (!numberofpages) numberofpages = 10;
+ for (i = firstPage; i < (firstPage + numberofpages); i++) {
+ if (i == thispage) {
+ resnav += "<li class=\"active\"><a href=\"#\">";
+ resnav += (i + 1);
+ resnav += "</a></li>";
+ } else {
+ resnav += "<li><a href=\"";
+ resnav += (navurlbase + "&amp;startRecord=" + (i * itemsperpage));
+ resnav += "\">" + (i + 1) + "</a></li>";
+ }
+ }
+ if ((localQuery && thispage >= (totalPagesNb - 1)) || (!localQuery && thispage >= (numberofpages - 1))) {
+ resnav += "<li class=\"disabled\"><a href=\"#\">&raquo;</a></li>";
+ } else {
+ resnav += "<li><a id=\"nextpage\" href=\"";
+ resnav += (navurlbase + "&amp;startRecord=" + ((thispage + 1) * itemsperpage));
+ resnav += "\">&raquo;</a>";
+ }
+ resnav += "</ul>";
+ return resnav;
+}
+
+/**
+ * Parses a string representing an integer value
+ * @param strIntValue formatted string
+ * @returns the number value or undefined when the string is undefined, or NaN when the string is not a number
+ */
+function parseFormattedInt(strIntValue) {
+ var inValue;
+ if(strIntValue != null && strIntValue.replace != null) {
+ /* Remove thousands separator and try to parse as integer */
+ intValue = parseInt(strIntValue.replace(/[\.\,]/g,''))
+ }
+ return intValue;
+}
+
+function statistics(offset, itemscount, itemsperpage, totalcount, localResourceSize, remoteResourceSize, remoteIndexCount, remotePeerCount, navurlbase, localQuery) {
+ var totalcountIntValue = parseFormattedInt(totalcount);
+ var offsetIntValue = parseFormattedInt(offset);
+ var itemscountIntValue = parseFormattedInt(itemscount);
+ var itemsperpageIntValue = parseFormattedInt(itemsperpage);
+
+ if (totalcountIntValue == 0) {
+ return;
+ }
+ if (offsetIntValue >= 0) document.getElementById("offset").innerHTML = offset;
+ if (offsetIntValue >= 0) document.getElementById("startRecord").setAttribute('value', offsetIntValue - 1);
+ if (itemscountIntValue >= 0) document.getElementById("itemscount").firstChild.nodeValue = itemscount;
document.getElementById("totalcount").firstChild.nodeValue = totalcount;
if (document.getElementById("localResourceSize") != null) document.getElementById("localResourceSize").firstChild.nodeValue = localResourceSize;
if (document.getElementById("remoteResourceSize") != null) document.getElementById("remoteResourceSize").firstChild.nodeValue = remoteResourceSize;
@@ -52,7 +113,7 @@ function statistics(offset, itemscount, itemsperpage, totalcount, localResourceS
// compose page navigation
if (document.getElementById("progressbar").getAttribute('class') != "progress-bar progress-bar-success") {
- var percent = 100 * (itemscount - offset + 1) / itemsperpage;
+ var percent = 100 * (itemscountIntValue - offsetIntValue + 1) / itemsperpageIntValue;
if (percent == 100) {
document.getElementById("progressbar").setAttribute('style',"transition:transform 0s;-webkit-transition:-webkit-transform 0s;");
document.getElementById("progressbar").setAttribute('class',"progress-bar progress-bar-success");
@@ -62,38 +123,9 @@ function statistics(offset, itemscount, itemsperpage, totalcount, localResourceS
}
var resnavElement = document.getElementById("resNav");
if (resnavElement != null) {
- var resnav = "<ul class=\"pagination\">";
- thispage = Math.floor(offset / itemsperpage);
- if (thispage == 0) {
- resnav += "<li class=\"disabled\"><a href=\"#\">&laquo;</a></li>";
- } else {
- resnav += "<li><a id=\"prevpage\" href=\"";
- resnav += (navurlbase + "&amp;startRecord=" + ((thispage - 1) * itemsperpage));
- resnav += "\">&laquo;</a></li>";
- }
-
- numberofpages = Math.floor(Math.min(9, 1 + ((totalcount.replace(/\./g,'') - 1) / itemsperpage)));
- if (!numberofpages) numberofpages = 9;
- for (i = 0; i < numberofpages; i++) {
- if (i == thispage) {
- resnav += "<li class=\"active\"><a href=\"#\">";
- resnav += (i + 1);
- resnav += "</a></li>";
- } else {
- resnav += "<li><a href=\"";
- resnav += (navurlbase + "&amp;startRecord=" + (i * itemsperpage));
- resnav += "\">" + (i + 1) + "</a></li>";
- }
- }
- if (thispage >= numberofpages) {
- resnav += "<li><a href=\"#\">&raquo;</a></li>";
- } else {
- resnav += "<li><a id=\"nextpage\" href=\"";
- resnav += (navurlbase + "&amp;startRecord=" + ((thispage + 1) * itemsperpage));
- resnav += "\">&raquo;</a>";
- }
- resnav += "</ul>";
- resnavElement.innerHTML = resnav;
+ resnavElement.innerHTML = renderPaginationButtons(offsetIntValue, itemscountIntValue, itemsperpageIntValue,
+ totalcountIntValue, parseFormattedInt(localResourceSize), parseFormattedInt(remoteResourceSize), parseFormattedInt(remoteIndexCount),
+ parseFormattedInt(remotePeerCount), navurlbase, localQuery);
}
}