Self hosted FLOSS fitness/workout, nutrition and weight tracker
Refactor to style guide
Peter van der Does7e5b7a987d4f
diff --git a/wger/exercises/static/js/exercises.js b/wger/exercises/static/js/exercises.jsindex b1ebb249a..1811dccc0 100644--- a/wger/exercises/static/js/exercises.js+++ b/wger/exercises/static/js/exercises.js@@ -1,93 +1,94 @@/*- * 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- */---/*- * wger exercise functions- */+ This file is part of wger Workout Manager.-"use strict";+ 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+ *//*- * Highlight a muscle in the overview+ wger exercise functions*/-function highlight_muscle(element) {- var div_id = $(element).data('target');- var is_front = ($(element).data('isFront') == 'True') ? 'front' : 'back';- var muscle_id = div_id.match(/\d+/);- var muscle_name = $(element).data('name');-- // Reset all other highlighted muscles- $('.muscle').removeClass('muscle-active');- $('.muscle').addClass('muscle-inactive');-- // Hightligh the current one- $(element).removeClass('muscle-inactive');- $(element).addClass('muscle-active');- // Set the corresponding background- $('#muscle-system').css('background-image',- 'url(/static/images/muscles/main/muscle-' + muscle_id + '.svg),'- + 'url(/static/images/muscles/muscular_system_' + is_front + '.svg)');+'use strict';- // Show the corresponding exercises- $('.exercise-list').hide();- $('#' + div_id).show();+/*+ Highlight a muscle in the overview+ */+function wgerHighlightMuscle(element) {+ var $muscle;+ var muscleId;+ var isFront;+ var divId;+ divId = $(element).data('target');+ isFront = ($(element).data('isFront') === 'True') ? 'front' : 'back';+ muscleId = divId.match(/\d+/);++ // Reset all other highlighted muscles+ $muscle = $('.muscle');+ $muscle.removeClass('muscle-active');+ $muscle.addClass('muscle-inactive');++ // Highlight the current one+ $(element).removeClass('muscle-inactive');+ $(element).addClass('muscle-active');++ // Set the corresponding background+ $('#muscle-system').css('background-image',+ 'url(/static/images/muscles/main/muscle-' + muscleId + '.svg),' ++ 'url(/static/images/muscles/muscular_system_' + isFront + '.svg)');++ // Show the corresponding exercises+ $('.exercise-list').hide();+ $('#' + divId).show();}/*- *- * D3js functions- *+ D3js functions*/-function draw_weight_log_chart(data, div_id) {-- if (data.length) {- var legend = [];- var min_values = [];- var chart_data = [];- for (var i = 0; i < data.length; i++) {- chart_data[i] = MG.convert.date(data[i], 'date');-- // Read the possible repetitions for the chart legend- legend[i] = data[i][0].reps;-- // Read the minimum values for each repetition- min_values[i] = d3.min(data[i], function (data) {- return data.weight;- });- }-- MG.data_graphic({- data: chart_data,- y_accessor: 'weight',- min_y: d3.min(min_values),- aggregate_rollover: true,- full_width: true,- top: 10,- left: 30,- right: 10,- height: 200,- legend: legend,- target: '#svg-' + div_id,- colors: ['#204a87', '#4e9a06', '#ce5c00', '#5c3566', '#2e3436', '8f5902', '#a40000']- });+function wgerDrawWeightLogChart(data, divId) {+ var chartData;+ var legend;+ var minValues;+ var i;+ if (data.length) {+ legend = [];+ minValues = [];+ chartData = [];+ for (i = 0; i < data.length; i++) {+ chartData[i] = MG.convert.date(data[i], 'date');++ // Read the possible repetitions for the chart legend+ legend[i] = data[i][0].reps;++ // Read the minimum values for each repetition+ minValues[i] = d3.min(data[i], function (repetitionData) {+ return repetitionData.weight;+ });}-}+ MG.data_graphic({+ data: chartData,+ y_accessor: 'weight',+ min_y: d3.min(minValues),+ aggregate_rollover: true,+ full_width: true,+ top: 10,+ left: 30,+ right: 10,+ height: 200,+ legend: legend,+ target: '#svg-' + divId,+ colors: ['#204a87', '#4e9a06', '#ce5c00', '#5c3566', '#2e3436', '8f5902', '#a40000']+ });+ }+}diff --git a/wger/exercises/templates/exercise/view.html b/wger/exercises/templates/exercise/view.htmlindex d0ca45002..b5ef70cd1 100644--- a/wger/exercises/templates/exercise/view.html+++ b/wger/exercises/templates/exercise/view.html@@ -42,7 +42,7 @@{% block header %}<script>$(document).ready(function() {- draw_weight_log_chart({{json|safe}}, "{{svg_uuid}}");+ wgerDrawWeightLogChart({{json|safe}}, "{{svg_uuid}}");});</script>{% endblock %}@@ -377,4 +377,4 @@ $(document).ready(function() {</ul></div>{% endif %}-{% endblock %}\ No newline at end of file+{% endblock %}diff --git a/wger/exercises/templates/muscles/overview.html b/wger/exercises/templates/muscles/overview.htmlindex ec54b3708..8fd32881d 100644--- a/wger/exercises/templates/muscles/overview.html+++ b/wger/exercises/templates/muscles/overview.html@@ -20,12 +20,12 @@ $(document).ready(function() {// Hightlight the first element- highlight_muscle($('.muscle').first());+ wgerHighlightMuscle($('.muscle').first());// Highlight on hover$('.muscle').hover(function(e) {e.preventDefault();- highlight_muscle(this);+ wgerHighlightMuscle(this);});// Highlight on clickdiff --git a/wger/manager/templates/workout/log.html b/wger/manager/templates/workout/log.htmlindex 0d095b4f3..106872caf 100644--- a/wger/manager/templates/workout/log.html+++ b/wger/manager/templates/workout/log.html@@ -75,7 +75,7 @@{% render_weight_log list exercise_list.div_uuid owner_user %}<script>$(document).ready(function() {- draw_weight_log_chart({{exercise_list.chart_data|safe}},+ wgerDrawWeightLogChart({{exercise_list.chart_data|safe}},"{{exercise_list.div_uuid}}");});</script>