From 647c1678f1d5cc6773be5d54c539100a4ebcae9c Mon Sep 17 00:00:00 2001 From: smilerz Date: Thu, 18 Mar 2021 12:09:53 -0500 Subject: [PATCH] added drag and drop to ingredients --- cookbook/templates/url_import.html | 60 +++++++++++++++++++++++------- cookbook/views/api.py | 1 + 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html index 1187dc83..3b564b44 100644 --- a/cookbook/templates/url_import.html +++ b/cookbook/templates/url_import.html @@ -135,9 +135,12 @@
-
- {% trans 'Keywords' %} - +
+
+ {% trans 'Keywords' %} + +
+
{% trans 'Keywords dragged here will be appended to current list'%}
@@ -193,14 +196,24 @@
-
- {% trans 'Ingredients' %} - +
+
+ {% trans 'Ingredients' %} + +
+
{% trans 'Ingredients dragged here will be appended to current list.'%}
-
-
[[i.amount]] [[i.unit.text]] [[i.ingredient.text]] [[i.note]]
-
+
    +
    +
  • +
    [[i.amount]]
    +
    [[i.unit.text]]
    +
    [[i.ingredient.text]]
    +
    [[i.note]]
    +
  • +
    +
@@ -643,6 +656,7 @@ }) }, loadRecipeHTML: function () { + // TODO this needs refactored to get HTML elements this.error = undefined this.loading = true this.parsed = false @@ -840,17 +854,35 @@ this.recipe_json.cookTime=v break; case 'ingredients': - let new_ingredient={ - unit: {id: Math.random() * 1000, text: ""}, - amount: "", - ingredient: {id: Math.random() * 1000, text: v} + this.$http.post('{% url 'api_ingredient_from_string' %}', {text: v}, {emulateJSON: true}).then((response) => { + console.log(response) + let new_ingredient={ + unit: {id: Math.random() * 1000, text: response.body.unit}, + amount: response.body.amount, + ingredient: {id: Math.random() * 1000, text: response.body.food}, + note: response.body.note } - this.recipe_json.recipeIngredient=[new_ingredient] + this.recipe_json.recipeIngredient.push(new_ingredient) + }).catch((err) => { + console.log(err) + this.makeToast(gettext('Error'), gettext('Something went wrong.'), 'danger') + }) + break; case 'instructions': this.recipe_json.recipeInstructions=this.recipe_json.recipeInstructions.concat(v) break; } + }, + parseIngredient: function(txt) { + this.$http.post('{% url 'api_ingredient_from_string' %}', {text: txt}, {emulateJSON: true}).then((response) => { + console.log(response) + let ing = [response.body.amount, response.body.unit, response.body.food, response.body.note] + return ing + }).catch((err) => { + console.log(err) + this.makeToast(gettext('Error'), gettext('Something went wrong.'), 'danger') + }) } } }); diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 135ffb06..814c786d 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -662,6 +662,7 @@ def ingredient_from_string(request): 'amount': amount, 'unit': unit, 'food': food, + 'note': note }, status=200 )