Added unit to db and structs/types.

This commit is contained in:
2026-01-26 22:09:32 +01:00
parent 7879f69255
commit 8a27639aad
14 changed files with 243 additions and 60 deletions
+12 -7
View File
@@ -115,7 +115,7 @@
<v-card-text>
<v-row no-gutters>
<v-col cols="2">
<v-col cols="2" style="padding: 5px;">
<v-row no-gutters>
<v-checkbox
v-model="store.articleEdit.bio"
@@ -126,16 +126,21 @@
<v-row no-gutters>
<v-col cols="5">
<v-sheet>
Herkunft:
</v-sheet>
Herkunft:
</v-col>
<v-col>
<v-sheet>
{{ originToString(store.article.origin) }}
</v-sheet>
{{ originToString(store.article.origin) }}
</v-col>
</v-row>
<v-row>
<v-select
v-model="store.articleEdit.default_unit"
:items="store.units"
label="Standard Einheit"
:readonly="!edit"
></v-select>
</v-row>
</v-col>
<v-col cols="5" style="padding: 5px;">
@@ -3,6 +3,7 @@
import {useLabelEditorStore} from "~/store/labelEditorStore";
import {Article} from "~/types/article";
import {Origin} from "~/types/origin";
import type {Unit} from "~/types/unit";
let store = useLabelEditorStore();
@@ -12,16 +13,18 @@
let name: Ref<string | null> = ref<string | null>(null);
let bio: Ref<boolean> = ref<boolean>(false);
let origin: Ref<Origin | null> = ref<Origin | null>(null);
let default_unit: Ref<Unit | null> = ref<Unit | null>(null);
let description: Ref<string | null> = ref<string | null>(null);
let ingredients: Ref<string | null> = ref<string | null>(null);
async function create() {
if (name.value != null && name.value.trim().length > 0 &&
origin.value != null && origin.value.trim().length > 0
origin.value != null && origin.value.trim().length > 0 &&
default_unit.value != null && default_unit.value.trim().length > 0
) {
loading.value = true;
const article: Article = new Article(0, name.value, bio.value, origin.value, description.value, ingredients.value, []);
const article: Article = new Article(0, name.value, bio.value, origin.value, description.value, ingredients.value, default_unit.value, []);
await store.createArticle(article);
@@ -102,6 +105,13 @@
label="Herkunft"
></v-select>
</v-col>
<v-col>
<v-select
v-model="default_unit"
:items="store.units"
label="Standard Einheit"
></v-select>
</v-col>
</v-row>
<v-textarea
@@ -1,47 +1,54 @@
<script setup lang="ts">
import type {Ref} from "vue";
import {useLabelEditorStore} from "~/store/labelEditorStore";
import { Variant } from "~/types/variant";
import type {Ref} from "vue";
import {useLabelEditorStore} from "~/store/labelEditorStore";
import { Variant } from "~/types/variant";
import type {Unit} from "~/types/unit";
let store = useLabelEditorStore();
let store = useLabelEditorStore();
let dialog: Ref<boolean> = ref<boolean>(false);
let loading: Ref<boolean> = ref<boolean>(false);
let dialog: Ref<boolean> = ref<boolean>(false);
let loading: Ref<boolean> = ref<boolean>(false);
let weight: Ref<string | null> = ref<string | null>(null);
let ean: Ref<string | null> = ref<string | null>(null);
let name: Ref<string | null> = ref<string | null>(null);
let description: Ref<string | null> = ref<string | null>(null);
let ingredients: Ref<string | null> = ref<string | null>(null);
let weight: Ref<string | null> = ref<string | null>(null);
let ean: Ref<string | null> = ref<string | null>(null);
let name: Ref<string | null> = ref<string | null>(null);
let unit: Ref<Unit | null> = ref<Unit | null>(null);
let description: Ref<string | null> = ref<string | null>(null);
let ingredients: Ref<string | null> = ref<string | null>(null);
async function create() {
if (store.article != null &&
weight.value != null && weight.value.trim().length > 0
) {
loading.value = true;
const variant: Variant = new Variant(0, weight.value, ean.value, name.value, description.value, ingredients.value);
await store.addVariant(variant);
closeDialog();
if (store.article != null) {
unit.value = store.article.default_unit;
}
}
function closeDialog() {
dialog.value = false;
clearVariables();
}
async function create() {
if (store.article != null &&
weight.value != null && weight.value.trim().length > 0 &&
unit.value != null && unit.value.trim().length > 0
) {
loading.value = true;
function clearVariables() {
weight.value = null;
ean.value = null;
name.value = null;
description.value = null;
ingredients.value = null;
const variant: Variant = new Variant(0, weight.value, ean.value, name.value, description.value, ingredients.value, unit.value);
loading.value = false;
}
await store.addVariant(variant);
closeDialog();
}
}
function closeDialog() {
dialog.value = false;
clearVariables();
}
function clearVariables() {
weight.value = null;
ean.value = null;
name.value = null;
description.value = null;
ingredients.value = null;
loading.value = false;
}
</script>
<template>
@@ -87,10 +94,21 @@ function clearVariables() {
autofocus
/>
<v-text-field
v-model.trim="weight"
label="Gewicht"
/>
<v-row>
<v-col>
<v-text-field
v-model.trim="weight"
label="Gewicht"
/>
</v-col>
<v-col>
<v-select
v-model="unit"
:items="store.units"
label="Einheit"
></v-select>
</v-col>
</v-row>
<v-textarea
v-model.trim="ean"
+13 -2
View File
@@ -3,6 +3,7 @@
import type {Ref} from "vue";
import {Variant} from "~/types/variant";
import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
import type {Unit} from "~/types/unit";
let store = useLabelEditorStore();
@@ -15,6 +16,7 @@
let weight: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.weight)));
let ean: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.ean)));
let name: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.name)));
let unit: Ref<Unit | null> = ref<Unit | null>(JSON.parse(JSON.stringify(props.variant.unit)));
let description: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.description)));
let ingredients: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.ingredients)));
@@ -35,13 +37,14 @@
weight.value = JSON.parse(JSON.stringify(props.variant.weight));
ean.value = JSON.parse(JSON.stringify(props.variant.ean));
name.value = JSON.parse(JSON.stringify(props.variant.name));
unit.value = JSON.parse(JSON.stringify(props.variant.unit));
description.value = JSON.parse(JSON.stringify(props.variant.description));
ingredients.value = JSON.parse(JSON.stringify(props.variant.ingredients));
}
async function updateVariant() {
if (weight.value != null) {
let updateVariant: Variant = new Variant(props.variant.id, weight.value, ean.value, name.value, description.value, ingredients.value);
if (weight.value != null && unit.value != null) {
let updateVariant: Variant = new Variant(props.variant.id, weight.value, ean.value, name.value, description.value, ingredients.value, unit.value);
await store.updateVariant(updateVariant);
@@ -137,6 +140,14 @@
:readonly="!edit"
/>
</v-row>
<v-row>
<v-select
v-model="unit"
:items="store.units"
label="Einheit"
:readonly="!edit"
></v-select>
</v-row>
<v-row>
<v-text-field
v-model.trim="ean"
+12 -2
View File
@@ -4,6 +4,7 @@ import {NotificationMessage} from "~/types/notificationMessage";
import type {RuntimeConfig} from "nuxt/schema";
import {Origin} from "~/types/origin";
import type {Variant} from "~/types/variant";
import {Unit} from "~/types/unit";
interface State {
config: RuntimeConfig,
@@ -21,6 +22,7 @@ interface State {
articleEdit: Article | null,
origins: Array<Origin>,
units: Array<Unit>,
}
export const useLabelEditorStore = defineStore('label_editor_store', {
@@ -42,8 +44,16 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
origins: [
Origin.EU,
Origin.NonEU,
Origin.EUnonEU
]
Origin.EUnonEU,
],
units: [
Unit.G,
Unit.Kg,
Unit.Ml,
Unit.L,
Unit.Stk,
],
}),
actions: {
// Notification
+5 -2
View File
@@ -1,5 +1,6 @@
import type {Variant} from "~/types/variant";
import type {Origin} from "~/types/origin";
import type {Unit} from "~/types/unit";
export class Article {
readonly id: number;
@@ -8,16 +9,18 @@ export class Article {
origin: Origin;
description: string | null;
ingredients: string | null;
default_unit: Unit;
variants: Array<Variant>;
constructor(id: number, name: string, bio: boolean, origin: Origin, description: string | null, ingredients: string | null, variants: Array<Variant> | null) {
constructor(id: number, name: string, bio: boolean, origin: Origin, description: string | null, ingredients: string | null, default_unit: Unit, variants: Array<Variant> | null) {
this.id = id;
this.name = name;
this.bio = bio;
this.origin = origin;
this.description = description;
this.ingredients = ingredients;
this.default_unit = default_unit;
if (variants == null) {
this.variants = [];
} else {
+22
View File
@@ -0,0 +1,22 @@
export enum Unit {
Kg = "Kg",
G = "G",
L = "L",
Ml = "Ml",
Stk = "Stk",
}
export function unitToString(unit: Unit): string {
switch (unit) {
case Unit.Kg:
return "Kilogramm";
case Unit.G:
return "Gramm";
case Unit.L:
return "Liter";
case Unit.Ml:
return "Milliliter";
case Unit.Stk:
return "Stück";
}
}
+5 -1
View File
@@ -1,3 +1,5 @@
import type {Unit} from "~/types/unit";
export class Variant {
readonly id: number;
weight: string;
@@ -5,13 +7,15 @@ export class Variant {
name: string | null;
description: string | null;
ingredients: string | null;
unit: Unit;
constructor(id: number, weight: string, ean: string|null, name: string|null, description:string|null, ingredients: string|null) {
constructor(id: number, weight: string, ean: string|null, name: string|null, description:string|null, ingredients: string|null, unit: Unit) {
this.id = id;
this.weight = weight;
this.ean = ean;
this.name = name;
this.description = description;
this.ingredients = ingredients;
this.unit = unit;
}
}