From 9555f0506d71067718c25df12222da63cf4081b6 Mon Sep 17 00:00:00 2001 From: Jonathan Foucher <jfoucher@gmail.com> Date: Mon, 16 Oct 2023 14:25:58 +0200 Subject: [PATCH] Sort surveys by creation date by default. Fixes https://gitlab.adullact.net/soluris/madis/-/issues/840 --- .../Maturity/Controller/SurveyController.php | 2 +- templates/Maturity/Survey/list.html.twig | 15 ++++++++++++--- .../_Utils/_serverside_datatable_base.html.twig | 1 - 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Domain/Maturity/Controller/SurveyController.php b/src/Domain/Maturity/Controller/SurveyController.php index bc27188b9..a72425a86 100644 --- a/src/Domain/Maturity/Controller/SurveyController.php +++ b/src/Domain/Maturity/Controller/SurveyController.php @@ -424,7 +424,7 @@ class SurveyController extends CRUDController public function listAction(): Response { - $surveys = $this->repository->findAll(); + $surveys = $this->getListData(); $referentiels = []; foreach ($surveys as $survey) { $referentiels[] = $survey->getReferentiel()->getName(); diff --git a/templates/Maturity/Survey/list.html.twig b/templates/Maturity/Survey/list.html.twig index e1b5962ad..e1666d841 100644 --- a/templates/Maturity/Survey/list.html.twig +++ b/templates/Maturity/Survey/list.html.twig @@ -94,6 +94,7 @@ {% if is_granted('ROLE_REFERENT') %} {% set dataTableOptions = { + columns: [ {"data": "referentiel", "className": "noVis"}, {"data": "collectivity"}, @@ -101,17 +102,20 @@ {"data": "createdAt", "visible": false}, {"data": "updatedAt", "visible": false}, {"data": "actions", "className": "noVis", "orderable": false} - ] + ], + order: [[3, 'desc' ]], } %} {% else %} {% set dataTableOptions = { + columns: [ {"data": "referentiel", "className": "noVis"}, {"data": "score", "visible": true}, {"data": "createdAt", "visible": false}, {"data": "updatedAt", "visible": false}, {"data": "actions", "className": "noVis", "orderable": false} - ] + ], + order: [[2, 'desc' ]], } %} {% endif %} @@ -120,11 +124,14 @@ <script> function setEvents() { var oTable = $('#table').DataTable(); + var col = 0; {% if is_granted('ROLE_REFERENT') %} col = 1; {% endif %} + //oTable.order([[col+2, 'desc']]) + $('#search_created_at').show('slide',function(){ $('input#search_created_at').val(''); }); @@ -155,7 +162,7 @@ $('#search_created_at').off('change'); $('#search_created_at').change(function(){ - console.log(oTable.column('2')); + console.log(oTable); oTable.column(col + 2).search($(this).val()).draw(); }); @@ -163,6 +170,8 @@ $('#search_updated_at').change(function(){ oTable.column(col + 3).search($(this).val()).draw(); }); + + console.log('oTable', oTable.order()); } $(document).ready(function() { diff --git a/templates/_Utils/_serverside_datatable_base.html.twig b/templates/_Utils/_serverside_datatable_base.html.twig index 9365522d8..5003f3b89 100644 --- a/templates/_Utils/_serverside_datatable_base.html.twig +++ b/templates/_Utils/_serverside_datatable_base.html.twig @@ -183,7 +183,6 @@ var oTable = $('#table').DataTable(); - console.log('oTable', oTable); $('#delete-all').on('click', function(event) { event.stopPropagation(); let data = oTable.rows().data().toArray().map(row => row.id); -- GitLab