276 lines
7.4 KiB
Vue
276 lines
7.4 KiB
Vue
<script setup lang="ts">
|
|
import {useLabelEditorStore} from "~/store/labelEditorStore";
|
|
import type {Ref} from "vue";
|
|
import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
|
|
import {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);
|
|
|
|
let calorific_value_kj: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let calorific_value_kcal: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let fat: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let saturated_fat: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let carbohydrates: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let sugar: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let fibers: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let protein: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
let salt: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
|
|
|
|
watch(dialog, async (oldDialog) => {
|
|
if (oldDialog) {
|
|
if (props.nutrition != null) {
|
|
calorific_value_kj.value = props.nutrition.calorific_value_kj;
|
|
calorific_value_kcal.value = props.nutrition.calorific_value_kcal;
|
|
fat.value = props.nutrition.fat;
|
|
saturated_fat.value = props.nutrition.saturated_fat;
|
|
carbohydrates.value = props.nutrition.carbohydrates;
|
|
sugar.value = props.nutrition.sugar;
|
|
fibers.value = props.nutrition.fibers;
|
|
protein.value = props.nutrition.protein;
|
|
salt.value = props.nutrition.salt;
|
|
}
|
|
}
|
|
})
|
|
|
|
async function createNutrition() {
|
|
if (store.article != null) {
|
|
await store.createArticleNutrition(store.article.id);
|
|
|
|
calorific_value_kj.value = 0;
|
|
calorific_value_kcal.value = 0;
|
|
fat.value = 0;
|
|
saturated_fat.value = 0;
|
|
carbohydrates.value = 0;
|
|
sugar.value = 0;
|
|
fibers.value = 0;
|
|
protein.value = 0;
|
|
salt.value = 0;
|
|
}
|
|
}
|
|
|
|
async function updateNutrition() {
|
|
if (props.nutrition != null) {
|
|
let nutrition = new Nutrition(props.nutrition.id,
|
|
parseFloat(calorific_value_kj.value.toString()),
|
|
parseFloat(calorific_value_kcal.value.toString()),
|
|
parseFloat(fat.value.toString()),
|
|
parseFloat(saturated_fat.value.toString()),
|
|
parseFloat(carbohydrates.value.toString()),
|
|
parseFloat(sugar.value.toString()),
|
|
parseFloat(fibers.value.toString()),
|
|
parseFloat(protein.value.toString()),
|
|
parseFloat(salt.value.toString()),
|
|
);
|
|
|
|
await store.updateNutrition(nutrition);
|
|
}
|
|
}
|
|
|
|
async function deleteNutrition() {
|
|
if (props.nutrition != null) {
|
|
await store.deleteArticleNutrition(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="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="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="fat"
|
|
:disabled="loading"
|
|
hint="Fett in g"
|
|
label="Fett"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="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="carbohydrates"
|
|
:disabled="loading"
|
|
hint="Kohlenhydrate in g"
|
|
label="Kohlenhydrate"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="sugar"
|
|
:disabled="loading"
|
|
hint="Zucker in g"
|
|
label="Zucker"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="fibers"
|
|
:disabled="loading"
|
|
hint="Ballaststoffe in g"
|
|
label="Ballaststoffe"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="protein"
|
|
:disabled="loading"
|
|
hint="Eiweiß in g"
|
|
label="Eiweiß"
|
|
suffix="g"
|
|
type="number"
|
|
></v-text-field>
|
|
|
|
<v-text-field
|
|
v-model="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> |