Adding project overview to dashboard, closes #55

This commit is contained in:
Dan Cryer 2013-05-22 17:15:02 +01:00
commit acb58ff5e0
4 changed files with 60 additions and 2 deletions

View file

@ -31,8 +31,14 @@ class IndexController extends \PHPCI\Controller
public function index()
{
$projects = $this->_projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));
$summary = $this->_buildStore->getBuildSummary();
$summaryView = new b8\View('BuildsTable');
$summaryView->builds = $summary['items'];
$this->view->builds = $this->getLatestBuildsHtml();
$this->view->projects = $projects['items'];
$this->view->summary = $summaryView->render();
return $this->view->render();
}
@ -50,7 +56,7 @@ class IndexController extends \PHPCI\Controller
*/
protected function getLatestBuildsHtml()
{
$builds = $this->_buildStore->getWhere(array(), 10, 0, array(), array('id' => 'DESC'));
$builds = $this->_buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC'));
$view = new b8\View('BuildsTable');
$view->builds = $builds['items'];

View file

@ -19,5 +19,32 @@ use PHPCI\Store\Base\BuildStoreBase;
*/
class BuildStore extends BuildStoreBase
{
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
public function getBuildSummary()
{
$query = 'SELECT COUNT(*) AS cnt FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
$count = (int)$res['cnt'];
} else {
$count = 0;
}
$query = 'SELECT * FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return new \PHPCI\Model\Build($item);
};
$rtn = array_map($map, $res);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
}

View file

@ -40,6 +40,24 @@
</div>
</div>
<div class="span9">
<h3>Project Overview</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Project</th>
<th>Commit</th>
<th>Branch</th>
<th>Status</th>
<th style="width: 1%"></th>
</tr>
</thead>
<tbody>
<?php print $summary; ?>
</tbody>
</table>
<h3>Last 5 Builds</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>

View file

@ -59,4 +59,11 @@ body
.icon-build-running
{
background: url('/assets/img/icon-build-running.png') no-repeat top left;
}
h3
{
border-bottom: 1px solid #f0f0f0;
margin-top: 0;
padding-top: 0;
}