diff --git a/wger/gym/templates/gym/partial_user_list.html b/wger/gym/templates/gym/partial_user_list.html
index d4bd4936..31e52f5d 100644
--- a/wger/gym/templates/gym/partial_user_list.html
+++ b/wger/gym/templates/gym/partial_user_list.html
@@ -4,7 +4,8 @@
href="{% static 'bower_components/datatables/media/css/dataTables.bootstrap.min.css' %}">
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/wger/weight/static/js/compare_weight.js b/wger/weight/static/js/compare_weight.js
new file mode 100644
index 00000000..f1d47bd9
--- /dev/null
+++ b/wger/weight/static/js/compare_weight.js
@@ -0,0 +1,81 @@
+/*
+ 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 () {
+ var url;
+ var username;
+ var nametext;
+ var chartParams;
+ var weightChart;
+ var checkboxes;
+ var data;
+ $('#compare').hide();
+
+ $('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("");
+ data = MG.convert.date(json, 'date');
+ weightChart.data = data;
+ // Plot the data
+ chartParams.data = data;
+ MG.data_graphic(chartParams);
+ } else {
+ Swal.fire({
+ text: users[index] + ' has no weight data',
+ type: 'error'
+ });
+ }
+ });
+ });
+ });
+});
diff --git a/wger/weight/urls.py b/wger/weight/urls.py
index 8a81c5eb..bb580e3a 100644
--- a/wger/weight/urls.py
+++ b/wger/weight/urls.py
@@ -28,26 +28,29 @@
name='add'),
path('/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/',
- views.overview,
- name='overview'),
+ views.overview,
+ name='overview'),
# url(r'^overview/$',
# views.overview,
# name='overview'),
path('api/get_weight_data/', # 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/',
+ views.compare_weight_data,
+ name='compare-weight-data'),
]
diff --git a/wger/weight/views.py b/wger/weight/views.py
index 616295b0..71907a59 100644
--- a/wger/weight/views.py
+++ b/wger/weight/views.py
@@ -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__)
@@ -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)
@@ -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'