From 663a0b025859b698e841e0095c7ab196525845bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Sun, 28 May 2023 20:06:33 +0200 Subject: [PATCH] Add select row to report --- benchmark/scripts/templates/base.html | 11 ++-- .../scripts/templates/partials/js_report.js | 11 ++++ .../scripts/templates/partials/js_select.html | 60 ------------------- .../scripts/templates/partials/js_select.js | 58 ++++++++++++++++++ .../partials/table_report_bootstrap.html | 2 +- .../partials/table_report_bulma.html | 2 +- .../templates/partials/table_select.html | 2 +- .../partials/table_select_design.html | 6 +- benchmark/scripts/templates/report.html | 10 ++++ benchmark/scripts/templates/select.html | 15 ++++- 10 files changed, 103 insertions(+), 74 deletions(-) create mode 100644 benchmark/scripts/templates/partials/js_report.js delete mode 100644 benchmark/scripts/templates/partials/js_select.html create mode 100644 benchmark/scripts/templates/partials/js_select.js diff --git a/benchmark/scripts/templates/base.html b/benchmark/scripts/templates/base.html index 44c7aca..1a4ce78 100644 --- a/benchmark/scripts/templates/base.html +++ b/benchmark/scripts/templates/base.html @@ -14,6 +14,10 @@ background-color: #0dcaf0; color:white; } + #report-table tbody tr.selected td{ + background-color: #0dcaf0; + color:white; + } {% else %} @@ -33,8 +37,7 @@ {% block content %} {% endblock %} - {% if framework == "bootstrap" %} - - {% endif %} + + {% block jscript %} + {% endblock %} \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/js_report.js b/benchmark/scripts/templates/partials/js_report.js new file mode 100644 index 0000000..4cbe71e --- /dev/null +++ b/benchmark/scripts/templates/partials/js_report.js @@ -0,0 +1,11 @@ +$(document).ready(function () { + // Check if row is selected + $('#report-table tbody').on('click', 'tr', function () { + if ($(this).hasClass('{{ selected }}')) { + $(this).removeClass('{{ selected }}'); + } else { + $('#report-table tbody tr.{{ selected }}').removeClass("{{ selected }}") + $(this).addClass('{{ selected }}'); + } + }); + }); \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/js_select.html b/benchmark/scripts/templates/partials/js_select.html deleted file mode 100644 index 4a0feb5..0000000 --- a/benchmark/scripts/templates/partials/js_select.html +++ /dev/null @@ -1,60 +0,0 @@ - \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/js_select.js b/benchmark/scripts/templates/partials/js_select.js new file mode 100644 index 0000000..011b927 --- /dev/null +++ b/benchmark/scripts/templates/partials/js_select.js @@ -0,0 +1,58 @@ +$(document).ready(function () { + var table = $('#file-table').DataTable({ + "paging": true, + "searching": true, + "ordering": true, + "info": true, + "select.items": "row", + "pageLength": 25, + "columnDefs": [{ + "targets": 8, + "orderable": false + }] + }); + // Check if row is selected + $('#file-table tbody').on('click', 'tr', function () { + if ($(this).hasClass('{{ selected }}')) { + $(this).removeClass('{{ selected }}'); + } else { + table.$('tr.{{ selected }}').removeClass('{{ selected }}'); + $(this).addClass('{{ selected }}'); + } + }); +}); +function showFile(selectedFile) { + var form = $('
' + + '' + + '
'); + $('body').append(form); + form.submit(); +} +function excel() { + var checkbox = document.getElementsByName("selected_files"); + var selectedFiles = []; + for (var i = 0; i < checkbox.length; i++) { + if (checkbox[i].checked) { + selectedFiles.push(checkbox[i].value); + } + } + if (selectedFiles.length == 0) { + alert("Select at least one file"); + return; + } + // send data to server with ajax post + $.ajax({ + type:'POST', + url:'/excel', + data: JSON.stringify(selectedFiles), + contentType: "application/json", + dataType: 'json', + success: function(data){ + alert("Se ha generado el archivo "+data.file); + }, + error: function (xhr, ajaxOptions, thrownError) { + var mensaje = JSON.parse(xhr.responseText || '{\"mensaje\": \"Error indeterminado\"}'); + alert(mensaje.mensaje); + } + }); +} \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/table_report_bootstrap.html b/benchmark/scripts/templates/partials/table_report_bootstrap.html index b3672b8..c434c5d 100644 --- a/benchmark/scripts/templates/partials/table_report_bootstrap.html +++ b/benchmark/scripts/templates/partials/table_report_bootstrap.html @@ -43,7 +43,7 @@ - +
diff --git a/benchmark/scripts/templates/partials/table_report_bulma.html b/benchmark/scripts/templates/partials/table_report_bulma.html index 371fa65..f126a8d 100644 --- a/benchmark/scripts/templates/partials/table_report_bulma.html +++ b/benchmark/scripts/templates/partials/table_report_bulma.html @@ -49,7 +49,7 @@
Dataset
- +
diff --git a/benchmark/scripts/templates/partials/table_select.html b/benchmark/scripts/templates/partials/table_select.html index 40357f5..5fbe858 100644 --- a/benchmark/scripts/templates/partials/table_select.html +++ b/benchmark/scripts/templates/partials/table_select.html @@ -1,4 +1,4 @@ -
Dataset
+
diff --git a/benchmark/scripts/templates/partials/table_select_design.html b/benchmark/scripts/templates/partials/table_select_design.html index 8a71dd2..7d6b5fb 100644 --- a/benchmark/scripts/templates/partials/table_select_design.html +++ b/benchmark/scripts/templates/partials/table_select_design.html @@ -4,8 +4,4 @@ }} {% include "partials/table_select.html" %} - - - - -{% include "partials/js_select.html" %} \ No newline at end of file + \ No newline at end of file diff --git a/benchmark/scripts/templates/report.html b/benchmark/scripts/templates/report.html index 23f47e8..50d768c 100644 --- a/benchmark/scripts/templates/report.html +++ b/benchmark/scripts/templates/report.html @@ -11,3 +11,13 @@ {% include "partials/table_report_bulma.html" %} {% endif %} {% endblock %} +{% block jscript %} + {% if framework == "bootstrap" %} + {% set selected = "selected" %} + {% else %} + {% set selected = "is-selected" %} + {% endif %} + +{% endblock %} diff --git a/benchmark/scripts/templates/select.html b/benchmark/scripts/templates/select.html index 228ce97..107eaed 100644 --- a/benchmark/scripts/templates/select.html +++ b/benchmark/scripts/templates/select.html @@ -3,7 +3,7 @@ {% if framework == "bootstrap" %} {% set button_class = "btn btn-primary bt-sm" %} {% set h1_class = "text-center" %} - {% set table_class = "table table-striped table-hover" %} + {% set table_class = "table table-striped table-hover table-bordered" %} {% set button_pre = '
Model