added ability to open ingredient editor from food/unit list
This commit is contained in:
parent
d50fb69ce9
commit
f0d59a8c9c
@ -30,6 +30,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
|
window.DEFAULT_FOOD = {{ food_id }}
|
||||||
|
window.DEFAULT_UNIT = {{ unit_id }}
|
||||||
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}'
|
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -228,7 +228,15 @@ def supermarket(request):
|
|||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
def ingredient_editor(request):
|
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')
|
@group_required('user')
|
||||||
|
@ -88,7 +88,9 @@
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td style="width: 5vw">
|
<td style="width: 5vw">
|
||||||
<b-button :disabled="i.changed !== true" :variant="(i.changed !== true) ? 'primary' : 'success'" @click="updateIngredient(i)">
|
<b-button :disabled="i.changed !== true"
|
||||||
|
:variant="(i.changed !== true) ? 'primary' : 'success'"
|
||||||
|
@click="updateIngredient(i)">
|
||||||
<i class="fas fa-save"></i>
|
<i class="fas fa-save"></i>
|
||||||
</b-button>
|
</b-button>
|
||||||
</td>
|
</td>
|
||||||
@ -137,6 +139,20 @@ export default {
|
|||||||
computed: {},
|
computed: {},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$i18n.locale = window.CUSTOM_LOCALE
|
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()
|
this.refreshList()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -80,7 +80,7 @@ import {BootstrapVue} from "bootstrap-vue"
|
|||||||
|
|
||||||
import "bootstrap-vue/dist/bootstrap-vue.css"
|
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 {StandardToasts, ToastMixin} from "@/utils/utils"
|
||||||
|
|
||||||
import GenericInfiniteCards from "@/components/GenericInfiniteCards"
|
import GenericInfiniteCards from "@/components/GenericInfiniteCards"
|
||||||
@ -158,7 +158,6 @@ export default {
|
|||||||
let target = e?.target ?? undefined
|
let target = e?.target ?? undefined
|
||||||
this.this_item = source
|
this.this_item = source
|
||||||
this.this_target = target
|
this.this_target = target
|
||||||
|
|
||||||
switch (e.action) {
|
switch (e.action) {
|
||||||
case "delete":
|
case "delete":
|
||||||
this.this_action = this.Actions.DELETE
|
this.this_action = this.Actions.DELETE
|
||||||
@ -173,6 +172,16 @@ export default {
|
|||||||
this.this_action = this.Actions.UPDATE
|
this.this_action = this.Actions.UPDATE
|
||||||
this.show_modal = true
|
this.show_modal = true
|
||||||
break
|
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":
|
case "move":
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
this.this_item = e.source
|
this.this_item = e.source
|
||||||
|
@ -6,7 +6,10 @@
|
|||||||
</template>
|
</template>
|
||||||
<b-dropdown-item v-on:click="$emit('item-action', 'edit')" v-if="show_edit"> <i class="fas fa-pencil-alt fa-fw"></i> {{ $t("Edit") }} </b-dropdown-item>
|
<b-dropdown-item v-on:click="$emit('item-action', 'edit')" v-if="show_edit"> <i class="fas fa-pencil-alt fa-fw"></i> {{ $t("Edit") }} </b-dropdown-item>
|
||||||
|
|
||||||
|
|
||||||
<b-dropdown-item v-on:click="$emit('item-action', 'delete')" v-if="show_delete"> <i class="fas fa-trash-alt fa-fw"></i> {{ $t("Delete") }} </b-dropdown-item>
|
<b-dropdown-item v-on:click="$emit('item-action', 'delete')" v-if="show_delete"> <i class="fas fa-trash-alt fa-fw"></i> {{ $t("Delete") }} </b-dropdown-item>
|
||||||
|
<b-dropdown-item v-on:click="$emit('item-action', 'ingredient-editor')" v-if="show_ingredient_editor"> <i class="fas fa-th-list fa-dw"></i> {{ $t("Ingredient Editor") }} </b-dropdown-item>
|
||||||
|
|
||||||
<b-dropdown-item v-on:click="$emit('item-action', 'add-shopping')" v-if="show_shopping">
|
<b-dropdown-item v-on:click="$emit('item-action', 'add-shopping')" v-if="show_shopping">
|
||||||
<i class="fas fa-cart-plus fa-fw"></i> {{ $t("Add_to_Shopping") }}
|
<i class="fas fa-cart-plus fa-fw"></i> {{ $t("Add_to_Shopping") }}
|
||||||
</b-dropdown-item>
|
</b-dropdown-item>
|
||||||
@ -24,8 +27,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {ResolveUrlMixin} from "@/utils/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "GenericContextMenu",
|
name: "GenericContextMenu",
|
||||||
|
mixins: [ResolveUrlMixin],
|
||||||
props: {
|
props: {
|
||||||
show_edit: { type: Boolean, default: true },
|
show_edit: { type: Boolean, default: true },
|
||||||
show_delete: { type: Boolean, default: true },
|
show_delete: { type: Boolean, default: true },
|
||||||
@ -33,6 +39,7 @@ export default {
|
|||||||
show_merge: { type: Boolean, default: false },
|
show_merge: { type: Boolean, default: false },
|
||||||
show_shopping: { type: Boolean, default: false },
|
show_shopping: { type: Boolean, default: false },
|
||||||
show_onhand: { type: Boolean, default: false },
|
show_onhand: { type: Boolean, default: false },
|
||||||
|
show_ingredient_editor: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
:show_move="useMove"
|
:show_move="useMove"
|
||||||
:show_shopping="useShopping"
|
:show_shopping="useShopping"
|
||||||
:show_onhand="useOnhand"
|
:show_onhand="useOnhand"
|
||||||
|
:show_ingredient_editor="useIngredientEditor"
|
||||||
@item-action="$emit('item-action', { action: $event, source: item })"
|
@item-action="$emit('item-action', { action: $event, source: item })"
|
||||||
>
|
>
|
||||||
</generic-context-menu>
|
</generic-context-menu>
|
||||||
@ -132,11 +133,12 @@ import GenericOrderedPill from "@/components/GenericOrderedPill"
|
|||||||
import RecipeCard from "@/components/RecipeCard"
|
import RecipeCard from "@/components/RecipeCard"
|
||||||
import { mixin as clickaway } from "vue-clickaway"
|
import { mixin as clickaway } from "vue-clickaway"
|
||||||
import { createPopper } from "@popperjs/core"
|
import { createPopper } from "@popperjs/core"
|
||||||
|
import {ApiMixin} from "@/utils/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "GenericHorizontalCard",
|
name: "GenericHorizontalCard",
|
||||||
components: { GenericContextMenu, RecipeCard, Badges, GenericPill, GenericOrderedPill },
|
components: { GenericContextMenu, RecipeCard, Badges, GenericPill, GenericOrderedPill },
|
||||||
mixins: [clickaway],
|
mixins: [clickaway, ApiMixin],
|
||||||
props: {
|
props: {
|
||||||
item: { type: Object },
|
item: { type: Object },
|
||||||
model: { type: Object },
|
model: { type: Object },
|
||||||
@ -186,6 +188,9 @@ export default {
|
|||||||
useDrag: function () {
|
useDrag: function () {
|
||||||
return this.useMove || this.useMerge
|
return this.useMove || this.useMerge
|
||||||
},
|
},
|
||||||
|
useIngredientEditor: function (){
|
||||||
|
return (this.model === this.Models.FOOD || this.model === this.Models.UNIT)
|
||||||
|
},
|
||||||
itemTags: function () {
|
itemTags: function () {
|
||||||
return this.model?.tags ?? []
|
return this.model?.tags ?? []
|
||||||
},
|
},
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
"Make_Ingredient": "Make Ingredient",
|
"Make_Ingredient": "Make Ingredient",
|
||||||
"Enable_Amount": "Enable Amount",
|
"Enable_Amount": "Enable Amount",
|
||||||
"Disable_Amount": "Disable Amount",
|
"Disable_Amount": "Disable Amount",
|
||||||
|
"Ingredient Editor": "Ingredient Editor",
|
||||||
"Add_Step": "Add Step",
|
"Add_Step": "Add Step",
|
||||||
"Keywords": "Keywords",
|
"Keywords": "Keywords",
|
||||||
"Books": "Books",
|
"Books": "Books",
|
||||||
|
Loading…
Reference in New Issue
Block a user