228 lines
5.5 KiB
Vue
228 lines
5.5 KiB
Vue
<script setup lang="ts">
|
|
import {useLabelEditorStore} from "~/store/labelEditorStore";
|
|
import type {Ref} from "vue";
|
|
import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
|
|
import type {Nutrition} from "~/types/nutrition.ts";
|
|
|
|
const props = defineProps({
|
|
nutrition: {type: Object as PropType<Nutrition | null>, required: true},
|
|
});
|
|
|
|
let store = useLabelEditorStore();
|
|
let loading: Ref<boolean> = ref<boolean>(false);
|
|
let dialog: Ref<boolean> = ref<boolean>(false);
|
|
|
|
async function createNutrition() {
|
|
if (store.article != null) {
|
|
await store.createArticleNutrition(store.article.id);
|
|
}
|
|
}
|
|
|
|
async function updateNutrition() {
|
|
if (props.nutrition != null) {
|
|
await store.updateNutrition(props.nutrition);
|
|
}
|
|
}
|
|
|
|
async function deleteNutrition() {
|
|
if (props.nutrition != null) {
|
|
await store.deleteNutrition(props.nutrition)
|
|
}
|
|
|
|
closeDialog();
|
|
}
|
|
|
|
function closeDialog() {
|
|
dialog.value = false;
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<v-dialog
|
|
v-model="dialog"
|
|
:scrollable="true"
|
|
width="800"
|
|
max-height="750"
|
|
height="750"
|
|
>
|
|
<template v-slot:activator="{ props }">
|
|
<v-btn
|
|
:flat="true"
|
|
v-bind="props"
|
|
size="small"
|
|
>
|
|
<v-icon v-if="nutrition != null" color="success">mdi-nutrition</v-icon>
|
|
<v-icon v-else>mdi-nutrition</v-icon>
|
|
|
|
<v-tooltip v-if="nutrition != null"
|
|
activator="parent"
|
|
location="bottom"
|
|
>
|
|
Nährwerte
|
|
</v-tooltip>
|
|
|
|
<v-tooltip v-else
|
|
activator="parent"
|
|
location="bottom"
|
|
>
|
|
Nährwerte hinzufügen
|
|
</v-tooltip>
|
|
</v-btn>
|
|
</template>
|
|
|
|
<v-card>
|
|
<v-card-title>
|
|
<v-row style="padding-top: 10px">
|
|
<v-icon size="small">
|
|
mdi-nutrition
|
|
</v-icon>
|
|
|
|
Nährwerte
|
|
|
|
<v-progress-circular v-if="loading" indeterminate :size="15" :width="2"></v-progress-circular>
|
|
</v-row>
|
|
</v-card-title>
|
|
|
|
<v-divider/>
|
|
|
|
<v-card-text>
|
|
|
|
<div v-if="props.nutrition != null">
|
|
<v-row>
|
|
<v-col>
|
|
<v-text-field
|
|
v-model="props.nutrition.calorific_value_kcal"
|
|
:disabled="loading"
|
|
hint="Brennwert in kcal"
|
|
label="Brennwert"
|
|
suffix="kcal"
|
|
type="number"
|
|
></v-text-field>
|
|
</v-col>
|
|
|
|
<v-col>
|
|
<v-text-field
|
|
v-model="props.nutrition.calorific_value_kj"
|
|
:disabled="loading"
|
|
hint="Brennwert in kj"
|
|
label="Brennwert"
|
|
suffix="kj"
|
|
type="number"
|
|
></v-text-field>
|
|
</v-col>
|
|
</v-row>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.fat"
|
|
:disabled="loading"
|
|
hint="Fett in g"
|
|
label="Fett"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.saturated_fat"
|
|
:disabled="loading"
|
|
hint="Gesättigte Fettsäuren in g"
|
|
label="Gesättigte Fettsäuren"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.carbohydrates"
|
|
:disabled="loading"
|
|
hint="Kohlenhydrate in g"
|
|
label="Kohlenhydrate"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.sugar"
|
|
:disabled="loading"
|
|
hint="Zucker in g"
|
|
label="Zucker"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.fibers"
|
|
:disabled="loading"
|
|
hint="Ballaststoffe in g"
|
|
label="Ballaststoffe"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.protein"
|
|
:disabled="loading"
|
|
hint="Eiweiß in g"
|
|
label="Eiweiß"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="props.nutrition.salt"
|
|
:disabled="loading"
|
|
hint="Salz in g"
|
|
label="Salz"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
</div>
|
|
|
|
<div v-else>
|
|
Keine Nährwerte hinterlegt
|
|
</div>
|
|
|
|
</v-card-text>
|
|
|
|
<v-divider/>
|
|
|
|
<v-card-actions>
|
|
<v-spacer/>
|
|
<v-btn
|
|
v-if="props.nutrition == null"
|
|
variant="text"
|
|
:disabled="loading"
|
|
@click="createNutrition()"
|
|
>
|
|
Hinzufügen
|
|
</v-btn>
|
|
|
|
<DeleteConfirm
|
|
v-else
|
|
title="Nährwert löschen?"
|
|
:disable="loading"
|
|
@delete="deleteNutrition()"
|
|
/>
|
|
<v-divider vertical/>
|
|
|
|
<v-btn
|
|
variant="text"
|
|
:disabled="loading"
|
|
@click="updateNutrition()"
|
|
>
|
|
Speichern
|
|
</v-btn>
|
|
|
|
<v-btn
|
|
variant="text"
|
|
:disabled="loading"
|
|
@click="closeDialog()"
|
|
>
|
|
Schließen
|
|
</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-dialog>
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
</style> |