mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
Adding very simple pagination to commits, both repository and history. Fixes #4
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
$app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$commits = $repository->getCommits();
|
||||
$pagenumber = $app['request']->get('page');
|
||||
$pagenumber = (empty($pagenumber)) ? 0 : $pagenumber;
|
||||
$commits = $repository->getCommits(null, $pagenumber);
|
||||
|
||||
foreach ($commits as $commit) {
|
||||
$date = $commit->getDate();
|
||||
@@ -13,6 +15,7 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) {
|
||||
return $app['twig']->render('commits.twig', array(
|
||||
'baseurl' => $app['baseurl'],
|
||||
'page' => 'commits',
|
||||
'pagenumber' => $pagenumber,
|
||||
'repo' => $repo,
|
||||
'branch' => $branch,
|
||||
'branches' => $repository->getBranches(),
|
||||
@@ -25,7 +28,9 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) {
|
||||
|
||||
$app->get('{repo}/commits/{branch}/{file}/', function($repo, $branch, $file) use($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$commits = $repository->getCommits($file);
|
||||
$pagenumber = $app['request']->get('page');
|
||||
$pagenumber = (empty($pagenumber)) ? 0 : $pagenumber;
|
||||
$commits = $repository->getCommits($file, $pagenumber);
|
||||
|
||||
foreach ($commits as $commit) {
|
||||
$date = $commit->getDate();
|
||||
@@ -36,6 +41,7 @@ $app->get('{repo}/commits/{branch}/{file}/', function($repo, $branch, $file) use
|
||||
return $app['twig']->render('commits.twig', array(
|
||||
'baseurl' => $app['baseurl'],
|
||||
'page' => 'commits',
|
||||
'pagenumber' => $pagenumber,
|
||||
'repo' => $repo,
|
||||
'branch' => $branch,
|
||||
'branches' => $repository->getBranches(),
|
||||
|
||||
@@ -22,7 +22,7 @@ $app['autoloader']->registerNamespace('Application', __DIR__.'/lib');
|
||||
$app->register(new Silex\Provider\TwigServiceProvider(), array(
|
||||
'twig.path' => __DIR__.'/views',
|
||||
'twig.class_path' => __DIR__.'/vendor',
|
||||
'twig.options' => array('cache' => __DIR__.'/cache'),
|
||||
// 'twig.options' => array('cache' => __DIR__.'/cache'),
|
||||
));
|
||||
$app->register(new Git\GitServiceProvider(), array(
|
||||
'git.client' => $config['git']['client'],
|
||||
|
||||
@@ -222,15 +222,22 @@ class Repository
|
||||
* @access public
|
||||
* @return array Commit log
|
||||
*/
|
||||
public function getCommits($file = null)
|
||||
public function getCommits($file = null, $page = 0)
|
||||
{
|
||||
$command = 'log --pretty=format:\'"%h": {"hash": "%H", "short_hash": "%h", "tree": "%T", "parent": "%P", "author": "%an", "author_email": "%ae", "date": "%at", "commiter": "%cn", "commiter_email": "%ce", "commiter_date": "%ct", "message": "%f"}\'';
|
||||
$page = 15 * $page;
|
||||
$pager = "--skip=$page --max-count=15";
|
||||
$command = 'log ' . $pager . ' --pretty=format:\'"%h": {"hash": "%H", "short_hash": "%h", "tree": "%T", "parent": "%P", "author": "%an", "author_email": "%ae", "date": "%at", "commiter": "%cn", "commiter_email": "%ce", "commiter_date": "%ct", "message": "%f"}\'';
|
||||
|
||||
if ($file) {
|
||||
$command .= " $file";
|
||||
}
|
||||
|
||||
$logs = $this->getClient()->run($this, $command);
|
||||
|
||||
if (empty($logs)) {
|
||||
throw new \RuntimeException('No commit log available');
|
||||
}
|
||||
|
||||
$logs = str_replace("\n", ',', $logs);
|
||||
$logs = json_decode("{ $logs }", true);
|
||||
|
||||
|
||||
@@ -39,6 +39,17 @@
|
||||
</table>
|
||||
{% endfor %}
|
||||
|
||||
<ul class="pager">
|
||||
{% if pagenumber != 0 %}
|
||||
<li class="previous">
|
||||
<a href="?page={{ pagenumber - 1 }}">← Older</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="next">
|
||||
<a href="?page={{ pagenumber + 1 }}">Newer →</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
{% include 'footer.twig' %}
|
||||
|
||||
Reference in New Issue
Block a user