{
console.log("getPlanEntries error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
getPlanTypes: function () {
@@ -401,7 +405,7 @@
}
}).catch((err) => {
console.log("getPlanTypes error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
buildGrid: function () {
@@ -451,7 +455,7 @@
this.recipes = response.data;
}).catch((err) => {
console.log("getRecipes error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
getMdNote: function () {
@@ -464,18 +468,18 @@
this.recipes = response.data;
}).catch((err) => {
console.log("getRecipes error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
updateUserNames: function () {
return this.$http.get("{% url 'api:username-list' %}?filter_list=[" + this.user_id_update + ']').then((response) => {
for (let u of response.data) {
- this.$set(this.user_names, u.id, u.username);
+ this.$set(this.user_names, u.id, u.username);
}
}).catch((err) => {
console.log("updateUserNames error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
dragChanged: function (date, meal_type, evt) {
@@ -501,7 +505,7 @@
this.$http.put(`{% url 'api:mealplan-list' %}${plan_entry.id}/`, plan_entry).then((response) => {
}).catch((err) => {
console.log("dragChanged update error", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
}
}
@@ -512,7 +516,7 @@
this.meal_plan[entry.meal_type_name].days[entry.date].items = this.meal_plan[entry.meal_type_name].days[entry.date].items.filter(item => item !== entry)
}).catch((err) => {
console.log("deleteEntry error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
})
},
updatePlanTypes: function () {
@@ -526,14 +530,14 @@
promise_list.push(this.$http.post("{% url 'api:mealtype-list' %}", x).then((response) => {
}).catch((err) => {
console.log("updatePlanTypes create error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
}))
} else if (x.delete) {
if (x.id !== undefined) {
promise_list.push(this.$http.delete(`{% url 'api:mealtype-list' %}${x.id}/`, x).then((response) => {
}).catch((err) => {
console.log("updatePlanTypes delete error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
}))
}
} else {
@@ -541,7 +545,7 @@
}).catch((err) => {
console.log("updatePlanTypes update error: ", err);
- this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
}))
}
}
@@ -556,14 +560,21 @@
}
},
cloneRecipe: function (recipe) {
- return {
+ let r = {
id: Math.round(Math.random() * 1000) + 10000,
recipe: recipe.id,
recipe_name: recipe.name,
+ recipe_multiplier: (this.new_note_multiplier > 1) ? this.new_note_multiplier : 1,
title: this.new_note_title,
note: this.new_note_text,
is_new: true
}
+
+ this.new_note_title = ''
+ this.new_note_text = ''
+ this.new_note_multiplier = ''
+
+ return r
},
cloneNote: function () {
let new_entry = {
@@ -579,6 +590,7 @@
this.new_note_title = ''
this.new_note_text = ''
+ this.new_note_multiplier = ''
return new_entry
},
planElementName: function (element) {
@@ -618,10 +630,10 @@
let first = true
for (let se of this.shopping_list) {
if (first) {
- url += `?r=${se.recipe}`
+ url += `?r=[${se.recipe},${se.recipe_multiplier}]`
first = false
} else {
- url += `&r=${se.recipe}`
+ url += `&r=[${se.recipe},${se.recipe_multiplier}]`
}
}
return url
diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html
index 37881d69e..6b71c738e 100644
--- a/cookbook/templates/shopping_list.html
+++ b/cookbook/templates/shopping_list.html
@@ -183,13 +183,6 @@
-
-
-
-
-
@@ -221,32 +214,42 @@
- {% trans 'Export' %}
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ {% trans 'Export' %}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -339,12 +342,25 @@
mounted: function () {
this.loadShoppingList()
+ {% if recipes %}
+ this.loading = true
+ this.edit_mode = true
+ let loadingRecipes = []
+ {% for r in recipes %}
+ loadingRecipes.push(this.loadInitialRecipe({{ r.recipe }}, {{ r.multiplier }}))
+ {% endfor %}
+
+ Promise.allSettled(loadingRecipes).then(() => {
+ this.loading = false
+ })
+ {% endif %}
+
{% if request.user.userpreference.shopping_auto_sync > 0 %}
setInterval(() => {
if ((this.shopping_list_id !== null) && !this.edit_mode) {
this.loadShoppingList(true)
}
- }, {{ request.user.userpreference.shopping_auto_sync }} * 1000 )
+ }, {% widthratio request.user.userpreference.shopping_auto_sync 1 1000 %})
{% endif %}
},
methods: {
@@ -365,6 +381,14 @@
solid: true
})
},
+ loadInitialRecipe: function (recipe, multiplier) {
+ return this.$http.get('{% url 'api:recipe-detail' 123456 %}'.replace('123456', recipe)).then((response) => {
+ this.addRecipeToList(response.data, multiplier)
+ }).catch((err) => {
+ console.log("getRecipes error: ", err);
+ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger')
+ })
+ },
loadShoppingList: function (autosync = false) {
if (this.shopping_list_id) {
@@ -433,6 +457,8 @@
this.shopping_list = response.body
this.shopping_list_id = this.shopping_list.id
+
+ window.history.pushState('shopping_list', '{% trans 'Shopping List' %}', "{% url 'view_shopping' 123456 %}".replace('123456', this.shopping_list_id));
}).catch((err) => {
console.log(err)
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error creating a resource!' %}' + err.bodyText, 'danger')
@@ -511,13 +537,13 @@
getRecipeUrl: function (id) { //TODO generic function that can be reused else were
return '{% url 'view_recipe' 123456 %}'.replace('123456', id)
},
- addRecipeToList: function (recipe) {
+ addRecipeToList: function (recipe, multiplier = 1) {
let slr = {
"created": true,
"id": Math.random() * 1000,
"recipe": recipe.id,
"recipe_name": recipe.name,
- "multiplier": 1
+ "multiplier": multiplier
}
this.shopping_list.recipes.push(slr)
diff --git a/cookbook/views/views.py b/cookbook/views/views.py
index e4a3ef37e..183e222e9 100644
--- a/cookbook/views/views.py
+++ b/cookbook/views/views.py
@@ -165,7 +165,17 @@ def meal_plan_entry(request, pk):
@group_required('user')
def shopping_list(request, pk=None):
- return render(request, 'shopping_list.html', {'shopping_list_id': pk})
+ raw_list = request.GET.getlist('r')
+
+ recipes = []
+ for r in raw_list:
+ r = r.replace('[', '').replace(']', '')
+ if re.match(r'^([1-9])+,([1-9])+[.]*([1-9])*$', r):
+ rid, multiplier = r.split(',')
+ if recipe := Recipe.objects.filter(pk=int(rid)).first():
+ recipes.append({'recipe': recipe.id, 'multiplier': multiplier})
+
+ return render(request, 'shopping_list.html', {'shopping_list_id': pk, 'recipes': recipes})
@group_required('guest')