Added filtration by new label to "Errors" tab.

This commit is contained in:
Dmitry Khomutov 2017-12-09 23:28:16 +07:00
parent 13f763c9e2
commit 6fcfa3668a
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
7 changed files with 112 additions and 24 deletions

View file

@ -74,7 +74,7 @@ var Build = Class.extend({
var fullUri = window.APP_URL + uri;
if (name == 'build-updated') {
fullUri = window.APP_URL + 'build/ajax-data/' + self.buildId + '?per_page=' + PER_PAGE + '&page=' + PAGE + '&plugin=' + BUILD_PLUGIN + '&severity=' + BUI;
fullUri = window.APP_URL + 'build/ajax-data/' + self.buildId + '?per_page=' + PER_PAGE + '&page=' + PAGE + '&plugin=' + BUILD_PLUGIN + '&severity=' + BUILD_SEVERITY + '&is_new=' + BUILD_IS_NEW;
}
$.ajax({

View file

@ -17,7 +17,7 @@ use PHPCensor\Controller;
/**
* Build Controller - Allows users to run and view builds.
*
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class BuildController extends Controller
@ -52,6 +52,7 @@ class BuildController extends Controller
{
$page = (integer)$this->getParam('page', 1);
$plugin = $this->getParam('plugin', '');
$isNew = $this->getParam('is_new', '');
$severity = $this->getParam('severity', null);
if (null !== $severity && '' !== $severity) {
@ -73,7 +74,7 @@ class BuildController extends Controller
/** @var User $user */
$user = $_SESSION['php-censor-user'];
$perPage = $user->getFinalPerPage();
$data = $this->getBuildData($build, $plugin, $severity, (($page - 1) * $perPage), $perPage);
$data = $this->getBuildData($build, $plugin, $severity, $isNew, (($page - 1) * $perPage), $perPage);
$pages = ($data['errors'] === 0)
? 1
: (integer)ceil($data['errors'] / $perPage);
@ -90,13 +91,15 @@ class BuildController extends Controller
$this->view->data = $data;
$this->view->plugin = urldecode($plugin);
$this->view->plugins = $errorStore->getKnownPlugins($buildId);
$this->view->plugins = $errorStore->getKnownPlugins($buildId, $severity, $isNew);
$this->view->severity = urldecode(null !== $severity ? $severity : '');
$this->view->severities = $errorStore->getKnownSeverities($buildId, $plugin);
$this->view->severities = $errorStore->getKnownSeverities($buildId, $plugin, $isNew);
$this->view->isNew = urldecode($isNew);
$this->view->isNews = ['only_new', 'only_old'];
$this->view->page = $page;
$this->view->perPage = $perPage;
$this->view->paginator = $this->getPaginatorHtml($buildId, $plugin, $severity, $data['errors'], $perPage, $page);
$this->view->paginator = $this->getPaginatorHtml($buildId, $plugin, $severity, $isNew, $data['errors'], $perPage, $page);
$this->layout->title = Lang::get('build_n', $buildId);
$this->layout->subtitle = $build->getProjectTitle();
@ -124,7 +127,7 @@ class BuildController extends Controller
$delete = Lang::get('delete_build');
$deleteLink = APP_URL . 'build/delete/' . $build->getId();
$project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($build->getProjectId());
$actions = '';
@ -166,12 +169,13 @@ class BuildController extends Controller
* @param Build $build
* @param string $plugin
* @param integer $severity
* @param string $isNew
* @param integer $start
* @param integer $perPage
*
* @return array
*/
protected function getBuildData(Build $build, $plugin, $severity, $start = 0, $perPage = 10)
protected function getBuildData(Build $build, $plugin, $severity, $isNew, $start = 0, $perPage = 10)
{
$data = [];
$data['status'] = (int)$build->getStatus();
@ -183,13 +187,13 @@ class BuildController extends Controller
/** @var \PHPCensor\Store\BuildErrorStore $errorStore */
$errorStore = b8\Store\Factory::getStore('BuildError');
$errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity);
$errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity, $isNew);
$errorView = new b8\View('Build/errors');
$errorView->build = $build;
$errorView->errors = $errors['items'];
$data['errors'] = $errorStore->getErrorTotalForBuild($build->getId(), $plugin, $severity);
$data['errors'] = $errorStore->getErrorTotalForBuild($build->getId(), $plugin, $severity, $isNew);
$data['errors_total'] = $errorStore->getErrorTotalForBuild($build->getId());
$data['error_html'] = $errorView->render();
@ -200,13 +204,14 @@ class BuildController extends Controller
* @param integer $buildId
* @param string $plugin
* @param integer $severity
* @param string $isNew
* @param integer $total
* @param integer $perPage
* @param integer $page
*
* @return string
*/
protected function getPaginatorHtml($buildId, $plugin, $severity, $total, $perPage, $page)
protected function getPaginatorHtml($buildId, $plugin, $severity, $isNew, $total, $perPage, $page)
{
$view = new b8\View('pagination');
@ -220,6 +225,10 @@ class BuildController extends Controller
$params['severity'] = $severity;
}
if (!empty($isNew)) {
$params['is_new'] = $isNew;
}
$urlPattern = $urlPattern . '?' . str_replace('%28%3Anum%29', '(:num)', http_build_query(array_merge($params, ['page' => '(:num)']))) . '#errors';
$paginator = new Paginator($total, $perPage, $page, $urlPattern);
@ -313,6 +322,7 @@ class BuildController extends Controller
$page = (integer)$this->getParam('page', 1);
$perPage = (integer)$this->getParam('per_page', 10);
$plugin = $this->getParam('plugin', '');
$isNew = $this->getParam('is_new', '');
$severity = $this->getParam('severity', null);
if (null !== $severity && '' !== $severity) {
@ -327,12 +337,12 @@ class BuildController extends Controller
if (!$build) {
$response->setResponseCode(404);
$response->setContent([]);
return $response;
}
$data = $this->getBuildData($build, $plugin, $severity, (($page - 1) * $perPage), $perPage);
$data['paginator'] = $this->getPaginatorHtml($buildId, $plugin, $severity, $data['errors'], $perPage, $page);
$data = $this->getBuildData($build, $plugin, $severity, $isNew, (($page - 1) * $perPage), $perPage);
$data['paginator'] = $this->getPaginatorHtml($buildId, $plugin, $severity, $isNew, $data['errors'], $perPage, $page);
$response->setContent($data);

View file

@ -188,6 +188,9 @@ PHP Censor',
'build_n' => 'Build %d',
'rebuild_now' => 'Rebuild Now',
'all_errors' => 'All errors',
'only_new' => 'Only new errors',
'only_old' => 'Only old errors',
'committed_by_x' => 'Committed by %s',
'commit_id_x' => 'Commit: %s',

View file

@ -181,6 +181,10 @@ PHP Censor',
'build_n' => 'Сборка %d',
'rebuild_now' => 'Пересобрать сейчас',
'all_errors' => 'Все ошибки',
'only_new' => 'Только новые',
'only_old' => 'Только старые',
'committed_by_x' => 'Отправил %s',
'commit_id_x' => 'Коммит: %s',

View file

@ -79,7 +79,7 @@ class BuildErrorStore extends Store
*
* @throws HttpException
*/
public function getByBuildId($buildId, $limit = null, $offset = 0, $plugin = null, $severity = null)
public function getByBuildId($buildId, $limit = null, $offset = 0, $plugin = null, $severity = null, $isNew = null)
{
if (is_null($buildId)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
@ -92,7 +92,14 @@ class BuildErrorStore extends Store
if (null !== $severity) {
$query .= ' AND {{severity}} = :severity';
}
$query .= ' ORDER BY plugin, severity';
if ('only_new' === $isNew) {
$query .= ' AND {{is_new}} = true';
} elseif ('only_old' === $isNew) {
$query .= ' AND {{is_new}} = false';
}
$query .= ' ORDER BY is_new, severity, plugin';
if (null !== $limit) {
$query .= ' LIMIT :limit';
}
@ -139,22 +146,32 @@ class BuildErrorStore extends Store
*
* @return integer
*/
public function getErrorTotalForBuild($buildId, $plugin = null, $severity = null)
public function getErrorTotalForBuild($buildId, $plugin = null, $severity = null, $isNew = null)
{
$query = 'SELECT COUNT(*) AS {{total}} FROM {{build_error}} WHERE {{build_id}} = :build';
if ($plugin) {
$query .= ' AND {{plugin}} = :plugin';
}
if (null !== $severity) {
$query .= ' AND {{severity}} = :severity';
}
if ('only_new' === $isNew) {
$query .= ' AND {{is_new}} = true';
} elseif ('only_old' === $isNew) {
$query .= ' AND {{is_new}} = false';
}
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId, \PDO::PARAM_INT);
if ($plugin) {
$stmt->bindValue(':plugin', $plugin, \PDO::PARAM_STR);
}
if (null !== $severity) {
$stmt->bindValue(':severity', (integer)$severity, \PDO::PARAM_INT);
}
@ -170,14 +187,30 @@ class BuildErrorStore extends Store
/**
* @param integer $buildId
* @param integer $severity
* @param string $isNew
*
* @return array
*/
public function getKnownPlugins($buildId)
public function getKnownPlugins($buildId, $severity = null, $isNew = '')
{
$query = 'SELECT DISTINCT {{plugin}} from {{build_error}} WHERE {{build_id}} = :build';
if (null !== $severity) {
$query .= ' AND {{severity}} = :severity';
}
if ('only_new' === $isNew) {
$query .= ' AND {{is_new}} = true';
} elseif ('only_old' === $isNew) {
$query .= ' AND {{is_new}} = false';
}
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId);
if (null !== $severity) {
$stmt->bindValue(':severity', (integer)$severity, \PDO::PARAM_INT);
}
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -196,16 +229,24 @@ class BuildErrorStore extends Store
/**
* @param integer $buildId
* @param string $plugin
* @param string $isNew
*
* @return array
*/
public function getKnownSeverities($buildId, $plugin = '')
public function getKnownSeverities($buildId, $plugin = '', $isNew = '')
{
$query = 'SELECT DISTINCT {{severity}} FROM {{build_error}} WHERE {{build_id}} = :build';
if ($plugin) {
$query .= ' AND {{plugin}} = :plugin';
}
if ('only_new' === $isNew) {
$query .= ' AND {{is_new}} = true';
} elseif ('only_old' === $isNew) {
$query .= ' AND {{is_new}} = false';
}
$stmt = Database::getConnection('read')->prepareCommon($query);
$stmt->bindValue(':build', $buildId);
if ($plugin) {

View file

@ -201,6 +201,31 @@ use PHPCensor\Model\BuildError;
<p><?= Lang::get('errors_selected'); ?>: <?= $data['errors']; ?> / <?= $data['errors_total']; ?></p>
<?php endif; ?>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<?php if (!empty($isNew)) {
echo Lang::get($isNew);
} else {
echo Lang::get('all_errors');
} ?>&nbsp;&nbsp;<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?plugin=<?= urlencode($plugin); ?>&severity=<?= urlencode($severity); ?>#errors"><?= Lang::get('all_errors'); ?></a>
</li>
<li class="divider"></li>
<?php if(!empty($isNews)): ?>
<?php foreach ($isNews as $currentIsNew) : ?>
<li <?= ($currentIsNew === $isNew) ? 'class="active"' : ''; ?>>
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?is_new=<?= urlencode($currentIsNew); ?>&plugin=<?= urlencode($plugin); ?>&severity=<?= urlencode($severity); ?>#errors">
<?= Lang::get($currentIsNew); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<?php if (!empty($plugin)) {
@ -210,13 +235,15 @@ use PHPCensor\Model\BuildError;
} ?>&nbsp;&nbsp;<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?severity=<?= urlencode($severity); ?>#errors"><?= Lang::get('all_plugins'); ?></a></li>
<li>
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?is_new=<?= urlencode($isNew); ?>&severity=<?= urlencode($severity); ?>#errors"><?= Lang::get('all_plugins'); ?></a>
</li>
<li class="divider"></li>
<?php if(!empty($plugins)): ?>
<?php foreach ($plugins as $currentPlugin) : ?>
<li <?= ($currentPlugin === $plugin) ? 'class="active"' : ''; ?>>
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?plugin=<?= urlencode($currentPlugin); ?>&severity=<?= urlencode($severity); ?>#errors">
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?is_new=<?= urlencode($isNew); ?>&plugin=<?= urlencode($currentPlugin); ?>&severity=<?= urlencode($severity); ?>#errors">
<?= Lang::get($currentPlugin); ?>
</a>
</li>
@ -233,13 +260,15 @@ use PHPCensor\Model\BuildError;
} ?>&nbsp;&nbsp;<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?plugin=<?= urlencode($plugin); ?>#errors"><?= Lang::get('all_severities'); ?></a></li>
<li>
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?is_new=<?= urlencode($isNew); ?>&plugin=<?= urlencode($plugin); ?>#errors"><?= Lang::get('all_severities'); ?></a>
</li>
<li class="divider"></li>
<?php if(!empty($severities)): ?>
<?php foreach ($severities as $currentSeverity) : ?>
<li <?= ($currentSeverity === $severity) ? 'class="active"' : ''; ?>>
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?plugin=<?= urlencode($plugin); ?>&severity=<?= urlencode($currentSeverity); ?>#errors">
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>?is_new=<?= urlencode($isNew); ?>&plugin=<?= urlencode($plugin); ?>&severity=<?= urlencode($currentSeverity); ?>#errors">
<?= Lang::get(BuildError::getSeverityName($currentSeverity)); ?>
</a>
</li>
@ -282,6 +311,7 @@ use PHPCensor\Model\BuildError;
var PAGE = <?= $page; ?>;
var BUILD_PLUGIN = '<?= $plugin; ?>';
var BUILD_SEVERITY = '<?= $severity; ?>';
var BUILD_IS_NEW = '<?= $isNew; ?>';
var ActiveBuild = new Build(<?= $build->getId(); ?>);
ActiveBuild.setupBuild(<?= json_encode($data); ?>, <?= json_encode($build->getFileLinkTemplate()); ?>);

View file

@ -23,6 +23,6 @@ use PHPCensor\Helper\Lang;
<?php endforeach; ?>
<?php if ($paginator->getNextUrl()): ?>
<li><a href="<?php echo $paginator->getNextUrl(); ?>"><?= Lang::get('prev_link'); ?></a></li>
<li><a href="<?php echo $paginator->getNextUrl(); ?>"><?= Lang::get('next_link'); ?></a></li>
<?php endif; ?>
</ul>