         console.error "messageNew did not return problem -- not authorized?"
 
   <> {###<div className="group-right-buttons">###}
+    {if tags.length
+      <TagEdit tags={tags} rootClassName="tagGather push-down"
+       className="label label-default"
+       href={(tag) -> changeSortLink sortBy, "tag.#{tag.key}"}>
+        {'Gather by tag '}
+        <span className="caret"/>
+      </TagEdit>
+    }
     {if superuser
       <div className="btn-group">
         <button className="btn btn-warning sortSetDefault" onClick={onSortSetDefault}>

  for sort in sortBy
    if sort.key.startsWith 'tag.'
      groupBy.push sort.key[4..]
  groupBy = null unless groupBy.length

  <table className="table table-striped">

changeSortLink = (sortBy, key) ->
  reverse = key of columnReverse
  ## Remove this sort if it exists, to move it to the beginning.
  seenNonTag = false
  newSortBy =
    for sort, i in sortBy
      if sort.key == key
        ## If this was already the first sort, reverse it.
        reverse = not sort.reverse unless seenNonTag
        continue
      else
        seenNonTag = true unless sort.key.startsWith 'tag.'
        sort
  ## New sort at the beginning
  newSortBy.splice 0, 0, {key, reverse}
  ## Put tags in front for clustering
  newSortBy = _.sortBy newSortBy, (sort) -> not sort.key.startsWith 'tag.'
  linkToSort newSortBy

Template.registerHelper 'groups', ->
