Merge branch 'bugfix-pagination'
This commit is contained in:
commit
de77a572a9
|
@ -38,7 +38,7 @@ var PHPCensor = {
|
|||
|
||||
getProjectBuilds: function () {
|
||||
$.ajax({
|
||||
url: APP_URL + 'project/ajax-builds/' + PROJECT_ID + '?branch=' + PROJECT_BRANCH + '&environment=' + PROJECT_ENVIRONMENT + '&per_page=' + PER_PAGE,
|
||||
url: APP_URL + 'project/ajax-builds/' + PROJECT_ID + '?branch=' + PROJECT_BRANCH + '&environment=' + PROJECT_ENVIRONMENT + '&per_page=' + PER_PAGE + '&page=' + PAGE,
|
||||
|
||||
success: function (data) {
|
||||
$('#latest-builds').html(data);
|
||||
|
|
|
@ -52,6 +52,25 @@ class ProjectController extends PHPCensor\Controller
|
|||
$this->buildService = new BuildService($this->buildStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $projectId
|
||||
*
|
||||
* @return b8\Http\Response
|
||||
*/
|
||||
public function ajaxBuilds($projectId)
|
||||
{
|
||||
$branch = $this->getParam('branch', '');
|
||||
$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);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($builds[0]);
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* View a specific project.
|
||||
*
|
||||
|
@ -65,20 +84,21 @@ class ProjectController extends PHPCensor\Controller
|
|||
{
|
||||
$branch = $this->getParam('branch', '');
|
||||
$environment = $this->getParam('environment', '');
|
||||
$page = (integer)$this->getParam('page', 1);
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
|
||||
if (empty($project)) {
|
||||
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
|
||||
}
|
||||
|
||||
$perPage = $_SESSION['php-censor-user']->getFinalPerPage();
|
||||
$page = $this->getParam('p', 1);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, urldecode($environment), urlencode($branch), (($page - 1) * $perPage), $perPage);
|
||||
$perPage = $_SESSION['php-censor-user']->getFinalPerPage();
|
||||
$builds = $this->getLatestBuildsHtml($projectId, $environment, $branch, (($page - 1) * $perPage), $perPage);
|
||||
$pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $perPage);
|
||||
|
||||
if ($page > $pages) {
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
$response->setHeader('Location', APP_URL.'project/view/'.$projectId);
|
||||
$response->setHeader('Location', APP_URL . 'project/view/' . $projectId);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -109,16 +129,18 @@ class ProjectController extends PHPCensor\Controller
|
|||
* Create a new pending build for a project.
|
||||
*
|
||||
* @param integer $projectId
|
||||
* @param string $type Build type: 'environment'|'branch'
|
||||
* @param string $id Build type id: environment name or branch name
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return b8\Http\Response\RedirectResponse
|
||||
*
|
||||
*/
|
||||
public function build($projectId, $type = null, $id = null)
|
||||
public function build($projectId)
|
||||
{
|
||||
$type = $this->getParam('type', 'branch');
|
||||
$id = $this->getParam('id', 'master');
|
||||
$debug = (boolean)$this->getParam('debug', false);
|
||||
|
||||
/* @var \PHPCensor\Model\Project $project */
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
$environment = null;
|
||||
|
@ -141,7 +163,6 @@ class ProjectController extends PHPCensor\Controller
|
|||
$branch = $project->getBranch();
|
||||
}
|
||||
|
||||
$debug = (boolean)$this->getParam('debug', false);
|
||||
$extra = null;
|
||||
|
||||
if ($debug && $this->currentUserIsAdmin()) {
|
||||
|
@ -155,7 +176,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
$project,
|
||||
$environment,
|
||||
null,
|
||||
urldecode($branch),
|
||||
$branch,
|
||||
null,
|
||||
$email,
|
||||
null,
|
||||
|
@ -524,24 +545,6 @@ class ProjectController extends PHPCensor\Controller
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $projectId
|
||||
*
|
||||
* @return b8\Http\Response
|
||||
*/
|
||||
public function ajaxBuilds($projectId)
|
||||
{
|
||||
$branch = $this->getParam('branch', '');
|
||||
$environment = $this->getParam('environment', '');
|
||||
$perPage = (integer)$this->getParam('per_page', 10);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, urldecode($environment), urldecode($branch), 0, $perPage);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($builds[0]);
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $projectId
|
||||
*
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
<tr>
|
||||
<th><?php Lang::out('project'); ?></th>
|
||||
<td style="text-align: right">
|
||||
<a href="<?php print APP_URL . 'project/view/' . $build->getProjectId(); ?>">
|
||||
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?>"></i>
|
||||
<?php print $build->getProject()->getTitle(); ?>
|
||||
<a href="<?= APP_URL . 'project/view/' . $build->getProjectId(); ?>">
|
||||
<i class="fa fa-<?= $build->getProject()->getIcon(); ?>"></i>
|
||||
<?= $build->getProject()->getTitle(); ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -80,12 +80,12 @@ if ($buildCount > 0) {
|
|||
|
||||
?>
|
||||
|
||||
<div class="small-box small-box-full bg-<?php print $subcls; ?>">
|
||||
<div class="small-box small-box-full bg-<?= $subcls; ?>">
|
||||
|
||||
<div class="inner">
|
||||
<h3>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>">
|
||||
<?php print $project->getTitle(); ?>
|
||||
<a href="<?= APP_URL; ?>project/view/<?= $project->getId(); ?>">
|
||||
<?= $project->getTitle(); ?>
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
|
@ -97,7 +97,7 @@ if ($buildCount > 0) {
|
|||
<div class="icon">
|
||||
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
|
||||
</div>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>" class="small-box-footer small-box-footer-project">
|
||||
<a href="<?= APP_URL; ?>project/view/<?= $project->getId(); ?>" class="small-box-footer small-box-footer-project">
|
||||
<div class="pull-left" style="margin-left: 10px">
|
||||
<?php if ($project->getAllowPublicStatus()): ?>
|
||||
<i class="fa fa-unlock"></i>
|
||||
|
@ -105,7 +105,7 @@ if ($buildCount > 0) {
|
|||
<i class="fa fa-lock"></i>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php Lang::out('view_project'); ?> (<?php print $counts; ?>) <i class="fa fa-arrow-circle-right"></i>
|
||||
<?php Lang::out('view_project'); ?> (<?= $counts; ?>) <i class="fa fa-arrow-circle-right"></i>
|
||||
</a>
|
||||
|
||||
<?php for ($idx=0; $idx < 5; $idx++) {
|
||||
|
|
|
@ -65,13 +65,13 @@ use PHPCensor\Model\Build;
|
|||
?>
|
||||
</span>
|
||||
<h3 class="timeline-header">
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
|
||||
<?php print $build->getProject()->getTitle(); ?>
|
||||
<a href="<?= APP_URL; ?>project/view/<?= $build->getProjectId(); ?>">
|
||||
<?= $build->getProject()->getTitle(); ?>
|
||||
</a>
|
||||
<span><?php print $environment; ?></span>
|
||||
<span><?= $environment; ?></span>
|
||||
—
|
||||
<a href="<?php print APP_URL; ?>build/view/<?php print $build->getId(); ?>">
|
||||
Build #<?php print $build->getId(); ?>
|
||||
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>">
|
||||
Build #<?= $build->getId(); ?>
|
||||
</a>
|
||||
—
|
||||
<?php print $label; ?>
|
||||
|
|
|
@ -80,25 +80,25 @@ foreach($projects as $project):
|
|||
}
|
||||
|
||||
?>
|
||||
<div class="project-box" id="project-box-<?php print $project->getId(); ?>">
|
||||
<div class="small-box small-box-full bg-<?php print $subcls; ?>">
|
||||
<div class="project-box" id="project-box-<?= $project->getId(); ?>">
|
||||
<div class="small-box small-box-full bg-<?= $subcls; ?>">
|
||||
|
||||
<div class="inner">
|
||||
<h3>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>">
|
||||
<?php print $project->getTitle(); ?>
|
||||
<a href="<?= APP_URL; ?>project/view/<?= $project->getId(); ?>">
|
||||
<?= $project->getTitle(); ?>
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
<p>
|
||||
<?php print $message; ?>
|
||||
<?= $message; ?>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
|
||||
</div>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>" class="small-box-footer small-box-footer-project">
|
||||
<a href="<?= APP_URL; ?>project/view/<?= $project->getId(); ?>" class="small-box-footer small-box-footer-project">
|
||||
<div class="pull-left" style="margin-left: 10px">
|
||||
<?php if ($project->getAllowPublicStatus()): ?>
|
||||
<i class="fa fa-unlock"></i>
|
||||
|
|
|
@ -96,16 +96,16 @@ use PHPCensor\Model\Build;
|
|||
?>
|
||||
</span>
|
||||
<h3 class="timeline-header">
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
|
||||
<?php print $build->getProject()->getTitle(); ?>
|
||||
<a href="<?= APP_URL; ?>project/view/<?= $build->getProjectId(); ?>">
|
||||
<?= $build->getProject()->getTitle(); ?>
|
||||
</a>
|
||||
<span><?php print $environment; ?></span>
|
||||
<span><?= $environment; ?></span>
|
||||
—
|
||||
<a href="<?php print APP_URL; ?>build/view/<?php print $build->getId(); ?>">
|
||||
Build #<?php print $build->getId(); ?>
|
||||
<a href="<?= APP_URL; ?>build/view/<?= $build->getId(); ?>">
|
||||
Build #<?= $build->getId(); ?>
|
||||
</a>
|
||||
—
|
||||
<?php print $label; ?>
|
||||
<?= $label; ?>
|
||||
</h3>
|
||||
|
||||
<div class="timeline-body">
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
var PROJECT_ENVIRONMENT = '<?= $environment; ?>';
|
||||
var PROJECT_BRANCH = '<?= $branch; ?>';
|
||||
var PER_PAGE = <?= $perPage; ?>;
|
||||
var PAGE = <?= $page; ?>;
|
||||
</script>
|
||||
|
||||
<div class="clearfix" style="margin-bottom: 20px;">
|
||||
|
@ -15,34 +16,37 @@
|
|||
<?php Lang::out('delete_project'); ?>
|
||||
</a>
|
||||
|
||||
<?php
|
||||
$build_url = APP_URL . 'project/build/' . $project->getId();
|
||||
?>
|
||||
<div class="pull-right btn-group">
|
||||
<?php if (!$project->getArchived()): ?>
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if (!empty($environment)): ?>
|
||||
<a class="btn btn-danger" href="<?= APP_URL . 'project/build/' . $project->getId(); ?>/environment/<?= urlencode($environment); ?>?debug=1">
|
||||
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['type' => 'environment', 'id' => $environment, 'debug' => 1]); ?>">
|
||||
<?php Lang::out('build_now_debug'); ?>
|
||||
</a>
|
||||
<?php elseif (!empty($branch)): ?>
|
||||
<a class="btn btn-danger" href="<?= APP_URL . 'project/build/' . $project->getId(); ?>/branch/<?= urlencode($branch); ?>?debug=1">
|
||||
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['type' => 'branch', 'id' => $branch, 'debug' => 1]); ?>">
|
||||
<?php Lang::out('build_now_debug'); ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a class="btn btn-danger" href="<?= APP_URL . 'project/build/' . $project->getId(); ?>?debug=1">
|
||||
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['debug' => 1]); ?>">
|
||||
<?php Lang::out('build_now_debug'); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($environment)): ?>
|
||||
<a class="btn btn-success" href="<?= APP_URL . 'project/build/' . $project->getId(); ?>/environment/<?= urlencode($environment); ?>">
|
||||
<a class="btn btn-success" href="<?= $build_url . '?' . http_build_query(['type' => 'environment', 'id' => $environment]); ?>">
|
||||
<?php Lang::out('build_now'); ?>
|
||||
</a>
|
||||
<?php elseif (!empty($branch)): ?>
|
||||
<a class="btn btn-success" href="<?= APP_URL . 'project/build/' . $project->getId(); ?>/branch/<?= urlencode($branch); ?>">
|
||||
<a class="btn btn-success" href="<?= $build_url . '?' . http_build_query(['type' => 'branch', 'id' => $branch]); ?>">
|
||||
<?php Lang::out('build_now'); ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a class="btn btn-success" href="<?= APP_URL . 'project/build/' . $project->getId(); ?>">
|
||||
<a class="btn btn-success" href="<?= $build_url . '?' . http_build_query(['debug' => 1]); ?>">
|
||||
<?php Lang::out('build_now'); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
@ -115,10 +119,19 @@
|
|||
|
||||
print '<div><ul class="pagination">';
|
||||
|
||||
$project_url = APP_URL . 'project/view/' . $project->getId() . ((!empty($branch)) ? '/' . urlencode($branch) : '');
|
||||
$project_url = APP_URL . 'project/view/' . $project->getId();
|
||||
$params = [];
|
||||
|
||||
if (!empty($branch)) {
|
||||
$params['branch'] = $branch;
|
||||
}
|
||||
|
||||
if (!empty($environment)) {
|
||||
$params['environment'] = $environment;
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
print '<li><a href="' . $project_url . '?p='.($page == 1 ? '1' : $page - 1).'">'.Lang::get('prev_link').'</a></li>';
|
||||
print '<li><a href="' . $project_url . '?' . http_build_query(array_merge($params, ['page' => ($page - 1)])) . '">' . Lang::get('prev_link') . '</a></li>';
|
||||
}
|
||||
|
||||
if ($pages > 1) {
|
||||
|
@ -136,27 +149,29 @@
|
|||
}
|
||||
|
||||
if ($start > 1) {
|
||||
print '<li><a href="' . $project_url . '">1...</a></li>';
|
||||
print '<li><a href="' . $project_url . '?' . http_build_query($params) . '">1...</a></li>';
|
||||
}
|
||||
|
||||
for($i = $start; $i <= $end; $i++)
|
||||
{
|
||||
if ($pages > $end && $i == $pages) continue;
|
||||
if ($pages > $end && $i == $pages) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($i == $page) {
|
||||
print '<li class="bg-blue"><span>' . $i . '</span></li>';
|
||||
} else {
|
||||
print '<li><a href="' . $project_url . '?p=' . $i . '">' . $i . '</a></li>';
|
||||
print '<li><a href="' . $project_url . '?' . http_build_query(array_merge($params, ['page' => $i])) . '">' . $i . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($pages > $end) {
|
||||
print '<li><a href="' . $project_url . '?p='.$pages.'">...'.$pages.'</a></li>';
|
||||
print '<li><a href="' . $project_url . '?' . http_build_query(array_merge($params, ['page' => $pages])) . '">...' . $pages . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $pages - 1) {
|
||||
print '<li><a href="' . $project_url . '?p='.($page == $pages ? $pages : $page + 1).'">'.Lang::get('next_link').'</a></li>';
|
||||
if ($page < ($pages - 1)) {
|
||||
print '<li><a href="' . $project_url . '?' . http_build_query(array_merge($params, ['page' => ($page == $pages) ? $pages : ($page + 1)])) . '">' . Lang::get('next_link') . '</a></li>';
|
||||
}
|
||||
|
||||
print '</ul></div>';
|
||||
|
|
|
@ -173,7 +173,7 @@
|
|||
<ul class="treeview-menu">
|
||||
<?php foreach($group['projects'] as $project): ?>
|
||||
<li>
|
||||
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>">
|
||||
<a href="<?php print APP_URL; ?>project/view/<?= $project->getId(); ?>">
|
||||
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
|
||||
<span><?php print $project->getTitle(); ?></span>
|
||||
</a>
|
||||
|
|
Loading…
Reference in a new issue