[chronojump-server] - Enabling group filters in results - Some changes in the style to use all the screen. - Adding a ne



commit d052917abb022b37e5b040295f81e03030e7414e
Author: Marcos Venteo <mventeo gmail com>
Date:   Wed Mar 28 11:39:53 2018 +0200

    - Enabling group filters in results
    - Some changes in the style to use all the screen.
    - Adding a new style design to datatables, background-shadow

 chronojumpserver/api.py                 |   20 ++++++++++++++-
 chronojumpserver/models.py              |    2 +-
 chronojumpserver/static/style.css       |   12 +++++++++
 chronojumpserver/templates/layout.html  |    2 +-
 chronojumpserver/templates/results.html |   41 +++++++++++++++++++++++++-----
 chronojumpserver/views.py               |   16 ++++++++++--
 6 files changed, 80 insertions(+), 13 deletions(-)
---
diff --git a/chronojumpserver/api.py b/chronojumpserver/api.py
index 9ae9d76..6b54b37 100755
--- a/chronojumpserver/api.py
+++ b/chronojumpserver/api.py
@@ -7,6 +7,7 @@ from chronojumpserver import app
 from chronojumpserver.database import db_session
 from chronojumpserver.models import Person, ResultEncoder, Station, Task
 from chronojumpserver.models import ResultSprint, Exercise, RFIDHistory
+from chronojumpserver.models import Group, GroupCoach, GroupPerson
 from flask import jsonify, request
 from flask_login import login_required
 from sqlalchemy.exc import IntegrityError, InvalidRequestError, OperationalError
@@ -19,7 +20,24 @@ 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()]
+    group_id = request.args.get('group_id')
+    org_id = request.args.get('org_id')
+    coach_id = request.args.get('coach_id')
+
+    if group_id == "all" :
+        groups_coach = [ result.group_id for result in GroupCoach.query.filter(GroupCoach.coach_id == 
coach_id)]
+        players_group = [ result.person_id for result in 
GroupPerson.query.filter(GroupPerson.group_id.in_(groups_coach))]
+        players = [ result.id for result in Person.query.filter(Person.id.in_(players_group))]
+
+        results = [result.serialize for result in 
ResultEncoder.query.filter(ResultEncoder.personId.in_(players))]
+        #print(results)
+    else:
+        players_group = [ result.person_id for result in GroupPerson.query.filter(GroupPerson.group_id == 
group_id)]
+        players = [ result.id for result in Person.query.filter(Person.id.in_(players_group))]
+        if len(players) > 0:
+            results = [result.serialize for result in 
ResultEncoder.query.filter(ResultEncoder.personId.in_(players))]
+        else:
+            results = []
     return jsonify(data=results)
 
 
diff --git a/chronojumpserver/models.py b/chronojumpserver/models.py
index 50b48e8..dd4c876 100755
--- a/chronojumpserver/models.py
+++ b/chronojumpserver/models.py
@@ -69,7 +69,7 @@ class GroupCoach(HelperMixin, Base):
     coach_id = Column(Integer, nullable=False)
 
 
-class groupPerson(HelperMixin, Base):
+class GroupPerson(HelperMixin, Base):
     __tablename__ = 'groupPerson'
 
     group_id = Column(Integer, nullable=False)
diff --git a/chronojumpserver/static/style.css b/chronojumpserver/static/style.css
index d163fb7..0e92ad8 100755
--- a/chronojumpserver/static/style.css
+++ b/chronojumpserver/static/style.css
@@ -160,3 +160,15 @@ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00894e', end
     font-weight: bold;
     padding-top: 10px;
 }
+
+#datatable_wrapper {
+  margin-top: 20px;
+  padding: 10px;
+  border-radius: 4px 4px 4px 4px;
+  -moz-border-radius: 4px 4px 4px 4px;
+  -webkit-border-radius: 4px 4px 4px 4px;
+  border: 1px solid rgba(240,235,240,1);
+  -webkit-box-shadow: 4px 4px 5px 0px rgba(240,235,240,1);
+  -moz-box-shadow: 4px 4px 5px 0px rgba(240,235,240,1);
+  box-shadow: 4px 4px 5px 0px rgba(240,235,240,1);
+}
diff --git a/chronojumpserver/templates/layout.html b/chronojumpserver/templates/layout.html
index f40e4cd..c29f4ec 100755
--- a/chronojumpserver/templates/layout.html
+++ b/chronojumpserver/templates/layout.html
@@ -43,7 +43,7 @@
     </nav>
     {% endblock %}
 
-    <div id="main" class="container">
+    <div id="main-content" class="container-fluid" style="margin-left: 30px;margin-right:30px">
         {% block content %}{% endblock %}
     </div>
 
diff --git a/chronojumpserver/templates/results.html b/chronojumpserver/templates/results.html
index 07c3f29..6bdbaed 100755
--- a/chronojumpserver/templates/results.html
+++ b/chronojumpserver/templates/results.html
@@ -13,7 +13,7 @@
 </div>
 
 <div id="resultsFilter" class="row">
-       <div class="col-sm-6">
+       <div class="col-sm-4">
                <label class="radio-inline dayfilter" style="margin-top:5px">
                        <input type="radio" name="filterByDayOptions" id="filterByDay1" value="1" >1d
                </label>
@@ -30,17 +30,26 @@
                        <input type="radio" name="filterByDayOptions" id="filterByDay5" value="all" 
checked>{{_('All')}}
                </label>
        </div>
-       <div class="col-sm-6">
+       <div class="col-sm-8">
                <div class="row" style="margin-left: -50px">
-                       <div class="col-sm-4">
+                       <div class="col-sm-3">
+                               <label for="player_filter" class="sr-only">{{_('By group')}}</label>
+                               <select name="group" class="form-control" id="groupSelect">
+                                       <option value="all">{{_('All groups')}}
+                                       {% for group in groups %}
+                                       <option value={{group.id}}>{{group.name}}</option>
+                                       {% endfor %}
+                               </select>
+                       </div>
+                       <div class="col-sm-3">
                                <label for="player_filter" class="sr-only">{{_('By player')}}</label>
                                <div id="filterByPlayer"></div>
                        </div>
-                       <div class="col-sm-4">
+                       <div class="col-sm-3">
                                <label for="fullname_filter" class="sr-only">{{_('By station')}}</label>
                                <div id="filterByStation"></div>
                        </div>
-                       <div class="col-sm-4">
+                       <div class="col-sm-3">
                                <label for="fullname_filter" class="sr-only">{{_('By exercice')}}</label>
                                <div id="filterByExercice"></div>
                        </div>
@@ -50,10 +59,12 @@
 
 </div>
 
-<div class="row" style="margin-top:20px">
+<div id="datatable_wrapper" class="row">
        <table id="results" class="table table-hovered" cellspacing="0" width="100%">
        </table>
        <div id="hiddenContainer" style="display:none"/>
+       <input type="hidden" id="org_id" value="{{org_id}}"/>
+       <input type="hidden" id="coach_id" value="{{coach_id}}"/>
 </div>
 
 
@@ -363,7 +374,14 @@ $(document).ready(function() {
 "order": [ 
        [1, 'desc']
 ],
-"ajax": "/api/v1/results",
+"ajax": {
+       url: "/api/v1/results",
+       data: function(d){
+               d.group_id = $('#groupSelect').val();
+               d.org_id = $('#org_id').val();
+               d.coach_id = $('#coach_id').val();;
+       }
+},
 "processing": true,
 "severSide": true,
 "language": {
@@ -509,7 +527,16 @@ function refreshIntervalTrigger() {
 
 refreshIntervalId = refreshIntervalTrigger();
 console.log("Interval refresh is enabled with id " + refreshIntervalId);
+
+/* Reload results for the group selected */
+$('#groupSelect').on('change', function() {
+       table.ajax.reload(enableDeletion, false);
 });
+
+});
+
+
+
 </script>
 
 {% endblock %}
diff --git a/chronojumpserver/views.py b/chronojumpserver/views.py
index 7916702..b21fd1f 100755
--- a/chronojumpserver/views.py
+++ b/chronojumpserver/views.py
@@ -4,7 +4,7 @@ from chronojumpserver import app
 from flask import render_template, request, redirect, url_for, abort, flash
 from urlparse import urlparse, urljoin
 from flask_wtf.file import FileField
-from chronojumpserver.models import Person, Station, RFIDHistory, User
+from chronojumpserver.models import Person, Station, RFIDHistory, User, Group, GroupCoach, GroupPerson, Coach
 from chronojumpserver.forms import PersonForm, LoginForm
 from flask_login import login_required, login_user, logout_user, current_user
 from chronojumpserver.database import db_session
@@ -43,8 +43,18 @@ def airport():
 @app.route('/results')
 @login_required
 def show_results():
-    """Show results view."""
-    return render_template('results.html')
+
+    user_id = current_user.id
+    coach = Coach.query.filter(Coach.user_id == user_id).first()
+    groups = []
+
+    groups_by_coach = [ g.id for g in GroupCoach.query.filter(GroupCoach.coach_id == coach.id)]
+    for g in Group.query.filter(Group.id.in_(groups_by_coach)):
+        groups.append({
+                'id': g.id,
+                'name': g.name.decode('utf-8')
+            })
+    return render_template('results.html', groups=groups, coach_id=coach.id, org_id=2)
 
 @app.route('/sprints')
 @login_required


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