Self hosted FLOSS fitness/workout, nutrition and weight tracker
Merge branch 'master' into nutrition-diary
Roland Geiderbedc27630e36
diff --cc wger/core/templates/misc/fragments/shariff_modal.htmlindex 32d21bab3,19e944838..c566a8ad9--- a/wger/core/templates/misc/fragments/shariff_modal.html+++ b/wger/core/templates/misc/fragments/shariff_modal.html@@@ -1,4 -1,8 +1,7 @@@{% load i18n wger_extras %}+ <style>+ .shariff li { overflow: visible; }+ </style>-<div class="modal fade" id="shariffModal"><div class="modal-dialog"><div class="modal-content">diff --cc wger/nutrition/static/js/nutrition.jsindex 869839fd5,90daaa17c..0d1e3f293--- a/wger/nutrition/static/js/nutrition.js+++ b/wger/nutrition/static/js/nutrition.js@@@ -65,82 -61,42 +61,68 @@@ function wgerInitIngredientDetail(url)/** Update the user's preferences*/- function init_ingredient_autocompleter()- {- // Init the autocompleter- $('#id_ingredient_searchfield').devbridgeAutocomplete({- serviceUrl: '/api/v2/ingredient/search/',- onSelect: function (suggestion) {- var ingredient_id = suggestion.data.id;-- // After clicking on a result set the value of the hidden field- $('#id_ingredient').val(ingredient_id);- $('#exercise_name').html(suggestion.value);-- // See if the ingredient has any units and set the values for the forms- $.get('/api/v2/ingredientweightunit/?ingredient=' + ingredient_id, function(unit_data) {-- // Remove any old units, if any- var options = $('#id_weight_unit').find('option');- $.each(options, function(index, option_obj) {- if (option_obj.value != '')- {- $(option_obj).remove();- }- });+ function wgerInitIngredientAutocompleter() {+ // Init the autocompleter+ $('#id_ingredient_searchfield').autocomplete({+ serviceUrl: '/api/v2/ingredient/search/',+ paramName: 'term',+ minChars: 3,+ onSelect: function (suggestion) {+ var ingredientId = suggestion.data.id;++ // After clicking on a result set the value of the hidden field+ $('#id_ingredient').val(ingredientId);+ $('#exercise_name').html(suggestion.value);++ // See if the ingredient has any units and set the values for the forms+ $.get('/api/v2/ingredientweightunit/?ingredient=' + ingredientId, function (unitData) {+ // Remove any old units, if any+ var options = $('#id_weight_unit').find('option');+ $.each(options, function (index, optionObj) {+ if (optionObj.value !== '') {+ $(optionObj).remove();+ }+ });- // Add new units, if any- $.each(unit_data.results, function(index, value) {- $.get('/api/v2/weightunit/' + value.unit + '/', function(unit) {- var unit_name = unit.name + ' (' + value.gram + 'g)';- $('#id_unit').append(new Option(unit_name, value.id));- $('#id_weight_unit').append(new Option(unit_name, value.id));- });- });- });- },- paramName: 'term',- transformResult: function(response) {- // why is response not already a JSON object??- var jsonResponse = $.parseJSON(response);- return {- suggestions: $.map(jsonResponse, function(item) {- return {value: item.value, data: {id: item.id}};- })- };- }- });+ // Add new units, if any+ $.each(unitData.results, function (index, value) {+ $.get('/api/v2/weightunit/' + value.unit + '/', function (unit) {+ var unitName = unit.name + ' (' + value.gram + 'g)';+ $('#id_unit').append(new Option(unitName, value.id));+ $('#id_weight_unit').append(new Option(unitName, value.id));+ });+ });+ });+ }+ });}+-+function draw_nutrition_diary_chart(plan_pk) {++ d3.json('/api/v2/nutritionplan/' + plan_pk + '/get_log_overview/', function(data) {+ if(data.length > 0) {++ data = MG.convert.date(data, 'date');+ $.getJSON('/api/v2/nutritionplan/' + plan_pk + '/nutritional_values/', function (nutritional_values) {+ MG.data_graphic({+ data: data,+ y_accessor: 'energy',+ x_accessor: 'date',+ full_width: true,+ top: 10,+ left: 30,+ right: 10,+ baselines: [{value: nutritional_values.total.energy,+ label: 'Planned calories (' + nutritional_values.total.energy + 'kcal)'}],+ target: '#nutrition_diary_chart',+ colors: '#4e9a06'+ });+ });+ }+ });+}+/** Draw the BMI chart*/diff --cc wger/nutrition/templates/plan/view.htmlindex fd481aad2,d40511b64..636f69c51--- a/wger/nutrition/templates/plan/view.html+++ b/wger/nutrition/templates/plan/view.html@@@ -24,14 -24,10 +24,14 @@@{# #}{% block header %}<script>+$(document).ready(function () {+ draw_nutrition_diary_chart({{ plan.pk }});+});+- function custom_modal_init()+ function wgerCustomModalInit(){// Init the autocompleter after loading the modal dialog- init_ingredient_autocompleter();+ wgerInitIngredientAutocompleter();}</script>{% endblock %}