aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-04-27 15:58:32 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2017-05-02 15:28:39 +0200
commitc37515f880bd05b86e3e848cc184018295ec1920 (patch)
treec64785ee1bce798fe05d6b06e63abff0a41ffcea /src/Wallabag/UserBundle
parente1d64050ad6f54e45d3954ffac21daaee58c6240 (diff)
downloadwallabag-c37515f880bd05b86e3e848cc184018295ec1920.tar.gz
wallabag-c37515f880bd05b86e3e848cc184018295ec1920.tar.zst
wallabag-c37515f880bd05b86e3e848cc184018295ec1920.zip
Add filter to users management page
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/UserBundle')
-rw-r--r--src/Wallabag/UserBundle/Controller/ManageController.php42
-rw-r--r--src/Wallabag/UserBundle/Form/SearchUserType.php29
-rw-r--r--src/Wallabag/UserBundle/Repository/UserRepository.php15
-rw-r--r--src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig61
-rw-r--r--src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig15
5 files changed, 134 insertions, 28 deletions
diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php
index 92ee2b41..f0e3d4de 100644
--- a/src/Wallabag/UserBundle/Controller/ManageController.php
+++ b/src/Wallabag/UserBundle/Controller/ManageController.php
@@ -10,6 +10,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11use Wallabag\UserBundle\Entity\User; 11use Wallabag\UserBundle\Entity\User;
12use Wallabag\CoreBundle\Entity\Config; 12use Wallabag\CoreBundle\Entity\Config;
13use Wallabag\UserBundle\Form\SearchUserType;
13 14
14/** 15/**
15 * User controller. 16 * User controller.
@@ -146,4 +147,45 @@ class ManageController extends Controller
146 ->getForm() 147 ->getForm()
147 ; 148 ;
148 } 149 }
150
151 /**
152 * @param Request $request
153 * @param int $page
154 *
155 * @Route("/search/{page}", name="user-search", defaults={"page" = 1})
156 *
157 * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
158 * because this controller is also called inside the layout template without any page as argument
159 *
160 * @return \Symfony\Component\HttpFoundation\Response
161 */
162 public function searchFormAction(Request $request, $page = 1, $currentRoute = null)
163 {
164 // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template)
165 if (null === $currentRoute && $request->query->has('currentRoute')) {
166 $currentRoute = $request->query->get('currentRoute');
167 }
168
169 $form = $this->createForm(SearchUserType::class);
170
171 $form->handleRequest($request);
172
173 if ($form->isSubmitted() && $form->isValid()) {
174 $this->get('logger')->info('searching users');
175 $em = $this->getDoctrine()->getManager();
176
177 $searchTerm = (isset($request->get('search_user')['term']) ? $request->get('search_user')['term'] : '');
178
179 $users = $em->getRepository('WallabagUserBundle:User')->getUsersForSearch($searchTerm);
180
181 return $this->render('WallabagUserBundle:Manage:index.html.twig', array(
182 'users' => $users,
183 ));
184 }
185
186 return $this->render('WallabagUserBundle:Manage:search_form.html.twig', [
187 'form' => $form->createView(),
188 'currentRoute' => $currentRoute,
189 ]);
190 }
149} 191}
diff --git a/src/Wallabag/UserBundle/Form/SearchUserType.php b/src/Wallabag/UserBundle/Form/SearchUserType.php
new file mode 100644
index 00000000..9ce46ee1
--- /dev/null
+++ b/src/Wallabag/UserBundle/Form/SearchUserType.php
@@ -0,0 +1,29 @@
1<?php
2
3namespace Wallabag\UserBundle\Form;
4
5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\Extension\Core\Type\TextType;
7use Symfony\Component\Form\FormBuilderInterface;
8use Symfony\Component\OptionsResolver\OptionsResolver;
9
10class SearchUserType extends AbstractType
11{
12 public function buildForm(FormBuilderInterface $builder, array $options)
13 {
14 $builder
15 ->setMethod('GET')
16 ->add('term', TextType::class, [
17 'required' => true,
18 'label' => 'user.new.form_search.term_label',
19 ])
20 ;
21 }
22
23 public function configureOptions(OptionsResolver $resolver)
24 {
25 $resolver->setDefaults([
26 'csrf_protection' => false,
27 ]);
28 }
29}
diff --git a/src/Wallabag/UserBundle/Repository/UserRepository.php b/src/Wallabag/UserBundle/Repository/UserRepository.php
index f913f52d..66bbab39 100644
--- a/src/Wallabag/UserBundle/Repository/UserRepository.php
+++ b/src/Wallabag/UserBundle/Repository/UserRepository.php
@@ -52,4 +52,19 @@ class UserRepository extends EntityRepository
52 ->getQuery() 52 ->getQuery()
53 ->getSingleScalarResult(); 53 ->getSingleScalarResult();
54 } 54 }
55
56 /**
57 * Retrieves users filtered with a search term.
58 *
59 * @param string $term
60 *
61 * @return QueryBuilder
62 */
63 public function getUsersForSearch($term)
64 {
65 return $this->createQueryBuilder('u')
66 ->andWhere('lower(u.username) LIKE lower(:term) OR lower(u.email) LIKE lower(:term) OR lower(u.name) LIKE lower(:term)')->setParameter('term', '%'.$term.'%')
67 ->getQuery()
68 ->getResult();
69 }
55} 70}
diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
index daba29e4..abc02852 100644
--- a/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
+++ b/src/Wallabag/UserBundle/Resources/views/Manage/index.html.twig
@@ -8,36 +8,41 @@
8 <div class="col s12"> 8 <div class="col s12">
9 <div class="card-panel"> 9 <div class="card-panel">
10 <div class="row"> 10 <div class="row">
11 <div class="input-field col s12"> 11 <div class="col s6">
12 <p class="help">{{ 'user.description'|trans|raw }}</p> 12 <p class="help">{{ 'user.description'|trans|raw }}</p>
13
14 <table class="bordered">
15 <thead>
16 <tr>
17 <th>{{ 'user.form.username_label'|trans }}</th>
18 <th>{{ 'user.form.email_label'|trans }}</th>
19 <th>{{ 'user.form.last_login_label'|trans }}</th>
20 <th>{{ 'user.list.actions'|trans }}</th>
21 </tr>
22 </thead>
23 <tbody>
24 {% for user in users %}
25 <tr>
26 <td>{{ user.username }}</td>
27 <td>{{ user.email }}</td>
28 <td>{% if user.lastLogin %}{{ user.lastLogin|date('Y-m-d H:i:s') }}{% endif %}</td>
29 <td>
30 <a href="{{ path('user_edit', { 'id': user.id }) }}">{{ 'user.list.edit_action'|trans }}</a>
31 </td>
32 </tr>
33 {% endfor %}
34 </tbody>
35 </table>
36 <br />
37 <p>
38 <a href="{{ path('user_new') }}" class="waves-effect waves-light btn">{{ 'user.list.create_new_one'|trans }}</a>
39 </p>
40 </div> 13 </div>
14 <div class="col s6">
15 <div class="input-field">
16 {{ render(controller("WallabagUserBundle:Manage:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }}
17 </div>
18 </div>
19
20 <table class="bordered">
21 <thead>
22 <tr>
23 <th>{{ 'user.form.username_label'|trans }}</th>
24 <th>{{ 'user.form.email_label'|trans }}</th>
25 <th>{{ 'user.form2017-03-10 16:51:07.last_login_label'|trans }}</th>
26 <th>{{ 'user.list.actions'|trans }}</th>
27 </tr>
28 </thead>
29 <tbody>
30 {% for user in users %}
31 <tr>
32 <td>{{ user.username }}</td>
33 <td>{{ user.email }}</td>
34 <td>{% if user.lastLogin %}{{ user.lastLogin|date('Y-m-d H:i:s') }}{% endif %}</td>
35 <td>
36 <a href="{{ path('user_edit', { 'id': user.id }) }}">{{ 'user.list.edit_action'|trans }}</a>
37 </td>
38 </tr>
39 {% endfor %}
40 </tbody>
41 </table>
42 <br />
43 <p>
44 <a href="{{ path('user_new') }}" class="waves-effect waves-light btn">{{ 'user.list.create_new_one'|trans }}</a>
45 </p>
41 </div> 46 </div>
42 </div> 47 </div>
43 </div> 48 </div>
diff --git a/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig
new file mode 100644
index 00000000..f59388d0
--- /dev/null
+++ b/src/Wallabag/UserBundle/Resources/views/Manage/search_form.html.twig
@@ -0,0 +1,15 @@
1<form name="search" method="GET" action="{{ path('user-search')}}">
2 {% if form_errors(form) %}
3 <span class="black-text">{{ form_errors(form) }}</span>
4 {% endif %}
5
6 {% if form_errors(form.term) %}
7 <span class="black-text">{{ form_errors(form.term) }}</span>
8 {% endif %}
9
10 <i class="material-icons prefix">search</i>
11 {{ form_widget(form.term, { 'attr': {'autocomplete': 'off', 'placeholder': 'user.search.placeholder'} }) }}
12 <label for="search_user_term" class="active">{{ 'user.search.label' | trans }}</label>
13
14 {{ form_rest(form) }}
15</form>