<%args>
        $testplan_days => []
</%args>

% my $days = $c->stash->{days} || ('unknown');
<h3>Testplans of last <% $days %> days</h3>

This list shows <b>testplans</b>. Note: For this testplan listing finished testruns are considered "FAIL"
unless its success state is exactly 100%.

<& /tapper/message.mas &>

% if (not @$testplan_days) {
<h4>No Testplan Instances found in the requested time frame</h4>
% }


% foreach my $day (@$testplan_days) {
% my $date = $day->{date};
<h4><a href="/tapper/testplan/date/<% $date->ymd('-') %>">
<% $date->day_abbr %> <% $date->month_abbr %> <% $date->day %>, <% $date->year %></a></h4>
    <table class="reportlist">
        <thead>
                <tr>
                         <th>ID</th>
                         <th>Updated At (local)</th>
                         <th>Name</th>
                         <th>Path</th>
                         <th>Success</th>
                         <th>Testruns<br>(success/running/scheduled/fail)</th>
                </tr>
        </thead>
        <tbody>
%    foreach my $instance (@{$day->{testplan_instances} || [] }) {
%    no warnings 'uninitialized';
%    my $sum              = $instance->{count_pass} + $instance->{count_fail} + $instance->{count_unfinished};
%    my $maxwidth         = 100;
%    my $width_fail       = int($maxwidth * ($sum ? $instance->{count_fail}       / $sum : 0));
%    my $width_pass       = int($maxwidth * ($sum ? $instance->{count_pass}       / $sum : 0));
%    my $width_running    = int($maxwidth * ($sum ? $instance->{count_running}    / $sum : 0));
%    my $width_schedule   = int($maxwidth * ($sum ? $instance->{count_schedule}   / $sum : 0));
%    my $width_prepare    = int($maxwidth * ($sum ? $instance->{count_prepare}    / $sum : 0));

%    my $path_link        = $instance->{path}; $path_link =~ s|/|\.|g;
                  <tr>
                        <td><a href="/tapper/testplan/id/<% $instance->{id} %>">tp<% $instance->{id} %></a></td>
                        <td><% $instance->{updated_at} || $instance->{created_at}  %></td>
                        <td><a title="Add <% $instance->{name} %> to filter" href="/<% $c->req->path %>/name/<% $instance->{name} %>">
                                <img src="/tapper/static/images/plus.png" size="16">
                            </a>
                            <a href="/tapper/testplan/name/<% $instance->{name} %>">
                                <% $instance->{name} %>
                            </a>
                        </td>
                        <td><a title="Add <% $instance->{path} %> to filter" href="/<% $c->req->path %>/path/<% $path_link %>">
                                <img src="/tapper/static/images/plus.png" size="16">
                            </a>
                            <a href="/tapper/testplan/path/<% $path_link %>">
                                <% $instance->{path} %>
                            </a>
                        </td>
                        <td>
                          <a href="/tapper/testplan/id/<% $instance->{id} %>" title="Click to show details">
                            <img src="/tapper/static/images/green_bar.png" height="16" width="<% $width_pass %>"><img src="/tapper/static/images/yellow_bar.png" height="16" width="<% $width_running %>"><img src="/tapper/static/images/yellow_bar_dimmed.png" height="16" width="<% $width_prepare %>"><img src="/tapper/static/images/yellow_bar_dimmed.png" height="16" width="<% $width_schedule + $width_prepare %>"><img src="/tapper/static/images/red_bar.png" height="16" width="<% $width_fail %>">
                          </a>
                        </td>
                        <td>(<% $instance->{count_pass} || 0 %>/<% $instance->{count_running} || 0 %>/<% ($instance->{count_schedule}+$instance->{count_prepare}) || 0 %>/<% $instance->{count_fail} || 0 %>)</td>
                </tr>
%    }
        </tbody>
    </table>

% }