Added new errors count to main dashboard and builds list.

This commit is contained in:
Dmitry Khomutov 2017-12-13 22:40:51 +07:00
commit ce23fac283
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
7 changed files with 76 additions and 13 deletions

View file

@ -191,6 +191,7 @@ PHP Censor',
'all_errors' => 'All errors',
'only_new' => 'Only new errors',
'only_old' => 'Only old errors',
'new_errors' => 'New errors',
'committed_by_x' => 'Committed by %s',
'commit_id_x' => 'Commit: %s',

View file

@ -184,6 +184,7 @@ PHP Censor',
'all_errors' => 'Все ошибки',
'only_new' => 'Только новые',
'only_old' => 'Только старые',
'new_errors' => 'Новых ошибок',
'committed_by_x' => 'Отправил %s',
'commit_id_x' => 'Коммит: %s',

View file

@ -3,6 +3,7 @@
namespace PHPCensor\Model;
use PHPCensor\Builder;
use PHPCensor\Store\BuildErrorStore;
use Symfony\Component\Yaml\Parser as YamlParser;
use PHPCensor\Model;
use b8\Store\Factory;
@ -20,12 +21,12 @@ class Build extends Model
const STAGE_FAILURE = 'failure';
const STAGE_FIXED = 'fixed';
const STAGE_BROKEN = 'broken';
const STATUS_PENDING = 0;
const STATUS_RUNNING = 1;
const STATUS_SUCCESS = 2;
const STATUS_FAILED = 3;
const SOURCE_UNKNOWN = 0;
const SOURCE_MANUAL_WEB = 1;
const SOURCE_MANUAL_CONSOLE = 2;
@ -47,6 +48,11 @@ class Build extends Model
*/
protected $modelName = 'Build';
/**
* @var integer
*/
protected $newErrorsCount = null;
/**
* @var array
*/
@ -1042,4 +1048,19 @@ OUT;
return 'source_unknown';
}
}
/**
* @return integer
*/
public function getNewErrorsCount()
{
if (null === $this->newErrorsCount) {
/** @var BuildErrorStore $store */
$store = Factory::getStore('BuildError');
$this->newErrorsCount = $store->getNewErrorsCount($this->getId());
}
return $this->newErrorsCount;
}
}

View file

@ -143,6 +143,7 @@ class BuildErrorStore extends Store
* @param integer $buildId
* @param string $plugin
* @param integer $severity
* @param string $isNew
*
* @return integer
*/
@ -295,4 +296,26 @@ class BuildErrorStore extends Store
return true;
}
/**
* @param integer $buildId
*
* @return integer
*/
public function getNewErrorsCount($buildId)
{
$query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}} WHERE {{build_id}} = :build AND {{is_new}} = true';
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
return (integer)$res['total'];
}
return 0;
}
}

View file

@ -1,4 +1,12 @@
<?php use PHPCensor\Helper\Lang; ?>
<?php
/**
* @var \PHPCensor\Model\Build[] $builds
*/
use PHPCensor\Helper\Lang;
?>
<?php if(empty($builds) || !count($builds)): ?>
<tr class="">
@ -15,21 +23,21 @@ switch($build->getStatus())
$cls = 'active';
$subcls = 'info';
$status = Lang::get('pending');
break;
case 1:
$cls = 'warning';
$subcls = 'warning';
$status = Lang::get('running');
break;
case 2:
$cls = 'success';
$subcls = 'success';
$status = Lang::get('success');
break;
case 3:
$cls = 'danger';
$subcls = 'danger';
@ -63,7 +71,7 @@ $branches = $build->getExtra('branches');
<i class="fa fa-code-fork"></i> <?= $build->getBranch(); ?>
</a>
<?= $branches ? ' + '.implode(', ', $branches) : ''; ?>
<?php if ($tag = $build->getTag()): ?> /
<?php if ($tag = $build->getTag()): ?> /
<a href="<?= $build->getTagLink(); ?>" target="_blank">
<i class="fa fa-tag"></i> <?= $tag; ?>
</a>
@ -78,6 +86,9 @@ $branches = $build->getExtra('branches');
<td>
<?= $build->getDuration(); ?> <?= Lang::get('seconds'); ?>
</td>
<td>
<?= $build->getNewErrorsCount(); ?>
</td>
<td>
<div class="btn-group btn-group-right">
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>build/view/<?php print $build->getId(); ?>"><?php Lang::out('view'); ?></a>

View file

@ -116,6 +116,7 @@ use PHPCensor\Helper\Lang;
<th><?php Lang::out('branch'); ?></th>
<th><?php Lang::out('environment'); ?></th>
<th><?php Lang::out('duration'); ?></th>
<th><?php Lang::out('new_errors'); ?></th>
<th></th>
</tr>
</thead>

View file

@ -61,7 +61,7 @@ use PHPCensor\Model\Build;
<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
<?php
echo $updated->format('H:i:s');
if ($build->getStatus() != Build::STATUS_PENDING) {
echo ' &mdash; ' . $build->getDuration(); ?> <?= Lang::get('seconds');
@ -73,18 +73,23 @@ use PHPCensor\Model\Build;
<?= $build->getProject()->getTitle(); ?>
</a>
<span><?= $environment; ?></span>
&mdash;
&mdash;
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>">
Build #<?= $build->getId(); ?>
<?php Lang::out('build'); ?> #<?= $build->getId(); ?>
</a>
&mdash;
&mdash;
<?php Lang::out($build->getSourceHumanize()); ?>
<?php if ($newErrorsCount = $build->getNewErrorsCount()): ?>
&mdash;
<?php Lang::out('new_errors'); ?>:
<?= $newErrorsCount; ?>
<?php endif; ?>
</h3>
<div class="timeline-body">
<a href="<?= $build->getBranchLink();?>"><i class="fa fa-code-fork"></i> <?php echo $build->getBranch(); ?></a>
<?= $branches ? ' + '.implode(', ', $branches) : ''; ?>
<?php if ($tag = $build->getTag()): ?> /
<?php if ($tag = $build->getTag()): ?> /
<a href="<?= $build->getTagLink(); ?>" target="_blank">
<i class="fa fa-tag"></i> <?= $tag; ?>
</a>