From ddaa9e6356a9ccf77d4c2e5ac9f8435baad1b16e Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 2 Jul 2020 13:16:15 +0200 Subject: [PATCH] added step time calculation --- cookbook/templates/recipe_view.html | 51 +++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index fc043d4fe..84376e240 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -216,7 +216,7 @@ {% endif %} -
+
{% for s in recipe.steps.all %}
@@ -224,25 +224,32 @@
-
+
+
+ {% if s.type == 'TEXT' %} + + {% elif s.type == 'TIME' %} + + {% endif %} + {% if s.name %}{{ s.name }}{% else %}{% trans 'Step' %} + {{ forloop.counter }}{% endif %} + {% if s.type == 'TIME' %} + - {{ s.time }} {% trans 'Minutes' %} + {% endif %} +
+
+ +
- {% if s.type == 'TEXT' %} - - {% elif s.type == 'TIME' %} - - {% endif %} - {% if s.name %}{{ s.name }}{% else %}{% trans 'Step' %} - {{ forloop.counter }}{% endif %} - {% if s.type == 'TIME' %} - - {{ s.time }} {% trans 'Minutes' %} - {% endif %}
-
@@ -480,6 +487,7 @@ if (step.ingredients.length > 0) { this.has_ingredients = true } + this.$set(step, 'time_finished', undefined) for (let i of step.ingredients) { this.$set(i, 'checked', false) } @@ -496,6 +504,23 @@ {{ request.user.userpreference.ingredient_decimals }} {% else %} 2 {% endif %} return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`); }, + updateTimes: function (step) { + let time_diff_first = 0 + for (let s of this.recipe.steps) { + if (s !== step) { + time_diff_first += s.time + } + } + + this.recipe.steps[0].time_finished = moment(step.time_finished).subtract(time_diff_first, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL); + + let time_diff = 0 + for (let s of this.recipe.steps) { + s.time_finished = moment(this.recipe.steps[0].time_finished).add(time_diff, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL); + time_diff += s.time + } + + } } });