[chronojump-server] Fixing error when deleting results. Adding a custom csv export button to improve the output result



commit 2d60532bce426e3c083174eecac7fa3250c5ae19
Author: Marcos Venteo <mventeo gmail com>
Date:   Mon Oct 16 10:39:38 2017 +0200

    Fixing error when deleting results. Adding a custom csv export button to improve the output result

 chronojumpserver/templates/results.html |   76 ++++++++++++++++++++++++++++---
 1 files changed, 69 insertions(+), 7 deletions(-)
---
diff --git a/chronojumpserver/templates/results.html b/chronojumpserver/templates/results.html
index c4da67d..4873225 100755
--- a/chronojumpserver/templates/results.html
+++ b/chronojumpserver/templates/results.html
@@ -110,10 +110,13 @@ $(document).ready(function() {
          }
 
 
-       }
+               }
   );
+
+
   /* Create the table for results with Datatables */
   var table = $('#results').DataTable({
+               "select": true,
        "columns": [{
                type: "num",
                title: "id",
@@ -245,7 +248,68 @@ $(document).ready(function() {
        ],
        "dom": "<'row'<'resultsFilter'>><'row'<'col-sm-6'B><'col-sm-6'f>>rtip",
        buttons: [
-                       { extend: 'csv', text: 'Exportar Resultats', className: "btn btn-primary", 
fieldSeparator: "&nbsp;"},
+                       { extend: "csv", text: "Exportar resultats", className: "btn btn-primary",
+                               action: function( e, dt, button, config ) {
+                                       var columns = ["Data", "Jugador", "EstaciĆ³", "Exercici",
+                                               "RL", "Carrega", "n", "Perdua", "Rep", "Rang", "Vm", "VM", 
"Pm", "PM"];
+
+                                       var csv = columns.join(";") + "\n";
+                                       var today = new Date();
+                                       var dd = today.getDate();
+                                       var mm = today.getMonth()+1;
+                                       var yyyy = today.getFullYear();
+                                       var hh = today.getHours();
+                                       var MM = today.getMinutes();
+
+                                       var filename = "resultats_" + yyyy + formatDateNumber(mm) + 
formatDateNumber(dd) + formatDateNumber(hh) + formatDateNumber(MM)   + ".csv";
+                                               var rows = $("#results").dataTable().$('tr', 
{"filter":"applied"});
+                                               rows.each(function( index ) {
+                                                 //console.log( index + ": " + table.row( this ).data() );
+                                                       var data = table.row(this).data();
+                                                       var date = new Date(data.dt);
+                                                       var _offsetHours = date.getTimezoneOffset()/60;
+                                                       var dateStr = formatDateNumber(date.getDate()) + "-" 
+ formatDateNumber(date.getMonth() + 1 ) + "-" +
+                                                               date.getFullYear() + " " + 
formatDateNumber(date.getHours() + _offsetHours) + ":"
+                                                               + formatDateNumber(date.getMinutes()) + ":00";
+                                                               csv += dateStr + ","
+                                                                               + data.personName + ";"
+                                                                               + data.stationName +";"
+                                                                               + data.exerciseName + ";"
+                                                                               + data.laterality + ";"
+                                                                               + data.resistance + ";"
+                                                                               + data.repetitions + ";"
+                                                                               + data.lossBySpeed + ";"
+                                                                               + data.numBySpeed + ";"
+                                                                               + data.rangeBySpeed + ";"
+                                                                               + data.vmeanBySpeed + ";"
+                                                                               + data.vmaxBySpeed + ";"
+                                                                               + data.pmeanBySpeed + ";"
+                                                                               + data.pmaxBySpeed + "\n";
+                                                       //console.log(index + ": " +dateStr);
+                                               });
+                                               var csvData = 'data:text/csv;charset=utf-8,' + "\uFEFF" + 
encodeURI(csv);
+                                               // For IE (tested 10+)
+                                               //console.log(filename);
+                                               //console.log(csv);
+            if (window.navigator.msSaveOrOpenBlob) {
+                var blob = new Blob([decodeURIComponent(encodeURI(csv))], {
+                    type: "text/csv;charset=utf-8;"
+                });
+                navigator.msSaveBlob(blob, filename);
+                                                               alert();
+            } else {
+                                                       var link=document.createElement('a');
+                $(link)
+                    .attr({
+                        'download': filename
+                        ,'href': csvData
+                        //,'target' : '_blank' //if you want it to open in a new window
+                });
+                                                               link.click();
+                                                               //alert(filename);
+            }
+                                               return csv;
+            }},
                        { text: 'Eliminar registres',
                          className: "btn btn-danger btnDeleteResults",
                          enabled: false,
@@ -370,14 +434,12 @@ $(document).ready(function() {
                  });
                }
          });
-         enableDeletion();
+               enableDeletion();
        }
   });
 
   /* Enable the result deletion */
   function enableDeletion() {
-
-
          // Called every time a delete checkbox is changed
          $('.deleteCheckbox').on('change', function() {
                  var totalChecked = $('.deleteCheckbox:checked').length;
@@ -402,8 +464,8 @@ $(document).ready(function() {
   function refreshIntervalTrigger() {
        return setInterval(function() {
           /* Set the interval for refresh */
-          table.ajax.reload(null, false);
-        }, 15000);
+          table.ajax.reload(enableDeletion, false);
+                }, 15000);
    };
 
    refreshIntervalId = refreshIntervalTrigger();


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