Patchwork [help-search] hgweb: add help searching

login
register
mail settings
Submitter Augie Fackler
Date Nov. 6, 2014, 7:55 p.m.
Message ID <dab7a85b5749d51fbaf4.1415303702@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/6614/
State Changes Requested
Headers show

Comments

Augie Fackler - Nov. 6, 2014, 7:55 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1409079849 14400
#      Tue Aug 26 15:04:09 2014 -0400
# Node ID dab7a85b5749d51fbaf426ffe4a405d6b718da91
# Parent  3a197c6997e223db6454af5937d912b008a8604f
hgweb: add help searching

I'm not sure the UI on this is reasonable - right now I add another
search box in the lower-right corner of the screen. I think it might
be better to have the existing search box search help when we're in a
help context, and search changesets otherwise. Thoughts?
Pierre-Yves David - Nov. 6, 2014, 7:56 p.m.
On 11/06/2014 07:55 PM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1409079849 14400
> #      Tue Aug 26 15:04:09 2014 -0400
> # Node ID dab7a85b5749d51fbaf426ffe4a405d6b718da91
> # Parent  3a197c6997e223db6454af5937d912b008a8604f
> hgweb: add help searching
>
> I'm not sure the UI on this is reasonable - right now I add another
> search box in the lower-right corner of the screen. I think it might
> be better to have the existing search box search help when we're in a
> help context, and search changesets otherwise. Thoughts?

"Search "babar" in Mercurial manual" link in the search result page?
Augie Fackler - Nov. 6, 2014, 7:58 p.m.
On Nov 6, 2014, at 2:56 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:

> 
> 
> On 11/06/2014 07:55 PM, Augie Fackler wrote:
>> # HG changeset patch
>> # User Augie Fackler <raf@durin42.com>
>> # Date 1409079849 14400
>> #      Tue Aug 26 15:04:09 2014 -0400
>> # Node ID dab7a85b5749d51fbaf426ffe4a405d6b718da91
>> # Parent  3a197c6997e223db6454af5937d912b008a8604f
>> hgweb: add help searching
>> 
>> I'm not sure the UI on this is reasonable - right now I add another
>> search box in the lower-right corner of the screen. I think it might
>> be better to have the existing search box search help when we're in a
>> help context, and search changesets otherwise. Thoughts?
> 
> "Search "babar" in Mercurial manual" link in the search result page?

I dunno. That means searching help takes two actions, which seems like a bummer.

I could add a radio button for changes/help to toggle what the current box is for, and use js to make it go the right place. Clients without js would just not get help searching...

> 
> -- 
> Pierre-Yves David
Pierre-Yves David - Nov. 6, 2014, 8 p.m.
On 11/06/2014 07:58 PM, Augie Fackler wrote:
>
> On Nov 6, 2014, at 2:56 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:
>
>>
>>
>> On 11/06/2014 07:55 PM, Augie Fackler wrote:
>>> # HG changeset patch
>>> # User Augie Fackler <raf@durin42.com>
>>> # Date 1409079849 14400
>>> #      Tue Aug 26 15:04:09 2014 -0400
>>> # Node ID dab7a85b5749d51fbaf426ffe4a405d6b718da91
>>> # Parent  3a197c6997e223db6454af5937d912b008a8604f
>>> hgweb: add help searching
>>>
>>> I'm not sure the UI on this is reasonable - right now I add another
>>> search box in the lower-right corner of the screen. I think it might
>>> be better to have the existing search box search help when we're in a
>>> help context, and search changesets otherwise. Thoughts?
>>
>> "Search "babar" in Mercurial manual" link in the search result page?
>
> I dunno. That means searching help takes two actions, which seems like a bummer.

I'm more offering this idea and a way to make the feature discoverable. 
I think the search help in help context is a good idea.

> I could add a radio button for changes/help to toggle what the current box is for, and use js to make it go the right place. Clients without js would just not get help searching...

I'm afraid this would add too much confusion/ugliness in the UI for low 
added value.
Augie Fackler - Nov. 6, 2014, 8:09 p.m.
On Nov 6, 2014, at 3:00 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:

> 
> 
> On 11/06/2014 07:58 PM, Augie Fackler wrote:
>> 
>> On Nov 6, 2014, at 2:56 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:
>> 
>>> 
>>> 
>>> On 11/06/2014 07:55 PM, Augie Fackler wrote:
>>>> # HG changeset patch
>>>> # User Augie Fackler <raf@durin42.com>
>>>> # Date 1409079849 14400
>>>> #      Tue Aug 26 15:04:09 2014 -0400
>>>> # Node ID dab7a85b5749d51fbaf426ffe4a405d6b718da91
>>>> # Parent  3a197c6997e223db6454af5937d912b008a8604f
>>>> hgweb: add help searching
>>>> 
>>>> I'm not sure the UI on this is reasonable - right now I add another
>>>> search box in the lower-right corner of the screen. I think it might
>>>> be better to have the existing search box search help when we're in a
>>>> help context, and search changesets otherwise. Thoughts?
>>> 
>>> "Search "babar" in Mercurial manual" link in the search result page?
>> 
>> I dunno. That means searching help takes two actions, which seems like a bummer.
> 
> I'm more offering this idea and a way to make the feature discoverable. I think the search help in help context is a good idea.

Okay. I'll see about making that change (when in a help context, search searches help) and will do a resend. I'll also see about adding the "search help for X" link on the normal SERP. Thanks!

> I could add a radio button for changes/help to toggle what the current box is for, and use js to make it go the right place. Clients without js would just not get help searching...
> 
> I'm afraid this would add too much confusion/ugliness in the UI for low added value.

Agreed.

> 
> -- 
> Pierre-Yves David

Patch

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -12,7 +12,7 @@  from mercurial.node import short, hex
 from mercurial import util
 from common import paritygen, staticfile, get_contact, ErrorResponse
 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
-from mercurial import graphmod, patch
+from mercurial import graphmod, patch, minirst
 from mercurial import help as helpmod
 from mercurial import scmutil
 from mercurial.i18n import _
@@ -26,6 +26,7 @@  from mercurial import revset
    'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
    'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff',
    'comparison', 'annotate', 'filelog', 'archive', 'static', 'graph', 'help',
+   'searchhelp',
 ]
 
 def log(web, req, tmpl):
@@ -1063,6 +1064,25 @@  def _getdoc(e):
         doc = _('(no help text available)')
     return doc
 
+def searchhelp(web, req, tmpl):
+    kw = req.form.get('q')[0]
+    matches = helpmod.topicmatch(kw)
+    doclines = []
+    if matches:
+        output = []
+        for t, title in (('topics', _('Topics')),
+                         ('commands', _('Commands')),
+                         ('extensions', _('Extensions')),
+                         ('extensioncommands', _('Extension Commands'))):
+            if matches[t]:
+                doclines.append({'topic': title, 'summary':''})
+                for lhs, rhs in matches[t]:
+                    doclines.append({'topic': lhs, 'summary': rhs})
+        doc = ''
+    else:
+        doc = _('No matches found.')
+    return tmpl('searchhelp', doclines=doclines, doc=doc, kw=kw)
+
 def help(web, req, tmpl):
     from mercurial import commands # avoid cycle
 
diff --git a/mercurial/templates/paper/help.tmpl b/mercurial/templates/paper/help.tmpl
--- a/mercurial/templates/paper/help.tmpl
+++ b/mercurial/templates/paper/help.tmpl
@@ -19,6 +19,10 @@ 
 <ul>
  <li class="active"><a href="{url|urlescape}help{sessionvars%urlparameter}">help</a></li>
 </ul>
+<form class="searchhelp" action="{url}searchhelp">
+{sessionvars%hiddenformentry}
+<p><input name="q" id="searchhelp" type="text" size="10" value="{kw|escape}"/></p>
+</form>
 </div>
 
 <div class="main">
diff --git a/mercurial/templates/paper/helptopics.tmpl b/mercurial/templates/paper/helptopics.tmpl
--- a/mercurial/templates/paper/helptopics.tmpl
+++ b/mercurial/templates/paper/helptopics.tmpl
@@ -19,6 +19,10 @@ 
 <ul>
 <li class="active">help</li>
 </ul>
+<form class="searchhelp" action="{url}searchhelp">
+{sessionvars%hiddenformentry}
+<p><input name="q" id="searchhelp" type="text" size="10" value="{kw|escape}"/></p>
+</form>
 </div>
 
 <div class="main">
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -11,6 +11,7 @@  shortlogentry = shortlogentry.tmpl
 graph = graph.tmpl
 help = help.tmpl
 helptopics = helptopics.tmpl
+searchhelp = searchhelp.tmpl
 
 helpentry = '
   <tr><td>
@@ -21,6 +22,10 @@  helpentry = '
     {summary|escape}
   </td></tr>'
 
+helpsearchresult = '{if(summary,
+                        "{helpentry}",
+                        "\n\n<tr><td colspan=2><h2>{topic}</h2></td></tr>")}'
+
 naventry = '<a href="{url|urlescape}log/{node|short}{sessionvars%urlparameter}">{label|escape}</a> '
 navshortentry = '<a href="{url|urlescape}shortlog/{node|short}{sessionvars%urlparameter}">{label|escape}</a> '
 navgraphentry = '<a href="{url|urlescape}graph/{node|short}{sessionvars%urlparameter}">{label|escape}</a> '
diff --git a/mercurial/templates/paper/searchhelp.tmpl b/mercurial/templates/paper/searchhelp.tmpl
new file mode 100644
--- /dev/null
+++ b/mercurial/templates/paper/searchhelp.tmpl
@@ -0,0 +1,49 @@ 
+{header}
+<title>Help Search: {kw|escape}</title>
+<link rel="alternate" type="application/atom+xml"
+   href="{url}atom-tags" title="Atom feed for {repo|escape}" />
+<link rel="alternate" type="application/rss+xml"
+   href="{url}rss-tags" title="RSS feed for {repo|escape}" />
+</head>
+<body>
+
+<div class="container">
+<div class="menu">
+<div class="logo">
+<a href="{logourl}">
+<img src="{staticurl}{logoimg}" alt="mercurial" /></a>
+</div>
+<ul>
+<li><a href="{url}shortlog{sessionvars%urlparameter}">log</a></li>
+<li><a href="{url}graph{sessionvars%urlparameter}">graph</a></li>
+<li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
+<li><a href="{url}bookmarks{sessionvars%urlparameter}">bookmarks</a></li>
+<li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
+</ul>
+<ul>
+ <li class="active"><a href="{url}help{sessionvars%urlparameter}">help</a></li>
+</ul>
+<form class="searchhelp" action="{url}searchhelp">
+{sessionvars%hiddenformentry}
+<p><input name="q" id="searchhelp" type="text" size="10" value="{kw|escape}"/></p>
+</form>
+</div>
+
+<div class="main">
+<h2><a href="{url}{sessionvars%urlparameter}">{repo|escape}</a></h2>
+
+<form class="search" action="{url}log">
+{sessionvars%hiddenformentry}
+<p><input name="rev" id="search1" type="text" size="30" /></p>
+<div id="hint">find changesets by author, revision,
+files, or words in the commit message</div>
+</form>
+{doc}
+<table class="bigtable">
+<tbody>{doclines % helpsearchresult}
+</tbody>
+</table>
+</div>
+</div>
+
+{footer}
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1145,6 +1145,10 @@  Dish up an empty repo; serve it cold.
   <ul>
   <li class="active">help</li>
   </ul>
+  <form class="searchhelp" action="/searchhelp">
+  
+  <p><input name="q" id="searchhelp" type="text" size="10" value=""/></p>
+  </form>
   </div>
   
   <div class="main">
@@ -1696,6 +1700,10 @@  Dish up an empty repo; serve it cold.
   <ul>
    <li class="active"><a href="/help">help</a></li>
   </ul>
+  <form class="searchhelp" action="/searchhelp">
+  
+  <p><input name="q" id="searchhelp" type="text" size="10" value=""/></p>
+  </form>
   </div>
   
   <div class="main">
@@ -1856,6 +1864,10 @@  Dish up an empty repo; serve it cold.
   <ul>
    <li class="active"><a href="/help">help</a></li>
   </ul>
+  <form class="searchhelp" action="/searchhelp">
+  
+  <p><input name="q" id="searchhelp" type="text" size="10" value=""/></p>
+  </form>
   </div>
   
   <div class="main">
@@ -2046,6 +2058,10 @@  Dish up an empty repo; serve it cold.
   <ul>
    <li class="active"><a href="/help">help</a></li>
   </ul>
+  <form class="searchhelp" action="/searchhelp">
+  
+  <p><input name="q" id="searchhelp" type="text" size="10" value=""/></p>
+  </form>
   </div>
   
   <div class="main">
@@ -2109,6 +2125,81 @@  Dish up an empty repo; serve it cold.
   </body>
   </html>
   
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT "searchhelp?q=ignore"
+  200 Script output follows
+  
+  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+  <head>
+  <link rel="icon" href="/static/hgicon.png" type="image/png" />
+  <meta name="robots" content="index, nofollow" />
+  <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
+  <script type="text/javascript" src="/static/mercurial.js"></script>
+  
+  <title>Help Search: ignore</title>
+  <link rel="alternate" type="application/atom+xml"
+     href="/atom-tags" title="Atom feed for test" />
+  <link rel="alternate" type="application/rss+xml"
+     href="/rss-tags" title="RSS feed for test" />
+  </head>
+  <body>
+  
+  <div class="container">
+  <div class="menu">
+  <div class="logo">
+  <a href="http://mercurial.selenic.com/">
+  <img src="/static/hglogo.png" alt="mercurial" /></a>
+  </div>
+  <ul>
+  <li><a href="/shortlog">log</a></li>
+  <li><a href="/graph">graph</a></li>
+  <li><a href="/tags">tags</a></li>
+  <li><a href="/bookmarks">bookmarks</a></li>
+  <li><a href="/branches">branches</a></li>
+  </ul>
+  <ul>
+   <li class="active"><a href="/help">help</a></li>
+  </ul>
+  <form class="searchhelp" action="/searchhelp">
+  
+  <p><input name="q" id="searchhelp" type="text" size="10" value="ignore"/></p>
+  </form>
+  </div>
+  
+  <div class="main">
+  <h2><a href="/">test</a></h2>
+  
+  <form class="search" action="/log">
+  
+  <p><input name="rev" id="search1" type="text" size="30" /></p>
+  <div id="hint">find changesets by author, revision,
+  files, or words in the commit message</div>
+  </form>
+  
+  <table class="bigtable">
+  <tbody>
+  
+  <tr><td colspan=2><h2>Topics</h2></td></tr>
+  <tr><td>
+  <a href="/help/config">
+  config
+  </a>
+  </td><td>
+  Configuration Files
+  </td></tr>
+  
+  <tr><td colspan=2><h2>Commands</h2></td></tr>
+  </tbody>
+  </table>
+  </div>
+  </div>
+  
+  <script type="text/javascript">process_dates()</script>
+
+  
+  </body>
+  </html>
+  
 
   $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS