diff --git a/boot.php b/boot.php index 5e36efe..2d1c087 100644 --- a/boot.php +++ b/boot.php @@ -14,5 +14,6 @@ $app->mount('', new GitList\Controller\MainController()); $app->mount('', new GitList\Controller\BlobController()); $app->mount('', new GitList\Controller\CommitController()); $app->mount('', new GitList\Controller\TreeController()); +$app->mount('', new GitList\Controller\NetworkController()); return $app; diff --git a/src/GitList/Controller/NetworkController.php b/src/GitList/Controller/NetworkController.php new file mode 100644 index 0000000..e1aa100 --- /dev/null +++ b/src/GitList/Controller/NetworkController.php @@ -0,0 +1,75 @@ +get('{repo}/network/{branch}/{page}.json', function($repo, $branch, $page) use ($app) { + /** @var $repository Repository */ + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + if ($branch === null) { + $branch = $repository->getHead(); + } + + $pager = $app['util.view']->getPager($page, $repository->getTotalCommits($branch)); + $commits = $repository->getPaginatedCommits($branch, $pager['current']); + + // format the commits for the json reponse + $jsonFormattedCommits = array(); + foreach( $commits as $commit ) { + /** @var $commit Commit */ + $jsonFormattedCommits[$commit->getHash()] = array( + 'hash' => $commit->getHash(), + 'parentsHash' => $commit->getParentsHash(), + 'date' => $commit->getDate()->format('U'), + 'message' => htmlentities( $commit->getMessage() ), + 'author' => array( + 'name' => $commit->getAuthor()->getName(), + 'email' => $commit->getAuthor()->getEmail() + ) + ); + } + + return $app->json(array( + 'repo' => $repo, + 'branch' => $branch, + 'nextPage' => $pager['last'] !== $pager['current'] ? $pager['next'] : null, + 'start' => $commits[0]->getHash(), + 'commits' => $jsonFormattedCommits + ), 200); + })->assert('repo', $app['util.routing']->getRepositoryRegex()) + ->assert('branch', $app['util.routing']->getBranchRegex()) + ->value('branch', null) + ->assert('page', '\d+') + ->value('page', '0') + ->bind('networkData'); + + + $route->get('{repo}/network/{branch}', function($repo, $branch) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + if ($branch === null) { + $branch = $repository->getHead(); + } + + return $app['twig']->render('network.twig', array( + 'repo' => $repo, + 'branch' => $branch, + )); + })->assert('repo', $app['util.routing']->getRepositoryRegex()) + ->assert('branch', $app['util.routing']->getBranchRegex()) + ->value('branch', null) + ->bind('network'); + + return $route; + } +} diff --git a/views/layout.twig b/views/layout.twig index 9addf44..cba683c 100644 --- a/views/layout.twig +++ b/views/layout.twig @@ -12,9 +12,11 @@
{% block body %}{% endblock %} + +