From 6b102f214eb253bcb03de0114be23ae5112b7ee0 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 29 Oct 2017 14:06:41 +0700 Subject: [PATCH 1/3] Added Paginator for build errors. Issue #85. --- public/assets/js/build.js | 5 +- src/PHPCensor/Controller/BuildController.php | 82 ++++++++++++++++--- .../Controller/ProjectController.php | 67 ++++++++++----- src/PHPCensor/Store/BuildErrorStore.php | 62 ++++---------- src/PHPCensor/View/Build/view.phtml | 14 ++++ src/PHPCensor/View/Project/view.phtml | 22 +---- src/PHPCensor/View/layout.phtml | 27 +++--- src/PHPCensor/View/pagination.phtml | 28 +++++++ 8 files changed, 190 insertions(+), 117 deletions(-) create mode 100644 src/PHPCensor/View/pagination.phtml diff --git a/public/assets/js/build.js b/public/assets/js/build.js index 9229a512..919e3829 100644 --- a/public/assets/js/build.js +++ b/public/assets/js/build.js @@ -22,7 +22,7 @@ var Build = Class.extend({ self.buildData = data.queryData; - // If the build has finished, stop updating every 10 seconds: + // If the build has finished, stop updating every 5 seconds: if (self.buildData && self.buildData.status > 1) { self.cancelQuery('build-updated'); $(window).trigger({type: 'build-complete'}); @@ -34,6 +34,7 @@ var Build = Class.extend({ $('.build-finished').html(self.buildData.finish_date ? self.buildData.finish_date : ''); $('#log pre').html(self.buildData.log); $('.errors-table tbody').html(self.buildData.error_html); + $('#paginator').html(self.buildData.paginator); if (self.buildData.errors == 0) { $('.errors-label').hide(); @@ -77,7 +78,7 @@ var Build = Class.extend({ var fullUri = window.APP_URL + uri; if (name == 'build-updated') { - fullUri = window.APP_URL + 'build/ajax-data/' + self.buildId; + fullUri = window.APP_URL + 'build/ajax-data/' + self.buildId + '?per_page=' + PER_PAGE + '&page=' + PAGE; } $.ajax({ diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index a00d4a93..bf4ceb54 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -5,11 +5,13 @@ namespace PHPCensor\Controller; use b8; use b8\Exception\HttpException\NotFoundException; use b8\Http\Response\JsonResponse; +use JasonGrimes\Paginator; use PHPCensor\BuildFactory; use PHPCensor\Helper\AnsiConverter; use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; use PHPCensor\Model\Project; +use PHPCensor\Model\User; use PHPCensor\Service\BuildService; use PHPCensor\Controller; @@ -40,10 +42,16 @@ class BuildController extends Controller } /** - * View a specific build. - */ + * View a specific build. + * + * @param integer $buildId + * + * @throws NotFoundException + */ public function view($buildId) { + $page = (integer)$this->getParam('page', 1); + try { $build = BuildFactory::getBuildById($buildId); } catch (\Exception $ex) { @@ -54,9 +62,24 @@ class BuildController extends Controller throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); } - $this->view->plugins = $this->getUiPlugins(); - $this->view->build = $build; - $this->view->data = $this->getBuildData($build); + /** @var User $user */ + $user = $_SESSION['php-censor-user']; + $perPage = $user->getFinalPerPage(); + $data = $this->getBuildData($build, (($page - 1) * $perPage), $perPage); + $pages = ($data['errors'] === 0) + ? 1 + : (integer)ceil($data['errors'] / $perPage); + + if ($page > $pages) { + $page = $pages; + } + + $this->view->plugins = $this->getUiPlugins(); + $this->view->build = $build; + $this->view->data = $data; + $this->view->page = $page; + $this->view->perPage = $perPage; + $this->view->paginator = $this->getPaginatorHtml($buildId, $data['errors'], $perPage, $page); $this->layout->title = Lang::get('build_n', $buildId); $this->layout->subtitle = $build->getProjectTitle(); @@ -121,9 +144,15 @@ class BuildController extends Controller } /** - * Get build data from database and json encode it: - */ - protected function getBuildData(Build $build) + * Get build data from database and json encode it. + * + * @param Build $build + * @param integer $start + * @param integer $perPage + * + * @return array + */ + protected function getBuildData(Build $build, $start = 0, $perPage = 10) { $data = []; $data['status'] = (int)$build->getStatus(); @@ -135,19 +164,40 @@ class BuildController extends Controller /** @var \PHPCensor\Store\BuildErrorStore $errorStore */ $errorStore = b8\Store\Factory::getStore('BuildError'); - $errors = $errorStore->getErrorsForBuild($build->getId()); + $errors = $errorStore->getByBuildId($build->getId(), $perPage, $start); $errorView = new b8\View('Build/errors'); $errorView->build = $build; - $errorView->errors = $errors; + $errorView->errors = $errors['items']; - $data['errors'] = $errorStore->getErrorTotalForBuild($build->getId()); + $data['errors'] = (integer)$errorStore->getErrorTotalForBuild($build->getId()); $data['error_html'] = $errorView->render(); - $data['since'] = (new \DateTime())->format('Y-m-d H:i:s'); return $data; } + /** + * @param integer $buildId + * @param integer $total + * @param integer $perPage + * @param integer $page + * + * @return string + */ + protected function getPaginatorHtml($buildId, $total, $perPage, $page) + { + $view = new b8\View('pagination'); + + $urlPattern = APP_URL . 'build/view/' . $buildId; + + $urlPattern = $urlPattern . '?' . str_replace('%28%3Anum%29', '(:num)', http_build_query(['page' => '(:num)'])) . '#errors'; + $paginator = new Paginator($total, $perPage, $page, $urlPattern); + + $view->paginator = $paginator; + + return $view->render(); + } + /** * Create a build using an existing build as a template: */ @@ -230,6 +280,9 @@ class BuildController extends Controller public function ajaxData($buildId) { + $page = (integer)$this->getParam('page', 1); + $perPage = (integer)$this->getParam('per_page', 10); + $response = new JsonResponse(); $build = BuildFactory::getBuildById($buildId); @@ -240,7 +293,10 @@ class BuildController extends Controller return $response; } - $response->setContent($this->getBuildData($build)); + $data = $this->getBuildData($build, (($page - 1) * $perPage), $perPage); + $data['paginator'] = $this->getPaginatorHtml($buildId, $data['errors'], $perPage, $page); + + $response->setContent($data); return $response; } diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index 836f0461..a8b909ae 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -94,30 +94,18 @@ class ProjectController extends PHPCensor\Controller throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } - $perPage = $_SESSION['php-censor-user']->getFinalPerPage(); + /** @var PHPCensor\Model\User $user */ + $user = $_SESSION['php-censor-user']; + $perPage = $user->getFinalPerPage(); $builds = $this->getLatestBuildsHtml($projectId, $environment, $branch, (($page - 1) * $perPage), $perPage); - $pages = $builds[1] == 0 ? 1 : (integer)ceil($builds[1] / $perPage); + $pages = ($builds[1] === 0) + ? 1 + : (integer)ceil($builds[1] / $perPage); if ($page > $pages) { - $response = new RedirectResponse(); - $response->setHeader('Location', APP_URL . 'project/view/' . $projectId); - - return $response; + $page = $pages; } - $urlPattern = APP_URL . 'project/view/' . $project->getId(); - $params = []; - if (!empty($branch)) { - $params['branch'] = $branch; - } - - if (!empty($environment)) { - $params['environment'] = $environment; - } - - $urlPattern = $urlPattern . '?' . str_replace('%28%3Anum%29', '(:num)', http_build_query(array_merge($params, ['page' => '(:num)']))); - $paginator = new Paginator($builds[1], $perPage, $page, $urlPattern); - $this->view->builds = $builds[0]; $this->view->total = $builds[1]; $this->view->project = $project; @@ -127,7 +115,7 @@ class ProjectController extends PHPCensor\Controller $this->view->environments = $project->getEnvironmentsNames(); $this->view->page = $page; $this->view->perPage = $perPage; - $this->view->paginator = $paginator; + $this->view->paginator = $this->getPaginatorHtml($projectId, $branch, $environment, $builds[1], $perPage, $page); $this->layout->title = $project->getTitle(); $this->layout->subtitle = ''; @@ -141,6 +129,38 @@ class ProjectController extends PHPCensor\Controller return $this->view->render(); } + /** + * @param integer $projectId + * @param string $branch + * @param string $environment + * @param integer $total + * @param integer $perPage + * @param integer $page + * + * @return string + */ + protected function getPaginatorHtml($projectId, $branch, $environment, $total, $perPage, $page) + { + $view = new b8\View('pagination'); + + $urlPattern = APP_URL . 'project/view/' . $projectId; + $params = []; + if (!empty($branch)) { + $params['branch'] = $branch; + } + + if (!empty($environment)) { + $params['environment'] = $environment; + } + + $urlPattern = $urlPattern . '?' . str_replace('%28%3Anum%29', '(:num)', http_build_query(array_merge($params, ['page' => '(:num)']))); + $paginator = new Paginator($total, $perPage, $page, $urlPattern); + + $view->paginator = $paginator; + + return $view->render(); + } + /** * Create a new pending build for a project. * @@ -259,9 +279,12 @@ class ProjectController extends PHPCensor\Controller $build = BuildFactory::getBuild($build); } - $view->builds = $builds['items']; + $view->builds = $builds['items']; - return [$view->render(), $builds['count']]; + return [ + $view->render(), + (integer)$builds['count'] + ]; } /** diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index f716fc70..fd97b530 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -60,23 +60,33 @@ class BuildErrorStore extends Store * * @param integer $buildId * @param integer $limit - * @param string $useConnection + * @param integer $offset * * @return array * * @throws HttpException */ - public function getByBuildId($buildId, $limit = 1000, $useConnection = 'read') + public function getByBuildId($buildId, $limit = null, $offset = 0) { if (is_null($buildId)) { throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - - $query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id LIMIT :limit'; - $stmt = Database::getConnection($useConnection)->prepareCommon($query); + $query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id ORDER BY plugin, severity'; + if (null !== $limit) { + $query .= ' LIMIT :limit'; + } + if ($offset) { + $query .= ' OFFSET :offset'; + } + $stmt = Database::getConnection()->prepareCommon($query); $stmt->bindValue(':build_id', $buildId); - $stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT); + if (null !== $limit) { + $stmt->bindValue(':limit', (integer)$limit, \PDO::PARAM_INT); + } + if ($offset) { + $stmt->bindValue(':offset', (integer)$offset, \PDO::PARAM_INT); + } if ($stmt->execute()) { $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); @@ -94,46 +104,6 @@ class BuildErrorStore extends Store } } - /** - * Get a list of errors for a given build, since a given time. - * - * @param integer $buildId - * @param string $since date string - * - * @return array - */ - public function getErrorsForBuild($buildId, $since = null) - { - $query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build'; - - if (!is_null($since)) { - $query .= ' AND created_date > :since'; - } - - $query .= ' LIMIT 15000'; - - $stmt = Database::getConnection('read')->prepareCommon($query); - - $stmt->bindValue(':build', $buildId, \PDO::PARAM_INT); - - if (!is_null($since)) { - $stmt->bindValue(':since', $since); - } - - if ($stmt->execute()) { - $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); - - $map = function ($item) { - return new BuildError($item); - }; - $rtn = array_map($map, $res); - - return $rtn; - } else { - return []; - } - } - /** * Gets the total number of errors for a given build. * diff --git a/src/PHPCensor/View/Build/view.phtml b/src/PHPCensor/View/Build/view.phtml index 8288fd5a..4ca2c143 100644 --- a/src/PHPCensor/View/Build/view.phtml +++ b/src/PHPCensor/View/Build/view.phtml @@ -204,6 +204,9 @@ use PHPCensor\Model\Build; +
+ +
@@ -214,10 +217,21 @@ use PHPCensor\Model\Build;
-
- +
+
diff --git a/src/PHPCensor/View/layout.phtml b/src/PHPCensor/View/layout.phtml index 5556256a..0d68a4ea 100644 --- a/src/PHPCensor/View/layout.phtml +++ b/src/PHPCensor/View/layout.phtml @@ -14,6 +14,19 @@ + + + + + + + + + + + + + - - - - -
@@ -245,14 +253,5 @@
- - - - - - - - - diff --git a/src/PHPCensor/View/pagination.phtml b/src/PHPCensor/View/pagination.phtml new file mode 100644 index 00000000..c1bc12cb --- /dev/null +++ b/src/PHPCensor/View/pagination.phtml @@ -0,0 +1,28 @@ + + From 42888630e75e4946a8127d0b628347e8a59d7c68 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 29 Oct 2017 21:26:43 +0700 Subject: [PATCH 2/3] Added filtration for errors by severity and plugin. Issue #85. --- public/assets/js/build.js | 10 +- src/PHPCensor/Controller/BuildController.php | 62 ++++++++++--- .../Controller/ProjectController.php | 10 +- src/PHPCensor/Languages/lang.en.php | 5 + src/PHPCensor/Languages/lang.ru.php | 7 +- src/PHPCensor/Model/BuildError.php | 24 +++++ src/PHPCensor/Store/BuildErrorStore.php | 93 ++++++++++++++++++- src/PHPCensor/View/Build/view.phtml | 78 ++++++++++++++-- 8 files changed, 253 insertions(+), 36 deletions(-) diff --git a/public/assets/js/build.js b/public/assets/js/build.js index 919e3829..c08f0201 100644 --- a/public/assets/js/build.js +++ b/public/assets/js/build.js @@ -36,12 +36,8 @@ var Build = Class.extend({ $('.errors-table tbody').html(self.buildData.error_html); $('#paginator').html(self.buildData.paginator); - if (self.buildData.errors == 0) { - $('.errors-label').hide(); - } else { - $('.errors-label').text(self.buildData.errors); - $('.errors-label').show(); - } + $('.errors-label').text(self.buildData.errors_total); + $('.errors-label').show(); switch (self.buildData.status) { case 0: @@ -78,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; + fullUri = window.APP_URL + 'build/ajax-data/' + self.buildId + '?per_page=' + PER_PAGE + '&page=' + PAGE + '&plugin=' + BUILD_PLUGIN + '&severity=' + BUI; } $.ajax({ diff --git a/src/PHPCensor/Controller/BuildController.php b/src/PHPCensor/Controller/BuildController.php index bf4ceb54..dd538db9 100644 --- a/src/PHPCensor/Controller/BuildController.php +++ b/src/PHPCensor/Controller/BuildController.php @@ -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); diff --git a/src/PHPCensor/Controller/ProjectController.php b/src/PHPCensor/Controller/ProjectController.php index a8b909ae..7bc5b9d4 100644 --- a/src/PHPCensor/Controller/ProjectController.php +++ b/src/PHPCensor/Controller/ProjectController.php @@ -66,7 +66,7 @@ class ProjectController extends PHPCensor\Controller $environment = $this->getParam('environment', ''); $page = (integer)$this->getParam('page', 1); $perPage = (integer)$this->getParam('per_page', 10); - $builds = $this->getLatestBuildsHtml($projectId, $environment, $branch, (($page - 1) * $perPage), $perPage); + $builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage); $this->response->disableLayout(); $this->response->setContent($builds[0]); @@ -97,7 +97,7 @@ class ProjectController extends PHPCensor\Controller /** @var PHPCensor\Model\User $user */ $user = $_SESSION['php-censor-user']; $perPage = $user->getFinalPerPage(); - $builds = $this->getLatestBuildsHtml($projectId, $environment, $branch, (($page - 1) * $perPage), $perPage); + $builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage); $pages = ($builds[1] === 0) ? 1 : (integer)ceil($builds[1] / $perPage); @@ -252,14 +252,14 @@ class ProjectController extends PHPCensor\Controller * Render latest builds for project as HTML table. * * @param int $projectId - * @param string $environment A urldecoded environment name. - * @param string $branch A urldecoded branch name. + * @param string $branch A urldecoded branch name. + * @param string $environment A urldecoded environment name. * @param int $start * @param int $perPage * * @return array */ - protected function getLatestBuildsHtml($projectId, $environment = '', $branch = '', $start = 0, $perPage = 10) + protected function getLatestBuildsHtml($projectId, $branch = '', $environment = '', $start = 0, $perPage = 10) { $criteria = ['project_id' => $projectId]; diff --git a/src/PHPCensor/Languages/lang.en.php b/src/PHPCensor/Languages/lang.en.php index f42e5987..b6f3d287 100644 --- a/src/PHPCensor/Languages/lang.en.php +++ b/src/PHPCensor/Languages/lang.en.php @@ -337,6 +337,11 @@ PHP Censor', 'stage_broken' => 'Broken', 'stage_fixed' => 'Fixed', 'severity' => 'Severity', + + 'all_plugins' => 'All plugins', + 'all_severities' => 'All severities', + 'filters' => 'Filters', + 'errors_selected' => 'Errors selected', 'build_details' => 'Build Details', 'commit_details' => 'Commit Details', diff --git a/src/PHPCensor/Languages/lang.ru.php b/src/PHPCensor/Languages/lang.ru.php index 23d7d552..d92e1166 100644 --- a/src/PHPCensor/Languages/lang.ru.php +++ b/src/PHPCensor/Languages/lang.ru.php @@ -325,7 +325,12 @@ PHP Censor', 'stage_failure' => 'Провал', 'stage_broken' => 'Поломка', 'stage_fixed' => 'Исправление', - 'severity' => 'Важность', + 'severity' => 'Уровень', + + 'all_plugins' => 'Все плагины', + 'all_severities' => 'Все уровни', + 'filters' => 'Фильтры', + 'errors_selected' => 'Ошибок выбрано', 'build_details' => 'Информация о сборке', 'commit_details' => 'Информация о коммитe', diff --git a/src/PHPCensor/Model/BuildError.php b/src/PHPCensor/Model/BuildError.php index 324e2671..3e8796dc 100644 --- a/src/PHPCensor/Model/BuildError.php +++ b/src/PHPCensor/Model/BuildError.php @@ -401,6 +401,30 @@ class BuildError extends Model } } + /** + * Get the language string key for this error's severity level. + * + * @param integer $severity + * + * @return string + */ + public static function getSeverityName($severity) + { + switch ($severity) { + case self::SEVERITY_CRITICAL: + return 'critical'; + + case self::SEVERITY_HIGH: + return 'high'; + + case self::SEVERITY_NORMAL: + return 'normal'; + + case self::SEVERITY_LOW: + return 'low'; + } + } + /** * Get the class to apply to HTML elements representing this error. * diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index fd97b530..93749e85 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -61,18 +61,27 @@ class BuildErrorStore extends Store * @param integer $buildId * @param integer $limit * @param integer $offset + * @param string $plugin + * @param integer $severity * * @return array * * @throws HttpException */ - public function getByBuildId($buildId, $limit = null, $offset = 0) + public function getByBuildId($buildId, $limit = null, $offset = 0, $plugin = null, $severity = null) { if (is_null($buildId)) { throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id ORDER BY plugin, severity'; + $query = 'SELECT * FROM {{build_error}} WHERE {{build_id}} = :build_id'; + if ($plugin) { + $query .= ' AND {{plugin}} = :plugin'; + } + if (null !== $severity) { + $query .= ' AND {{severity}} = :severity'; + } + $query .= ' ORDER BY plugin, severity'; if (null !== $limit) { $query .= ' LIMIT :limit'; } @@ -81,6 +90,12 @@ class BuildErrorStore extends Store } $stmt = Database::getConnection()->prepareCommon($query); $stmt->bindValue(':build_id', $buildId); + if ($plugin) { + $stmt->bindValue(':plugin', $plugin, \PDO::PARAM_STR); + } + if (null !== $severity) { + $stmt->bindValue(':severity', (integer)$severity, \PDO::PARAM_INT); + } if (null !== $limit) { $stmt->bindValue(':limit', (integer)$limit, \PDO::PARAM_INT); } @@ -108,17 +123,31 @@ class BuildErrorStore extends Store * Gets the total number of errors for a given build. * * @param integer $buildId + * @param string $plugin + * @param integer $severity * * @return array */ - public function getErrorTotalForBuild($buildId) + public function getErrorTotalForBuild($buildId, $plugin = null, $severity = 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'; + } $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); + } if ($stmt->execute()) { $res = $stmt->fetch(\PDO::FETCH_ASSOC); @@ -127,4 +156,62 @@ class BuildErrorStore extends Store return []; } } + + /** + * @param integer $buildId + * + * @return array + */ + public function getKnownPlugins($buildId) + { + $query = 'SELECT DISTINCT {{plugin}} from {{build_error}} WHERE {{build_id}} = :build'; + $stmt = Database::getConnection('read')->prepareCommon($query); + $stmt->bindValue(':build', $buildId); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return $item['plugin']; + }; + $rtn = array_map($map, $res); + + return $rtn; + } else { + return []; + } + } + + /** + * @param integer $buildId + * @param string $plugin + * + * @return array + */ + public function getKnownSeverities($buildId, $plugin = '') + { + $query = 'SELECT DISTINCT {{severity}} from {{build_error}} WHERE {{build_id}} = :build'; + if ($plugin) { + $query .= ' AND {{plugin}} = :plugin'; + } + + $stmt = Database::getConnection('read')->prepareCommon($query); + $stmt->bindValue(':build', $buildId); + if ($plugin) { + $stmt->bindValue(':plugin', $plugin); + } + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return (integer)$item['severity']; + }; + $rtn = array_map($map, $res); + + return $rtn; + } else { + return []; + } + } } diff --git a/src/PHPCensor/View/Build/view.phtml b/src/PHPCensor/View/Build/view.phtml index 4ca2c143..69d25806 100644 --- a/src/PHPCensor/View/Build/view.phtml +++ b/src/PHPCensor/View/Build/view.phtml @@ -2,6 +2,7 @@ use PHPCensor\Helper\Lang; use PHPCensor\Model\Build; +use PHPCensor\Model\BuildError; /** * @var Build $build @@ -172,10 +173,10 @@ use PHPCensor\Model\Build;
  • - + - +
  • @@ -190,6 +191,65 @@ use PHPCensor\Model\Build;
    + getStatus() > Build::STATUS_RUNNING): ?> +
    +
    +

    +
    +
    + +

    : /

    + + +
    + + +
    +
    + + +
    +
    +
    + @@ -217,11 +277,13 @@ use PHPCensor\Model\Build; ' . PHP_EOL; +foreach ($uiPlugins as $uiPlugin) { + print '' . PHP_EOL; } ?> From 7174c271e55d4b0e03fb48179aae945eb50bf122 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 30 Oct 2017 21:03:53 +0700 Subject: [PATCH 3/3] Added links to errors from summary block (Information tab). Issue #85. --- public/assets/js/build-plugins/summary.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/assets/js/build-plugins/summary.js b/public/assets/js/build-plugins/summary.js index e6fddae4..d6e50a4d 100644 --- a/public/assets/js/build-plugins/summary.js +++ b/public/assets/js/build-plugins/summary.js @@ -55,12 +55,17 @@ var SummaryPlugin = ActiveBuild.UiPlugin.extend({ for (var stage in summary) { for (var plugin in summary[stage]) { - var data = summary[stage][plugin], + var data = summary[stage][plugin], duration = data.started ? ((data.ended || Math.floor(Date.now() / 1000)) - data.started) : '-'; + + var pluginName = Lang.get(plugin); + if ('test' === stage && 2 < data.status) { + pluginName = '' + Lang.get(plugin) + ''; + } tbody.append( '' + '' + - '' + + '' + '' +
    ' + Lang.get('stage_' + stage) + '' + Lang.get(plugin) + '' + pluginName + '' + this.statusLabels[data.status] + '