refactoring

This commit is contained in:
Simon Vieille 2015-05-07 00:51:52 +02:00
parent a9f335b9f0
commit e07371b6fb
4 changed files with 131 additions and 4 deletions

View file

@ -3,5 +3,9 @@ home:
defaults: {_controller: Gist\Controller\EditController::createAction, _locale: en}
view:
path: /{gist}/{commit}
path: /view/{gist}/{commit}
defaults: {_controller: Gist\Controller\ViewController::viewAction, _locale: en, commit: 0}
revisions:
path: /revs/{gist}
defaults: {_controller: Gist\Controller\ViewController::revisionsAction, _locale: en}

View file

@ -35,17 +35,41 @@ class ViewController
'gist' => $gist,
'type' => $gist->getType(),
'history' => $history,
'commit' => $commit,
'content' => $app['gist']->highlight($gist->getType(), $content),
)
);
}
public function revisionsAction(Request $request, Application $app, $gist)
{
$gist = GistQuery::create()->findOneByFile($gist);
if (null === $gist) {
return $this->notFoundResponse($app);
}
$history = $app['gist']->getHistory($gist);
if (empty($history)) {
return $this->notFoundResponse($app);
}
return $app['twig']->render(
'View/revisions.html.twig',
array(
'gist' => $gist,
'history' => $history,
)
);
}
protected function notFoundResponse(Application $app)
{
return $app['twig']->render('View/notFound.html.twig');
}
protected function getContentByCommit(Application $app, Gist $gist, $commit, $history)
protected function getContentByCommit(Application $app, Gist $gist, &$commit, $history)
{
if ($commit === 0) {
$commit = $history[0]['commit'];

View file

@ -0,0 +1,94 @@
{% extends 'base.html.twig' %}
{% block css %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
{{ parent() }}
{% endblock %}
{% block body %}
<div class="row">
<div class="col-md-12">
{% if not gist.cipher %}
<ul class="nav nav-tabs">
<li>
<a href="{{ path('view', {gist: gist.file}) }}">View</a>
</li>
<li class="active">
<a href="{{ path('revisions', {gist: gist.file}) }}">
Révisions
<span class="badge">{{ history|length }}</span>
</a>
</li>
</ul>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
{% if not gist.cipher %}
<div class="pull-right actions">
<a class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
RAW
</a>
<a class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
Download
</a>
<a class="btn btn-success btn-sm">
<span class="glyphicon glyphicon-copy"></span>
Fork
</a>
</div>
{% endif %}
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
</div>
<div class="panel-body">
<div class="tab-content">
{% if not gist.cipher %}
<div id="revisions" class="tab-pane in active">
{% for commit in history %}
<div class="commit">
<p>
<a href="{{ path('view', {gist: gist.file, commit: commit.commit}) }}" class="btn btn-warning btn-sm">
{{ commit.commit|slice(0, 10) }}
</a>
{% if loop.first %}<span class="btn btn-info btn-sm">init</span>{% endif %}
{% if not loop.first %}
<a href="#diff-{{ loop.index }}" data-target="#diff-{{ loop.index }}" class="btn btn-default btn-sm show-diff">
diff
</a>
{% endif %}
</p>
<p>
{{ commit.date|date('date.format'|trans) }}
</p>
<div>
{% if not loop.first %}
<div class="diff" id="diff-{{ loop.index }}">
{{ commit.diff|raw }}
</div>
{% endif %}
</div>
</div>
{% if not loop.last %}
<hr />
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
{{ parent() }}
{% endblock %}

View file

@ -12,10 +12,10 @@
{% if not gist.cipher %}
<ul class="nav nav-tabs">
<li class="active">
<a href="#view" data-toggle="tab">View</a>
<a href="{{ path('view', {gist: gist.file}) }}">View</a>
</li>
<li>
<a href="#revisions" data-toggle="tab">
<a href="{{ path('revisions', {gist: gist.file}) }}">
Révisions
<span class="badge">{{ history|length }}</span>
</a>
@ -46,6 +46,11 @@
<div class="panel-body">
<div class="tab-content">
<div id="view" class="tab-pane active in">
<div class="pull-right">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
</div>
<div class="btn-toolbar">
<div class="btn-group" id="languages">
<div class="btn-group">