From b89c38a6960ad23f211b273d572bb9d982eaa3e0 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 8 Jul 2020 21:53:55 +0200 Subject: [PATCH] error messages --- .../templates/forms/edit_internal_recipe.html | 4 +--- cookbook/templates/include/vue_base.html | 5 ++++- cookbook/templates/meal_plan.html | 19 +++++++++++++++++++ cookbook/templates/url_import.html | 16 +++++++++++++++- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 7e6d8375..d71ba928 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -10,9 +10,6 @@ {% include 'include/vue_base.html' %} - - - @@ -450,6 +447,7 @@ }, methods: { makeToast: function(title, message, variant=null) { + //TODO remove duplicate function in favor of central one this.$bvToast.toast(message, { title: title, variant: variant, diff --git a/cookbook/templates/include/vue_base.html b/cookbook/templates/include/vue_base.html index f2a07ee0..b25455dc 100644 --- a/cookbook/templates/include/vue_base.html +++ b/cookbook/templates/include/vue_base.html @@ -10,4 +10,7 @@ - \ No newline at end of file + + + + diff --git a/cookbook/templates/meal_plan.html b/cookbook/templates/meal_plan.html index f57243fc..792716e9 100644 --- a/cookbook/templates/meal_plan.html +++ b/cookbook/templates/meal_plan.html @@ -367,6 +367,15 @@ this.getRecipes(); }, methods: { + makeToast: function(title, message, variant=null) { + //TODO remove duplicate function in favor of central one + this.$bvToast.toast(message, { + title: title, + variant: variant, + toaster: 'b-toaster-top-center', + solid: true + }) + }, updatePlan: function () { let planEntryPromise = this.getPlanEntries(); let planTypePromise = this.getPlanTypes(); @@ -380,6 +389,7 @@ this.plan_entries = response.data; }).catch((err) => { console.log("getPlanEntries error: ", err); + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, getPlanTypes: function () { @@ -391,6 +401,7 @@ } }).catch((err) => { console.log("getPlanTypes error: ", err); + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, buildGrid: function () { @@ -440,6 +451,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') }) }, getMdNote: function () { @@ -452,6 +464,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') }) }, updateUserNames: function () { @@ -466,6 +479,7 @@ }).catch((err) => { console.log("updateUserNames error: ", err); + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, dragChanged: function (date, meal_type, evt) { @@ -491,6 +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') }) } } @@ -501,6 +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') }) }, updatePlanTypes: function () { @@ -514,12 +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') })) } 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') })) } } else { @@ -527,6 +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') })) } } diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html index 9135d2b5..939bad8f 100644 --- a/cookbook/templates/url_import.html +++ b/cookbook/templates/url_import.html @@ -281,6 +281,15 @@ this.searchIngredients('') }, methods: { + makeToast: function (title, message, variant = null) { + //TODO remove duplicate function in favor of central one + this.$bvToast.toast(message, { + title: title, + variant: variant, + toaster: 'b-toaster-top-center', + solid: true + }) + }, loadRecipe: function () { this.recipe_data = undefined this.error = undefined @@ -292,6 +301,7 @@ this.error = err.data this.loading = false console.log(err) + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, importRecipe: function () { @@ -299,7 +309,8 @@ this.$http.post(`{% url 'data_import_url' %}`, this.recipe_data).then((response) => { location.href = response.data }).catch((err) => { - console.log("dragChanged create error", err); + console.log(err); + this.makeToast('{% trans 'Error' %}','{% trans 'An error occurred while trying to import this recipe!' %}' + err.bodyText, 'danger') }) }, deleteIngredient: function (i) { @@ -341,6 +352,7 @@ this.keywords_loading = false }).catch((err) => { console.log(err) + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, searchUnits: function (query) { @@ -358,6 +370,7 @@ this.units_loading = false }).catch((err) => { console.log(err) + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, searchIngredients: function (query) { @@ -376,6 +389,7 @@ this.ingredients_loading = false }).catch((err) => { console.log(err) + this.makeToast('{% trans 'Error' %}','{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, }