[chronojump-server] Stations can now be added from Chronojump Server
- From: Marcos Venteo Garcia <mventeo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Stations can now be added from Chronojump Server
- Date: Mon, 26 Jun 2017 06:39:30 +0000 (UTC)
commit 93fc4c4f058ef205f880114eccb58080481f1ea9
Author: Marcos Venteo <mventeo gmail com>
Date: Mon Jun 26 08:39:09 2017 +0200
Stations can now be added from Chronojump Server
chronojumpserver/api.py | 43 +++++++++++++-----
chronojumpserver/js/players.js | 21 +--------
chronojumpserver/js/results.js | 10 +++--
chronojumpserver/js/sprints.js | 4 +-
chronojumpserver/js/stations.js | 41 +++++++++++++++--
chronojumpserver/models.py | 6 +-
chronojumpserver/static/style.css | 4 +-
chronojumpserver/templates/player_list.html | 5 --
chronojumpserver/templates/station_list.html | 63 +++++++++++++++-----------
chronojumpserver/views.py | 18 +++++++-
10 files changed, 135 insertions(+), 80 deletions(-)
---
diff --git a/chronojumpserver/api.py b/chronojumpserver/api.py
index 539f4f0..f75245e 100755
--- a/chronojumpserver/api.py
+++ b/chronojumpserver/api.py
@@ -5,7 +5,8 @@
"""
from chronojumpserver import app
from chronojumpserver.database import db_session
-from chronojumpserver.models import Person, ResultEncoder, Station, Task, ResultSprint
+from chronojumpserver.models import Person, ResultEncoder, Station, Task
+from chronojumpserver.models import ResultSprint
from flask import jsonify, request
from time import sleep
import os
@@ -14,17 +15,21 @@ import subprocess
@app.route('/api/v1/results')
def get_all_results():
+ """Return all results as a json list."""
results = [result.serialize for result in ResultEncoder.query.all()]
return jsonify(data=results)
+
@app.route('/api/v1/sprints')
def get_all_sprints():
+ """Return all sprints as a json list."""
results = [result.serialize for result in ResultSprint.query.all()]
return jsonify(data=results)
@app.route('/api/v1/players')
def get_all_players():
+ """Return all the playes with the active tasks."""
players = []
for player in Person.query.all():
_player = player.serialize
@@ -50,6 +55,7 @@ def get_all_players():
@app.route('/api/v1/exercises')
def get_exercises_by_station():
+ """Return all the exercises of a given station."""
stationId = request.args.get('station_id')
print "STATION ID IS %s" % stationId
station = Station.query.filter(Station.id == stationId).first()
@@ -105,7 +111,7 @@ def register_rfid():
@app.route('/api/v1/tasks', methods=['PUT', 'DELETE'])
def add_modify_delete_task():
- """API to register a new task that could be free or parametrized."""
+ """Add/Modify or delete a task."""
if request.method == 'PUT':
personId = request.form['playerId']
stationId = request.form['stationId']
@@ -141,15 +147,15 @@ def add_modify_delete_task():
# Get the task with the id."""
db_session.query(Task).filter_by(id=taskId).update({
'type': taskType,
- 'stationId':stationId,
- 'exerciseId':exerciseId,
- 'sets':sets,
- 'nreps':nreps,
- 'load':load,
- 'speed':speed,
- 'percentMaxSpeed':percentMaxSpeed,
- 'laterality':laterality,
- 'comment':description
+ 'stationId': stationId,
+ 'exerciseId': exerciseId,
+ 'sets': sets,
+ 'nreps': nreps,
+ 'load': load,
+ 'speed': speed,
+ 'percentMaxSpeed': percentMaxSpeed,
+ 'laterality': laterality,
+ 'comment': description
})
db_session.commit()
elif request.method == "DELETE":
@@ -159,6 +165,19 @@ def add_modify_delete_task():
db_session.delete(t)
db_session.commit()
+ return jsonify(msg='Task has been successfully added')
+
+@app.route('/api/v1/stations', methods=['PUT', 'DELETE'])
+def add_modify_delete_stations():
+ if request.method == "PUT":
+ stationId = request.form['stationId']
+ stationName = request.form['stationName']
+ stationType = request.form['stationType']
+ if int(stationId) == -1:
+ # New station
+ s = Station(name=stationName, type=stationType)
+ db_session.add(s)
+ db_session.commit()
- return jsonify(msg='Task has been successfully added')
+ return jsonify(msg="Success")
diff --git a/chronojumpserver/js/players.js b/chronojumpserver/js/players.js
index 5464361..cb60e3e 100755
--- a/chronojumpserver/js/players.js
+++ b/chronojumpserver/js/players.js
@@ -44,21 +44,6 @@ function addModifyDeleteTask(action) {
var percentMaxSpeed = $('#taskpercentMaxSpeed').val();
var laterality = $('#taskLaterality').val();
-
- console.log('PlayerId: ' + playerId);
- console.log('TaskId: ' + taskId);
- console.log('Description: ' + description);
- console.log('Task Type: ' + taskType);
- console.log('Station selected: ' + stationId);
- console.log('Exercise selected: ' + exerciseId);
- console.log('Sets selected: ' + sets);
- console.log('Repeats selected: ' + reps);
- console.log('Speed selected: ' + load);
- console.log('percentMaxSpeed selected: ' + percentMaxSpeed);
- console.log('laterality selected: ' + laterality);
-
-
-
// Set the method
if (action == 2) {
method = 'DELETE';
@@ -85,16 +70,12 @@ function addModifyDeleteTask(action) {
laterality: laterality
}
}).done(function(data) {
- console.log(data);
- console.log('The task has been added');
var table = $('#players').DataTable();
table.ajax.reload(null, false);
}).fail(function(xhr, status, error){
var err = eval("(" + xhr.responseText + ")");
alert(err.msg);
- }).always(function(){
-
- });;
+ });
}
diff --git a/chronojumpserver/js/results.js b/chronojumpserver/js/results.js
index c07442f..a7d8118 100755
--- a/chronojumpserver/js/results.js
+++ b/chronojumpserver/js/results.js
@@ -3,6 +3,8 @@
* Author: Marcos Venteo <mventeo gmail com>
* version: 1.0
*
+ * Copyright (C) 2017 Xavier de Blas <xaviblas gmail com>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -44,7 +46,7 @@ $(document).ready(function() {
}
);
-
+ /* Create the table for results with Datatables */
var table = $('#results').DataTable({
"columns": [{
type: "num",
@@ -252,8 +254,8 @@ $(document).ready(function() {
setInterval(function() {
- /* Set the interval for refresh */
- table.ajax.reload(null, false);
- }, 5000);
+ /* Set the interval for refresh */
+ table.ajax.reload(null, false);
+ }, 15000);
});
diff --git a/chronojumpserver/js/sprints.js b/chronojumpserver/js/sprints.js
index cc1401b..49f5450 100644
--- a/chronojumpserver/js/sprints.js
+++ b/chronojumpserver/js/sprints.js
@@ -1,5 +1,5 @@
/*!
- * Results javascript functions for Chronojump Server
+ * ResultSprints javascript functions for Chronojump Server
* Author: Marcos Venteo <mventeo gmail com>
* version: 1.0
*
@@ -232,6 +232,6 @@ $(document).ready(function() {
setInterval(function() {
/* Set the interval for refresh */
table.ajax.reload(null, false);
- }, 5000);
+ }, 15000);
});
diff --git a/chronojumpserver/js/stations.js b/chronojumpserver/js/stations.js
index 6e3c060..b99e2df 100644
--- a/chronojumpserver/js/stations.js
+++ b/chronojumpserver/js/stations.js
@@ -19,6 +19,41 @@
*/
+/* Show stationModalForm to create a new station */
+$('#btnShowStationModalForm').on('click', function() {
+ $('#stationModalForm').modal();
+});
+
+/* Show exerciseModalForm to create a new exercise */
+$('#btnAddStation').on('click', function() {
+ var stationName = $('#stationName').val();
+ var stationType = $('#stationType').val();
+ // Hide the modal form
+
+ $.ajax({
+ url: '/api/v1/stations',
+ method: 'PUT',
+ data: {
+ stationId: -1,
+ stationName: stationName,
+ stationType: stationType
+ }
+ }).done(function(data) {
+ var table = $('#players').DataTable();
+ table.ajax.reload(null, false);
+ $('#stationModalForm').modal('hide');
+ // Reload the page
+ window.location.reload(false);
+ }).fail(function(xhr, status, error){
+ var err = eval("(" + xhr.responseText + ")");
+ alert(err.msg);
+ });
+});
+
+
+
+/* Load exercises from the station selected creating a datatable and loading
+ the exercises via Ajax */
function loadExercises(station_id, first=false) {
if ( first == false) {
$('#exercises').DataTable().destroy();
@@ -76,7 +111,7 @@ function loadExercises(station_id, first=false) {
"search": "Cerca:"
}
});
- //table.ajax.reload(null, false);
+
}
@@ -87,8 +122,6 @@ $(document).ready(function() {
var stationSelected = 1;
// Load the exercises of first station
- loadExercises(stationSelected, true);
-
-
+ //loadExercises(stationSelected, true);
});
diff --git a/chronojumpserver/models.py b/chronojumpserver/models.py
index f609ff3..2bec6c4 100755
--- a/chronojumpserver/models.py
+++ b/chronojumpserver/models.py
@@ -108,7 +108,7 @@ class Station(HelperMixin, Base):
def serialize(self):
return {
'id': self.id,
- 'name': self.name
+ 'name': self.name.decode('utf-8')
}
def __repr__(self):
@@ -162,9 +162,9 @@ class Exercise(HelperMixin, Base):
"""Serialize the object in json."""
return {
'id': self.id,
- 'name': self.name,
+ 'name': self.name.decode('utf-8'),
'stationId': self.stationId,
- 'stationName': self.station.name
+ 'stationName': self.station.name.decode('utf-8')
}
def __repr__(self):
diff --git a/chronojumpserver/static/style.css b/chronojumpserver/static/style.css
index 240ad24..16222df 100755
--- a/chronojumpserver/static/style.css
+++ b/chronojumpserver/static/style.css
@@ -64,9 +64,9 @@ body.home {
vertical-align: middle;
}
-#btnAddStation, #btnAddExercise {
+#btnShowStationModalForm, #btnShowExerciseModalForm {
position: relative;
- top: -24px;
+ top: -23px;
right: -10px;
float: right;
}
diff --git a/chronojumpserver/templates/player_list.html b/chronojumpserver/templates/player_list.html
index 2271190..fdadc79 100755
--- a/chronojumpserver/templates/player_list.html
+++ b/chronojumpserver/templates/player_list.html
@@ -22,11 +22,6 @@
<div class="modal-body">
<input type="hidden" id="playerId">
<input type="hidden" id="taskId">
- <div class="" style="margin-bottom: 10px;">
- <form class="form-inline" >
-
- </form>
- </div>
<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">Parametritzada</a></li>
diff --git a/chronojumpserver/templates/station_list.html b/chronojumpserver/templates/station_list.html
index 8defb85..fe0bdfc 100644
--- a/chronojumpserver/templates/station_list.html
+++ b/chronojumpserver/templates/station_list.html
@@ -9,41 +9,20 @@
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
- <h3 class="panel-title">Estacions</h3><button id="btnAddStation" class="btn btn-default
btn-sm">Afegir Estació</button>
+ <h3 class="panel-title">Estacions</h3><button id="btnShowStationModalForm" class="btn
btn-default btn-sm">Afegir Estació</button>
</div>
- <ul class="list-group">
+ <ul id="stationList" class="list-group">
{% for station in stations %}
- <li class="list-group-item"><a
onclick="loadExercises({{station.id}});">{{station.name}}</a></li>
+ <li id="station-{{station.id}}" class="list-group-item"><a
onclick="loadExercises({{station.id}});">{{station.name}}</a></li>
{% endfor %}
- </ul>
+ </ul>
</div>
-
-
</div>
<div class="col-sm-8">
{% if stations|length > 0 %}
<div class="panel panel-default">
<div class="panel-heading">
- <h2 class="panel-title">Detall de l'Estació <span
id="stationName">{{stations[0].name}}</span></h2>
- </div>
- <div class="panel-body">
- <form class="form-inline">
- <div class="form-group">
- <label class="control-label">Nom:</label>
- <input class="form-control" name="stationName" id="stationName" type="text"
value="{{stations[0].name}}" />
- </div>
- <div class="form-group">
- <label class="control-label">Tipus:</label>
- <input class="form-control" name="stationType" id="stationType" type="text"
value="{{stations[0].type}}" />
- </div>
- <button class="btn btn-primary">Actualitzar Estació</button>
- </form>
- </div>
- </div>
-
- <div class="panel panel-default">
- <div class="panel-heading">
- <h3 class="panel-title">Exercisis de l'Estació</h3><button id="btnAddExercise" class="btn
btn-default btn-sm">Afegir Exercisi</button>
+ <h3 class="panel-title">Exercisis de l'Estació</h3><button id="btnShowExerciseModalForm"
class="btn btn-default btn-sm">Afegir Exercisi</button>
</div>
<table id="exercises" class="table table-hovered">
</table>
@@ -51,6 +30,38 @@
{% endif %}
</div>
</div>
+<div id="stationModalForm" class="modal fade" tabindex="-1" role="dialog">
+ <div class="modal-dialog" role="document">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal"
aria-label="Close"><span aria-hidden="true">×</span></button>
+ <h4 id="modal-title" class="modal-title">Nova Estació</h4>
+ </div>
+ <div class="modal-body">
+ <form class="form">
+ <div class="form-group">
+ <label for="stationName" class="control-label">Nom</label>
+ <input id="stationName" name="stationName" type="text" class="form-control"/>
+ </div>
+ <div class="form-group">
+ <label for="stationType" class="control-label">Tipus</label>
+ <select id="stationType" name="stationType" class="form-control">
+ <option value="G">Gravitatori</option>
+ <option value="I">Inercial</option>
+ <option value="S">Sprint</option>
+ </select>
+ </div>
+ </form>
+ </div> <!-- .modal-body -->
+ <div class="modal-footer">
+ <button type="button" class="pull-left btn btn-default"
data-dismiss="modal">Cancelar</button>
+ <button id="btnAddStation" type="button" class="pull-right btn
btn-primary">Afegir</button>
+ </div>
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
{% endblock %}
{% block script %}
diff --git a/chronojumpserver/views.py b/chronojumpserver/views.py
index 9fe3247..a765869 100755
--- a/chronojumpserver/views.py
+++ b/chronojumpserver/views.py
@@ -31,13 +31,27 @@ def show_sprints():
@app.route('/player_list')
def show_players():
"""Show players view."""
- return render_template('player_list.html', stations=Station.query.all())
+ stations = []
+ for station in Station.query.all():
+ stations.append({
+ 'id': station.id,
+ 'name': station.name.decode('utf-8'),
+ 'type': station.type
+ })
+ return render_template('player_list.html', stations=stations)
@app.route('/stations')
def show_stations():
"""Show Stations and Exercises."""
- return render_template('station_list.html', stations=Station.query.all())
+ stations = []
+ for station in Station.query.all():
+ stations.append({
+ 'id': station.id,
+ 'name': station.name.decode('utf-8'),
+ 'type': station.type
+ })
+ return render_template('station_list.html', stations=stations)
@app.route('/player/<player_id>', methods=['GET', 'POST'])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]