[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): 
  #   Gervase Markham <gerv@gerv.net>
  #   Max Kanat-Alexander <mkanat@bugzilla.org>
  #%]

[%# INTERFACE:
  # bugs: list of hashes. May be empty. Each hash has three members:
  #   bug: A Bugzilla::Bug object
  #   count: integer. The number of dupes
  #   delta: integer. The change in count in the last $changedsince days
  #
  # bug_ids: list of integers. May be empty. The IDs of the bugs in $bugs.
  #
  # sortby: string. the column on which we are sorting the buglist.
  # reverse: boolean. True if we are reversing the current sort.
  # maxrows: integer. Max number of rows to display.
  # changedsince: integer. The number of days ago for the changedsince column.
  # openonly: boolean. True if we are only showing open bugs.
  # product: array of strings. Restrict to these products only.
  #%]

[%# *** Column Headers *** %]

[% SET columns = [
    { name => "id", description => "$terms.Bug #" },
    { name => "count", description => "Dupe<br>Count" },
    { name => "delta",
      description => "Change in last<br>$changedsince day(s)" },
    { name => "component", description => field_descs.component },
    { name => "bug_severity", description => field_descs.bug_severity },
] %]

[% columns.push({ name => "op_sys", description => field_descs.op_sys }) IF Bugzilla.get_field('op_sys').enabled %]
[% columns.push({ name => "target_milestone", description => field_descs.target_milestone }) IF Bugzilla.get_field('target_milestone').enabled %]
[% columns.push({ name => "short_desc", description => field_descs.short_desc }) %]

[% SET base_args = [] %]
[% FOREACH param = ['maxrows', 'openonly', 'format', 'sortvisible',
                    'changedsince', 'product'] 
%]
  [% NEXT IF NOT ${param}.defined %]
  [% FOREACH value = ${param} %]
    [% filtered_value = value FILTER url_quote %]
    [% base_args.push("$param=$filtered_value") %]
  [% END %]
[% END %]
[% IF sortvisible %]
  [% bug_ids_string = bug_ids.nsort.join(',') FILTER url_quote %]
  [% base_args.push("bug_id=$bug_ids_string") %]
[% END %]
[% base_args_string = base_args.join('&amp;') %]

[% IF bugs.size %]
  <table id="duplicates_table" cellpadding="0" cellspacing="0">
    <thead>
      <tr>
        [% FOREACH column = columns %]
          [% IF column.name == sortby %]
            [%# We add this to the column object so it doesn't affect future 
              # iterations of the loop.
              #%]
            [% column.reverse_sort = reverse ? 0 : 1 %]
          [% END %]
          <th class="[% column.name FILTER html %]">
            <a href="duplicates.cgi?sortby=[% column.name FILTER url_quote %]
                     [% IF column.reverse_sort.defined %]
                      [%- %]&amp;reverse=[% column.reverse_sort FILTER url_quote %]
                     [% END %]
                     [% IF base_args_string %]
                       [% "&amp;$base_args_string" FILTER none %]
                     [% END %]"
            >[% column.description FILTER none %]</a>
          </th>
        [% END %]
      </tr>
    </thead>

    [%# *** Buglist *** %]

    <tbody>
      [% FOREACH item = bugs %]
        [% SET bug = item.bug %]
        <tr [% " class='resolved'" IF NOT bug.isopened %]>
          <td class="id">
            [% bug.id FILTER bug_link(bug) FILTER none %]
          </td>
          <td class="count">[% item.count FILTER html %]</td>
          <td class="delta">[% item.delta FILTER html %]</td>
          <td class="component">[% bug.component_obj.name FILTER html %]</td>
          <td class="bug_severity">
            [%- bug.bug_severity_obj.name FILTER html IF bug.bug_severity %]
          </td>
          [% IF Bugzilla.get_field('op_sys').enabled %]
          <td class="op_sys">
            [%- bug.op_sys_obj.name FILTER html IF bug.op_sys %]
          </td>
          [% END %]
          <td class="target_milestone">
            [% bug.target_milestone_obj.name FILTER html IF bug.target_milestone %]
          </td>
          <td class="short_desc">[% bug.short_desc FILTER html %]</td>
        </tr>
      [% END %]
    </tbody>
  </table>
[% ELSE %]
  <h3>No duplicate [% terms.bugs %] found.</h3>
[% END %]
