diff --git a/vue/src/apps/IngredientEditorView/IngredientEditorView.vue b/vue/src/apps/IngredientEditorView/IngredientEditorView.vue index d0361fd6e..0fee00aff 100644 --- a/vue/src/apps/IngredientEditorView/IngredientEditorView.vue +++ b/vue/src/apps/IngredientEditorView/IngredientEditorView.vue @@ -4,24 +4,31 @@
- - + + + + + + + + @finish-action="finishGenericAction"/>
@@ -31,9 +38,12 @@ + + + + @finish-action="finishGenericAction()"/>
@@ -100,7 +110,7 @@ @click="updateIngredient(i)"> - @@ -187,7 +197,7 @@ export default { this.ingredients = result.data this.loading = false }).catch((err) => { - StandardToasts.makeStandardToast(this,StandardToasts.FAIL_FETCH, err) + StandardToasts.makeStandardToast(this, StandardToasts.FAIL_FETCH, err) this.loading = false }) } @@ -209,20 +219,79 @@ export default { apiClient.updateIngredient(i.id, i).then(r => { this.$set(i, 'changed', false) }).catch(err => { - StandardToasts.makeStandardToast(this,StandardToasts.FAIL_UPDATE, err) + StandardToasts.makeStandardToast(this, StandardToasts.FAIL_UPDATE, err) }) }) }, - deleteIngredient: function (i){ - if (confirm(this.$t('delete_confirmation', this.$t('Ingredient')))){ + deleteIngredient: function (i) { + if (confirm(this.$t('delete_confirmation', this.$t('Ingredient')))) { let apiClient = new ApiApiFactory() apiClient.destroyIngredient(i.id).then(r => { - StandardToasts.makeStandardToast(this,StandardToasts.SUCCESS_DELETE) + StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_DELETE) this.ingredients = this.ingredients.filter(li => li.id !== i.id) }).catch(err => { - StandardToasts.makeStandardToast(this,StandardToasts.FAIL_DELETE, err) + StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err) }) } + }, + finishGenericAction: function (e) { + console.log('PARAMETER ', e) + if (e !== 'cancel') { + if (this.generic_action === this.Actions.DELETE) { + this.ingredients = [] + if (this.generic_model === this.Models.FOOD) { + this.food = null; + } else { + this.unit = null; + } + } + + if (this.generic_action === this.Actions.UPDATE) { + if (this.generic_model === this.Models.FOOD) { + this.food = e.item + this.ingredients.forEach((element, i) => { + if (element.food.id === this.food.id) { + this.ingredients[i].food = this.food + } + }) + } else { + this.unit = e.item + this.ingredients.forEach((element, i) => { + if (element.unit?.id === this.unit.id) { + this.ingredients[i].unit = this.unit + } + }) + } + } + + if (this.generic_action === this.Actions.MERGE) { + if (this.generic_model === this.Models.FOOD) { + this.ingredients.forEach((element, i) => { + if (element.food.id === this.food.id) { + this.ingredients[i].food = e.target_object + } + }) + this.food = e.target_object + } else { + this.ingredients.forEach((element, i) => { + if (element.unit?.id === this.unit.id) { + this.ingredients[i].unit = e.target_object + } + }) + this.unit = e.target_object + } + this.refreshList() + } + } + + if (this.generic_model === this.Models.FOOD) { + this.$refs.food_multiselect.search(''); + } else { + this.$refs.unit_multiselect.search(''); + } + + this.generic_action = null; + this.generic_model = null; } }, diff --git a/vue/src/components/GenericMultiselect.vue b/vue/src/components/GenericMultiselect.vue index f434978cc..f391a7395 100644 --- a/vue/src/components/GenericMultiselect.vue +++ b/vue/src/components/GenericMultiselect.vue @@ -140,7 +140,7 @@ export default { }, nothingSelected() { if (this.multiple || !this.initial_single_selection) { - return this.selected_objects.length === 0 && this.initial_selection.length === 0 + return this.selected_objects?.length === 0 && this.initial_selection?.length === 0 } else { return !this.selected_objects && !this.initial_single_selection } diff --git a/vue/src/components/Modals/GenericModalForm.vue b/vue/src/components/Modals/GenericModalForm.vue index 715a2efed..6073ee707 100644 --- a/vue/src/components/Modals/GenericModalForm.vue +++ b/vue/src/components/Modals/GenericModalForm.vue @@ -200,7 +200,7 @@ export default { } else { this.genericAPI(this.model, this.Actions.UPDATE, this.form_data) .then((result) => { - this.$emit("finish-action") + this.$emit("finish-action", { item: result.data }) StandardToasts.makeStandardToast(this,StandardToasts.SUCCESS_UPDATE) }) .catch((err) => { @@ -246,7 +246,7 @@ export default { target: this.form_data.target.id, }) .then((result) => { - this.$emit("finish-action", { target: this.form_data.target.id }) + this.$emit("finish-action", { target: this.form_data.target.id, target_object: this.form_data.target }) //TODO temporary workaround to not change other apis StandardToasts.makeStandardToast(this,StandardToasts.SUCCESS_MERGE) }) .catch((err) => {