Started adding nutrition editing logic.
This commit is contained in:
1 parent
3ae697d852
commit
d613f8c1d7
6 files changed
+306
-15
No files matched your search
@@ -96,7 +96,9 @@
|
||||
|
||||
<v-divider vertical/>
|
||||
|
||||
<Nutrition v-bind:nutrition="store.article.nutrition"/>
|
||||
<Nutrition
|
||||
v-bind:nutrition="store.article.nutrition"
|
||||
/>
|
||||
|
||||
<v-btn
|
||||
:flat="true"
|
||||
|
||||
@@ -12,12 +12,23 @@
|
||||
let loading: Ref<boolean> = ref<boolean>(false);
|
||||
let dialog: Ref<boolean> = ref<boolean>(false);
|
||||
|
||||
async function updateNutrition() {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -75,16 +86,119 @@
|
||||
<v-divider/>
|
||||
|
||||
<v-card-text>
|
||||
test
|
||||
|
||||
<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"
|
||||
:disable="loading"
|
||||
@delete="deleteNutrition()"
|
||||
/>
|
||||
<v-divider vertical/>
|
||||
@@ -92,7 +206,7 @@
|
||||
<v-btn
|
||||
variant="text"
|
||||
:disabled="loading"
|
||||
@click="closeDialog()"
|
||||
@click="updateNutrition()"
|
||||
>
|
||||
Speichern
|
||||
</v-btn>
|
||||
|
||||
@@ -8,6 +8,7 @@ import {Unit} from "~/types/unit";
|
||||
import type {Label} from "~/types/label";
|
||||
import type {Settings} from "~/types/settings";
|
||||
import type {Supplier} from "~/types/supplier";
|
||||
import type {Nutrition} from "~/types/nutrition.ts";
|
||||
|
||||
interface State {
|
||||
config: RuntimeConfig,
|
||||
@@ -455,5 +456,56 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
this.addNotification(true, 'Fehler beim löschen des Lieferanten.');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
// Nutrition
|
||||
async createArticleNutrition(articleID: number) {
|
||||
try {
|
||||
let article = await $fetch<Article>(this.config.public.url + '/article/' + articleID +'/nutrition', {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
this.article = article;
|
||||
|
||||
this.addNotification(false, 'Nährwert angelegt');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim anlegen der Nährwerte.');
|
||||
}
|
||||
},
|
||||
|
||||
async updateNutrition(nutrition: Nutrition): Promise<Nutrition> {
|
||||
try {
|
||||
let updatedNutrition = await $fetch<Nutrition>(this.config.public.url + '/nutrition/' + nutrition.id, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(nutrition),
|
||||
});
|
||||
|
||||
this.addNotification(false, 'Nährwert aktualisiert.');
|
||||
return updatedNutrition;
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim aktualisieren des Nährwerts.');
|
||||
return nutrition;
|
||||
}
|
||||
},
|
||||
|
||||
async deleteNutrition(nutrition: Nutrition): Promise<Nutrition | null> {
|
||||
try {
|
||||
await $fetch(this.config.public.url + '/nutrition/' + nutrition.id, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
this.addNotification(false, 'Nährwert gelöscht.');
|
||||
return null;
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim löschen des Nährwerts.');
|
||||
return nutrition
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
// ...
|
||||
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user