<!--!
       groups    - a dict, where:
                     key       - is the value shared by all results in this group
                     value     - is the list of corresponding tickets

       headers   - a sequence of header structure:
                     .name     - field name for this header
                     .label    - what to display for this header

       fields    - dict of field name to field structure:
                     .label    - field label

       query     - the actual Query instance used to perform the query

-->
<div xmlns="http://www.w3.org/1999/xhtml"
     xmlns:py="http://genshi.edgewall.org/"
     xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="macros.html" />
  
  <py:def function="num_matches(v)">
    <span class="numrows">${v == 0 and _('(No matches)') or ngettext('(%(count)s match)', '(%(count)s matches)', v, count=v)}</span>
  </py:def>
  
  <h2 class="report-result" py:if="paginator.has_more_pages">
    ${_('Results')} <span class="numresults">(${paginator.displayed_items()})</span>
  </h2>
  <xi:include py:if="paginator.show_index" href="page_index.html" />
  <py:for each="group_index, (groupname, results) in enumerate(groups)">
    <h2 class="report-result" py:if="groupname">
      ${fields[query.group].label}:
      ${query.group in ['owner', 'reporter'] and authorinfo(groupname) or groupname}
      ${num_matches(len(results))}
    </h2>
    <table class="listing tickets">
      <thead>
        <tr>
          <th py:for="header in headers"
            class="$header.name${query.order == header.name and (query.desc and ' desc' or ' asc') or ''}">
            <a title="${_('Sort by %(title)s%(order)s', title=header.label, order=(query.order == header.name and not query.desc and _(' (descending)') or ''))}"
              href="$header.href">${header.label}</a>
          </th>
        </tr>
      </thead>

      <tbody>
        <tr py:if="not results" class="even">
          <td colspan="${len(headers)}">
            ${_('No tickets found')}
          </td>
        </tr>
        <py:for each="idx, result in enumerate(results)">
          <py:with vars="ticket_context = context('ticket', result.id)">
            <py:if test="'TICKET_VIEW' in perm(ticket_context.resource)">

              <tr class="${idx % 2 and 'odd' or 'even'} prio${result.priority_value}${
                'added' in result and ' added' or ''}${
                'changed' in result and ' changed' or ''}${
                'removed' in result and ' removed' or ''}">
                <py:for each="idx, header in enumerate(headers)" py:choose="">
                  <py:with vars="name = header.name; value = result[name]">
                    <td py:when="name == 'id'" class="id"><a href="$result.href" title="${_('View ticket')}" class="${classes(closed=result.status == 'closed')}">#$result.id</a></td>
                    <td py:otherwise="" class="$name" py:choose="">
                      <a py:when="name == 'summary'" href="$result.href" title="${_('View ticket')}">$value</a>
                      <py:when test="isinstance(value, datetime)">${dateinfo(value)}</py:when>
                      <py:when test="name == 'reporter'">${authorinfo(value)}</py:when>
                      <py:when test="name == 'cc'">${format_emails(ticket_context, value)}</py:when>
                      <py:when test="name == 'owner' and value">${authorinfo(value)}</py:when>
                      <py:when test="name == 'milestone'"><a title="${_('View milestone')}" href="${href.milestone(value)}">${value}</a></py:when>
                      <py:when test="header.wikify">${wiki_to_oneliner(ticket_context, value)}</py:when>
                      <py:otherwise>$value</py:otherwise>
                    </td>
                  </py:with>
                </py:for>
              </tr>

              <py:with vars="result_rows = [t for t in row if result[t]]">
                <tr py:if="result_rows" class="fullrow">
                  <td colspan="${len(headers)}">
                    <!--! FIXME: message_contains_tag -->
                    <p class="meta">${_('Reported by')} <strong>${authorinfo(result.reporter)}</strong>,
                      ${dateinfo(result.time)}前.</p>
                  </td>
                </tr>
                <py:choose>
                  <tr py:when="ticket_context.resource in context" class="fullrow">
                    <td colspan="${len(headers)}">
                      <p class="meta"><em>(this ticket)</em></p>
                    </td>
                  </tr>
                  <tr py:otherwise="" py:for="r in result_rows" class="fullrow">
                    <th class="meta">${labels[r]}</th>
                    <td colspan="${len(headers)-1}" xml:space="preserve">
                      ${wiki_to_html(ticket_context, result[r])}
                    </td>
                  </tr>
                </py:choose>
              </py:with>
            </py:if>
          </py:with>
        </py:for>
        <tr py:if="group_index == len(groups)-1 and last_group_is_partial">
          <td colspan="${len(headers)}">
            <i>${_('(more results for this group on next page)')}</i>
          </td>
        </tr>
      </tbody>
    </table>
  </py:for>
  <xi:include py:if="paginator.show_index" href="page_index.html" />
</div>


