diff --git a/cookbook/migrations/0070_auto_20200701_2007.py b/cookbook/migrations/0070_auto_20200701_2007.py new file mode 100644 index 00000000..4a6783df --- /dev/null +++ b/cookbook/migrations/0070_auto_20200701_2007.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.7 on 2020-07-01 18:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0069_auto_20200629_2134'), + ] + + operations = [ + migrations.AddField( + model_name='step', + name='time', + field=models.IntegerField(blank=True, default=0), + ), + migrations.AlterField( + model_name='step', + name='kind', + field=models.CharField(choices=[('TEXT', 'Text'), ('TIME', 'Time')], default='TEXT', max_length=16), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index de087b85..b438ee70 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -160,11 +160,13 @@ class Ingredient(models.Model): class Step(models.Model): TEXT = 'TEXT' + TIME = 'TIME' name = models.CharField(max_length=128, default='', blank=True) - kind = models.CharField(choices=((TEXT, _('Text')),), default=TEXT, max_length=16) + kind = models.CharField(choices=((TEXT, _('Text')), (TIME, _('Time')),), default=TEXT, max_length=16) instruction = models.TextField(blank=True) ingredients = models.ManyToManyField(Ingredient, blank=True) + time = models.IntegerField(default=0, blank=True) order = models.IntegerField(default=0) class Meta: diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 6179c675..98b7f3b2 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -38,7 +38,6 @@
-

@@ -82,149 +81,176 @@
-

{% trans 'Step' %} [[step_index+1]]

+

{% trans 'Step' %} [[step_index+1]] + +

-
+
+
+ + +
-
-
- -
-
-
-
- -
+ -
-
- + +
@@ -309,6 +335,10 @@ }) }, updateRecipe: function (view_after) { + this.sortSteps() + for (let s of this.recipe.steps) { + this.sortIngredients(s) + } this.$http.put("{% url 'api:recipe-detail' recipe.pk %}", this.recipe, {}).then((response) => { console.log(view_after) @@ -344,7 +374,7 @@ }, addStep: function () { //TODO see if default can be generated from options request this.recipe.steps.push( - {'instruction': '', ingredients: []} + {'instruction': '', ingredients: [], kind: 'TEXT'} ) }, sortSteps: function () { @@ -376,6 +406,11 @@ step.ingredients = step.ingredients.filter(item => item !== ingredient) } }, + removeStep: function (step) { + if (confirm('{% trans 'Are you sure that you want to delete this step?' %}')) { + this.recipe.steps = this.recipe.steps.filter(item => item !== step) + } + }, addFoodType: function (tag, index) { let [tmp, step, id] = index.split('_')