Skip to content

Commit

Permalink
Merge 24a2fd5 into 7d2c0e8
Browse files Browse the repository at this point in the history
  • Loading branch information
justMuriithi committed Jun 18, 2019
2 parents 7d2c0e8 + 24a2fd5 commit be70919
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 20 deletions.
14 changes: 12 additions & 2 deletions wger/gym/templates/gym/partial_user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
href="{% static 'bower_components/datatables/media/css/dataTables.bootstrap.min.css' %}">
<script src="{% static 'bower_components/datatables/media/js/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'bower_components/datatables/media/js/dataTables.bootstrap.min.js' %}"></script>

<script src="{% static 'js/compare_weight.js' %}"></script>
<input type="hidden" name="table_id_var" value="{{ table_id }}">

<script>
Expand All @@ -25,11 +25,17 @@
});

</script>


<div id="compare_weight_diagrams"></div>
<button id="compare" class="btn btn-success btn-sm" style="margin-top: 10px">Compare</button>

<table class="table table-hover" id="{{ table_id }}">


<thead>
<tr>
<th></th>
{% for key in user_table.keys %}
<th>{{ key }}</th>
{% endfor %}
Expand All @@ -38,6 +44,10 @@
<tbody>
{% for current_user in user_table.users %}
<tr>
<td>
<input type="checkbox" class="checkbox" id="{{current_user.obj.username}}"
value="{{current_user.obj.first_name}} {{current_user.obj.last_name}}">
</td>
<td>
{{current_user.obj.pk}}
</td>
Expand All @@ -64,4 +74,4 @@
</tr>
{% endfor %}
</tbody>
</table>
</table>
78 changes: 78 additions & 0 deletions wger/weight/static/js/compare_weight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
This file is part of wger Workout Manager.
wger Workout Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
wger Workout Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
*/
'use strict';

$(document).ready(function () {
$('#compare').hide();
var url;
var username;
var nametext;
var chartParams;
var weightChart;
var checkboxes;
var data;

$('input[type=checkbox].checkbox').change(function () {
checkboxes = $('input[type=checkbox].checkbox:checked');
if (checkboxes.size() === 2) {
$('#compare').show();
} else {
$('#compare').hide();
$('#compare_weight_diagrams').empty();
}
});


$('#compare').click(function () {
var users = [];
$(checkboxes).each(function (index) {
username = $(this).attr('id');
nametext = $(this).attr('value');
url = '/weight/api/compare_weight_data/' + username;
users.push(nametext + ' (' + username + ')');
d3.json(url).then(function (json) {
weightChart = {};
chartParams = {
animate_on_load: true,
full_width: true,
top: 10,
left: 30,
right: 10,
show_secondary_x_label: true,
xax_count: 10,
target: '[data-id="weight_diagram_' + index + '"]',
x_accessor: 'date',
y_accessor: 'weight',
min_y_from_data: true,
colors: ['#3465a4'],
title: users[index]
};

if (json.length) {
$('#compare_weight_diagrams').append("<div data-id='weight_diagram_" + index + "'></div>");
data = MG.convert.date(json, 'date');
weightChart.data = data;
// Plot the data
chartParams.data = data;
MG.data_graphic(chartParams);

} else {
alert(users[index] + ' has no weight data');
}
});
});
});
});
27 changes: 15 additions & 12 deletions wger/weight/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,29 @@
name='add'),

path('<pk>/edit/',
login_required(views.WeightUpdateView.as_view()),
name='edit'),
login_required(views.WeightUpdateView.as_view()),
name='edit'),

path('export-csv/',
views.export_csv,
name='export-csv'),
views.export_csv,
name='export-csv'),
path('import-csv/',
login_required(views.WeightCsvImportFormPreview(WeightCsvImportForm)),
name='import-csv'),
login_required(views.WeightCsvImportFormPreview(WeightCsvImportForm)),
name='import-csv'),

path('overview/<username>',
views.overview,
name='overview'),
views.overview,
name='overview'),
# url(r'^overview/$',
# views.overview,
# name='overview'),
path('api/get_weight_data/<username>', # JS
views.get_weight_data,
name='weight-data'),
views.get_weight_data,
name='weight-data'),
path('api/get_weight_data/', # JS
views.get_weight_data,
name='weight-data'),
views.get_weight_data,
name='weight-data'),
path('api/compare_weight_data/<username>',
views.compare_weight_data,
name='compare-weight-data'),
]
29 changes: 23 additions & 6 deletions wger/weight/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from wger.weight import helpers
from wger.utils.helpers import check_access
from wger.utils.generic_views import WgerFormMixin
from django.contrib.auth.models import User


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -160,13 +161,12 @@ def overview(request, username=None):
return render(request, 'overview.html', template_data)


@api_view(['GET'])
def get_weight_data(request, username=None):
'''
Process the data to pass it to the JS libraries to generate an SVG image
'''
def return_chart_data(request, username=None, action="get"):

is_owner, user = check_access(request.user, username)
if action == "get":
is_owner, user = check_access(request.user, username)
else:
user = User.objects.get(username=username)

date_min = request.GET.get('date_min', False)
date_max = request.GET.get('date_max', True)
Expand All @@ -187,6 +187,23 @@ def get_weight_data(request, username=None):
return Response(chart_data)


@api_view(['GET'])
def get_weight_data(request, username=None):
'''
Process the data to pass it to the JS libraries to generate an SVG image
'''
return return_chart_data(request, username, "get")


@api_view(['GET'])
def compare_weight_data(request, username=None):
'''
Process the data to pass it to the JS libraries to generate an SVG image
'''

return return_chart_data(request, username, "compare")


class WeightCsvImportFormPreview(FormPreview):
preview_template = 'import_csv_preview.html'
form_template = 'import_csv_form.html'
Expand Down

0 comments on commit be70919

Please sign in to comment.