diff --git a/cookbook/templates/ingredient_editor.html b/cookbook/templates/ingredient_editor.html
index 28597135..a53215f4 100644
--- a/cookbook/templates/ingredient_editor.html
+++ b/cookbook/templates/ingredient_editor.html
@@ -30,6 +30,8 @@
{% endif %}
diff --git a/cookbook/views/views.py b/cookbook/views/views.py
index e5bca25f..da129345 100644
--- a/cookbook/views/views.py
+++ b/cookbook/views/views.py
@@ -228,7 +228,15 @@ def supermarket(request):
@group_required('user')
def ingredient_editor(request):
- return render(request, 'ingredient_editor.html', {})
+ template_vars = {'food_id': -1, 'unit_id': -1}
+ food_id = request.GET.get('food_id', None)
+ if food_id and re.match(r'^(\d)+$', food_id):
+ template_vars['food_id'] = food_id
+
+ unit_id = request.GET.get('unit_id', None)
+ if unit_id and re.match(r'^(\d)+$', unit_id):
+ template_vars['unit_id'] = unit_id
+ return render(request, 'ingredient_editor.html', template_vars)
@group_required('user')
diff --git a/vue/src/apps/IngredientEditorView/IngredientEditorView.vue b/vue/src/apps/IngredientEditorView/IngredientEditorView.vue
index e8958128..c85d0869 100644
--- a/vue/src/apps/IngredientEditorView/IngredientEditorView.vue
+++ b/vue/src/apps/IngredientEditorView/IngredientEditorView.vue
@@ -88,7 +88,9 @@
-
+
|
@@ -137,6 +139,20 @@ export default {
computed: {},
mounted() {
this.$i18n.locale = window.CUSTOM_LOCALE
+ if (window.DEFAULT_FOOD !== -1) {
+ this.food = {id: window.DEFAULT_FOOD}
+ let apiClient = new ApiApiFactory()
+ apiClient.retrieveFood(this.food.id).then(r => {
+ this.food = r.data
+ })
+ }
+ if (window.DEFAULT_UNIT !== -1) {
+ this.unit = {id: window.DEFAULT_UNIT}
+ let apiClient = new ApiApiFactory()
+ apiClient.retrieveUnit(this.unit.id).then(r => {
+ this.unit = r.data
+ })
+ }
this.refreshList()
},
methods: {
diff --git a/vue/src/apps/ModelListView/ModelListView.vue b/vue/src/apps/ModelListView/ModelListView.vue
index 8a2b49f8..09d52344 100644
--- a/vue/src/apps/ModelListView/ModelListView.vue
+++ b/vue/src/apps/ModelListView/ModelListView.vue
@@ -80,7 +80,7 @@ import {BootstrapVue} from "bootstrap-vue"
import "bootstrap-vue/dist/bootstrap-vue.css"
-import {CardMixin, ApiMixin, getConfig} from "@/utils/utils"
+import {CardMixin, ApiMixin, getConfig, resolveDjangoUrl} from "@/utils/utils"
import {StandardToasts, ToastMixin} from "@/utils/utils"
import GenericInfiniteCards from "@/components/GenericInfiniteCards"
@@ -158,7 +158,6 @@ export default {
let target = e?.target ?? undefined
this.this_item = source
this.this_target = target
-
switch (e.action) {
case "delete":
this.this_action = this.Actions.DELETE
@@ -173,6 +172,16 @@ export default {
this.this_action = this.Actions.UPDATE
this.show_modal = true
break
+ case "ingredient-editor": {
+ let url = resolveDjangoUrl("view_ingredient_editor")
+ if (this.this_model === this.Models.FOOD) {
+ window.location.href = url + '?food_id=' + e.source.id
+ }
+ if (this.this_model === this.Models.UNIT) {
+ window.location.href = url + '?unit_id=' + e.source.id
+ }
+ break
+ }
case "move":
if (target == null) {
this.this_item = e.source
diff --git a/vue/src/components/ContextMenu/GenericContextMenu.vue b/vue/src/components/ContextMenu/GenericContextMenu.vue
index b513bc64..c900f0fd 100644
--- a/vue/src/components/ContextMenu/GenericContextMenu.vue
+++ b/vue/src/components/ContextMenu/GenericContextMenu.vue
@@ -6,7 +6,10 @@
{{ $t("Edit") }}
+
{{ $t("Delete") }}
+ {{ $t("Ingredient Editor") }}
+
{{ $t("Add_to_Shopping") }}
@@ -24,8 +27,11 @@
diff --git a/vue/src/components/GenericHorizontalCard.vue b/vue/src/components/GenericHorizontalCard.vue
index b12cf6a0..028f9af1 100644
--- a/vue/src/components/GenericHorizontalCard.vue
+++ b/vue/src/components/GenericHorizontalCard.vue
@@ -61,6 +61,7 @@
:show_move="useMove"
:show_shopping="useShopping"
:show_onhand="useOnhand"
+ :show_ingredient_editor="useIngredientEditor"
@item-action="$emit('item-action', { action: $event, source: item })"
>
@@ -132,11 +133,12 @@ import GenericOrderedPill from "@/components/GenericOrderedPill"
import RecipeCard from "@/components/RecipeCard"
import { mixin as clickaway } from "vue-clickaway"
import { createPopper } from "@popperjs/core"
+import {ApiMixin} from "@/utils/utils";
export default {
name: "GenericHorizontalCard",
components: { GenericContextMenu, RecipeCard, Badges, GenericPill, GenericOrderedPill },
- mixins: [clickaway],
+ mixins: [clickaway, ApiMixin],
props: {
item: { type: Object },
model: { type: Object },
@@ -186,6 +188,9 @@ export default {
useDrag: function () {
return this.useMove || this.useMerge
},
+ useIngredientEditor: function (){
+ return (this.model === this.Models.FOOD || this.model === this.Models.UNIT)
+ },
itemTags: function () {
return this.model?.tags ?? []
},
diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json
index 284f4316..3f89c6a2 100644
--- a/vue/src/locales/en.json
+++ b/vue/src/locales/en.json
@@ -64,6 +64,7 @@
"Make_Ingredient": "Make Ingredient",
"Enable_Amount": "Enable Amount",
"Disable_Amount": "Disable Amount",
+ "Ingredient Editor": "Ingredient Editor",
"Add_Step": "Add Step",
"Keywords": "Keywords",
"Books": "Books",