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
5683fa37dc
commit
abd50bf4bd
4 changed files with 88 additions and 23 deletions
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue