mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
refactored the tree controller
This commit is contained in:
@@ -1,53 +1,17 @@
|
||||
<?php
|
||||
|
||||
$app->get('{repo}/', function($repo) use($app) {
|
||||
$app->get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$defaultBranch = $repository->getHead();
|
||||
$tree = $repository->getTree($defaultBranch);
|
||||
|
||||
return $app['twig']->render('tree.twig', array(
|
||||
'page' => 'files',
|
||||
'files' => $tree->output(),
|
||||
'repo' => $repo,
|
||||
'branch' => $defaultBranch,
|
||||
'path' => '',
|
||||
'parent' => '',
|
||||
'breadcrumbs' => array(),
|
||||
'branches' => $repository->getBranches(),
|
||||
'tags' => $repository->getTags(),
|
||||
'readme' => $app['utils']->getReadme($repo, $defaultBranch),
|
||||
));
|
||||
})->assert('repo', '[\w-._]+')
|
||||
->bind('repository');
|
||||
|
||||
$app->get('{repo}/tree/{branch}/', function($repo, $branch) use($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$tree = $repository->getTree($branch);
|
||||
|
||||
return $app['twig']->render('tree.twig', array(
|
||||
'page' => 'files',
|
||||
'files' => $tree->output(),
|
||||
'repo' => $repo,
|
||||
'branch' => $branch,
|
||||
'path' => '',
|
||||
'parent' => '',
|
||||
'breadcrumbs' => array(),
|
||||
'branches' => $repository->getBranches(),
|
||||
'tags' => $repository->getTags(),
|
||||
'readme' => $app['utils']->getReadme($repo, $branch),
|
||||
));
|
||||
})->assert('repo', '[\w-._]+')
|
||||
->assert('branch', '[\w-._]+')
|
||||
->bind('tree');
|
||||
|
||||
$app->get('{repo}/tree/{branch}/{tree}/', function($repo, $branch, $tree) use($app) {
|
||||
$repository = $app['git']->getRepository($app['git.repos'] . $repo);
|
||||
$files = $repository->getTree("$branch:'$tree'/");
|
||||
if (!$branch) {
|
||||
$branch = $repository->getHead();
|
||||
}
|
||||
$files = $repository->getTree($tree ? "$branch:'$tree'/" : $branch);
|
||||
$breadcrumbs = $app['utils']->getBreadcrumbs($tree);
|
||||
|
||||
$parent = null;
|
||||
if (($slash = strrpos($tree, '/')) !== false) {
|
||||
$parent = substr($tree, 0, $slash);
|
||||
} else {
|
||||
} elseif (!empty($tree)) {
|
||||
$parent = '';
|
||||
}
|
||||
|
||||
@@ -56,14 +20,25 @@ $app->get('{repo}/tree/{branch}/{tree}/', function($repo, $branch, $tree) use($a
|
||||
'files' => $files->output(),
|
||||
'repo' => $repo,
|
||||
'branch' => $branch,
|
||||
'path' => "$tree/",
|
||||
'path' => $tree ? $tree.'/' : $tree,
|
||||
'parent' => $parent,
|
||||
'breadcrumbs' => $breadcrumbs,
|
||||
'branches' => $repository->getBranches(),
|
||||
'tags' => $repository->getTags(),
|
||||
'readme' => $app['utils']->getReadme($repo, $branch),
|
||||
));
|
||||
})->assert('tree', '.+')
|
||||
->assert('repo', '[\w-._]+')
|
||||
})->assert('repo', '[\w-._]+')
|
||||
->assert('branch', '[\w-._]+')
|
||||
->bind('tree_dir');
|
||||
->assert('tree', '.+')
|
||||
->bind('tree');
|
||||
|
||||
$app->get('{repo}/{branch}/', function($repo, $branch) use($app, $treeController) {
|
||||
return $treeController($repo, $branch);
|
||||
})->assert('repo', '[\w-._]+')
|
||||
->assert('branch', '[\w-._]+')
|
||||
->bind('branch');
|
||||
|
||||
$app->get('{repo}/', function($repo) use($app, $treeController) {
|
||||
return $treeController($repo);
|
||||
})->assert('repo', '[\w-._]+')
|
||||
->bind('repository');
|
||||
|
||||
@@ -24,6 +24,10 @@ class Utils
|
||||
*/
|
||||
public function getBreadcrumbs($spec)
|
||||
{
|
||||
if (!$spec) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$paths = explode('/', $spec);
|
||||
|
||||
foreach ($paths as $i => $path) {
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li class="dropdown-header">Branches</li>
|
||||
{% for item in branches %}
|
||||
<li><a href="{{ path('tree', {repo: repo, branch: item}) }}">{{ item }}</a></li>
|
||||
<li><a href="{{ path('branch', {repo: repo, branch: item}) }}">{{ item }}</a></li>
|
||||
{% endfor %}
|
||||
{% if tags %}
|
||||
<li class="dropdown-header">Tags</li>
|
||||
{% for item in tags %}
|
||||
<li><a href="{{ path('tree', {repo: repo, branch: item}) }}">{{ item }}</a></li>
|
||||
<li><a href="{{ path('branch', {repo: repo, branch: item}) }}">{{ item }}</a></li>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="{{ path('repository', {repo: repo}) }}">{{ repo }}</a></li>
|
||||
{% for breadcrumb in breadcrumbs %}
|
||||
<span class="divider">/</span>
|
||||
<li{% if loop.last %} class="active"{% endif %}>{% if not loop.last %}<a href="{{ path('tree_dir', {repo: repo, branch: branch, tree: breadcrumb.path}) }}">{{ breadcrumb.dir }}</a>{% endif %}{% if loop.last %}{{ breadcrumb.dir }}{% endif %}</li>
|
||||
<span class="divider">/</span>
|
||||
<li{% if loop.last %} class="active"{% endif %}>{% if not loop.last %}<a href="{{ path('tree', {repo: repo, branch: branch, tree: breadcrumb.path}) }}">{{ breadcrumb.dir }}</a>{% endif %}{% if loop.last %}{{ breadcrumb.dir }}{% endif %}</li>
|
||||
{% endfor %}
|
||||
|
||||
{% block extra %}{% endblock %}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<div class="commit-view">
|
||||
<div class="commit-header">
|
||||
<span class="pull-right"><a class="btn btn-small" href="{{ path('tree', {repo: repo, branch: commit.getHash}) }}" title="Browse code at this point in history"><i class="icon-list-alt"></i> Browse code</a></span>
|
||||
<span class="pull-right"><a class="btn btn-small" href="{{ path('branch', {repo: repo, branch: commit.getHash}) }}" title="Browse code at this point in history"><i class="icon-list-alt"></i> Browse code</a></span>
|
||||
<h4>{{ commit.getMessage }}</h4>
|
||||
</div>
|
||||
<div class="commit-body">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<ul class="nav nav-tabs">
|
||||
<li{% if page == 'files' %} class="active"{% endif %}><a href="{{ path('tree', {repo: repo, branch: branch}) }}">Files</a></li>
|
||||
<li{% if page == 'files' %} class="active"{% endif %}><a href="{{ path('branch', {repo: repo, branch: branch}) }}">Files</a></li>
|
||||
<li{% if page == 'commits' %} class="active"{% endif %}><a href="{{ path('commits', {repo: repo, branch: branch}) }}">Commits</a></li>
|
||||
<li{% if page == 'stats' %} class="active"{% endif %}><a href="{{ path('stats', {repo: repo, branch: branch}) }}">Stats</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
@@ -18,9 +18,15 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if parent is not empty %}
|
||||
{% if parent is not null %}
|
||||
<tr>
|
||||
<td><i class="icon-spaced"></i> <a href="{{ path('tree_dir', {repo: repo, branch: branch, tree: parent}) }}">..</a></td>
|
||||
<td><i class="icon-spaced"></i>
|
||||
{% if not parent %}
|
||||
<a href="{{ path('branch', {repo: repo, branch: branch}) }}">..</a>
|
||||
{% else %}
|
||||
<a href="{{ path('tree', {repo: repo, branch: branch, tree: parent}) }}">..</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@@ -29,7 +35,7 @@
|
||||
<tr>
|
||||
<td><i class="{{ file.type == "folder" or file.type == "symlink" ? "icon-folder-open" : "icon-file" }} icon-spaced"></i> <a href="
|
||||
{%- if file.type == "folder" or file.type == "symlink" %}
|
||||
{{ path('tree_dir', {repo: repo, branch: branch, tree: path ~ (file.type == "symlink" ? file.path : file.name)}) }}
|
||||
{{ path('tree', {repo: repo, branch: branch, tree: path ~ (file.type == "symlink" ? file.path : file.name)}) }}
|
||||
{% else %}
|
||||
{{ path('blob', {repo: repo, branch: branch, file: path ~ (file.type == "symlink" ? file.path : file.name)}) }}
|
||||
{% endif -%}
|
||||
|
||||
Reference in New Issue
Block a user