Add more statistics on the projects list page

This commit is contained in:
William MARTIN 2011-02-23 14:29:01 +01:00
parent 4e00051a10
commit 5e6d61b3a7
3 changed files with 69 additions and 4 deletions

View File

@ -40,9 +40,11 @@ class IDF_Views
public function index($request, $match)
{
$projects = self::getProjects($request->user);
$stats = self::getProjectsStatistics ($projects);
return Pluf_Shortcuts_RenderToResponse('idf/index.html',
array('page_title' => __('Projects'),
'projects' => $projects),
'projects' => $projects,
'stats' => new Pluf_Template_ContextVars($stats)),
$request);
}
@ -343,4 +345,41 @@ class IDF_Views
return Pluf::factory('IDF_Project')->getList(array('filter' => $sql,
'order' => 'name ASC'));
}
}
/**
* Returns statistics on a list of projects.
*
* @param ArrayObject IDF_Project
* @return Associative array of statistics
*/
public static function getProjectsStatistics($projects)
{
// Init the return var
$forgestats = array('downloads' => 0,
'reviews' => 0,
'issues' => 0,
'docpages' => 0,
'commits' => 0);
// Count for each projects
foreach ($projects as $p) {
$pstats = $p->getStats ();
$forgestats['downloads'] += $pstats['downloads'];
$forgestats['reviews'] += $pstats['reviews'];
$forgestats['issues'] += $pstats['issues'];
$forgestats['docpages'] += $pstats['docpages'];
$forgestats['commits'] += $pstats['commits'];
}
// Count projects
$forgestats['projects'] = count($projects);
// Count members
$db =& Pluf::db();
$sql = "SELECT count(id) as `nb` FROM indefero_users WHERE first_name != '---'";
$ret = $db->select ($sql);
$forgestats['members'] = $ret[0]['nb'];
return $forgestats;
}
}

View File

@ -1,5 +1,5 @@
{extends "idf/base-simple.html"}
{block docclass}yui-t1{/block}
{block docclass}yui-t2{/block}
{block tabhome} class="active"{/block}
{block subtabs}<a href="{url 'IDF_Views::index'}" class="active">{trans 'Projects'}</a>{/block}
{block body}
@ -15,6 +15,17 @@
{/if}
{/block}
{block context}
<p><strong>{trans 'Managed Projects:'}</strong> {$projects.count()}</p>
<div id="stats" class="issue-submit-info">
<h3 class="a-c">Forge statistics</h3>
<table>
<tr><td class="right">{trans 'Projects:'}</td><td>{$stats.projects}</td></tr>
<tr><td class="right">{trans 'Members:'}</td><td>{$stats.members}</td></tr>
<tr><td class="right">{trans 'Issues:'}</td><td>{$stats.issues}</td></tr>
<tr><td class="right">{trans 'Commits:'}</td><td>{$stats.commits}</td></tr>
<tr><td class="right">{trans 'Documentations:'}</td><td>{$stats.docpages}</td></tr>
<tr><td class="right">{trans 'Downloads:'}</td><td>{$stats.downloads}</td></tr>
<tr><td class="right">{trans 'Code reviews:'}</td><td>{$stats.reviews}</td></tr>
</table>
</div>
{/block}
{block foot}<div id="branding">Powered by <a href="http://www.indefero.net" title="InDefero, bug tracking and more">InDefero</a>,<br />a <a href="http://www.ceondo.com">Céondo Ltd</a> initiative.</div>{/block}

View File

@ -994,3 +994,18 @@ span.scm-action.renamed {
span.scm-action.property-changed {
background-color: blue;
}
/*
* Stats on index
*/
#stats > h3 {
text-decoration : underline;
}
#stats table tr td {
border-style: none;
}
#stats td {
padding: .2em;
}