# HG changeset patch # User Thomas Arendsen Hein # Date 1146501505 -7200 # Node ID d1943df604c49ded5240a6d7a530b529a629da60 # Parent eba364839c6732b491f1b6fb309ddf18dbc6df2a Make hgwebdir columns sortable. diff -r eba364839c67 -r d1943df604c4 mercurial/hgweb.py --- a/mercurial/hgweb.py Mon May 01 10:04:25 2006 +0200 +++ b/mercurial/hgweb.py Mon May 01 18:38:25 2006 +0200 @@ -1050,7 +1050,8 @@ if ui.configbool("web", "allow" + i, False): yield {"type" : i, "node": nodeid, "url": url} - def entries(**map): + def entries(sortcolumn="", descending=False, **map): + rows = [] parity = 0 for name, path in self.repos: u = ui.ui() @@ -1069,17 +1070,36 @@ except OSError: continue - yield dict(contact=(get("ui", "username") or # preferred - get("web", "contact") or # deprecated - get("web", "author", "unknown")), # also - name=get("web", "name", name), + contact = (get("ui", "username") or # preferred + get("web", "contact") or # deprecated + get("web", "author", "")) # also + description = get("web", "description", "") + name = get("web", "name", name) + row = dict(contact=contact or "unknown", + contact_sort=contact.upper() or "unknown", + name=name, + name_sort=name.upper(), url=url, - parity=parity, - shortdesc=get("web", "description", "unknown"), - lastupdate=d, + description=description or "unknown", + description_sort=description.upper() or "unknown", + lastchange=d, + lastchange_sort=d[1]-d[0], archives=archivelist(u, "tip", url)) - - parity = 1 - parity + if not sortcolumn: + # fast path for unsorted output + row['parity'] = parity + parity = 1 - parity + yield row + else: + rows.append((row["%s_sort" % sortcolumn], row)) + if rows: + rows.sort() + if descending: + rows.reverse() + for key, row in rows: + row['parity'] = parity + parity = 1 - parity + yield row virtual = req.env.get("PATH_INFO", "").strip('/') if virtual: @@ -1100,4 +1120,20 @@ req.write(staticfile(static, fname) or tmpl("error", error="%r not found" % fname)) else: - req.write(tmpl("index", entries=entries)) + sortable = ["name", "description", "contact", "lastchange"] + sortcolumn = "" + if req.form.has_key('sort'): + sortcolumn = req.form['sort'][0] + descending = sortcolumn.startswith('-') + if descending: + sortcolumn = sortcolumn[1:] + if sortcolumn not in sortable: + sortcolumn = "" + + sort = [("sort_%s" % column, + "%s%s" % ((not descending and column == sortcolumn) + and "-" or "", column)) + for column in sortable] + req.write(tmpl("index", entries=entries, + sortcolumn=sortcolumn, descending=descending, + **dict(sort))) diff -r eba364839c67 -r d1943df604c4 templates/index.tmpl --- a/templates/index.tmpl Mon May 01 10:04:25 2006 +0200 +++ b/templates/index.tmpl Mon May 01 18:38:25 2006 +0200 @@ -7,10 +7,10 @@ - - - - + + + + #entries%indexentry# diff -r eba364839c67 -r d1943df604c4 templates/map --- a/templates/map Mon May 01 10:04:25 2006 +0200 +++ b/templates/map Mon May 01 18:38:25 2006 +0200 @@ -43,7 +43,7 @@ filelogparent = '' filediffchild = '' filelogchild = '' -indexentry = '' +indexentry = '' index = index.tmpl archiveentry = '#type|escape# ' notfound = notfound.tmpl
NameDescriptionContactLast changeNameDescriptionContactLast change  
parent #rev#:#node|short#
child #rev#:#node|short#
child #rev#:#node|short#
#name|escape##shortdesc##contact|obfuscate##lastupdate|age# ago
#name|escape##description##contact|obfuscate##lastchange|age# ago