Adding a branch filter to the project page, allowing users to view builds from a specific branch.
Closes #600
This commit is contained in:
parent
24498d1bc4
commit
0aa342e774
|
@ -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');
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,23 @@
|
|||
<h1><i class="glyphicon glyphicon-th-list"></i> <?php print htmlspecialchars($project->getTitle()); ?></h1>
|
||||
<h1>
|
||||
<i class="glyphicon glyphicon-th-list"></i> <?php print htmlspecialchars($project->getTitle()); ?>
|
||||
<small><?php echo $branch ?></small>
|
||||
<div class="btn-group pull-right branch-btn">
|
||||
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
Branch <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<?php foreach ($branches as $curbranch) : ?>
|
||||
<li <?php echo ($curbranch == $branch) ? 'class="active"' : ''?>>
|
||||
<a href="<?php echo PHPCI_URL ?>project/view/<?php print $project->getId(); ?>/<?php echo urlencode($curbranch) ?>">
|
||||
<?php echo $curbranch ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<li class="divider"></li>
|
||||
<li><a href="<?php echo PHPCI_URL ?>project/view/<?php print $project->getId(); ?>">All</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</h1>
|
||||
|
||||
|
||||
<div class="row">
|
||||
|
@ -9,7 +28,10 @@
|
|||
</div>
|
||||
|
||||
<div class="list-group">
|
||||
<a class="list-group-item" href="<?php echo PHPCI_URL ?>project/build/<?php print $project->getId(); ?>"><i class="glyphicon glyphicon-cog"></i> Build Now</a>
|
||||
<a class="list-group-item"
|
||||
href="<?php echo PHPCI_URL ?>project/build/<?php print $project->getId() . ((!empty($branch)) ? '/' . urlencode($branch) : ''); ?>">
|
||||
<i class="glyphicon glyphicon-cog"></i> Build <?php print (!empty($branch)) ? 'Branch' : ''; ?> Now
|
||||
</a>
|
||||
|
||||
<?php if($this->User()->getIsAdmin()): ?>
|
||||
<a class="list-group-item" href="<?php echo PHPCI_URL ?>project/edit/<?php print $project->getId(); ?>"><i class="glyphicon glyphicon-edit"></i> Edit Project</a>
|
||||
|
@ -60,8 +82,15 @@
|
|||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="col-lg-9">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading"><h3 class="panel-title">Builds</h3></div>
|
||||
<div class="panel-heading">
|
||||
|
||||
<h3 class="panel-title">Builds</h3>
|
||||
</div>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -83,8 +112,10 @@
|
|||
|
||||
print '<div><ul class="pagination">';
|
||||
|
||||
$project_url = PHPCI_URL . 'project/view/' . $project->getId() . ((!empty($branch)) ? '/' . urlencode($branch) : '');
|
||||
|
||||
if ($page > 1) {
|
||||
print '<li><a href="' . PHPCI_URL . 'project/view/'.$project->getId().'?p='.($page == 1 ? '1' : $page - 1).'">« Prev</a></li>';
|
||||
print '<li><a href="' . $project_url . '?p='.($page == 1 ? '1' : $page - 1).'">« Prev</a></li>';
|
||||
}
|
||||
|
||||
if ($pages > 1) {
|
||||
|
@ -93,13 +124,13 @@
|
|||
if ($i == $page) {
|
||||
print '<li><span>' . $i . '</span></li>';
|
||||
} else {
|
||||
print '<li><a href="' . PHPCI_URL . 'project/view/' . $project->getId() . '?p=' . $i . '">' . $i . '</a></li>';
|
||||
print '<li><a href="' . $project_url . '?p=' . $i . '">' . $i . '</a></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $pages) {
|
||||
print '<li><a href="' . PHPCI_URL . 'project/view/'.$project->getId().'?p='.($page == $pages ? $pages : $page + 1).'">Next »</a></li>';
|
||||
print '<li><a href="' . $project_url . '?p='.($page == $pages ? $pages : $page + 1).'">Next »</a></li>';
|
||||
}
|
||||
|
||||
print '</ul></div>';
|
||||
|
@ -115,7 +146,7 @@
|
|||
setInterval(function()
|
||||
{
|
||||
$.ajax({
|
||||
url: '<?php echo PHPCI_URL ?>project/builds/<?php print $project->getId(); ?>',
|
||||
url: '<?php echo PHPCI_URL ?>project/builds/<?php print $project->getId() . ((!empty($branch)) ? '/' . urlencode($branch) : ''); ?>',
|
||||
|
||||
success: function (data) {
|
||||
$('#latest-builds').html(data);
|
||||
|
|
|
@ -98,4 +98,4 @@ ul.pagination {
|
|||
ul.pagination > li > span:focus {
|
||||
color: #333;
|
||||
background-color: #fff;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue