refactoring
This commit is contained in:
parent
a9f335b9f0
commit
e07371b6fb
|
@ -3,5 +3,9 @@ home:
|
||||||
defaults: {_controller: Gist\Controller\EditController::createAction, _locale: en}
|
defaults: {_controller: Gist\Controller\EditController::createAction, _locale: en}
|
||||||
|
|
||||||
view:
|
view:
|
||||||
path: /{gist}/{commit}
|
path: /view/{gist}/{commit}
|
||||||
defaults: {_controller: Gist\Controller\ViewController::viewAction, _locale: en, commit: 0}
|
defaults: {_controller: Gist\Controller\ViewController::viewAction, _locale: en, commit: 0}
|
||||||
|
|
||||||
|
revisions:
|
||||||
|
path: /revs/{gist}
|
||||||
|
defaults: {_controller: Gist\Controller\ViewController::revisionsAction, _locale: en}
|
||||||
|
|
|
@ -35,17 +35,41 @@ class ViewController
|
||||||
'gist' => $gist,
|
'gist' => $gist,
|
||||||
'type' => $gist->getType(),
|
'type' => $gist->getType(),
|
||||||
'history' => $history,
|
'history' => $history,
|
||||||
|
'commit' => $commit,
|
||||||
'content' => $app['gist']->highlight($gist->getType(), $content),
|
'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)
|
protected function notFoundResponse(Application $app)
|
||||||
{
|
{
|
||||||
return $app['twig']->render('View/notFound.html.twig');
|
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) {
|
if ($commit === 0) {
|
||||||
$commit = $history[0]['commit'];
|
$commit = $history[0]['commit'];
|
||||||
|
|
94
src/Gist/Resources/views/View/revisions.html.twig
Normal file
94
src/Gist/Resources/views/View/revisions.html.twig
Normal 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 %}
|
|
@ -12,10 +12,10 @@
|
||||||
{% if not gist.cipher %}
|
{% if not gist.cipher %}
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<a href="#view" data-toggle="tab">View</a>
|
<a href="{{ path('view', {gist: gist.file}) }}">View</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="#revisions" data-toggle="tab">
|
<a href="{{ path('revisions', {gist: gist.file}) }}">
|
||||||
Révisions
|
Révisions
|
||||||
<span class="badge">{{ history|length }}</span>
|
<span class="badge">{{ history|length }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -46,6 +46,11 @@
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div id="view" class="tab-pane active in">
|
<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-toolbar">
|
||||||
<div class="btn-group" id="languages">
|
<div class="btn-group" id="languages">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
|
Loading…
Reference in a new issue