Added filtration for errors by severity and plugin. Issue #85.
This commit is contained in:
parent
6b102f214e
commit
42888630e7
8 changed files with 253 additions and 36 deletions
|
|
@ -50,7 +50,15 @@ class BuildController extends Controller
|
|||
*/
|
||||
public function view($buildId)
|
||||
{
|
||||
$page = (integer)$this->getParam('page', 1);
|
||||
$page = (integer)$this->getParam('page', 1);
|
||||
$plugin = $this->getParam('plugin', '');
|
||||
|
||||
$severity = $this->getParam('severity', null);
|
||||
if (null !== $severity && '' !== $severity) {
|
||||
$severity = (integer)$severity;
|
||||
} else {
|
||||
$severity = null;
|
||||
}
|
||||
|
||||
try {
|
||||
$build = BuildFactory::getBuildById($buildId);
|
||||
|
|
@ -65,7 +73,7 @@ class BuildController extends Controller
|
|||
/** @var User $user */
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
$perPage = $user->getFinalPerPage();
|
||||
$data = $this->getBuildData($build, (($page - 1) * $perPage), $perPage);
|
||||
$data = $this->getBuildData($build, $plugin, $severity, (($page - 1) * $perPage), $perPage);
|
||||
$pages = ($data['errors'] === 0)
|
||||
? 1
|
||||
: (integer)ceil($data['errors'] / $perPage);
|
||||
|
|
@ -74,12 +82,21 @@ class BuildController extends Controller
|
|||
$page = $pages;
|
||||
}
|
||||
|
||||
$this->view->plugins = $this->getUiPlugins();
|
||||
/** @var \PHPCensor\Store\BuildErrorStore $errorStore */
|
||||
$errorStore = b8\Store\Factory::getStore('BuildError');
|
||||
|
||||
$this->view->uiPlugins = $this->getUiPlugins();
|
||||
$this->view->build = $build;
|
||||
$this->view->data = $data;
|
||||
|
||||
$this->view->plugin = urldecode($plugin);
|
||||
$this->view->plugins = $errorStore->getKnownPlugins($buildId);
|
||||
$this->view->severity = urldecode(null !== $severity ? $severity : '');
|
||||
$this->view->severities = $errorStore->getKnownSeverities($buildId, $plugin);
|
||||
|
||||
$this->view->page = $page;
|
||||
$this->view->perPage = $perPage;
|
||||
$this->view->paginator = $this->getPaginatorHtml($buildId, $data['errors'], $perPage, $page);
|
||||
$this->view->paginator = $this->getPaginatorHtml($buildId, $plugin, $severity, $data['errors'], $perPage, $page);
|
||||
|
||||
$this->layout->title = Lang::get('build_n', $buildId);
|
||||
$this->layout->subtitle = $build->getProjectTitle();
|
||||
|
|
@ -147,12 +164,14 @@ class BuildController extends Controller
|
|||
* Get build data from database and json encode it.
|
||||
*
|
||||
* @param Build $build
|
||||
* @param string $plugin
|
||||
* @param integer $severity
|
||||
* @param integer $start
|
||||
* @param integer $perPage
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBuildData(Build $build, $start = 0, $perPage = 10)
|
||||
protected function getBuildData(Build $build, $plugin, $severity, $start = 0, $perPage = 10)
|
||||
{
|
||||
$data = [];
|
||||
$data['status'] = (int)$build->getStatus();
|
||||
|
|
@ -164,33 +183,44 @@ class BuildController extends Controller
|
|||
|
||||
/** @var \PHPCensor\Store\BuildErrorStore $errorStore */
|
||||
$errorStore = b8\Store\Factory::getStore('BuildError');
|
||||
$errors = $errorStore->getByBuildId($build->getId(), $perPage, $start);
|
||||
$errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity);
|
||||
|
||||
$errorView = new b8\View('Build/errors');
|
||||
$errorView->build = $build;
|
||||
$errorView->errors = $errors['items'];
|
||||
|
||||
$data['errors'] = (integer)$errorStore->getErrorTotalForBuild($build->getId());
|
||||
$data['error_html'] = $errorView->render();
|
||||
$data['errors'] = (integer)$errorStore->getErrorTotalForBuild($build->getId(), $plugin, $severity);
|
||||
$data['errors_total'] = (integer)$errorStore->getErrorTotalForBuild($build->getId());
|
||||
$data['error_html'] = $errorView->render();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $buildId
|
||||
* @param string $plugin
|
||||
* @param integer $severity
|
||||
* @param integer $total
|
||||
* @param integer $perPage
|
||||
* @param integer $page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPaginatorHtml($buildId, $total, $perPage, $page)
|
||||
protected function getPaginatorHtml($buildId, $plugin, $severity, $total, $perPage, $page)
|
||||
{
|
||||
$view = new b8\View('pagination');
|
||||
|
||||
$urlPattern = APP_URL . 'build/view/' . $buildId;
|
||||
$params = [];
|
||||
if (!empty($plugin)) {
|
||||
$params['plugin'] = $plugin;
|
||||
}
|
||||
|
||||
$urlPattern = $urlPattern . '?' . str_replace('%28%3Anum%29', '(:num)', http_build_query(['page' => '(:num)'])) . '#errors';
|
||||
if (null !== $severity) {
|
||||
$params['severity'] = $severity;
|
||||
}
|
||||
|
||||
$urlPattern = $urlPattern . '?' . str_replace('%28%3Anum%29', '(:num)', http_build_query(array_merge($params, ['page' => '(:num)']))) . '#errors';
|
||||
$paginator = new Paginator($total, $perPage, $page, $urlPattern);
|
||||
|
||||
$view->paginator = $paginator;
|
||||
|
|
@ -282,6 +312,14 @@ class BuildController extends Controller
|
|||
{
|
||||
$page = (integer)$this->getParam('page', 1);
|
||||
$perPage = (integer)$this->getParam('per_page', 10);
|
||||
$plugin = $this->getParam('plugin', '');
|
||||
|
||||
$severity = $this->getParam('severity', null);
|
||||
if (null !== $severity && '' !== $severity) {
|
||||
$severity = (integer)$severity;
|
||||
} else {
|
||||
$severity = null;
|
||||
}
|
||||
|
||||
$response = new JsonResponse();
|
||||
$build = BuildFactory::getBuildById($buildId);
|
||||
|
|
@ -293,8 +331,8 @@ class BuildController extends Controller
|
|||
return $response;
|
||||
}
|
||||
|
||||
$data = $this->getBuildData($build, (($page - 1) * $perPage), $perPage);
|
||||
$data['paginator'] = $this->getPaginatorHtml($buildId, $data['errors'], $perPage, $page);
|
||||
$data = $this->getBuildData($build, $plugin, $severity, (($page - 1) * $perPage), $perPage);
|
||||
$data['paginator'] = $this->getPaginatorHtml($buildId, $plugin, $severity, $data['errors'], $perPage, $page);
|
||||
|
||||
$response->setContent($data);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue