Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Refactor to code style

Peter van der Does0e368cf56da2
diff --git a/wger/weight/static/js/weight.js b/wger/weight/static/js/weight.js
index adade5b63..912b07dbc 100644
--- a/wger/weight/static/js/weight.js
+++ b/wger/weight/static/js/weight.js
@@ -1,80 +1,82 @@
/*
- * 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";
+ This file is part of wger Workout Manager.
-$(document).ready(function () {
+ 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.
- var weight_chart = {};
- var chart_params = {
- animate_on_load: true,
- full_width: true,
- top: 10,
- left: 30,
- right: 10,
- show_secondary_x_label: true,
- xax_count: 10,
- target: '#weight_diagram',
- x_accessor: 'date',
- y_accessor: 'weight',
- min_y_from_data: true,
- colors: ['#3465a4']
- }
+ 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';
- var username = $('#current-username').data('currentUsername');
- var url = "/weight/api/get_weight_data/" + username;
-
- d3.json(url, function (json) {
+function modifyTimePeriod(data, pastNumberDays) {
+ var filtered;
+ var date;
+ if (data.length) {
+ if (pastNumberDays !== 'all') {
+ date = new Date();
+ date.setDate(date.getDate() - pastNumberDays);
+ filtered = MG.clone(data).filter(function (value) {
+ return value.date >= date;
+ });
+ return filtered;
+ }
+ }
+ return data;
+}
- if (json.length) {
- var data = MG.convert.date(json, 'date');
- weight_chart.data = data;
+$(document).ready(function () {
+ var url;
+ var username;
+ var chartParams;
+ var weightChart;
+ weightChart = {};
+ chartParams = {
+ animate_on_load: true,
+ full_width: true,
+ top: 10,
+ left: 30,
+ right: 10,
+ show_secondary_x_label: true,
+ xax_count: 10,
+ target: '#weight_diagram',
+ x_accessor: 'date',
+ y_accessor: 'weight',
+ min_y_from_data: true,
+ colors: ['#3465a4']
+ };
- // Plot the data
- chart_params.data = data;
- MG.data_graphic(chart_params);
- }
- });
+ username = $('#current-username').data('currentUsername');
+ url = '/weight/api/get_weight_data/' + username;
- $('.modify-time-period-controls button').click(function () {
- var past_n_days = $(this).data('time_period');
- var data = modify_time_period(weight_chart.data, past_n_days);
+ d3.json(url, function (json) {
+ var data;
+ if (json.length) {
+ data = MG.convert.date(json, 'date');
+ weightChart.data = data;
- // change button state
- $(this).addClass('active').siblings().removeClass('active');
- if (data.length) {
- chart_params.data = data;
- MG.data_graphic(chart_params);
- }
- });
-});
+ // Plot the data
+ chartParams.data = data;
+ MG.data_graphic(chartParams);
+ }
+ });
+ $('.modify-time-period-controls button').click(function () {
+ var pastNumberDays = $(this).data('time_period');
+ var data = modifyTimePeriod(weightChart.data, pastNumberDays);
-function modify_time_period(data, past_n_days) {
+ // change button state
+ $(this).addClass('active').siblings().removeClass('active');
if (data.length) {
- if (past_n_days !== 'all') {
- var date = new Date();
- date.setDate(date.getDate() - past_n_days);
- var filtered = MG.clone(data).filter(function (value) {
- return value.date >= date;
- })
- return filtered;
- }
+ chartParams.data = data;
+ MG.data_graphic(chartParams);
}
- return data;
-}
+ });
+});