diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 56dc9ed0..dbeee05f 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -62,7 +62,7 @@ class ProjectController extends \PHPCI\Controller /** * View a specific project. */ - public function view($projectId) + public function view($projectId, $branch = '') { $project = $this->projectStore->getById($projectId); @@ -72,18 +72,20 @@ class ProjectController extends \PHPCI\Controller $per_page = 10; $page = $this->getParam('p', 1); - $builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * $per_page)); + $builds = $this->getLatestBuildsHtml($projectId, urldecode($branch), (($page - 1) * $per_page)); $pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $per_page); if ($page > $pages) { throw new NotFoundException('Page with number: ' . $page . ' not found'); } - $this->view->builds = $builds[0]; - $this->view->total = $builds[1]; - $this->view->project = $project; - $this->view->page = $page; - $this->view->pages = $pages; + $this->view->builds = $builds[0]; + $this->view->total = $builds[1]; + $this->view->project = $project; + $this->view->branch = urldecode($branch); + $this->view->branches = $this->projectStore->getKnownBranches($projectId); + $this->view->page = $page; + $this->view->pages = $pages; $this->config->set('page_title', $project->getTitle()); @@ -93,16 +95,20 @@ class ProjectController extends \PHPCI\Controller /** * Create a new pending build for a project. */ - public function build($projectId) + public function build($projectId, $branch = '') { /* @var \PHPCI\Model\Project $project */ $project = $this->projectStore->getById($projectId); + if (empty($branch)) { + $branch = $project->getBranch(); + } + if (empty($project)) { throw new NotFoundException('Project with id: ' . $projectId . ' not found'); } - $build = $this->buildService->createBuild($project, null, null, $_SESSION['user']->getEmail()); + $build = $this->buildService->createBuild($project, null, urldecode($branch), $_SESSION['user']->getEmail()); header('Location: '.PHPCI_URL.'build/view/' . $build->getId()); exit; @@ -127,18 +133,27 @@ class ProjectController extends \PHPCI\Controller /** * AJAX get latest builds. */ - public function builds($projectId) + public function builds($projectId, $branch = '') { - $builds = $this->getLatestBuildsHtml($projectId); + $builds = $this->getLatestBuildsHtml($projectId, urldecode($branch)); die($builds[0]); } /** - * Render latest builds for project as HTML table. - */ - protected function getLatestBuildsHtml($projectId, $start = 0) + * Render latest builds for project as HTML table. + * + * @param $projectId + * @param string $branch A urldecoded branch name. + * @param int $start + * @return array + */ + protected function getLatestBuildsHtml($projectId, $branch = '', $start = 0) { $criteria = array('project_id' => $projectId); + if (!empty($branch)) { + $criteria['branch'] = $branch; + } + $order = array('id' => 'DESC'); $builds = $this->buildStore->getWhere($criteria, 10, $start, array(), $order); $view = new b8\View('BuildsTable'); diff --git a/PHPCI/Store/ProjectStore.php b/PHPCI/Store/ProjectStore.php index 0596d0c9..6f81b8f4 100644 --- a/PHPCI/Store/ProjectStore.php +++ b/PHPCI/Store/ProjectStore.php @@ -9,6 +9,7 @@ namespace PHPCI\Store; +use b8\Database; use PHPCI\Store\Base\ProjectStoreBase; /** @@ -19,5 +20,23 @@ use PHPCI\Store\Base\ProjectStoreBase; */ class ProjectStore extends ProjectStoreBase { - // This class has been left blank so that you can modify it - changes in this file will not be overwritten. + public function getKnownBranches($projectId) + { + $query = 'SELECT DISTINCT branch from build WHERE project_id = :pid'; + $stmt = Database::getConnection('read')->prepare($query); + $stmt->bindValue(':pid', $projectId); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return $item['branch']; + }; + $rtn = array_map($map, $res); + + return $rtn; + } else { + return array(); + } + } } diff --git a/PHPCI/View/Project/view.phtml b/PHPCI/View/Project/view.phtml index 3aeb75a7..704a6ba5 100644 --- a/PHPCI/View/Project/view.phtml +++ b/PHPCI/View/Project/view.phtml @@ -1,4 +1,23 @@ -

getTitle()); ?>

+

+ getTitle()); ?> + +
+ + +
+

@@ -9,7 +28,10 @@
- Build Now + + Build Now + User()->getIsAdmin()): ?> Edit Project @@ -60,8 +82,15 @@
+ + + +
-

Builds

+
+ +

Builds

+
@@ -83,8 +112,10 @@ print '
    '; + $project_url = PHPCI_URL . 'project/view/' . $project->getId() . ((!empty($branch)) ? '/' . urlencode($branch) : ''); + if ($page > 1) { - print '
  • « Prev
  • '; + print '
  • « Prev
  • '; } if ($pages > 1) { @@ -93,13 +124,13 @@ if ($i == $page) { print '
  • ' . $i . '
  • '; } else { - print '
  • ' . $i . '
  • '; + print '
  • ' . $i . '
  • '; } } } if ($page < $pages) { - print '
  • Next »
  • '; + print '
  • Next »
  • '; } print '
'; @@ -115,7 +146,7 @@ setInterval(function() { $.ajax({ - url: 'project/builds/getId(); ?>', + url: 'project/builds/getId() . ((!empty($branch)) ? '/' . urlencode($branch) : ''); ?>', success: function (data) { $('#latest-builds').html(data); diff --git a/public/assets/css/phpci.css b/public/assets/css/phpci.css index a4fa440a..faff0ad0 100644 --- a/public/assets/css/phpci.css +++ b/public/assets/css/phpci.css @@ -98,4 +98,4 @@ ul.pagination { ul.pagination > li > span:focus { color: #333; background-color: #fff; - } \ No newline at end of file + }