Fix the special case of a empty issue tracker, for the issue summary.

This commit is contained in:
William MARTIN 2011-06-15 11:18:41 +02:00
parent 69ae1c08ef
commit ef5b93e3f7
3 changed files with 123 additions and 104 deletions

View File

@ -84,53 +84,66 @@ class IDF_Views_Issue
public $summary_precond = array('IDF_Precondition::accessIssues'); public $summary_precond = array('IDF_Precondition::accessIssues');
public function summary($request, $match) public function summary($request, $match)
{ {
$tagStatistics = array();
$ownerStatistics = array();
$status = array();
$isTrackerEmpty = false;
$prj = $request->project; $prj = $request->project;
$opened = $prj->getIssueCountByStatus('open'); $opened = $prj->getIssueCountByStatus('open');
$closed = $prj->getIssueCountByStatus('closed'); $closed = $prj->getIssueCountByStatus('closed');
$otags = implode(',', $prj->getTagIdsByStatus('open'));
// Issue status statistics // Check if the tracker is empty
$status = array(); if ($opened === 0 && $closed === 0) {
$status['Open'] = array($opened, (int)(100 * $opened / ($opened + $closed))); $isTrackerEmpty = true;
$status['Closed'] = array($closed, (int)(100 * $closed / ($opened + $closed))); } else {
if ($opened > 0 || $closed > 0) {
// Issue status statistics
$status['Open'] = array($opened, (int)(100 * $opened / ($opened + $closed)));
$status['Closed'] = array($closed, (int)(100 * $closed / ($opened + $closed)));
}
// Issue owner statistics if ($opened > 0) {
$sqlIssueTable = Pluf::factory('IDF_Issue')->getSqlTable(); // Issue owner statistics
$sqlUsersTable = Pluf::factory('Pluf_User')->getSqlTable(); $sqlIssueTable = Pluf::factory('IDF_Issue')->getSqlTable();
$query = <<<"QUERY" $sqlUsersTable = Pluf::factory('Pluf_User')->getSqlTable();
$otags = implode(',', $prj->getTagIdsByStatus('open'));
$query = <<<"QUERY"
SELECT CONCAT(first_name, " ", last_name) as name, nb FROM (SELECT uid as id,count(uid) as nb FROM (SELECT ifnull(owner, -1) as uid FROM $sqlIssueTable WHERE status IN ($otags)) as ff group by uid) AS ff LEFT JOIN $sqlUsersTable using(id) SELECT CONCAT(first_name, " ", last_name) as name, nb FROM (SELECT uid as id,count(uid) as nb FROM (SELECT ifnull(owner, -1) as uid FROM $sqlIssueTable WHERE status IN ($otags)) as ff group by uid) AS ff LEFT JOIN $sqlUsersTable using(id)
QUERY; QUERY;
$db = Pluf::db(); $db = Pluf::db();
$dbData = $db->select($query); $dbData = $db->select($query);
$ownerStatistics = array(); foreach ($dbData as $k => $v) {
foreach ($dbData as $k => $v) { $key = ($v['name'] === null) ? __('Not assigned') : $v['name'];
$key = ($v['name'] === null) ? __('Not assigned') : $v['name']; $ownerStatistics[$key] = array($v['nb'], (int)(100 * $v['nb'] / $opened));
$ownerStatistics[$key] = array($v['nb'], (int)(100 * $v['nb'] / $opened)); }
}
// Issue class tag statistics // Issue class tag statistics
$tags = $prj->getTagCloud(); $tags = $prj->getTagCloud();
$tagStatistics = array(); foreach ($tags as $t) {
foreach ($tags as $t) { $tagStatistics[$t->class][$t->name] = array($t->nb_use, $t->id);
$tagStatistics[$t->class][$t->name] = array($t->nb_use, $t->id); }
} foreach($tagStatistics as $k => $v) {
foreach($tagStatistics as $k => $v) { $nbIssueInClass = 0;
$nbIssueInClass = 0; foreach ($v as $val) {
foreach ($v as $val) { $nbIssueInClass += $val[0];
$nbIssueInClass += $val[0]; }
} foreach ($v as $kk => $vv) {
foreach ($v as $kk => $vv) { $tagStatistics[$k][$kk] = array($vv[0], (int)(100 * $vv[0] / $nbIssueInClass), $vv[1]);
$tagStatistics[$k][$kk] = array($vv[0], (int)(100 * $vv[0] / $nbIssueInClass), $vv[1]); }
}
// Sort
krsort($tagStatistics);
arsort($ownerStatistics);
} }
} }
// Sort
krsort($tagStatistics);
arsort($ownerStatistics);
$title = sprintf(__('Summary of tracked issues in %s.'), (string) $prj); $title = sprintf(__('Summary of tracked issues in %s.'), (string) $prj);
return Pluf_Shortcuts_RenderToResponse('idf/issues/summary.html', return Pluf_Shortcuts_RenderToResponse('idf/issues/summary.html',
array('page_title' => $title, array('page_title' => $title,
'trackerEmpty' => $isTrackerEmpty,
'project' => $prj, 'project' => $prj,
'tagStatistics' => $tagStatistics, 'tagStatistics' => $tagStatistics,
'ownerStatistics' => $ownerStatistics, 'ownerStatistics' => $ownerStatistics,

View File

@ -3,87 +3,93 @@
{block docclass}yui-t2{assign $inSummaryIssues=true}{/block} {block docclass}yui-t2{assign $inSummaryIssues=true}{/block}
{block body} {block body}
{if $trackerEmpty}
{aurl 'create_url', 'IDF_Views_Issue::create', array($project.shortname)}
<p>{blocktrans}The issue tracker is empty<br />You can create your first issue <a href="{$create_url}">here</a>.{/blocktrans}</p>
{else}
<div class='issue-summary'> <div class='issue-summary'>
{foreach $tagStatistics as $key => $class} {foreach $tagStatistics as $key => $class}
<div> <div>
<h2>Unresolved: By {$key}</h2> <h2>Unresolved: By {$key}</h2>
<table class='issue-summary'> <table class='issue-summary'>
<tbody> <tbody>
{foreach $class as $key => $value} {foreach $class as $key => $value}
<tr> <tr>
<td class="name"><a href="{url 'IDF_Views_Issue::listLabel', array($project.shortname, $value[2], 'open')}">{$key}</a></td> <td class="name"><a href="{url 'IDF_Views_Issue::listLabel', array($project.shortname, $value[2], 'open')}">{$key}</a></td>
<td class="count">{$value[0]}</td> <td class="count">{$value[0]}</td>
<td class="graph"> <td class="graph">
<table class='graph'> <table class='graph'>
<tbody><tr> <tbody><tr>
<td style="width:{$value[1] * 0.8}%" class="graph-color" valign="center"> <td style="width:{$value[1] * 0.8}%" class="graph-color" valign="center">
<div class="colour-bar"></div> <div class="colour-bar"></div>
</td> </td>
<td>&nbsp;&nbsp;&nbsp;{$value[1]}%</td> <td>&nbsp;&nbsp;&nbsp;{$value[1]}%</td>
</tr> </tr>
</tbody>
</table>
</td>
</tr>
{/foreach}
</tbody> </tbody>
</table> </table>
</td> </div>
</tr>
{/foreach}
</tbody>
</table>
</div>
{/foreach} {/foreach}
</div> </div>
<div class='issue-summary'> <div class='issue-summary'>
{if $status}
<div> <div>
<h2>Status Summary</h2> <h2>Status Summary</h2>
<table class='issue-summary'> <table class='issue-summary'>
<tbody> <tbody>
{foreach $status as $key => $value} {foreach $status as $key => $value}
<tr> <tr>
<td class="name"><a href="{url 'IDF_Views_Issue::listStatus', array($project.shortname, $key)}">{$key}</a></td> <td class="name"><a href="{url 'IDF_Views_Issue::listStatus', array($project.shortname, $key)}">{$key}</a></td>
<td class="count">{$value[0]}</td> <td class="count">{$value[0]}</td>
<td class="graph"> <td class="graph">
<table class='graph'> <table class='graph'>
<tbody><tr> <tbody><tr>
<td style="width:{$value[1] * 0.8}%" class="graph-color" valign="center"> <td style="width:{$value[1] * 0.8}%" class="graph-color" valign="center">
<div class="colour-bar"></div> <div class="colour-bar"></div>
</td> </td>
<td>&nbsp;&nbsp;&nbsp;{$value[1]}%</td> <td>&nbsp;&nbsp;&nbsp;{$value[1]}%</td>
</tr> </tr>
</tbody>
</table>
</td>
</tr>
{/foreach}
</tbody> </tbody>
</table> </table>
</td> </div>
</tr> {/if}
{/foreach}
</tbody>
</table>
</div>
<div> {if $ownerStatistics}
<h2>Unresolved: By Assignee</h2> <div>
<table class='issue-summary'> <h2>Unresolved: By Assignee</h2>
<tbody> <table class='issue-summary'>
{foreach $ownerStatistics as $key => $value} <tbody>
<tr> {foreach $ownerStatistics as $key => $value}
<td class="name">{$key}</td> <tr>
<td class="count">{$value[0]}</td> <td class="name">{$key}</td>
<td class="graph"> <td class="count">{$value[0]}</td>
<table class='graph'> <td class="graph">
<tbody><tr> <table class='graph'>
<td style="width:{$value[1] * 0.8}%" class="graph-color" valign="center"> <tbody><tr>
<div class="colour-bar"></div> <td style="width:{$value[1] * 0.8}%" class="graph-color" valign="center">
</td> <div class="colour-bar"></div>
<td>&nbsp;&nbsp;&nbsp;{$value[1]}%</td> </td>
</tr> <td>&nbsp;&nbsp;&nbsp;{$value[1]}%</td>
</tr>
</tbody>
</table>
</td>
</tr>
{/foreach}
</tbody> </tbody>
</table> </table>
</td> </div>
</tr> {/if}
{/foreach}
</tbody>
</table>
</div> </div>
{/if}
</div>
{/block} {/block}

View File

@ -1128,7 +1128,7 @@ table.issue-summary {
table.issue-summary tr td { table.issue-summary tr td {
border: 0; border: 0;
padding: .1em; padding: .1em .005em;
} }
table.issue-summary td.graph { table.issue-summary td.graph {