#1258 retain old search pattern in web ui
Merged 2 years ago by mikem. Opened 3 years ago by tkopecek.
tkopecek/koji issue1130  into  master

@@ -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 @@ 

            <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 -->

file modified
+22 -14
@@ -1,9 +1,9 @@ 

+ #import cgi

  #from kojiweb import util

  

  #include "includes/header.chtml"

  

    <h4>Search</h4>

- 

    <form action="search">

      <table>

        <tr>
@@ -11,21 +11,26 @@ 

          <tr><td colspan="3" 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>
@@ -33,9 +38,12 @@ 

        <tr>

          <th>&nbsp;</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>

+           #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>

        </tr>

        <tr>

file modified
+8 -4
@@ -189,14 +189,18 @@ 

      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 ''

  

Fixes: https://pagure.io/koji/issue/1130

Please double-check escaping if I'm not introducing some html injection.

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

3 years ago

rebased onto b35d3a9b7afe067a08b54888d8a3e8a2f1c6a433

3 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

3 years ago

@mikem - It is marked as testing-done, ready for merge?

Ah, I had envisioned including the search form in the results page, but this is helpful too. Perhaps not obvious where to look if you used the full search form instead of the top bar.

This doesn't propagate the search type. If you search for tags matching k*, the resulting page is prefilled with a search for packages instead.

If I search for &lt;, the box on the results page is prefilled with <. Suspicious.

rebased onto 6f89906

3 years ago

I've addded support to search page directly and fixed search type.
Html escaping is problem, as all templates go through XHTMLFilter, so '<' is converted to '<' and it is then escaped by cgi.escape back to '&lt', which is displayed as '<' in browser. (see html source of final page). So raw query is already lost inside the template - I don't think it is worthy to rewrite XHTMLFilter usage just because of this usecase.

Metadata Update from @tkopecek:
- Pull-request untagged with: testing-done

3 years ago

I've added support to search page directly and fixed search type.

I see the changes in search.chtml, but they don't do anything because a different template is used for search results.

Combining the two templates seems to make things work.

https://github.com/mikem23/koji-playground/commits/pagure/pr/1258

Tests well with devtools/fakeweb

example screenshot of above attached to #1130

I think I've convinced myself that the XHTMLFilter business is safe

Yes, this works better. There were more combinations which I've not investigated enough (find exactly one result, find more results, wrong query).

Does it make sense now to put whole search form search.html in one row now? It is less scrolling if there are more results.

Does it make sense now to put whole search form search.html in one row now?

Sure, seems to look ok that way. I've updated my branch

https://github.com/mikem23/koji-playground/commits/pagure/pr/1258

Cases that appear to work fine for me (via fakeweb at least):

  • single result (jumps straight to that page)
  • navigating through result pages (works, and still preserves form)
  • no match (shows "No search results")
  • invalid search (shows error message and preserves form)

Commit 2cf37f6 fixes this pull-request

Pull-Request has been merged by mikem

2 years ago