#4 Account: more features to manage gists
This commit is contained in:
parent
f36c0b8eeb
commit
143299fad8
|
@ -45,8 +45,13 @@ logout:
|
||||||
path: /my/logout
|
path: /my/logout
|
||||||
|
|
||||||
my:
|
my:
|
||||||
path: /my
|
path: /my/{page}
|
||||||
defaults: {_controller: Gist\Controller\MyController::myAction, _locale: en}
|
defaults:
|
||||||
|
_controller: Gist\Controller\MyController::myAction
|
||||||
|
_locale: en
|
||||||
|
page: 1
|
||||||
|
requirements:
|
||||||
|
page: \d+
|
||||||
|
|
||||||
revisions:
|
revisions:
|
||||||
path: /revs/{gist}
|
path: /revs/{gist}
|
||||||
|
|
|
@ -33,6 +33,7 @@ gist:
|
||||||
download: 'Download'
|
download: 'Download'
|
||||||
clone: 'Clone'
|
clone: 'Clone'
|
||||||
embed: 'Embed:'
|
embed: 'Embed:'
|
||||||
|
add: 'New'
|
||||||
|
|
||||||
date:
|
date:
|
||||||
format: 'Y-m-d h:i:s'
|
format: 'Y-m-d h:i:s'
|
||||||
|
@ -73,6 +74,8 @@ form:
|
||||||
yes: 'Yes'
|
yes: 'Yes'
|
||||||
no: 'No'
|
no: 'No'
|
||||||
submit: 'Send'
|
submit: 'Send'
|
||||||
|
success:
|
||||||
|
gist: 'Gist removed.'
|
||||||
type:
|
type:
|
||||||
label: 'Language: %value%'
|
label: 'Language: %value%'
|
||||||
choice:
|
choice:
|
||||||
|
|
|
@ -33,6 +33,7 @@ gist:
|
||||||
download: 'Télécharger'
|
download: 'Télécharger'
|
||||||
clone: 'Clôner'
|
clone: 'Clôner'
|
||||||
embed: 'Insérer : '
|
embed: 'Insérer : '
|
||||||
|
add: 'Ajouter'
|
||||||
|
|
||||||
date:
|
date:
|
||||||
format: 'd/m/Y H\hi s\s'
|
format: 'd/m/Y H\hi s\s'
|
||||||
|
@ -74,6 +75,8 @@ form:
|
||||||
yes: 'Oui'
|
yes: 'Oui'
|
||||||
no: 'Non'
|
no: 'Non'
|
||||||
submit: 'Envoyer'
|
submit: 'Envoyer'
|
||||||
|
success:
|
||||||
|
gist: 'Votre Gist a bien a été supprimé.'
|
||||||
type:
|
type:
|
||||||
label: 'Langage : %value%'
|
label: 'Langage : %value%'
|
||||||
choice:
|
choice:
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Gist\Controller;
|
namespace Gist\Controller;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Gist\Model\GistQuery;
|
||||||
|
use Gist\Form\DeleteGistForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MyController
|
* Class MyController
|
||||||
|
@ -10,8 +12,44 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
*/
|
*/
|
||||||
class MyController extends Controller
|
class MyController extends Controller
|
||||||
{
|
{
|
||||||
public function myAction(Request $request)
|
public function myAction(Request $request, $page)
|
||||||
{
|
{
|
||||||
return $this->render('My/my.html.twig');
|
$page = (int) $page;
|
||||||
|
$gists = $this->getUser()->getGistsPager($page);
|
||||||
|
|
||||||
|
$app = $this->getApp();
|
||||||
|
$form = new DeleteGistForm($app['form.factory'], $app['translator']);
|
||||||
|
$form = $form->build()->getForm();
|
||||||
|
|
||||||
|
if ($request->isMethod('post')) {
|
||||||
|
$form->submit($request);
|
||||||
|
|
||||||
|
if ($form->isValid()) {
|
||||||
|
$id = (int) $form->getData()['id'];
|
||||||
|
|
||||||
|
foreach ($gists as $gist) {
|
||||||
|
if ($gist->getId() === $id) {
|
||||||
|
$gist->delete();
|
||||||
|
$deleted = true;
|
||||||
|
$gists = $this->getUser()->getGistsPager($page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextPage = min($page + 1, $gists->getLastPage());
|
||||||
|
$previousPage = max($page - 1, 1);
|
||||||
|
|
||||||
|
return $this->render(
|
||||||
|
'My/my.html.twig',
|
||||||
|
array(
|
||||||
|
'gists' => $gists,
|
||||||
|
'page' => $page,
|
||||||
|
'form' => $form->createView(),
|
||||||
|
'deleted' => !empty($deleted),
|
||||||
|
'nextPage' => $nextPage,
|
||||||
|
'previousPage' => $previousPage,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/Gist/Form/DeleteGistForm.php
Normal file
28
src/Gist/Form/DeleteGistForm.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Gist\Form;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DeleteGistForm
|
||||||
|
* @author Simon Vieille <simon@deblan.fr>
|
||||||
|
*/
|
||||||
|
class DeleteGistForm extends AbstractForm
|
||||||
|
{
|
||||||
|
public function build(array $options = array())
|
||||||
|
{
|
||||||
|
$this->builder->add(
|
||||||
|
'id',
|
||||||
|
'hidden',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'constraints' => array(
|
||||||
|
new NotBlank(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->builder;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,4 +27,12 @@ class User extends BaseUser implements UserInterface
|
||||||
|
|
||||||
return parent::getGists($criteria, $con);
|
return parent::getGists($criteria, $con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGistsPager($page, $maxPerPage = 10)
|
||||||
|
{
|
||||||
|
return GistQuery::create()
|
||||||
|
->filterByUser($this)
|
||||||
|
->orderByCreatedAt(Criteria::DESC)
|
||||||
|
->paginate($page, $maxPerPage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,19 +4,85 @@
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
{% if deleted %}
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<p>{{ 'form.success.gist'|trans }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
{{ 'my.title'|trans }}
|
{{ 'my.title'|trans }}
|
||||||
|
<div class="pull-right actions">
|
||||||
|
<a href="{{ path('home', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm">
|
||||||
|
<span class="glyphicon glyphicon-copy"></span>
|
||||||
|
{{ 'gist.action.add'|trans }}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
{% set gists = user.gists %}
|
<div id="form-deletion">
|
||||||
|
{{ form(form) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if gists|length == 0 %}
|
{% if gists.nbResults == 0 %}
|
||||||
{{ 'my.nothing'|trans }}
|
{{ 'my.nothing'|trans }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for gist in user.gists %}
|
{% set pager %}
|
||||||
|
{% if gists.haveToPaginate %}
|
||||||
|
<ul class="pagination">
|
||||||
|
<li>
|
||||||
|
{% set params = app.request.attributes.get('_route_params')|merge({page: 1}) %}
|
||||||
|
<a href="{{ path('my', params) }}" aria-label="Previous">
|
||||||
|
<span aria-hidden="true">
|
||||||
|
<span class="glyphicon glyphicon-step-backward"></span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
{% set params = app.request.attributes.get('_route_params')|merge({page: previousPage}) %}
|
||||||
|
<a href="{{ path('my', params) }}" aria-label="Previous">
|
||||||
|
<span aria-hidden="true">
|
||||||
|
<span class="glyphicon glyphicon glyphicon-chevron-left"></span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{% for p in gists.links(10) %}
|
||||||
|
<li {% if p == page %}class="active"{% endif %}>
|
||||||
|
{% set params = app.request.attributes.get('_route_params')|merge({page: p}) %}
|
||||||
|
<a href="{{ path('my', params) }}">{{ p }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<li>
|
||||||
|
{% set params = app.request.attributes.get('_route_params')|merge({page: nextPage}) %}
|
||||||
|
<a href="{{ path('my', params) }}" aria-label="Previous">
|
||||||
|
<span aria-hidden="true">
|
||||||
|
<span class="glyphicon glyphicon glyphicon-chevron-right"></span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
{% set params = app.request.attributes.get('_route_params')|merge({page: 1}) %}
|
||||||
|
<a href="{{ path('my', params) }}" aria-label="Previous">
|
||||||
|
<span aria-hidden="true">
|
||||||
|
<span class="glyphicon glyphicon-step-forward"></span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
{% endset %}
|
||||||
|
|
||||||
|
{{ pager }}
|
||||||
|
|
||||||
|
{% for gist in gists %}
|
||||||
<div class="commit">
|
<div class="commit">
|
||||||
<p>
|
<p>
|
||||||
<strong>{{ gist.title ? gist.title : 'gist.untitled'|trans }}</strong>,
|
<strong>{{ gist.title ? gist.title : 'gist.untitled'|trans }}</strong>,
|
||||||
|
@ -37,9 +103,15 @@
|
||||||
<span class="glyphicon glyphicon-lock"></span>
|
<span class="glyphicon glyphicon-lock"></span>
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<button class="btn btn-delete btn-sm" data-id="{{ gist.id }}">
|
||||||
|
<span class="glyphicon btn-delete glyphicon-remove" data-id="{{ gist.id }}"></span>
|
||||||
|
</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{{ pager }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -77,3 +77,8 @@ div.diff {
|
||||||
#options {
|
#options {
|
||||||
margin-bottom: 17px;
|
margin-bottom: 17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-delete {
|
||||||
|
background: #DE3336;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,13 @@ var editorEvents = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var myEvents = function() {
|
||||||
|
$('.btn-delete').click(function() {
|
||||||
|
$('#form_id').val($(this).data('id'));
|
||||||
|
$('#form-deletion form').submit();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var mainEditorEvents = function() {
|
var mainEditorEvents = function() {
|
||||||
$('.cipher-input').change(function() {
|
$('.cipher-input').change(function() {
|
||||||
if ($('.cipher-input:checked').val() === 'yes') {
|
if ($('.cipher-input:checked').val() === 'yes') {
|
||||||
|
@ -142,6 +149,7 @@ var viewerEvents = function() {
|
||||||
var bootstrap = function() {
|
var bootstrap = function() {
|
||||||
editorEvents();
|
editorEvents();
|
||||||
viewerEvents();
|
viewerEvents();
|
||||||
|
myEvents();
|
||||||
mainEditorEvents();
|
mainEditorEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue