Mon Jan 9 05:24:26 UTC 2006 Alberto Bertogli <albertogli@telpin.com.ar>
* Implement a search box.
This implements a small search box that appears on the right top besides the
logo (which will be changed to a small version in a following patch).
{
hunk ./config.py.sample 42
+
+ # By default, darcsweb's search looks in the last 100 commits; you can
+ # change that number by specifying it here.
+ # Note that search are not cached, so if you have tons of commits and
+ # set the limit to a very high number, they will take time.
+ #searchlimit = 100
hunk ./darcsweb.cgi 166
+def highlight(s, l):
+ "Highlights appearences of s in l"
+ import re
+ # build the regexp by leaving "(s)", replacing '(' and ') first
+ s = s.replace('\\', '\\\\')
+ s = s.replace('(', '\\(')
+ s = s.replace(')', '\\)')
+ s = '(' + escape(s) + ')'
+ try:
+ pat = re.compile(s, re.I)
+ repl = '<span style="color:#e00000">\\1</span>'
+ l = re.sub(pat, repl, l)
+ except:
+ pass
+ return l
+
hunk ./darcsweb.cgi 261
-<a href="http://darcs.net" title="darcs">
-<img src="%(logo)s" alt="darcs logo" style="float:right; border-width:0px;"/>
-</a>
+ <div class="search_box">
+ <form action="%(myname)s" method="get"><div>
+ <input type="hidden" name="r" value="%(reponame)s"/>
+ <input type="hidden" name="a" value="search"/>
+ <input type="text" name="s" size="20" class="search_text"/>
+ <input type="submit" value="search" class="search_button"/>
+ <a href="http://darcs.net" title="darcs">
+ <img src="%(logo)s" alt="darcs logo" class="logo"/>
+ </a>
+ </div></form>
+ </div>
+ <a href="%(myname)s">repos</a> /
+ <a href="%(myreponame)s;a=summary">%(reponame)s</a> /
+ %(action)s
+</div>
hunk ./darcsweb.cgi 282
+ 'myname': config.myname,
+ 'myreponame': config.myreponame,
+ 'action': action
hunk ./darcsweb.cgi 286
- print '<a href="%s">repos</a> /' % config.myname
- print '<a href="%s;a=summary">%s</a>' % (config.myreponame,
- config.reponame),
- print '/ ' + action
- print "</div>"
hunk ./darcsweb.cgi 575
+ def matches(self, s):
+ "Defines if the patch matches a given string"
+ if s.lower() in self.comment.lower():
+ return self.comment
+ elif s.lower() in self.name.lower():
+ return self.name
+ elif s.lower() in self.author.lower():
+ return self.author
+ elif s == self.hash:
+ return self.hash
+
+ s = s.lower()
+ for l in (self.adds, self.removes, self.modifies,
+ self.diradds, self.dirremoves,
+ self.replaces.keys(), self.moves.keys(),
+ self.moves.keys() ):
+ for i in l:
+ if s in i.lower():
+ return i
+ return ''
+
hunk ./darcsweb.cgi 1943
+def do_search(s):
+ print_header()
+ print_navbar()
+ ps = get_last_patches(config.searchlimit)
+
+ print '<div class="title">Search last %d commits for "%s"</div>' \
+ % (config.searchlimit, escape(s))
+ print '<table cellspacing="0">'
+
+ alt = False
+ for p in ps:
+ match = p.matches(s)
+ if not match:
+ continue
+
+ if alt:
+ print '<tr class="dark">'
+ else:
+ print '<tr class="light">'
+ alt = not alt
+
+ print """
+ <td><i>%(age)s</i></td>
+ <td>%(author)s</td>
+ <td>
+ <a class="list" title="%(fullname)s" href="%(myrname)s;a=commit;h=%(hash)s">
+ <b>%(name)s</b>
+ </a><br/>
+ %(match)s
+ </td>
+ <td class="link">
+ <a href="%(myrname)s;a=commit;h=%(hash)s">commit</a> |
+ <a href="%(myrname)s;a=commitdiff;h=%(hash)s">commitdiff</a>
+ </td>
+ """ % {
+ 'age': how_old(p.local_date),
+ 'author': shorten_str(p.shortauthor, 26),
+ 'myrname': config.myreponame,
+ 'hash': p.hash,
+ 'name': escape(shorten_str(p.name)),
+ 'fullname': escape(p.name),
+ 'match': highlight(s, shorten_str(match)),
+ }
+ print "</tr>"
+
+ print '</table>'
+ print_footer()
+
+
hunk ./darcsweb.cgi 2194
+ if "searchlimit" in dir(base):
+ config.searchlimit = base.searchlimit
+ else:
+ config.searchlimit = 100
+
hunk ./darcsweb.cgi 2373
+elif action == 'search':
+ if form.has_key('s'):
+ s = form["s"].value
+ else:
+ s = ''
+ do_search(s)
+ if config.cachedir:
+ cache.cancel()
+
hunk ./style.css 72
+div.search_box {
+ float:right;
+ text-align:right;
+}
+
+input.search_text {
+ font-size:xx-small;
+ background-color: #edece6;
+ vertical-align: top;
+}
+
+input.search_button {
+ font-size:xx-small;
+ vertical-align: top;
+}
+
hunk ./style.css 155
- clear:both;
+ /*clear:both;*/
hunk ./style.css 257
+
+img.logo {
+ border-width:0px;
+ vertical-align:top;
+ margin-left:12pt;
+ margin-right:5pt;
+}
}