From a888254769c65edb66ddbe2ab0e417d28d361f5c Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Sun, 3 Sep 2017 18:09:44 +0000 Subject: [PATCH] Add UI for numbered page navigation when Javascript re-sorting is enabled. --- htroot/js/yacysearch.js | 27 +++++++++++++++++++++------ htroot/js/yacysort.js | 16 ++++++++++++++-- htroot/yacysearch.html | 11 ++++------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js index 8ae63aa59..3bb9001cc 100644 --- a/htroot/js/yacysearch.js +++ b/htroot/js/yacysearch.js @@ -42,9 +42,12 @@ function fadeOutBar() { } /** + * @param offset item number to start with + * @param itemsperpage count of items requested per page + * @param totalcount count of items available from YaCy node for this query * @returns pagination buttons */ -function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, localQuery) { +function renderPaginationButtons(offset, itemsperpage, totalcount, navurlbase, localQuery, jsResort) { var resnav = ""; @@ -95,7 +110,7 @@ function parseFormattedInt(strIntValue) { return intValue; } -function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCount, remoteIndexCount, remotePeerCount, navurlbase, localQuery, feedRunning) { +function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCount, remoteIndexCount, remotePeerCount, navurlbase, localQuery, feedRunning, jsResort) { var totalcountIntValue = parseFormattedInt(totalcount); var offsetIntValue = parseFormattedInt(offset); var itemscountIntValue = parseFormattedInt(itemscount); @@ -174,7 +189,7 @@ function statistics(offset, itemscount, itemsperpage, totalcount, localIndexCoun } var resnavElement = document.getElementById("resNav"); if (resnavElement != null) { - resnavElement.innerHTML = renderPaginationButtons(offsetIntValue, itemsperpageIntValue, totalcountIntValue, navurlbase, localQuery); + resnavElement.innerHTML = renderPaginationButtons(offsetIntValue, itemsperpageIntValue, totalcountIntValue, navurlbase, localQuery, jsResort); } } diff --git a/htroot/js/yacysort.js b/htroot/js/yacysort.js index e4aad608b..048ee145d 100644 --- a/htroot/js/yacysort.js +++ b/htroot/js/yacysort.js @@ -28,8 +28,20 @@ var displayPage = function() { } }); - $("#offset").html($("#resultscontainer .searchresults.earlierpage").length + 1); - $("#itemscount").html($("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length); + // TODO: The following statistical displays could maybe be moved to the latestinfo() call. + + var offset = $("#resultscontainer .searchresults.earlierpage").length + 1; + var itemscount = $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length; + + // TODO: This seems to often be smaller than the "totalcount" that statistics() ends up with. Why is that? + var totalcount = $("#resultscontainer .searchresults").length; + + $("#offset").html(offset); + $("#itemscount").html(itemscount); + + $("#resNav").html(renderPaginationButtons(offset, requestedResults, totalcount, null, theLocalQuery, true)); + + //latestinfo(); console.log("Showing results " + ($("#resultscontainer .searchresults.earlierpage").length + 1) + " - " + ($("#resultscontainer .searchresults.earlierpage").length + requestedResults) + " out of " + $("#resultscontainer .searchresults").length + "; notEarlierPage = " + $("#resultscontainer .searchresults:not(.earlierpage)").length); }; diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html index ba95d5c12..82aff1d50 100644 --- a/htroot/yacysearch.html +++ b/htroot/yacysearch.html @@ -16,6 +16,7 @@ #(/jsResort)# @@ -209,11 +210,7 @@ document.getElementById("Enter").innerHTML = "search again"; :: :: :: - #(jsResort)# - - :: -



Prev Page    Next Page

- #(/jsResort)# + :: #(/num-results)# @@ -254,9 +251,9 @@ function latestinfo() { if(rsp && rsp.offset != null) { #(jsResort)# - statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning); + statistics(rsp.offset, rsp.itemscount, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning, false); :: - statistics($("#resultscontainer .searchresults.earlierpage").length + 1, $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning); + statistics($("#resultscontainer .searchresults.earlierpage").length + 1, $("#resultscontainer .searchresults.earlierpage").length + $("#resultscontainer .searchresults.currentpage").length, rsp.itemsperpage, rsp.totalcount, rsp.localIndexCount, rsp.remoteIndexCount, rsp.remotePeerCount, rsp.navurlBase, #[localQuery]#, rsp.feedRunning, true); #(/jsResort)# if(rsp.feedRunning) { /* Refresh statistics while server feeders are still running */