PR#1258: retain old search pattern in web ui
Merges #1258 https://pagure.io/koji/pull-request/1258 Fixes: #1130 https://pagure.io/koji/issue/1130 RFE: search results page should include search form with current search prefilled
This commit is contained in:
commit
2cf37f6c4e
5 changed files with 122 additions and 109 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#encoding UTF-8
|
||||
#import cgi
|
||||
#import koji
|
||||
#from kojiweb import util
|
||||
#from koji_cli.lib import greetings
|
||||
|
|
@ -35,21 +36,26 @@ $localnav
|
|||
<form action="search" id="headerSearch">
|
||||
<input type="hidden" name="match" value="glob"/>
|
||||
<select name="type">
|
||||
<option value="package">Packages</option>
|
||||
<option value="build">Builds</option>
|
||||
<option value="tag">Tags</option>
|
||||
<option value="target">Build Targets</option>
|
||||
<option value="user">Users</option>
|
||||
<option value="host">Hosts</option>
|
||||
<option value="rpm">RPMs</option>
|
||||
<option $util.toggleSelected($self, $type, "package") value="package">Packages</option>
|
||||
<option $util.toggleSelected($self, $type, "build") value="build">Builds</option>
|
||||
<option $util.toggleSelected($self, $type, "tag") value="tag">Tags</option>
|
||||
<option $util.toggleSelected($self, $type, "target") value="target">Build Targets</option>
|
||||
<option $util.toggleSelected($self, $type, "user") value="user">Users</option>
|
||||
<option $util.toggleSelected($self, $type, "host") value="host">Hosts</option>
|
||||
<option $util.toggleSelected($self, $type, "rpm") value="rpm">RPMs</option>
|
||||
#if $mavenEnabled
|
||||
<option value="maven">Maven Artifacts</option>
|
||||
<option $util.toggleSelected($self, $type, "maven") value="maven">Maven Artifacts</option>
|
||||
#end if
|
||||
#if $winEnabled
|
||||
<option value="win">Windows Artifacts</option>
|
||||
<option $util.toggleSelected($self, $type, "win") value="win">Windows Artifacts</option>
|
||||
#end if
|
||||
</select>
|
||||
<input type="text" name="terms" title="You can use glob expressions here (e.g. 'bash-*')"/>
|
||||
#try
|
||||
#set $old_terms = cgi.escape($terms)
|
||||
#except
|
||||
#set $old_terms = ""
|
||||
#end try
|
||||
<input type="text" name="terms" title="You can use glob expressions here (e.g. 'bash-*')" value="$old_terms"/>
|
||||
<input type="submit" value="Search"/>
|
||||
</form>
|
||||
</div><!-- end header -->
|
||||
|
|
|
|||
|
|
@ -2273,7 +2273,7 @@ def search(environ, start=None, order=None):
|
|||
else:
|
||||
typeLabel = '%ss' % type
|
||||
values['typeLabel'] = typeLabel
|
||||
return _genHTML(environ, 'searchresults.chtml')
|
||||
return _genHTML(environ, 'search.chtml')
|
||||
else:
|
||||
return _genHTML(environ, 'search.chtml')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,48 +1,124 @@
|
|||
#import cgi
|
||||
#from kojiweb import util
|
||||
#from six.moves.urllib.parse import quote
|
||||
|
||||
#include "includes/header.chtml"
|
||||
|
||||
<h4>Search</h4>
|
||||
|
||||
<h4>Search</h4>
|
||||
<form action="search">
|
||||
<table>
|
||||
<tr>
|
||||
#if $error
|
||||
<tr><td colspan="3" class="error">$error</td></tr>
|
||||
<tr><td colspan="5" class="error">$error</td></tr>
|
||||
#end if
|
||||
<th>Search</th>
|
||||
<td><input type="text" name="terms"/></td>
|
||||
#try
|
||||
#set $old_terms = cgi.escape($terms)
|
||||
#except
|
||||
#set $old_terms = ""
|
||||
#end try
|
||||
<td><input type="text" name="terms" value="$old_terms"/></td>
|
||||
<td>
|
||||
<select name="type">
|
||||
<option value="package">Packages</option>
|
||||
<option value="build">Builds</option>
|
||||
<option value="tag">Tags</option>
|
||||
<option value="target">Build Targets</option>
|
||||
<option value="user">Users</option>
|
||||
<option value="host">Hosts</option>
|
||||
<option value="rpm">RPMs</option>
|
||||
<option $util.toggleSelected($self, $type, "package") value="package">Packages</option>
|
||||
<option $util.toggleSelected($self, $type, "build") value="build">Builds</option>
|
||||
<option $util.toggleSelected($self, $type, "tag") value="tag">Tags</option>
|
||||
<option $util.toggleSelected($self, $type, "target") value="target">Build Targets</option>
|
||||
<option $util.toggleSelected($self, $type, "user") value="user">Users</option>
|
||||
<option $util.toggleSelected($self, $type, "host") value="host">Hosts</option>
|
||||
<option $util.toggleSelected($self, $type, "rpm") value="rpm">RPMs</option>
|
||||
#if $mavenEnabled
|
||||
<option value="maven">Maven Artifacts</option>
|
||||
<option $util.toggleSelected($self, $type, "maven") value="maven">Maven Artifacts</option>
|
||||
#end if
|
||||
#if $winEnabled
|
||||
<option value="win">Windows Artifacts</option>
|
||||
<option $util.toggleSelected($self, $type, "win") value="win">Windows Artifacts</option>
|
||||
#end if
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<td colspan="2">
|
||||
<input type="radio" name="match" value="glob" id="radioglob" checked="checked"/><abbr title="? will match any single character, * will match any sequence of zero or more characters" id="abbrglob">glob</abbr>
|
||||
<input type="radio" name="match" value="regexp" id="radioregexp"/><abbr title="full POSIX regular expressions" id="abbrregexp">regexp</abbr>
|
||||
<input type="radio" name="match" value="exact" id="radioexact"/><abbr title="exact matches only" id="abbrexact">exact</abbr>
|
||||
<td>
|
||||
#if not $varExists('match')
|
||||
#set $match='glob'
|
||||
#end if
|
||||
<input type="radio" name="match" value="glob" $util.toggleSelected($self, $match, "glob", True) id="radioglob"/><abbr title="? will match any single character, * will match any sequence of zero or more characters" id="abbrglob">glob</abbr>
|
||||
<input type="radio" name="match" value="regexp" $util.toggleSelected($self, $match, "regexp", True) id="radioregexp"/><abbr title="full POSIX regular expressions" id="abbrregexp">regexp</abbr>
|
||||
<input type="radio" name="match" value="exact" $util.toggleSelected($self, $match, "exact", True) id="radioexact"/><abbr title="exact matches only" id="abbrexact">exact</abbr>
|
||||
</td>
|
||||
<td colspan="2"><input type="submit" value="Search"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<td colspan="2"><input type="submit" value="Search"/></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
||||
#if $varExists('results')
|
||||
|
||||
<table class="data-list">
|
||||
<tr>
|
||||
<td class="paginate" colspan="2">
|
||||
#if $len($resultPages) > 1
|
||||
<form class="pageJump" action="">
|
||||
Page:
|
||||
<select onchange="javascript: window.location = 'search?start=' + this.value * $resultRange + '$util.passthrough($self, 'order', 'terms', 'type', 'match')';">
|
||||
#for $pageNum in $resultPages
|
||||
<option value="$pageNum"#if $pageNum == $resultCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
|
||||
#end for
|
||||
</select>
|
||||
</form>
|
||||
#end if
|
||||
#if $resultStart > 0
|
||||
<a href="search?start=#echo $resultStart - $resultRange #$util.passthrough($self, 'order', 'terms', 'type', 'match')"><<<</a>
|
||||
#end if
|
||||
#if $totalResults != 0
|
||||
<strong>Results #echo $resultStart + 1 # through #echo $resultStart + $resultCount # of $totalResults</strong>
|
||||
#end if
|
||||
#if $resultStart + $resultCount < $totalResults
|
||||
<a href="search?start=#echo $resultStart + $resultRange#$util.passthrough($self, 'order', 'terms', 'type', 'match')">>>></a>
|
||||
#end if
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="list-header">
|
||||
<th><a href="search?order=$util.toggleOrder($self, 'id')$util.passthrough($self, 'terms', 'type', 'match')">ID</a> $util.sortImage($self, 'id')</th>
|
||||
<th><a href="search?order=$util.toggleOrder($self, 'name')$util.passthrough($self, 'terms', 'type', 'match')">Name</a> $util.sortImage($self, 'name')</th>
|
||||
</tr>
|
||||
#if $len($results) > 0
|
||||
#for $result in $results
|
||||
<tr class="$util.rowToggle($self)">
|
||||
<td>$result.id</td>
|
||||
<td><a href="${infoURL % $result}">$result.name</a></td>
|
||||
</tr>
|
||||
#end for
|
||||
#else
|
||||
<tr class="row-odd">
|
||||
<td colspan="2">No search results</td>
|
||||
</tr>
|
||||
#end if
|
||||
<tr>
|
||||
<td class="paginate" colspan="2">
|
||||
#if $len($resultPages) > 1
|
||||
<form class="pageJump" action="">
|
||||
Page:
|
||||
<select onchange="javascript: window.location = 'search?start=' + this.value * $resultRange + '$util.passthrough($self, 'order', 'terms', 'type', 'match')';">
|
||||
#for $pageNum in $resultPages
|
||||
<option value="$pageNum"#if $pageNum == $resultCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
|
||||
#end for
|
||||
</select>
|
||||
</form>
|
||||
#end if
|
||||
#if $resultStart > 0
|
||||
<a href="search?start=#echo $resultStart - $resultRange #$util.passthrough($self, 'order', 'terms', 'type', 'match')"><<<</a>
|
||||
#end if
|
||||
#if $totalResults != 0
|
||||
<strong>Results #echo $resultStart + 1 # through #echo $resultStart + $resultCount # of $totalResults</strong>
|
||||
#end if
|
||||
#if $resultStart + $resultCount < $totalResults
|
||||
<a href="search?start=#echo $resultStart + $resultRange#$util.passthrough($self, 'order', 'terms', 'type', 'match')">>>></a>
|
||||
#end if
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
#end if
|
||||
|
||||
#include "includes/footer.chtml"
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
#from kojiweb import util
|
||||
#from six.moves.urllib.parse import quote
|
||||
|
||||
#include "includes/header.chtml"
|
||||
|
||||
<h4>Search Results for $typeLabel matching "$terms"</h4>
|
||||
|
||||
<table class="data-list">
|
||||
<tr>
|
||||
<td class="paginate" colspan="2">
|
||||
#if $len($resultPages) > 1
|
||||
<form class="pageJump" action="">
|
||||
Page:
|
||||
<select onchange="javascript: window.location = 'search?start=' + this.value * $resultRange + '$util.passthrough($self, 'order', 'terms', 'type', 'match')';">
|
||||
#for $pageNum in $resultPages
|
||||
<option value="$pageNum"#if $pageNum == $resultCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
|
||||
#end for
|
||||
</select>
|
||||
</form>
|
||||
#end if
|
||||
#if $resultStart > 0
|
||||
<a href="search?start=#echo $resultStart - $resultRange #$util.passthrough($self, 'order', 'terms', 'type', 'match')"><<<</a>
|
||||
#end if
|
||||
#if $totalResults != 0
|
||||
<strong>Results #echo $resultStart + 1 # through #echo $resultStart + $resultCount # of $totalResults</strong>
|
||||
#end if
|
||||
#if $resultStart + $resultCount < $totalResults
|
||||
<a href="search?start=#echo $resultStart + $resultRange#$util.passthrough($self, 'order', 'terms', 'type', 'match')">>>></a>
|
||||
#end if
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="list-header">
|
||||
<th><a href="search?order=$util.toggleOrder($self, 'id')$util.passthrough($self, 'terms', 'type', 'match')">ID</a> $util.sortImage($self, 'id')</th>
|
||||
<th><a href="search?order=$util.toggleOrder($self, 'name')$util.passthrough($self, 'terms', 'type', 'match')">Name</a> $util.sortImage($self, 'name')</th>
|
||||
</tr>
|
||||
#if $len($results) > 0
|
||||
#for $result in $results
|
||||
<tr class="$util.rowToggle($self)">
|
||||
<td>$result.id</td>
|
||||
<td><a href="${infoURL % $result}">$result.name</a></td>
|
||||
</tr>
|
||||
#end for
|
||||
#else
|
||||
<tr class="row-odd">
|
||||
<td colspan="2">No search results</td>
|
||||
</tr>
|
||||
#end if
|
||||
<tr>
|
||||
<td class="paginate" colspan="2">
|
||||
#if $len($resultPages) > 1
|
||||
<form class="pageJump" action="">
|
||||
Page:
|
||||
<select onchange="javascript: window.location = 'search?start=' + this.value * $resultRange + '$util.passthrough($self, 'order', 'terms', 'type', 'match')';">
|
||||
#for $pageNum in $resultPages
|
||||
<option value="$pageNum"#if $pageNum == $resultCurrentPage then ' selected="selected"' else ''#>#echo $pageNum + 1#</option>
|
||||
#end for
|
||||
</select>
|
||||
</form>
|
||||
#end if
|
||||
#if $resultStart > 0
|
||||
<a href="search?start=#echo $resultStart - $resultRange #$util.passthrough($self, 'order', 'terms', 'type', 'match')"><<<</a>
|
||||
#end if
|
||||
#if $totalResults != 0
|
||||
<strong>Results #echo $resultStart + 1 # through #echo $resultStart + $resultCount # of $totalResults</strong>
|
||||
#end if
|
||||
#if $resultStart + $resultCount < $totalResults
|
||||
<a href="search?start=#echo $resultStart + $resultRange#$util.passthrough($self, 'order', 'terms', 'type', 'match')">>>></a>
|
||||
#end if
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
#include "includes/footer.chtml"
|
||||
|
|
@ -189,14 +189,18 @@ def toggleOrder(template, sortKey, orderVar='order'):
|
|||
else:
|
||||
return sortKey
|
||||
|
||||
def toggleSelected(template, var, option):
|
||||
def toggleSelected(template, var, option, checked=False):
|
||||
"""
|
||||
If the passed in variable var equals the literal value in option,
|
||||
return 'selected="selected"', otherwise return ''.
|
||||
Used for setting the selected option in select boxes.
|
||||
return 'selected="selected"', otherwise return ''. If checked is True,
|
||||
'"checked="checked"' string is returned
|
||||
Used for setting the selected option in select and radio boxes.
|
||||
"""
|
||||
if var == option:
|
||||
return 'selected="selected"'
|
||||
if checked:
|
||||
return 'checked="checked"'
|
||||
else:
|
||||
return 'selected="selected"'
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue