Updated dashboard

This commit is contained in:
Dan Cryer 2014-12-03 10:01:26 +00:00
parent b356f59206
commit 06aa165160
4 changed files with 75 additions and 62 deletions

View file

@ -70,13 +70,24 @@ class HomeController extends \PHPCI\Controller
protected function getSummaryHtml($projects)
{
$summaryBuilds = array();
$successes = array();
$failures = array();
foreach ($projects['items'] as $project) {
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
$success = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_SUCCESS);
$failure = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_FAILED);
$successes[$project->getId()] = $success;
$failures[$project->getId()] = $failure;
}
$summaryView = new b8\View('SummaryTable');
$summaryView->projects = $projects['items'];
$summaryView->builds = $summaryBuilds;
$summaryView->successful = $successes;
$summaryView->failed = $failures;
return $summaryView->render();
}

View file

@ -53,6 +53,21 @@ class BuildStore extends BuildStoreBase
}
}
public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS)
{
$query = 'SELECT * FROM build WHERE project_id = :pid AND status = :status ORDER BY id DESC LIMIT 1';
$stmt = Database::getConnection('read')->prepare($query);
$stmt->bindValue(':pid', $projectId);
$stmt->bindValue(':status', $status);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
return new Build($res);
} else {
return array();
}
}
public function getByProjectAndCommit($projectId, $commitId)
{
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id AND `commit_id` = :commit_id';

View file

@ -1,5 +1,10 @@
<div class="row">
<div class="col-lg-5 col-md-5 col-sm-5">
<div class="col-sm-5">
<?php print $summary; ?>
</div>
<div class="col-sm-7 pull-left">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Latest Builds</h3>
@ -12,25 +17,6 @@
<?php
foreach ($builds as $build):
switch ($build->getProject()->getType()) {
case 'github':
$icon = 'github';
break;
case 'bitbucket':
$icon = 'bitbucket';
break;
case 'git':
case 'gitlab':
$icon = 'git';
break;
default:
$icon = 'cog';
break;
}
switch ($build->getStatus()) {
case \PHPCI\Model\Build::STATUS_NEW:
$updated = $build->getCreated();
@ -69,13 +55,17 @@
<!-- /.timeline-label -->
<!-- timeline item -->
<li>
<i class="fa fa-<?php print $icon; ?> bg-<?php print $color; ?>"></i>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> <?php print $updated->format('g:ia'); ?></span>
<h3 class="timeline-header">
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?>
</a>
-
<a href="<?php print PHPCI_URL; ?>build/view/<?php print $build->getId(); ?>">
Build #<?php print $build->getId(); ?>
</a>
</h3>
<div class="timeline-body">
@ -95,21 +85,4 @@
</div>
</div>
<div class="col-lg-7 col-md-7 col-sm-7">
<div class="box box-default">
<div class="box-header"><h3 class="box-title">Project Overview</h3></div>
<table class="table">
<thead>
<tr>
<th>Project</th>
<th>Health</th>
<th style="width: 100px"></th>
</tr>
</thead>
<tbody id="project-overview">
<?php print $summary; ?>
</tbody>
</table>
</div>
</div>
</div>

View file

@ -66,37 +66,51 @@ foreach($projects as $project):
if ($failures == 0) {
$health = 'Good';
$subcls = 'success';
$subcls = 'green';
} elseif ($failures > $successes) {
$health = 'Bad';
$subcls = 'danger';
$subcls = 'red';
} else {
$health = 'Warning';
$subcls = 'warning';
$subcls = 'yellow';
}
?>
<tr class="<?php print $cls; ?>">
<td>
<a href='<?php echo PHPCI_URL ?>project/view/<?php echo $project->getId() ?>'><strong><?php echo htmlspecialchars($project->getTitle()) ?></strong></a>
<br>
Last Success: <?php print is_null($success) ? 'Never' : $success; ?>
<br>
Last Failure: <?php print is_null($failure) ? 'Never' : $failure; ?>
</td>
<td>
<span class='label label-<?php echo $subcls ?>'>
<?php echo $health ?>
</span>
<br>
<?php
foreach ($statuses as $status) {
print '<img alt="'.$status.'" src="' . PHPCI_URL . 'assets/img/icon-build-' . $status . '.png">';
}
?>
</td>
<div class="small-box bg-<?php print $subcls; ?>">
<div class="inner">
<h3>
<?php print $project->getTitle(); ?>
</h3>
<p>
<?php if ($failures > 0): ?>
<?php print $failures; ?> out of the last
<?php print count($builds[$project->getId()]); ?> builds have failed.
<?php if (!is_null($successful[$project->getId()])): ?>
The last successful build was
<?php print $successful[$project->getId()]->getFinished()->format('M j Y'); ?>
<?php else: ?>
This project has never built successfully.
<?php endif; ?>
<?php else: ?>
All of the last <?php print count($builds[$project->getId()]); ?> builds passed.
<?php if (!is_null($failed[$project->getId()])): ?>
The last failed build was
<?php print $failed[$project->getId()]->getFinished()->format('M j Y'); ?>
<?php else: ?>
This project has never failed to build.
<?php endif; ?>
<?php endif; ?>
</p>
</div>
<div class="icon">
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
</div>
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $project->getId(); ?>" class="small-box-footer">
View Project <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
<td><a class="btn btn-default btn-sm" href='<?php echo PHPCI_URL ?>project/build/<?php echo $project->getId(); ?>'>build now &raquo;</a></td>
</tr>
<?php endforeach; ?>