[chronojump-server] Now the user can add macro tasks
- From: Marcos Venteo Garcia <mventeo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Now the user can add macro tasks
- Date: Tue, 13 Feb 2018 21:11:06 +0000 (UTC)
commit e1365d9d7e2d5cf25a8785ee2f58b08af8f61d1f
Author: Marcos Venteo <mventeo gmail com>
Date: Tue Feb 13 22:01:47 2018 +0100
Now the user can add macro tasks
chronojumpserver/templates/player_list.html | 1140 ++++++++++++++++-----------
chronojumpserver/templates/results.html | 2 +-
2 files changed, 697 insertions(+), 445 deletions(-)
---
diff --git a/chronojumpserver/templates/player_list.html b/chronojumpserver/templates/player_list.html
index 9d474dd..7cda5cc 100755
--- a/chronojumpserver/templates/player_list.html
+++ b/chronojumpserver/templates/player_list.html
@@ -24,33 +24,33 @@
<input type="hidden" id="playerId">
<input type="hidden" id="taskId">
<nav class="navbar navbar-default">
- <ul class="nav navbar-nav">
- <!--<li id="taskParamSelector" role="presentation"
class="active"><a href="#paramTask" aria-controls="paramTask" role="pill" data-toggle="tab"></a></li>-->
- <!--<li id="taskFreeSelector" role="presentation"><a
href="#freeTask" aria-controls="freeTask" role="tab" data-toggle="pill">Lliure</a></li>-->
+ <ul id="taskTypeTabs" class="nav navbar-nav" role="tablist">
+ <li id="taskParamSelector" role="presentation"
class="active"><a href="#singleTask" aria-controls="paramTask" >Individual</a></li>
+ <li id="taskFreeSelector" role="presentation"><a
href="#macroTask" aria-controls="freeTask" >Múltiple</a></li>
</ul>
- <form class="navbar-form navbar-left">
+ <form class="navbar-form navbar-right">
<div class="form-group">
<label for="station">Estació:</label>
<select name="station" class="form-control"
id="stationSelect">
- {% for station in stations %}
- <option
data-station-type="{{station.type}}" value={{station.id}}>{{station.name}}</option>
- {% endfor %}
- </select>
+ {% for station in stations %}
+ <option data-station-type="{{station.type}}"
value={{station.id}}>{{station.name}}</option>
+ {% endfor %}
+ </select>
</div>
<div class="form-group" style="margin-left: 20px">
<label for="station">Exercici:</label>
<select name="exercise" class="form-control" disabled
id="exerciseSelect">
- <option value=""></option>
- </select>
+ <option value=""></option>
+ </select>
</div>
</form>
</nav>
<div class="tab-content">
- <div role="tabpanel" id="paramTask" class="tab-pane active">
+ <div role="tabpanel" id="singleTask" class="tab-pane fade in active">
<form class="form-horizontal" style="margin-top: 10px">
<div class="form-group">
@@ -101,15 +101,86 @@
</div>
</form>
</div>
- <div role="tabpanel" id="freeTask" class="tab-pane">
+ <div role="tabpanel" id="macroTask" class="tab-pane fade">
<!-- Disabled panel -->
+ <form class="form-horizontal" style="margin-top: 10px">
+ <div class="form-group">
+ <label for="numTasks" class="col-sm-2
control-label taskParameter"># Tasques:</label>
+ <div class="col-sm-2">
+ <input id="numTasks" name="numTaks"
type="number" class="form-control taskParameter" value="1" min="1"></input>
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="numSets2" class="col-sm-2
control-label taskParameter"># Series:</label>
+ <div class="col-sm-2">
+ <input id="numSets2" name="numSets2"
type="number" class="form-control taskParameter" value="1" min="1"></input>
+ </div>
+ <label for="numReps2" class="col-sm-2
control-label"># Repeticions:</label>
+ <div class="col-sm-2">
+ <input id="numReps2" name="numReps2"
type="number" class="form-control" value="1" min="1"></input>
+ </div>
+ <label for="taskLoad2" class="col-sm-2
control-label">Carrega (Kg):</label>
+ <div class="col-sm-2">
+ <input id="taskLoad2"
name="taskLoad2" type="number" class="form-control" ></input>
+ </div>
+ </div>
+ <div class="form-group taskParameter">
+ <label for="taskMaxSpeed2" class="col-sm-2
control-label" style="padding-top:0;margin-top: -5px;">Max Vm<br>registrada (m/s):</label>
+ <div class="col-sm-2">
+ <input id="taskMaxSpeed2"
name="taskMaxSpeed2" type="number" class="form-control" disabled readonly></input>
+ </div>
+ <label for="taskpercentMaxSpeed2"
class="col-sm-2 control-label" style="padding-top:0;margin-top: -5px;">Max Vm<br>registrada (%):</label>
+ <div class="col-sm-2">
+ <input id="taskpercentMaxSpeed2"
name="taskpercentMaxSpeed2" type="number" class="form-control" disabled max="100" min="0"></input>
+ </div>
+ <label for="taskSpeed2" class="col-sm-2
control-label">Velocitat (m/s):</label>
+ <div class="col-sm-2">
+ <input id="taskSpeed2"
name="taskSpeed2" type="number" class="form-control" min="-1" step="0.1" disabled></input>
+ </div>
+ </div>
+ <div class="form-group taskParameter">
+ <label for="recipient-name" class="col-sm-2
control-label">Lateralitat:</label>
+ <div class="col-sm-10">
+ <select class="form-control"
id="taskLaterality2" name="taskLaterality2">
+ <option value="RL">RL -
ambdúes extremitats</option>
+ <option value="R,L">R,L -
Primer amb la dreta, després amb l'esquerra</option>
+ <option value="R">R - Només
extremitat dreta</option>
+ <option value="L">L - Només
extremitat esquerra</option>
+ </select>
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-sm-12">
+
+ </div>
+ </div>
+ <hr/>
+ <table class="table hide" id="tasksTable">
+ <caption>Pots modificar les tasques abans
d'afegir-les.</caption>
+ <thead>
+ <tr>
+ <th>#</th>
+ <th>Carrega (Kg)</th>
+ <th>Max Vm registrada (%)</th>
+ <th>Velocitat (m/s)</th>
+ <!--<th>Perdua</th>-->
+ </tr>
+ </thead>
+ <tbody>
+
+ </tbody>
+ </table>
+ </form>
</div>
</div>
</div> <!-- .modal-body -->
<div class="modal-footer">
<button type="button" class="pull-left btn btn-default"
data-dismiss="modal">Cancelar</button>
- <button id="btnAddTask" type="button" class="pull-right btn btn-primary
hidden" onclick="addModifyDeleteTask(0)">Afegeix la tasca</button>
+ <button id="btnResetMacroTask" type="button" class="pull-left btn btn-default
hidden" >Reset</button>
+ <button id="btnCreateTasks" type="button" class="pull-right btn btn-primary
hidden" >Crear tasques</button>
+ <button id="btnAddTask" type="button" class="pull-right btn btn-primary
hidden" onclick="addModifyDeleteTask(0)">Afegir</button>
+ <button id="btnAddMacroTask" type="button" class="pull-right btn btn-primary
hidden" onclick="addMacroTask()">Afegir tasques</button>
<button id="btnUpdateTask" type="button" class="pull-right btn btn-primary"
onclick="addModifyDeleteTask(1)">Modificar la tasca</button>
<button id="btnDeleteTask" type="button" class="pull-right btn btn-danger
hidden" onclick="addModifyDeleteTask(2)">Eliminar</button>
</div>
@@ -125,455 +196,636 @@
<script src="{{ url_for('assets', filename='DataTables/media/js/dataTables.bootstrap.min.js') }}"></script>
<script>
/*!
- * Player javascript functions for Chronojump Server
- * Author: Marcos Venteo <mventeo gmail com>
- * version: 1.0
- */
+* Player javascript functions for Chronojump Server
+* Author: Marcos Venteo <mventeo gmail com>
+* version: 1.0
+*/
+
+var taskTypeInt = 0; // 0 - Single, 1 - Macro
+
+/* To show the tab and control possible buttons */
+$('#taskTypeTabs a').click(function (e) {
+ e.preventDefault()
+ $(this).tab('show');
+ if ($(this).attr("href") == "#macroTask") {
+ taskTypeInt = 1;
+ $('#btnAddTask').addClass('hidden');
+ $('#btnResetMacroTask').removeClass('hidden');
+ var rowCount = $('#tasksTable tr').length;
+ console.log(rowCount);
+ if (rowCount > 0) {
+ $('#btnAddMacroTask').removeClass('hidden');
+
+ } else {
+ $('#btnCreateTasks').removeClass('hidden');
+
+ }
+ } else {
+ taskTypeInt = 0;
+ $('#btnAddTask').removeClass('hidden');
+ $('#btnCreateTasks').addClass('hidden');
+ $('#btnAddMacroTask').addClass('hidden');
+ $('#btnResetMacroTask').addClass('hidden');
+ }
+})
+
+/* */
+$('#btnCreateTasks').click(function(e) {
+ e.preventDefault();
+ var numTasks = $('#numTasks').val();
+ // TODO: Validate that all necessary fields are file before create the table
+
+ $('#tasksTable').removeClass("hide");
+ for (i = 0; i < numTasks; i++) {
+ createTaskInTable(i);
+ }
+ $('#btnCreateTasks').addClass('hidden');
+ $('#btnAddMacroTask').removeClass('hidden');
+
+});
+
+/* Remove all macro task to start again */
+$('#btnResetMacroTask').click(function(e) {
+ removeMacroTasksTable();
+});
+
+function removeMacroTasksTable() {
+ console.log("Removing rows " + $('#tasksTable tr').length);
+ $('#tasksTable tr').remove();
+ $('#tasksTable').addClass("hidden");
+ if (taskTypeInt == 1) {
+ $('#btnCreateTasks').removeClass('hidden');
+ $('#btnAddMacroTask').addClass('hidden');
+ }
+}
+
+
+function createTaskInTable(numTask) {
+ var html = "<tr>";
+ var load = $('#taskLoad2').val();
+ var speed = $('#taskSpeed2').val();
+ $('#tasksTable').removeClass("hidden");
+ var percentMaxSpeed = $('#taskpercentMaxSpeed2').val();
+ html += "<td>" + (numTask + 1) + "</td>";
+ html += "<td><input class='macroLoad form-control' type='number' value=" + load + " /></td>";
+ console.log(percentMaxSpeed);
+ if (percentMaxSpeed == '') {
+ html += "<td><input class='macroPercentMaxSpeed form-control' disabled type='number' /></td>";
+ } else {
+ html += "<td><input class='macroPercentMaxSpeed form-control' type='number' value="+
percentMaxSpeed +"/></td>";
+ }
+ html += "<td><input class='macroSpeed form-control' type='number' value=" + speed + " /></td>";
+ html += "</tr>";
+ $('#tasksTable > tbody:last-child').append(html);
+}
+
+/* Function to add/Modify or delete a task called from Task Modal Form. */
+function addMacroTask() {
+ /* Function to add or modify the task */
+ var playerId = $('#playerId').val();
+ var description = $('#taskComment').val();
+ var taskId = $('#taskId').val();
+ var stationId = $('#stationSelect').val();
+ var exerciseId = $('#exerciseSelect').val();
+ var sets = $('#numSets2').val();
+ if (sets == '') sets=-1;
+ var reps = $('#numReps2').val();
+ if (reps == '') reps=-1;
+ var laterality = $('#taskLaterality2').val();
+
+
+ // For both Add or Modify we'll use PUT method
+ method = 'PUT';
+
+ var numTasks = $('#numTasks').val();
+ $('#taskModalForm').modal('hide');
+ for(i = 0; i < numTasks; i++) {
+ var load = $('.macroLoad').eq(i).val();
+ if (load == '') load=-1;
+ var percentMaxSpeed = console.log($('.macroPercentMaxSpeed').eq(i).val());
+ if (percentMaxSpeed == '') percentMaxSpeed = -1;
+ var speed = ($('.macroSpeed').eq(i).val());
+ if (speed == '') speed=-1;
+ $.ajax({
+ url: '/api/v1/tasks',
+ method: method,
+ data: {
+ playerId: playerId,
+ description: description,
+ taskId: taskId,
+ type: 'P',
+ stationId: stationId,
+ exerciseId: exerciseId,
+ sets: sets,
+ reps: reps,
+ load: load,
+ speed: speed,
+ percentMaxSpeed: percentMaxSpeed,
+ laterality: laterality
+ }
+ }).done(function(data) {
+ var table = $('#players').DataTable();
+ table.ajax.reload(null, false);
+ }).fail(function(xhr, status, error){
+ var err = eval("(" + xhr.responseText + ")");
+ alert(err.msg);
+ });
+ }
+}
+
+
/* Function to add/Modify or delete a task called from Task Modal Form. */
function addModifyDeleteTask(action) {
- /*
- action could be : 0 - Add
- 1 - Modify
- 2 - delete
- */
- /* Function to add or modify the task */
- var playerId = $('#playerId').val();
- var description = $('#taskComment').val();
- var taskId = $('#taskId').val();
- if ($('#paramTask').hasClass('active')) {
- var taskType = 'P';
- } else {
- var taskType = 'F';
- }
- var stationId = $('#stationSelect').val();
- var exerciseId = $('#exerciseSelect').val();
- var sets = $('#numSets').val();
- if (sets == '') sets=-1;
- var reps = $('#numReps').val();
- if (reps == '') reps=-1;
- var load = $('#taskLoad').val();
- if (load == '') load=-1;
- var speed = $('#taskSpeed').val();
- if (speed == '') speed=-1;
- var percentMaxSpeed = $('#taskpercentMaxSpeed').val();
- if (percentMaxSpeed == '') percentMaxSpeed = -1;
- var laterality = $('#taskLaterality').val();
-
- // Set the method
- if (action == 2) {
- method = 'DELETE';
- } else {
- // For both Add or Modify we'll use PUT method
- method = 'PUT';
- }
- $('#taskModalForm').modal('hide');
- $.ajax({
- url: '/api/v1/tasks',
- method: method,
- data: {
- playerId: playerId,
- description: description,
- taskId: taskId,
- type: taskType,
- stationId: stationId,
- exerciseId: exerciseId,
- sets: sets,
- reps: reps,
- load: load,
- speed: speed,
- percentMaxSpeed: percentMaxSpeed,
- laterality: laterality
- }
- }).done(function(data) {
- var table = $('#players').DataTable();
- table.ajax.reload(null, false);
- }).fail(function(xhr, status, error){
- var err = eval("(" + xhr.responseText + ")");
- alert(err.msg);
- });
+ /*
+ action could be : 0 - Add
+ 1 - Modify
+ 2 - delete
+ */
+ /* Function to add or modify the task */
+ var playerId = $('#playerId').val();
+ var description = $('#taskComment').val();
+ var taskId = $('#taskId').val();
+ var taskType = 'P';
+ var stationId = $('#stationSelect').val();
+ var exerciseId = $('#exerciseSelect').val();
+ var sets = $('#numSets').val();
+ if (sets == '') sets=-1;
+ var reps = $('#numReps').val();
+ if (reps == '') reps=-1;
+ var load = $('#taskLoad').val();
+ if (load == '') load=-1;
+ var speed = $('#taskSpeed').val();
+ if (speed == '') speed=-1;
+ var percentMaxSpeed = $('#taskpercentMaxSpeed').val();
+ if (percentMaxSpeed == '') percentMaxSpeed = -1;
+ var laterality = $('#taskLaterality').val();
+
+ // Set the method
+ if (action == 2) {
+ method = 'DELETE';
+ } else {
+ // For both Add or Modify we'll use PUT method
+ method = 'PUT';
+ }
+ $('#taskModalForm').modal('hide');
+ console.log(taskType);
+ $.ajax({
+ url: '/api/v1/tasks',
+ method: method,
+ data: {
+ playerId: playerId,
+ description: description,
+ taskId: taskId,
+ type: taskType,
+ stationId: stationId,
+ exerciseId: exerciseId,
+ sets: sets,
+ reps: reps,
+ load: load,
+ speed: speed,
+ percentMaxSpeed: percentMaxSpeed,
+ laterality: laterality
+ }
+ }).done(function(data) {
+ var table = $('#players').DataTable();
+ table.ajax.reload(null, false);
+ }).fail(function(xhr, status, error){
+ var err = eval("(" + xhr.responseText + ")");
+ alert(err.msg);
+ });
}
/*
- Load Players and tasks
+Load Players and tasks
*/
$(document).ready(function() {
- var table = $('#players').DataTable({
- "columns": [{
- type: "num",
- title: "id",
- data: 'id',
- visible: false
- },
- {
- type: "html",
- title: "",
- data: 'imageName',
- orderable: false,
- render: function(value, type, row) {
- // If player has a photo saved, used it
- var href = '/player/' + row.id;
- if (value) {
- var src = '/static/images/photos/' + value;
- } else {
- // Otherwise show the no_image icon
- var src = '/static/images/no_image.png';
- }
- var html = '<a href="' + href + '" class="player-link"><img src="' + src + '"
class="img-circle" height="32"></a>';
- return html;
- }
- },
- {
- type: "html",
- data: "name",
- title: "Nom",
- render: function(data, type, row) {
- return '<a href="/player/' + row.id + '">' + data + '</a>';
- }
- },
- {
- type: "num",
- data: 'weight',
- title: "Pes",
- render: $.fn.dataTable.render.number('', ',', 2)
- },
- {
- type: "num",
- data: "height",
- title: "Alçada",
- render: $.fn.dataTable.render.number('', ',', 2)
- },
- /*{
- type: "html",
- data: "rfid",
- title: "RFID"
- },*/
- {
- type: "html",
- title: "Tasques",
- data: "tasks",
- orderable: false,
- render: function(value) {
- if (value.length > 0) {
- var html = "<ol>";
- $.each(value, function(index, task) {
- if (task.type == 'F') {
- var _desc = task.description;
- } else {
- // Compose the description based on values
-
- var _desc = task.station + ":";
- _desc += task.exercise + " ";
- if (task.sets > 1) {
- _desc += task.sets + "x" + task.nreps + ' repeticions';
- } else {
- _desc += task.nreps + ' repeticions';
- }
- if (task.speed > 0 || task.load > 0){
- _desc += " (";
- if (task.load > 0) {
- _desc += "pes: " + task.load + " kg ";
- }
- if (task.speed >0) {
- _desc += "vel: " + task.speed + " m/s";
- }
- _desc += ")";
- }
- }
- html += "<li><a class='task-link' "
- html += "data-task-id='" + task.id + "' "
- html += "data-task-type='" + task.type + "' "
- html += "data-task-station-id='" + task.stationId + "' "
- html += "data-task-exercise-id='" + task.exerciseId + "' "
- html += "data-task-sets='" + task.sets + "' "
- html += "data-task-nreps='" + task.nreps + "' "
- html += "data-task-load='" + task.load + "' "
- html += "data-task-speed='" + task.speed + "' "
- html += "data-task-percent-max-speed='" + task.percentMaxSpeed + "' "
- html += "data-task-laterality='" + task.laterality + "' "
- html += "data-task-comment='" + task.description + "'"
- html += ">" + _desc + "</a></li>";
- });
- html += "</ol>";
- return html;
- } else {
- return '<ol></ol>';
- }
- }
- },
- {
- type: "html",
- data: null,
- title: "",
- orderable: false,
- className: 'colAlignRight',
- render: function(val) {
- return "<button class='btn btn-primary'>Afegeix</button>"
- }
- }
- ],
- "dom": '<"toolbar">frtip',
- "pageLength": 10,
- "order": [
- [2, 'asc']
- ],
- "ajax": "/api/v1/players",
- "processing": true,
- "severSide": true,
- "language": {
- "lengthMenu": "Mostrant _MENU_ jugadors per pàgina",
- "zeroRecords": "No hi han jugadors per mostrar",
- "info": "Mostrant els jugadors _START_ a _END_ d'un total de _TOTAL_",
- "infoEmpty": "La busqueda no ha retornat resultats",
- "infoFiltered": "(filtrat de _MAX_ jugadors)",
- "decimal": ",",
- "thousands": ".",
- "paginate": {
- "first": '<i class="fa fa-fast-backward"></i>',
- "last": '<i class="fa fa-fast-forward"></i>',
- "next": '<i class="fa fa-forward"></i>',
- "previous": '<i class="fa fa-backward"></i>'
- },
- "search": "Cerca:"
- }
- });
-
- /* Button to add players inside the datatable */
- $('div.toolbar').html('<a class="btn btn-primary pull-left" href="/player/add">Nou Jugador</a>');
-
- /* To show the modal form to add the tasks */
- $('#players').on('click', 'button', function() {
- var player = table.row($(this).parents('tr')).data();
-
- $('#modal-title').text('Afegir nova tasca per ' + player.name);
- $('#taskModalForm').modal();
- $('#playerId').val(player.id);
- $('#taskId').val('-1');
- //refreshExercises(null);
- // Modal is empty
- /*$("#stationSelect").val($("#stationSelect option:first").val());
-
- $('#numSets').val(-1);
- $('#numReps').val(-1);
- $('#taskLoad').val(-1);
- $('#taskSpeed').val(-1);
- $('#taskpercentMaxSpeed').val(-1);
- $('#taskLaterality').val($("#taskLaterality option:first").val());
- $('#taskComment').val('');*/
- $('#taskParamSelector').removeClass('active');
- $('#taskFreeSelector').removeClass('active');
- $('#paramTask').removeClass('active');
- $('#paramFree').removeClass('active');
- $('#taskParamSelector').addClass('active');
- $('#paramTask').addClass('active');
- $('#btnDeleteTask').removeClass('show').addClass('hidden');
- $('#btnUpdateTask').removeClass('show').addClass('hidden');
- $('#btnAddTask').removeClass('hidden').addClass('show');
- get_maximum_mean_velocity();
- });
-
- /* To show the model to modify the task */
- $('#players').on('click', 'a.task-link', function() {
- var player = table.row($(this).parents('tr')).data();
-
- $('#modal-title').text('Modificar tasca #' + $(this).attr('data-task-id') + ' per ' + player.name);
- var taskType = $(this).attr('data-task-type');
- var taskSets = $(this).attr('data-task-sets');
- var taskReps = $(this).attr('data-task-nreps');
- var taskLoad = $(this).attr('data-task-load');
- var taskSpeed = $(this).attr('data-task-speed');
- var taskPercentMaxSpeed = $(this).attr('data-task-percent-max-speed');
- var taskLaterality = $(this).attr('data-task-laterality');
- var stationId = $(this).attr('data-task-station-id');
- var exerciseId = $(this).attr('data-task-exercise-id');
- var taskComment = $(this).attr('data-task-comment');
-
- $('#taskParamSelector').removeClass('active');
- $('#taskFreeSelector').removeClass('active');
- $('#paramTask').removeClass('active');
- $('#paramFree').removeClass('active');
- if (taskType == 'P') {
- // Show panel for parametrized tasks
- $('#taskParamSelector').addClass('active');
- $('#paramTask').addClass('active');
-
- } else {
- // Show the panel for free tasks
- $('#taskFreeSelector').addClass('active');
- $('#freeTask').addClass('active');
-
- }
-
- // Fill the modal
- $('#playerId').val(player.id);
- $('#taskId').val($(this).attr('data-task-id'));
- $('#stationSelect').val(stationId);
- showHideParameters();
- refreshExercises(exerciseId);
- $('#numSets').val(taskSets);
- $('#numReps').val(taskReps);
- $('#taskLoad').val(taskLoad);
- $('#taskSpeed').val(taskSpeed);
- $('#taskpercentMaxSpeed').val(taskPercentMaxSpeed);
- $('#taskLaterality').val(taskLaterality);
- $('#taskComment').val(taskComment);
-
- // Hide and show the buttons
- $('#btnDeleteTask').removeClass('hidden').addClass('show');
- $('#btnUpdateTask').removeClass('hidden').addClass('show');
- $('#btnAddTask').removeClass('show').addClass('hidden');
- $('#taskModalForm').modal();
- get_maximum_mean_velocity();
- if (taskLoad > 0) {
- $('#taskSpeed').prop('disabled', false);
+ var table = $('#players').DataTable({
+ "columns": [{
+ type: "num",
+ title: "id",
+ data: 'id',
+ visible: false
+ },
+ {
+ type: "html",
+ title: "",
+ data: 'imageName',
+ orderable: false,
+ render: function(value, type, row) {
+ // If player has a photo saved, used it
+ var href = '/player/' + row.id;
+ if (value) {
+ var src = '/static/images/photos/' + value;
+ } else {
+ // Otherwise show the no_image icon
+ var src = '/static/images/no_image.png';
+ }
+ var html = '<a href="' + href + '" class="player-link"><img src="' + src + '"
class="img-circle" height="32"></a>';
+ return html;
+ }
+ },
+ {
+ type: "html",
+ data: "name",
+ title: "Nom",
+ render: function(data, type, row) {
+ return '<a href="/player/' + row.id + '">' + data + '</a>';
+ }
+ },
+ {
+ type: "num",
+ data: 'weight',
+ title: "Pes",
+ render: $.fn.dataTable.render.number('', ',', 2)
+ },
+ {
+ type: "num",
+ data: "height",
+ title: "Alçada",
+ render: $.fn.dataTable.render.number('', ',', 2)
+ },
+ /*{
+ type: "html",
+ data: "rfid",
+ title: "RFID"
+ },*/
+ {
+ type: "html",
+ title: "Tasques",
+ data: "tasks",
+ orderable: false,
+ render: function(value) {
+ if (value.length > 0) {
+ var html = "<ol>";
+ $.each(value, function(index, task) {
+ var _desc = task.station + ":";
+ _desc += task.exercise + " ";
+ if (task.sets > 1) {
+ _desc += task.sets + "x" + task.nreps + ' repeticions';
+ } else {
+ _desc += task.nreps + ' repeticions';
+ }
+ if (task.speed > 0 || task.load > 0){
+ _desc += " (";
+ if (task.load > 0) {
+ _desc += "pes: " + task.load + " kg ";
+ }
+ if (task.speed >0) {
+ _desc += "vel: " + task.speed + " m/s";
+ }
+ _desc += ")";
+ }
+ /*if (task.type == 'F') {
+ var _desc = task.description;
+ } else {
+ // Compose the description based on values
+
+
+ }
+ }*/
+ html += "<li><a class='task-link' "
+ html += "data-task-id='" + task.id + "' "
+ html += "data-task-type='" + task.type + "' "
+ html += "data-task-station-id='" + task.stationId + "' "
+ html += "data-task-exercise-id='" + task.exerciseId + "' "
+ html += "data-task-sets='" + task.sets + "' "
+ html += "data-task-nreps='" + task.nreps + "' "
+ html += "data-task-load='" + task.load + "' "
+ html += "data-task-speed='" + task.speed + "' "
+ html += "data-task-percent-max-speed='" + task.percentMaxSpeed + "' "
+ html += "data-task-laterality='" + task.laterality + "' "
+ html += "data-task-comment='" + task.description + "'"
+ html += ">" + _desc + "</a></li>";
+ });
+ html += "</ol>";
+ return html;
+ } else {
+ return '<ol></ol>';
+ }
}
- if (taskpercentMaxSpeed > 0){
- $('#taskpercentMaxSpeed').prop('disabled', false);
+ },
+ {
+ type: "html",
+ data: null,
+ title: "",
+ orderable: false,
+ className: 'colAlignRight',
+ render: function(val) {
+ return "<button class='btn btn-primary'>Afegeix</button>"
}
+ }
+],
+"dom": '<"toolbar">frtip',
+"pageLength": 10,
+"order": [
+ [2, 'asc']
+],
+"ajax": "/api/v1/players",
+"processing": true,
+"severSide": true,
+"language": {
+ "lengthMenu": "Mostrant _MENU_ jugadors per pàgina",
+ "zeroRecords": "No hi han jugadors per mostrar",
+ "info": "Mostrant els jugadors _START_ a _END_ d'un total de _TOTAL_",
+ "infoEmpty": "La busqueda no ha retornat resultats",
+ "infoFiltered": "(filtrat de _MAX_ jugadors)",
+ "decimal": ",",
+ "thousands": ".",
+ "paginate": {
+ "first": '<i class="fa fa-fast-backward"></i>',
+ "last": '<i class="fa fa-fast-forward"></i>',
+ "next": '<i class="fa fa-forward"></i>',
+ "previous": '<i class="fa fa-backward"></i>'
+ },
+ "search": "Cerca:"
+}
+});
- });
-
- /* Each time the user selects a station, the exercise from this station is
- refreshed. */
- $('#stationSelect').on('change', function() {
- //Ajax call to retrieve all the exercises. Call the function below.
-
- // Hide Show parameters based on station type
- showHideParameters();
- // Show the exercises of this station
- refreshExercises(null);
-
-
-
- });
-
- $('#exerciseSelect').on('change', function() {
- get_maximum_mean_velocity();
- });
-
- /* Show or Hide Parameters based on Station Type */
- function showHideParameters() {
- var optSelected = $('#stationSelect').find(':selected').attr('data-station-type');
- // Show or hide some of the elememts of the task depending of station type
- if (optSelected != 'S') {
- $('.taskParameter').show();
- $('label[for="numReps"]').removeClass('col-sm-offset-6');
- } else {
- $('.taskParameter').hide();
- $('label[for="numReps"]').removeClass('col-sm-offset-4').addClass('col-sm-offset-6');
- }
- }
-
- /* Refresh the exercises based on the value selected in station */
- function refreshExercises(exerciseId) {
- var stationId = $('#stationSelect').val();
-
- $('#exerciseSelect').find('option').remove().end();
- $('#exerciseSelect').attr('disabled', true);
- if (stationId != '') {
- // AJAX Call to get the exercises of station selected
- $.ajax({
- url: '/api/v1/exercises',
- method: "GET",
- data: {
- station_id: stationId
- }
- }).done(function(data) {
- // Ok, add options in exercise Select
- // First remove previous options
-
- // Add all the exercises of the station
- var count = 0;
- $.each(data.data, function(i, item) {
- count ++;
- $('#exerciseSelect').append($('<option>', {
- value: item.id,
- text: item.name
- }));
- })
- // If exerciseId is not Null, set the values
- if (exerciseId) {
- $('#exerciseSelect').val(exerciseId);
- }
- if (count > 0) {
- $('#exerciseSelect').removeAttr('disabled');
- // Set the first option as selected
- $('#exerciseSelect').val($('#exerciseSelect option:first').val());
- //$('#exerciseSelect').val($('#exerciseSelect option:first').val());
- }
- // Calculate maximum_mean_velocity
- get_maximum_mean_velocity();
- });
- }
- }
-
-
-
- $('#taskLoad').change(function() {
- get_maximum_mean_velocity()
- });
-
- $('#taskLaterality').change(function() {
- get_maximum_mean_velocity();
- });
-
- /* Get max velocity when user selects station, exercice and resistance */
- function get_maximum_mean_velocity() {
- var resistance = $('#taskLoad').val();
- var stationId = $('#stationSelect').val();
- var personId = $('#playerId').val();
-
- var exerciseId = $('#exerciseSelect').val();
- if (exerciseId == null) {
- exerciseId = $('#exerciseSelect option:first').val();
- }
- var laterality = $('#taskLaterality').val();
- /*console.log("Check velocity max");
- console.log("Resistance: " + resistance);
- console.log("Station Id: " + stationId);
- console.log("Exercise Id: " + exerciseId);
- console.log("Person Id: " + personId);
- console.log("Laterality:" + laterality);*/
- if (resistance) {
- $.ajax({
- url: '/api/v1/get_maximum_mean_velocity',
- method: "GET",
- data: {
- station_id: stationId,
- exerciseId: exerciseId,
- personId: personId,
- resistance: resistance,
- laterality: laterality
- }
- }).done(function(data) {
- // Ok, add options in exercise Select
- // First remove previous options
-
- if (data.maximum_mean_velocity > 0 ) {
- //console.log("Enable taskPercentMaxSpeed");
- $('#taskSpeed').prop('disabled', false);
+/* Button to add players inside the datatable */
+$('div.toolbar').html('<a class="btn btn-primary pull-left" href="/player/add">Nou Jugador</a>');
+
+/* To show the modal form to add the tasks */
+$('#players').on('click', 'button', function() {
+ var player = table.row($(this).parents('tr')).data();
+
+ $('#modal-title').text('Afegir nova tasca per ' + player.name);
+ $('#taskModalForm').modal();
+ $('#playerId').val(player.id);
+ $('#taskId').val('-1');
+ $('#numTasks').val(1);
+
+ //refreshExercises(null);
+ // Modal is empty
+ /*$("#stationSelect").val($("#stationSelect option:first").val());
+
+ $('#numSets').val(-1);
+ $('#numReps').val(-1);
+ $('#taskLoad').val(-1);
+ $('#taskSpeed').val(-1);
+ $('#taskpercentMaxSpeed').val(-1);
+ $('#taskLaterality').val($("#taskLaterality option:first").val());
+ $('#taskComment').val('');*/
+ $('#taskParamSelector').removeClass('active');
+ $('#taskFreeSelector').removeClass('active');
+ $('#paramTask').removeClass('active');
+ $('#paramFree').removeClass('active');
+ $('#taskParamSelector').addClass('active');
+ $('#paramTask').addClass('active');
+ $('#btnDeleteTask').removeClass('show').addClass('hidden');
+ $('#btnUpdateTask').removeClass('show').addClass('hidden');
+ $('#btnAddTask').removeClass('hidden').addClass('show');
+ $('#taskParamSelector').removeClass('hide');
+ $('#taskFreeSelector').removeClass('hide');
+ taskTypeInt = 0;
+ $('#btnAddTask').removeClass('hidden');
+ $('#btnCreateTasks').addClass('hidden');
+ $('#btnAddMacroTask').addClass('hidden');
+ $('#btnResetMacroTask').addClass('hidden');
+ removeMacroTasksTable();
+ get_maximum_mean_velocity();
+});
+
+/* To show the form to modify the task */
+$('#players').on('click', 'a.task-link', function() {
+ var player = table.row($(this).parents('tr')).data();
+
+ $('#modal-title').text('Modificar tasca #' + $(this).attr('data-task-id') + ' per ' + player.name);
+ var taskType = $(this).attr('data-task-type');
+ var taskSets = $(this).attr('data-task-sets');
+ var taskReps = $(this).attr('data-task-nreps');
+ var taskLoad = $(this).attr('data-task-load');
+ var taskSpeed = $(this).attr('data-task-speed');
+ var taskPercentMaxSpeed = $(this).attr('data-task-percent-max-speed');
+ var taskLaterality = $(this).attr('data-task-laterality');
+ var stationId = $(this).attr('data-task-station-id');
+ var exerciseId = $(this).attr('data-task-exercise-id');
+ var taskComment = $(this).attr('data-task-comment');
+
+ $('#taskParamSelector').removeClass('active');
+ $('#taskFreeSelector').removeClass('active');
+ $('#paramTask').removeClass('active');
+ $('#paramFree').removeClass('active');
+ if (taskType == 'P') {
+ // Show panel for parametrized tasks
+ $('#taskParamSelector').addClass('active');
+ $('#paramTask').addClass('active');
+
+ } else {
+ // Show the panel for free tasks
+ $('#taskFreeSelector').addClass('active');
+ $('#freeTask').addClass('active');
+
+ }
+
+ // Fill the modal
+ $('#playerId').val(player.id);
+ $('#taskId').val($(this).attr('data-task-id'));
+ $('#stationSelect').val(stationId);
+ showHideParameters();
+ refreshExercises(exerciseId);
+ $('#numSets').val(taskSets);
+ $('#numReps').val(taskReps);
+ $('#taskLoad').val(taskLoad);
+ $('#taskSpeed').val(taskSpeed);
+ $('#taskpercentMaxSpeed').val(taskPercentMaxSpeed);
+ $('#taskLaterality').val(taskLaterality);
+ $('#taskComment').val(taskComment);
+
+ // Hide and show the buttons
+ $('#btnDeleteTask').removeClass('hidden').addClass('show');
+ $('#btnUpdateTask').removeClass('hidden').addClass('show');
+ $('#btnAddTask').removeClass('show').addClass('hidden');
+ $('#taskModalForm').modal();
+ get_maximum_mean_velocity();
+ if (taskLoad > 0) {
+ $('#taskSpeed').prop('disabled', false);
+ }
+ if (taskpercentMaxSpeed > 0){
+ $('#taskpercentMaxSpeed').prop('disabled', false);
+ }
+
+ /* Hide the Macro Tasks */
+ $('#btnCreateTasks').addClass('hide');
+ $('#btnAddMacroTasks').addClass('hide');
+
+ /* Hide the option to select individual and macro task */
+ $('#taskParamSelector').addClass('hide');
+ $('#taskFreeSelector').addClass('hide');
+
+});
+
+/* Each time the user selects a station, the exercise from this station is
+refreshed. */
+$('#stationSelect').on('change', function() {
+ //Ajax call to retrieve all the exercises. Call the function below.
+
+ // Hide Show parameters based on station type
+ showHideParameters();
+ // Show the exercises of this station
+ refreshExercises(null);
+
+
+
+});
+
+$('#exerciseSelect').on('change', function() {
+ get_maximum_mean_velocity();
+});
+
+/* Show or Hide Parameters based on Station Type */
+function showHideParameters() {
+ var optSelected = $('#stationSelect').find(':selected').attr('data-station-type');
+ // Show or hide some of the elememts of the task depending of station type
+ if (optSelected != 'S') {
+ $('.taskParameter').show();
+ $('label[for="numReps"]').removeClass('col-sm-offset-6');
+ } else {
+ $('.taskParameter').hide();
+ $('label[for="numReps"]').removeClass('col-sm-offset-4').addClass('col-sm-offset-6');
+ }
+}
+
+/* Refresh the exercises based on the value selected in station */
+function refreshExercises(exerciseId) {
+ var stationId = $('#stationSelect').val();
+
+ $('#exerciseSelect').find('option').remove().end();
+ $('#exerciseSelect').attr('disabled', true);
+ if (stationId != '') {
+ // AJAX Call to get the exercises of station selected
+ $.ajax({
+ url: '/api/v1/exercises',
+ method: "GET",
+ data: {
+ station_id: stationId
+ }
+ }).done(function(data) {
+ // Ok, add options in exercise Select
+ // First remove previous options
+
+ // Add all the exercises of the station
+ var count = 0;
+ $.each(data.data, function(i, item) {
+ count ++;
+ $('#exerciseSelect').append($('<option>', {
+ value: item.id,
+ text: item.name
+ }));
+ })
+ // If exerciseId is not Null, set the values
+ if (exerciseId) {
+ $('#exerciseSelect').val(exerciseId);
+ }
+ if (count > 0) {
+ $('#exerciseSelect').removeAttr('disabled');
+ // Set the first option as selected
+ $('#exerciseSelect').val($('#exerciseSelect option:first').val());
+ //$('#exerciseSelect').val($('#exerciseSelect option:first').val());
+ }
+ // Calculate maximum_mean_velocity
+ get_maximum_mean_velocity();
+ });
+ }
+}
+
+
+
+$('#taskLoad').change(function() {
+ get_maximum_mean_velocity()
+});
+
+$('#taskLoad2').change(function() {
+ console.log("load2");
+ get_maximum_mean_velocity()
+});
+
+$('#taskLaterality').change(function() {
+ get_maximum_mean_velocity();
+});
+
+$('#taskLaterality2').change(function() {
+ get_maximum_mean_velocity();
+});
+
+/* Get max velocity when user selects station, exercice and resistance */
+function get_maximum_mean_velocity() {
+ if (taskTypeInt == 0) {
+ var resistance = $('#taskLoad').val();
+ var laterality = $('#taskLaterality').val();
+ } else {
+ var resistance = $('#taskLoad2').val();
+ var laterality = $('#taskLaterality2').val();
+ }
+ console.log("Resistance is " + resistance);
+ var stationId = $('#stationSelect').val();
+ var playerId = $('#playerId').val();
+ var exerciseId = $('#exerciseSelect').val();
+ if (exerciseId == null) {
+ exerciseId = $('#exerciseSelect option:first').val();
+ }
+
+ console.log("Check velocity max");
+ console.log("Resistance: " + resistance);
+ console.log("Station Id: " + stationId);
+ console.log("Exercise Id: " + exerciseId);
+ console.log("Person Id: " + playerId);
+ console.log("Laterality:" + laterality);
+ if (resistance) {
+ $.ajax({
+ url: '/api/v1/get_maximum_mean_velocity',
+ method: "GET",
+ data: {
+ station_id: stationId,
+ exerciseId: exerciseId,
+ personId: playerId,
+ resistance: resistance,
+ laterality: laterality
+ }
+ }).done(function(data) {
+ // Ok, add options in exercise Select
+ // First remove previous options
+ console.log(taskTypeInt);
+ if (data.maximum_mean_velocity > 0 ) {
+ //console.log("Enable taskPercentMaxSpeed");
+ if (taskTypeInt == 0) {
+ $('#taskSpeed').prop('disabled', false);
$('#taskMaxSpeed').val(data.maximum_mean_velocity.toFixed(2));
$('#taskMaxSpeed').prop('disabled', false);
- $('#taskpercentMaxSpeed').prop('disabled', false);
- } else {
- // No velocity max, means disable velocityMAx control
- //console.log("Disable taskPercentMaxSpeed");
- $('#taskSpeed').prop('disabled', false);
+ $('#taskpercentMaxSpeed').prop('disabled', false);
+ } else {
+ $('#taskSpeed2').prop('disabled', false);
+ $('#taskMaxSpeed2').val(data.maximum_mean_velocity.toFixed(2));
+ $('#taskMaxSpeed2').prop('disabled', false);
+ $('#taskpercentMaxSpeed2').prop('disabled', false);
+ }
+ } else {
+ // No velocity max, means disable velocityMAx control
+ //console.log("Disable taskPercentMaxSpeed");
+ if (taskTypeInt == 0) {
+ $('#taskSpeed').prop('disabled', false);
$('#taskMaxSpeed').val('');
$('#taskMaxSpeed').prop('disabled', true);
- $('#taskpercentMaxSpeed').prop('disabled', true);
- }
- });
- } else {
- // Wait until user enters resistance
- }
- }
-
- // Refresh Exercises at the begining
- refreshExercises(null);
+ $('#taskpercentMaxSpeed').prop('disabled', true);
+ } else {
+ $('#taskSpeed2').prop('disabled', false);
+ $('#taskMaxSpeed2').val('');
+ $('#taskMaxSpeed2').prop('disabled', true);
+ $('#taskpercentMaxSpeed2').prop('disabled', true);
+ }
+
+ }
+ });
+ } else {
+ // Wait until user enters resistance
+ }
+}
+
+// Refresh Exercises at the begining
+refreshExercises(null);
});
diff --git a/chronojumpserver/templates/results.html b/chronojumpserver/templates/results.html
index 538ddf6..015c02c 100755
--- a/chronojumpserver/templates/results.html
+++ b/chronojumpserver/templates/results.html
@@ -202,7 +202,7 @@ $(document).ready(function() {
},
{
type: "num",
- data: "lossBySpeed",
+ data: "lossByPower",
title: "Pèrdua"
},
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]