Skip to content
Permalink
Browse files

Enable api table page navigation with search query

Applied the same default results page size as when a type filter is
defined for proper and consistend page navigation when combining type
filter and search query.
  • Loading branch information...
luccioman committed Mar 30, 2018
1 parent 9c7faa0 commit 86c902b85336ec43fa4e67f69a8163d8bdb35d54
Showing with 14 additions and 9 deletions.
  1. +3 −3 htroot/Table_API_p.html
  2. +11 −6 htroot/Table_API_p.java
@@ -53,13 +53,13 @@ <h2>Process Scheduler</h2>
<span id="resCounter" style="display: inline;">
#(navigation)#
::
#(left)#<img src="env/grafics/navdl.gif" alt="no previous page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&amp;maximumRecords=#[maximumRecords]#&amp;inline=#(inline)#false::true#(/inline)#&amp;filter=#[filter]#" target="_self"><img src="env/grafics/navsl.gif" alt="previous page" /></a>#(/left)#
#(left)#<img src="env/grafics/navdl.gif" alt="no previous page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&amp;maximumRecords=#[maximumRecords]#&amp;inline=#(inline)#false::true#(/inline)#&amp;filter=#[filter]#&amp;query=#[query]#" target="_self"><img src="env/grafics/navsl.gif" alt="previous page" /></a>#(/left)#
#[startRecord]#-#[to]# of #[of]#
#(right)#<img src="env/grafics/navdr.gif" alt="no next page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&amp;maximumRecords=#[maximumRecords]#&amp;inline=#(inline)#false::true#(/inline)#&amp;filter=#[filter]#" target="_self"><img src="env/grafics/navsr.gif" alt="next page" /></a>#(/right)#
#(right)#<img src="env/grafics/navdr.gif" alt="no next page" />::<a href="Table_API_p.html?startRecord=#[startRecord]#&amp;maximumRecords=#[maximumRecords]#&amp;inline=#(inline)#false::true#(/inline)#&amp;filter=#[filter]#&amp;query=#[query]#" target="_self"><img src="env/grafics/navsr.gif" alt="next page" /></a>#(/right)#
<img src="env/grafics/nave.gif" alt="" />
#(/navigation)#

<input type="hidden" name="startRecord" value="#[startRecord]#" />
<input type="hidden" name="startRecord" value="0" /> <!-- This form is used to type a new query, so we start at record zero -->
<input type="hidden" name="maximumRecords" value="#[maximumRecords]#" />
<input type="hidden" name="inline" value="#(inline)#false::true#(/inline)#" />
<input type="hidden" name="filter" value="#[filter]#" />
@@ -47,6 +47,9 @@

public class Table_API_p {

/** Default results page size */
private static final int DEFAULT_MAX_RECORDS = 25;

public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
@@ -55,18 +58,18 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("showtable", 0);

int startRecord = 0;
int maximumRecords = 25;
int maximumRecords = DEFAULT_MAX_RECORDS;
Pattern query = QueryParams.catchall_pattern;
if (post != null && post.containsKey("startRecord")) {
startRecord = post.getInt("startRecord", 0);
}
if (post != null && post.containsKey("maximumRecords")) {
maximumRecords = post.getInt("maximumRecords", 0);
}
String queryParam = "";
if (post != null && post.containsKey("query") && !post.get("query", "").isEmpty()) {
query = Pattern.compile(".*" + post.get("query", "") + ".*");
startRecord = 0;
maximumRecords = 1000;
queryParam = post.get("query", "");
query = Pattern.compile(".*" + queryParam + ".*");
}
final boolean inline = (post != null && post.getBoolean("inline"));

@@ -445,8 +448,8 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("showtable_maximumRecords", maximumRecords);
prop.put("showtable_inline", (inline) ? 1 : 0);
prop.put("showtable_filter", typefilter.pattern());
prop.put("showtable_query", query.pattern().replaceAll("\\.\\*", ""));
if (tablesize >= maximumRecords) {
prop.put("showtable_query", queryParam);
if (filteredSize > maximumRecords) {
prop.put("showtable_navigation", 1);
prop.put("showtable_navigation_startRecord", startRecord);
prop.put("showtable_navigation_to", Math.min(tablesize, startRecord + maximumRecords));
@@ -456,13 +459,15 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("showtable_navigation_left_maximumRecords", maximumRecords);
prop.put("showtable_navigation_left_inline", (inline) ? 1 : 0);
prop.put("showtable_navigation_left_filter", typefilter.pattern());
prop.put("showtable_navigation_left_query", queryParam);
prop.put("showtable_navigation_left", startRecord == 0 ? 0 : 1);
prop.put("showtable_navigation_filter", typefilter.pattern());
prop.put("showtable_navigation_right", startRecord + maximumRecords >= filteredSize ? 0 : 1);
prop.put("showtable_navigation_right_startRecord", Math.min(filteredSize - maximumRecords, startRecord + maximumRecords));
prop.put("showtable_navigation_right_maximumRecords", maximumRecords);
prop.put("showtable_navigation_right_inline", (inline) ? 1 : 0);
prop.put("showtable_navigation_right_filter", typefilter.pattern());
prop.put("showtable_navigation_right_query", queryParam);
} else {
prop.put("showtable_navigation", 0);
}

0 comments on commit 86c902b

Please sign in to comment.
You can’t perform that action at this time.