Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Move JS weight functions to own file

Roland Geider9527911ca6bb
diff --git a/wger/weight/static/js/weight.js b/wger/weight/static/js/weight.js
new file mode 100644
index 000000000..254a506ed
--- /dev/null
+++ b/wger/weight/static/js/weight.js
@@ -0,0 +1,67 @@
+/*
+ * 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 weight_chart = {};
+ var chart_params = {
+ animate_on_load: true,
+ full_width: true,
+ height: 300,
+ show_secondary_x_label: true,
+ xax_count: 10,
+ target: '#weight_diagram',
+ x_accessor: 'date',
+ y_accessor: 'weight'
+ }
+
+
+ var username = $('#current-username').data('currentUsername');
+ var url = "/weight/api/get_weight_data/" + username;
+
+ d3.json(url, function (json) {
+
+ var data = MG.convert.date(json, 'date');
+ weight_chart.data = data;
+
+ // Plot the data
+ chart_params.data = data;
+ MG.data_graphic(chart_params);
+ });
+
+ $('.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);
+
+ // change button state
+ $(this).addClass('active').siblings().removeClass('active');
+
+ chart_params.data = data;
+ MG.data_graphic(chart_params);
+ });
+});
+
+
+function modify_time_period(data, past_n_days) {
+ if (past_n_days !== 'all' || past_n_days !== '') {
+ return MG.clone(data).slice(past_n_days * -1);
+ }
+
+ return data;
+}
+
diff --git a/wger/weight/templates/overview.html b/wger/weight/templates/overview.html
index 5aff62dcf..52352c704 100644
--- a/wger/weight/templates/overview.html
+++ b/wger/weight/templates/overview.html
@@ -1,73 +1,30 @@
{% extends "base.html" %}
{% load i18n staticfiles wger_extras %}
-<!--
- Title
--->
+{# #}
+{# Title #}
+{# #}
{% block title %}{% trans "Weight overview" %}{% endblock %}
-<!--
- Header data
--->
+{# #}
+{# HEader #}
+{# #}
{% block header %}
<link rel="stylesheet" type="text/css" href="{% static 'bower_components/metrics-graphics/dist/metricsgraphics.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/metricsgraphics-custom.css' %}">
+<script src="{% static 'js/weight.js' %}"></script>
<script src="{% static 'bower_components/metrics-graphics/dist/metricsgraphics.min.js' %}"></script>
+{% endblock %}
-<script type="text/javascript">
-var globals = {};
-var modify_time_period_params = {
- animate_on_load: true,
- full_width: true,
- height: 300,
- show_secondary_x_label: true,
- xax_count: 10,
- target: '#weight_diagram',
- x_accessor: 'date',
- y_accessor: 'weight',
-}
-
-$(document).ready(function () {
-
- d3.json("/weight/api/get_weight_data/{{ owner_user.username }}", function(json) {
-
- data = MG.convert.date(json, 'date');
- globals.data = data;
-
- // Plot the data
- modify_time_period_params.data = data;
- MG.data_graphic(modify_time_period_params);
- });
-
- $('.modify-time-period-controls button').click(function() {
- var past_n_days = $(this).data('time_period');
- var data = modify_time_period(globals.data, past_n_days);
-
- // change button state
- $(this).addClass('active').siblings().removeClass('active');
-
- modify_time_period_params.data = data;
- MG.data_graphic(modify_time_period_params);
- });
-});
-
-
-function modify_time_period(data, past_n_days) {
- if (past_n_days !== 'all' || past_n_days !== '') {
- return MG.clone(data).slice(past_n_days * -1);
- }
- return data;
-}
-</script>
-{% endblock %}
+{# #}
+{# Content #}
+{# #}
+{% block content %}
+<div id="current-username" data-current-username="{{ owner_user.username }}"></div>
-<!--
- Main Content
--->
-{% block content %}
{% if not min_date %}
<p>
{% trans "There is no chart here because there are no weight entries." %}
@@ -125,9 +82,9 @@ function modify_time_period(data, past_n_days) {
{% endblock %}
-<!--
- Side bar
--->
+{# #}
+{# Side bar #}
+{# #}
{% block sidebar %}
<p>
<a href="{% url 'weight:add' %}" class="btn btn-success btn-sm wger-modal-dialog">