[chronojump-server] Column ID added to results just for sort purpose Filters by Player, By Station and by Exercice have



commit 8f2a17702e052703a4182059ba202937bb9367c1
Author: Marcos Venteo García <mventeo gmail com>
Date:   Wed May 24 22:50:42 2017 +0200

    Column ID added to results just for sort purpose
    Filters by Player, By Station and by Exercice have been added and now are operative

 chronojump-flask/chronojump_server.py   |    4 +-
 chronojump-flask/templates/results.html |  279 +++++++++++--------------------
 2 files changed, 99 insertions(+), 184 deletions(-)
---
diff --git a/chronojump-flask/chronojump_server.py b/chronojump-flask/chronojump_server.py
index c8dc529..ed15887 100644
--- a/chronojump-flask/chronojump_server.py
+++ b/chronojump-flask/chronojump_server.py
@@ -207,12 +207,12 @@ def uploader():
 
 def get_all_results():
     """Query to get all the results to serve via ajax."""
-    sql = "select results.dt, person.name, station.name, " \
+    sql = "select results.id, results.dt, person.name, station.name, " \
           " results.exerciseName, results.resistance, results.repetitions, " \
           "lossBySpeed, numBySpeed, rangeBySpeed, vmeanBySpeed, " \
           "vmaxBySpeed, pmeanBySpeed, pmaxBySpeed, comments " \
           "FROM results, person, station where person.id = results.personId and " \
-          "station.id = results.stationId "
+          "station.id = results.stationId order by results.id desc"
     print sql
     db = mysql.connect()
     cursor = db.cursor()
diff --git a/chronojump-flask/templates/results.html b/chronojump-flask/templates/results.html
index 5a3a04b..8a44d76 100644
--- a/chronojump-flask/templates/results.html
+++ b/chronojump-flask/templates/results.html
@@ -10,23 +10,9 @@
 <script type="text/javascript">
        $(document).ready(function() {
                // Initialize datatable with results
-               /*
-               <th>Data</th>
-               <th>Jugador</th>
-               <th>Estació</th>
-               <th>Exercici</th>
-               <th>Càrrega</th>
-               <th>n</th>
-               <th>Pèrdua</th>
-               <th>[&nbsp;rep</th>
-               <th>rang</th>
-               <th>Vm</th>
-               <th>VM</th>
-               <th>Pm</th>
-               <th>PM&nbsp;]</th>
-               </thead>*/
                var table = $('#results').DataTable({
                        "columns" : [
+                               { type: "num", title: "id", visible:false},
                 { type : "date" , title : "Data",
                                        render: function(value) {
                                                // Compare with today
@@ -50,7 +36,7 @@
                                                } else {
                                                        return dd2 + "/" + (mm2 +1) + "/"+ yy2 + " " + hh + 
":" + MM;
                                                }
-                                               
+
                                        }
                    },
                 { type : "html" , title : "Jugador"},
@@ -66,9 +52,11 @@
                                { type : "num" , title: "Pm", render: $.fn.dataTable.render.number( '', ',', 
2 )},
                                { type : "num" , title: "PM]", render: $.fn.dataTable.render.number( '', ',', 
2 )}
             ],
-            "pageLength": 25,
+            "pageLength": 10,
             "order" : [ [ 0, 'desc' ]],
                        "ajax" : "/api/v1/results",
+                       "processing" : true,
+            "severSide" : true,
                        "language": {
                 "lengthMenu": "Mostrant _MENU_ resultats per pàgina",
                 "zeroRecords": "No hi han resultats per mostrar",
@@ -84,7 +72,63 @@
                     "previous": '<i class="fa fa-backward"></i>'
                 },
                 "search" : "Cerca:"
-            }
+            },
+                       initComplete: function () {
+                   this.api().columns().every( function () {
+
+                       var column = this;
+                                       var idx = column.index();
+                                       if (idx == 2) {
+                                               var select = $('<select class="form-control"><option 
value="">Tots els jugadors</option></select>')
+                                   .appendTo( $('#filterByPlayer') )
+                                   .on( 'change', function () {
+                                       var val = $.fn.dataTable.util.escapeRegex(
+                                           $(this).val()
+                                       );
+
+                                       column
+                                           .search( val ? '^'+val+'$' : '', true, false )
+                                           .draw();
+                                   } );
+
+                               column.data().unique().sort().each( function ( d, j ) {
+                                                   select.append( '<option value="'+d+'">'+d+'</option>' )
+                               } );
+                                       } else if (idx == 3 ){
+                                               var select = $('<select class="form-control"><option 
value="">Totes les estacions</option></select>')
+                                   .appendTo( $('#filterByStation') )
+                                   .on( 'change', function () {
+                                       var val = $.fn.dataTable.util.escapeRegex(
+                                           $(this).val()
+                                       );
+
+                                       column
+                                           .search( val ? '^'+val+'$' : '', true, false )
+                                           .draw();
+                                   } );
+
+                               column.data().unique().sort().each( function ( d, j ) {
+                                                   select.append( '<option value="'+d+'">'+d+'</option>' )
+                               } );
+                                       } else if (idx== 4) {
+                                               var select = $('<select class="form-control"><option 
value="">Tots els exercicis</option></select>')
+                                   .appendTo( $('#filterByExercice') )
+                                   .on( 'change', function () {
+                                       var val = $.fn.dataTable.util.escapeRegex(
+                                           $(this).val()
+                                       );
+
+                                       column
+                                           .search( val ? '^'+val+'$' : '', true, false )
+                                           .draw();
+                                   } );
+
+                               column.data().unique().sort().each( function ( d, j ) {
+                                                   select.append( '<option value="'+d+'">'+d+'</option>' )
+                               } );
+                                       }
+                        } );
+               }
                });
 
                setInterval( function () {
@@ -96,173 +140,44 @@
 {% endblock %}
 
 {% block main_content %}
-       <div class="row">
-
+<h2>Resultats</h2>
+<div class="row" style="margin-top: 15px;">
+       <div class="col-sm-3">
+               <label class="radio-inline dayfilter" style="margin-top:5px">
+                 <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1" disabled>1d
+               </label>
+               <label class="radio-inline dayfilter" style="margin-top:5px">
+                 <input type="radio" name="inlineRadioOptions" id="inlineRadio2" 
value="option2"disabled="">3d
+               </label>
+               <label class="radio-inline dayfilter" style="margin-top:5px">
+                 <input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" disabled>7d
+               </label>
+               <label class="radio-inline dayfilter" style="margin-top:5px">
+                 <input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" disabled>14d
+               </label>
+               <label class="radio-inline dayfilter" style="margin-top:5px">
+                 <input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" checked>Tots
+               </label>
        </div>
-
-       <table id="results" class="table table-hovered " cellspacing="0" width="100%">
-       </table>
-
+       <div class="col-sm-3">
+               <label for="player_filter" class="sr-only">Per Jugador</label>
+               <div id="filterByPlayer"></div>
+       </div>
+       <div class="col-sm-3">
+               <label for="fullname_filter" class="sr-only">Per Estació</label>
+               <div id="filterByStation"></div>
+       </div>
+       <div class="col-sm-3">
+               <label for="fullname_filter" class="sr-only">Per Exercici</label>
+               <div id="filterByExercice"></div>
        </div>
 
-{% endblock %}
-
-
-
-<!--
-               {% if (not date or date == "") %}
-               {% set date = "1" %}
-               {% endif %}
-
-               {% if (not pId or pId == "") %}
-               {% set pId = "All" %}
-               {% endif %}
-
-               {% if (not sId or sId == "") %}
-               {% set sId = "All" %}
-               {% endif %}
-
-               {% if (not persons or persons == "") %}
-               {% set persons = "" %}
-               {% endif %}
-
-               {% if (not stations or stations == "") %}
-               {% set stations = "" %}
-               {% endif %}
-
-
-               <div class="main">
-               {{ header|safe }}
-
-               <form action=results>
-                       <div id="textbox"><p class="alignleft">
-
-                               Data:
-
-                               <span class="noselect">
-                                       {% if date == "1" %}
-                                       <input type="radio" id="date1" name="date" value="1" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="date1" name="date" value="1">
-                                       {% endif %}
-                                       <label for="date1">1d</label>
-
-                                       {% if date == "3" %}
-                                       <input type="radio" id="date3" name="date" value="3" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="date3" name="date" value="3">
-                                       {% endif %}
-                                       <label for="date3">3d</label>
-
-                                       {% if date == "7" %}
-                                       <input type="radio" id="date7" name="date" value="7" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="date7" name="date" value="7">
-                                       {% endif %}
-                                       <label for="date7">7d</label>
-
-                                       {% if date == "14" %}
-                                       <input type="radio" id="date14" name="date" value="14" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="date14" name="date" value="14">
-                                       {% endif %}
-                                       <label for="date14">14d</label>
-
-                                       {% if date == "Any" %}
-                                       <input type="radio" id="dateAny" name="date" value="Any" 
checked="checked">
-                                       {% else %}
-                                       <input type="radio" id="dateAny" name="date" value="Any">
-                                       {% endif %}
-                                       <label for="dateAny">Sempre</label>
-                               </span>
-
-                               &nbsp;&nbsp;&nbsp;
-
-                               <span class="styled-select slate">
-                                       <select name="pId">
-                                               {% if pId == "All" %}
-                                               <option value="All" selected="selected">Tots els 
jugadors</option>
-                                               {% else %}
-                                               <option value="All">Tots els jugadors</option>
-                                               {% endif %}
-
-                                               {% for row in persons %}
-                                               {% if pId|string() == row[0]|string() %}
-                                               <option value="{{row[0]}}" 
selected="selected">{{row[1]}}</option>
-                                               {% else %}
-                                               <option value="{{row[0]}}">{{row[1]}}</option>
-                                               {% endif %}
-                                               {% endfor %}
-                                       </select>
-                               </span>
-
-                               &nbsp;&nbsp;&nbsp;
-
-                               <span class="styled-select slate">
-                                       <select name="sId">
-                                               {% if sId == "All" %}
-                                               <option value="All" selected="selected">Totes les 
estacions</option>
-                                               {% else %}
-                                               <option value="All">Totes les estacions</option>
-                                               {% endif %}
-
-                                               {% for row in stations %}
-                                               {% if sId|string() == row[0]|string() %}
-                                               <option value="{{row[0]}}" 
selected="selected">{{row[1]}}</option>
-                                               {% else %}
-                                               <option value="{{row[0]}}">{{row[1]}}</option>
-                                               {% endif %}
-                                               {% endfor %}
-                                       </select>
-                               </span>
-
-                               </p>
-                               <p class="alignright"><input type="submit" value="Actualitza"></p></div>
-                       <div style="clear: both;"></div>
-               </form>
+</div>
 
+<div class="row" style="margin-top:20px">
+       <table id="results" class="table table-hovered" cellspacing="0" width="100%">
+       </table>
+</div>
 
-               <table class="table">
-                       <thead>
-                               <th>Data</th>
-                               {% if pId == "All" %}
-                                       <th>Jugador</th>
-                               {% endif %}
-                               {% if sId == "All" %}
-                                       <th>Estació</th>
-                               {% endif %}
-                               <th>Exercici</th>
-                               <th>Càrrega</th>
-                               <th>n</th>
-                               <th>Pèrdua</th>
-                               <th>[&nbsp;rep</th>
-                               <th>rang</th>
-                               <th>Vm</th>
-                               <th>VM</th>
-                               <th>Pm</th>
-                               <th>PM&nbsp;]</th>
-                       </thead>
 
-                       {% for row in results %}
-                       <tr>
-                               <td>{{row[0]}}</td>
-                               {% if pId == "All" %}
-                                       <td>{{row[1]}}</td>
-                               {% endif %}
-                               {% if sId == "All" %}
-                                       <td>{{row[2]}}</td>
-                               {% endif %}
-                               <td>{{row[3]}}</td>
-                               <td>{{row[4]}}</td>
-                               <td>{{row[5]}}</td>
-                               <td>{{row[6]}}</td>
-                               <td>{{row[7]}}</td>
-                               <td>{{row[8]}}</td>
-                               <td>{{row[9]}}</td>
-                               <td>{{row[10]}}</td>
-                               <td>{{row[11]}}</td>
-                               <td>{{row[12]}}</td>
-                       </tr>
-                       {% endfor %}
-               </table>
--->
+{% endblock %}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]