Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: improve entity type UI (#1544)

Ell8c7947b2591d
diff --git a/backend/internal/data/migrations/postgres/20260416120000_merge_entities.go b/backend/internal/data/migrations/postgres/20260416120000_merge_entities.go
index a647697e..1c7f7801 100644
--- a/backend/internal/data/migrations/postgres/20260416120000_merge_entities.go
+++ b/backend/internal/data/migrations/postgres/20260416120000_merge_entities.go
@@ -37,7 +37,7 @@ func Up20260402120000(ctx context.Context, tx *sql.Tx) error {
// 2. Seed default entity types per group
_, err = tx.ExecContext(ctx, `
INSERT INTO entity_types (id, created_at, updated_at, name, description, is_location, group_entity_types)
- SELECT gen_random_uuid(), now(), now(), 'Location', '', true, g.id FROM groups g;
+ SELECT gen_random_uuid(), now(), now(), 'global.location', '', true, g.id FROM groups g;
`)
if err != nil {
return fmt.Errorf("step 2a: seed Location entity type: %w", err)
@@ -45,7 +45,7 @@ func Up20260402120000(ctx context.Context, tx *sql.Tx) error {
_, err = tx.ExecContext(ctx, `
INSERT INTO entity_types (id, created_at, updated_at, name, description, is_location, group_entity_types)
- SELECT gen_random_uuid(), now(), now(), 'Item', '', false, g.id FROM groups g;
+ SELECT gen_random_uuid(), now(), now(), 'global.item', '', false, g.id FROM groups g;
`)
if err != nil {
return fmt.Errorf("step 2b: seed Item entity type: %w", err)
@@ -83,7 +83,7 @@ func Up20260402120000(ctx context.Context, tx *sql.Tx) error {
_, err = tx.ExecContext(ctx, `
UPDATE entities SET entity_type_entities = et.id
FROM entity_types et
- WHERE et.group_entity_types = entities.group_entities AND et.name = 'Item';
+ WHERE et.group_entity_types = entities.group_entities AND et.name = 'global.item';
`)
if err != nil {
return fmt.Errorf("step 6: set entity_type on existing entities: %w", err)
@@ -112,7 +112,7 @@ func Up20260402120000(ctx context.Context, tx *sql.Tx) error {
1, false, false, 0, 0, 0, false, false,
l.group_locations, et.id, l.location_children
FROM locations l
- JOIN entity_types et ON et.group_entity_types = l.group_locations AND et.name = 'Location';
+ JOIN entity_types et ON et.group_entity_types = l.group_locations AND et.name = 'global.location';
`)
if err != nil {
return fmt.Errorf("step 8: insert locations as entities: %w", err)
diff --git a/backend/internal/data/migrations/sqlite3/20260416120001_merge_entities.go b/backend/internal/data/migrations/sqlite3/20260416120001_merge_entities.go
index 39117f98..3a9512f9 100644
--- a/backend/internal/data/migrations/sqlite3/20260416120001_merge_entities.go
+++ b/backend/internal/data/migrations/sqlite3/20260416120001_merge_entities.go
@@ -69,10 +69,10 @@ func mergeCreateEntityTypes(ctx context.Context, db *sql.DB) error {
seedSQL := `INSERT INTO entity_types (id, created_at, updated_at, name, description, is_location, group_entity_types)
SELECT ` + uuidExpr + `, datetime('now'), datetime('now'), $1, '', $2, g.id FROM groups g;`
- if _, err := db.ExecContext(ctx, seedSQL, "Location", true); err != nil {
+ if _, err := db.ExecContext(ctx, seedSQL, "global.location", true); err != nil {
return fmt.Errorf("seed Location type: %w", err)
}
- if _, err := db.ExecContext(ctx, seedSQL, "Item", false); err != nil {
+ if _, err := db.ExecContext(ctx, seedSQL, "global.item", false); err != nil {
return fmt.Errorf("seed Item type: %w", err)
}
@@ -157,7 +157,7 @@ func mergeMigrateData(ctx context.Context, db *sql.DB) error {
i.sold_time, i.sold_to, i.sold_price, i.sold_notes,
i.group_items, et.id, i.item_children
FROM items i
- JOIN entity_types et ON et.group_entity_types = i.group_items AND et.name = 'Item';
+ JOIN entity_types et ON et.group_entity_types = i.group_items AND et.name = 'global.item';
`); err != nil {
return fmt.Errorf("insert items as entities: %w", err)
}
@@ -175,7 +175,7 @@ func mergeMigrateData(ctx context.Context, db *sql.DB) error {
1, 0, 0, 0, 0, 0, 0, 0,
l.group_locations, et.id, l.location_children
FROM locations l
- JOIN entity_types et ON et.group_entity_types = l.group_locations AND et.name = 'Location';
+ JOIN entity_types et ON et.group_entity_types = l.group_locations AND et.name = 'global.location';
`); err != nil {
return fmt.Errorf("insert locations as entities: %w", err)
}
diff --git a/frontend/components/App/CreateModal.vue b/frontend/components/App/CreateModal.vue
index fff86ffd..baa3da21 100644
--- a/frontend/components/App/CreateModal.vue
+++ b/frontend/components/App/CreateModal.vue
@@ -3,7 +3,11 @@
<DialogScrollContent>
<DialogHeader>
<div class="mr-4 flex place-items-center justify-between">
- <DialogTitle>{{ title }}</DialogTitle>
+ <DialogTitle>
+ <slot name="title">
+ {{ title }}
+ </slot>
+ </DialogTitle>
<slot name="header-actions" />
</div>
</DialogHeader>
@@ -30,7 +34,11 @@
<Drawer v-else :dialog-id="dialogId">
<DrawerContent class="max-h-[90%]">
<DrawerHeader>
- <DrawerTitle>{{ title }}</DrawerTitle>
+ <DrawerTitle>
+ <slot name="title">
+ {{ title }}
+ </slot>
+ </DrawerTitle>
</DrawerHeader>
<div class="flex justify-center">
<slot name="header-actions" />
@@ -54,7 +62,7 @@
defineProps<{
dialogId: DialogID;
- title: string;
+ title?: string;
hideFooter?: boolean;
}>();
</script>
diff --git a/frontend/components/App/QuickMenuModal.vue b/frontend/components/App/QuickMenuModal.vue
index 12875a65..a08ab643 100644
--- a/frontend/components/App/QuickMenuModal.vue
+++ b/frontend/components/App/QuickMenuModal.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useI18n } from "vue-i18n";
- import { DialogID, type NoParamDialogIDs, type OptionalDialogIDs } from "@/components/ui/dialog-provider/utils";
+ import { DialogID, type NoParamDialogIDs } from "@/components/ui/dialog-provider/utils";
import {
CommandDialog,
CommandEmpty,
@@ -15,7 +15,7 @@
export type QuickMenuAction =
| { text: string; href: string; type: "navigate" }
- | { text: string; dialogId: NoParamDialogIDs | OptionalDialogIDs; shortcut: string; type: "create" };
+ | { text: string; dialogId: DialogID; shortcut: string; type: "create"; id?: number };
const props = defineProps({
actions: {
@@ -40,7 +40,15 @@
const item = props.actions.filter(item => 'shortcut' in item).find(item => item.shortcut === e.key);
if (item) {
e.preventDefault();
- openDialog(item.dialogId as NoParamDialogIDs);
+ if (item.dialogId === DialogID.CreateEntity) {
+ if (item.id === 0) {
+ openDialog(DialogID.CreateEntity, { params: { baseType: 'item' } });
+ } else if (item.id === 1) {
+ openDialog(DialogID.CreateEntity, { params: { baseType: 'location' } });
+ }
+ } else {
+ openDialog(item.dialogId as NoParamDialogIDs);
+ }
}
// if esc is pressed, close the dialog
if (e.key === 'Escape') {
diff --git a/frontend/components/Item/CreateModal.vue b/frontend/components/Entity/CreateModal.vue
similarity index 57%
rename from frontend/components/Item/CreateModal.vue
rename to frontend/components/Entity/CreateModal.vue
index c470956f..04cde6b7 100644
--- a/frontend/components/Item/CreateModal.vue
+++ b/frontend/components/Entity/CreateModal.vue
@@ -1,10 +1,37 @@
<template>
- <BaseModal :dialog-id="DialogID.CreateItem" :title="$t('components.item.create_modal.title')">
+ <BaseModal :dialog-id="DialogID.CreateEntity">
+ <template #title>
+ <div class="flex items-center gap-2 text-nowrap">
+ <span>Create</span>
+ <Select :model-value="selectedEntityType?.id">
+ <SelectTrigger class="h-7 p-1">
+ <SelectValue
+ class="text-xl"
+ :placeholder="$t('components.entity.create_modal.type_selector_placeholder')"
+ />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem
+ v-for="type in subItemCreate ? entityTypes.filter(t => !t.isLocation) : entityTypes"
+ :key="type.id"
+ :value="type.id"
+ @click="onEntityTypeChanged(type.id)"
+ >
+ <div class="flex items-center gap-2">
+ <MdiMapMarkerOutline v-if="type.isLocation" class="size-4" />
+ <MdiPackageVariantClosed v-else class="size-4" />
+ <span>{{ t(type.name) }}</span>
+ </div>
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </div>
+ </template>
<template #header-actions>
<div class="flex gap-2">
<TooltipProvider :delay-duration="0">
<!-- Template selector button -->
- <Tooltip>
+ <Tooltip v-if="!selectedEntityType?.isLocation">
<TooltipTrigger>
<TemplateSelector v-model="selectedTemplate" compact @template-selected="handleTemplateSelected" />
</TooltipTrigger>
@@ -21,7 +48,7 @@
</Button>
</TooltipTrigger>
<TooltipContent>
- <p>{{ $t("components.item.create_modal.product_tooltip_scan_barcode") }}</p>
+ <p>{{ $t("components.entity.create_modal.product_tooltip_scan_barcode") }}</p>
</TooltipContent>
</Tooltip>
<Tooltip>
@@ -31,7 +58,7 @@
</Button>
</TooltipTrigger>
<TooltipContent>
- <p>{{ $t("components.item.create_modal.product_tooltip_input_barcode") }}</p>
+ <p>{{ $t("components.entity.create_modal.product_tooltip_input_barcode") }}</p>
</TooltipContent>
</Tooltip>
</ButtonGroup>
@@ -42,19 +69,6 @@
<form class="flex min-w-0 flex-col gap-2" @submit.prevent="create()">
<LocationSelector v-model="form.location" />
- <!-- Entity Type selector (shown when multiple item types exist) -->
- <div v-if="showEntityTypeSelector" class="flex w-full flex-col gap-1.5">
- <Label class="px-1">{{ $t("global.type") || "Type" }}</Label>
- <select
- class="w-full rounded-md border bg-background px-3 py-2 text-sm"
- :value="selectedEntityType?.id || ''"
- @change="onEntityTypeChanged(($event.target as HTMLSelectElement).value)"
- >
- <option value="">{{ $t("global.select") || "Select type..." }}</option>
- <option v-for="et in itemTypes" :key="et.id" :value="et.id">{{ et.name }}</option>
- </select>
- </div>
-
<!-- Template Info Display - Collapsible banner with distinct styling -->
<div v-if="templateData" class="rounded-lg border-l-4 border-l-primary bg-primary/5 p-3">
<div class="flex items-start justify-between gap-2">
@@ -80,7 +94,7 @@
variant="ghost"
size="icon"
class="size-7 shrink-0"
- :aria-label="$t('components.item.create_modal.clear_template')"
+ :aria-label="$t('components.entity.create_modal.clear_template')"
@click="clearTemplate"
>
<MdiClose class="size-4" />
@@ -144,10 +158,10 @@
v-if="subItemCreate"
v-model="parent"
v-model:search="query"
- :label="$t('components.item.create_modal.parent_item')"
+ :label="$t('components.entity.create_modal.parent_item')"
:items="results"
item-text="name"
- no-results-text="Type to search..."
+ :no-results-text="$t('components.entity.create_modal.item_selector_no_results_text')"
:is-loading="isLoading"
:trigger-search="triggerSearch"
/>
@@ -156,41 +170,45 @@
v-model="form.name"
:trigger-focus="focused"
:autofocus="true"
- :label="$t('components.item.create_modal.item_name')"
+ :label="
+ $t('components.entity.create_modal.entity_name', {
+ type: selectedEntityType ? t(selectedEntityType.name) : '',
+ })
+ "
:max-length="255"
:min-length="1"
/>
<FormTextField
+ v-if="!selectedEntityType?.isLocation"
v-model.number="form.quantity"
- :label="$t('components.item.create_modal.item_quantity')"
+ :label="
+ $t('components.entity.create_modal.entity_quantity', {
+ type: t(selectedEntityType ? selectedEntityType.name : 'global.entity'),
+ })
+ "
type="number"
step="any"
/>
<FormTextArea
v-model="form.description"
- :label="$t('components.item.create_modal.item_description')"
+ :label="
+ $t('components.entity.create_modal.entity_description', {
+ type: t(selectedEntityType ? selectedEntityType.name : 'global.entity'),
+ })
+ "
:max-length="1000"
/>
<TagSelector v-model="form.tags" :tags="tags ?? []" />
- <div class="flex w-full flex-col gap-1.5">
- <Label for="image-create-photo" class="flex w-full px-1">
- {{ $t("components.item.create_modal.item_photo") }}
- </Label>
- <div class="relative inline-block">
- <Button type="button" variant="outline" class="w-full" aria-hidden="true" @click.prevent="">
- {{ $t("components.item.create_modal.upload_photos") }}
- </Button>
- <Input
- id="image-create-photo"
- ref="fileInput"
- class="absolute left-0 top-0 size-full cursor-pointer opacity-0"
- type="file"
- accept="image/png,image/jpeg,image/gif,image/avif,image/webp,android/force-camera-workaround"
- multiple
- @change="previewImage"
- />
- </div>
- </div>
+ <PhotoUploader
+ :label="
+ $t('components.entity.create_modal.entity_photo', {
+ type: t(selectedEntityType ? selectedEntityType.name : 'global.entity'),
+ })
+ "
+ :button-label="$t('components.entity.create_modal.upload_photos')"
+ :existing-count="form.photos.length"
+ @selected="appendPhotos"
+ />
<div class="mt-4 flex flex-row-reverse">
<ButtonGroup>
<Button :disabled="loading" type="submit" class="group">
@@ -210,75 +228,12 @@
</ButtonGroup>
</div>
- <!-- photo preview area is AFTER the create button, to avoid pushing the button below the screen on small displays -->
- <div v-if="form.photos.length > 0" class="mt-4 border-t px-4 pb-4">
- <div v-for="(photo, index) in form.photos" :key="index">
- <div class="mt-8 w-full">
- <img
- :src="photo.fileBase64"
- class="w-full rounded object-fill shadow-sm"
- :alt="$t('components.item.create_modal.uploaded')"
- />
- </div>
- <div class="mt-2 flex items-center gap-2">
- <TooltipProvider class="flex gap-2" :delay-duration="0">
- <Tooltip>
- <TooltipTrigger>
- <Button size="icon" type="button" variant="destructive" @click.prevent="deleteImage(index)">
- <MdiDelete />
- <div class="sr-only">{{ $t("components.item.create_modal.delete_photo") }}</div>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <p>{{ $t("components.item.create_modal.delete_photo") }}</p>
- </TooltipContent>
- </Tooltip>
- <Tooltip>
- <TooltipTrigger>
- <Button
- size="icon"
- type="button"
- variant="default"
- @click.prevent="
- async () => {
- await rotateBase64Image90Deg(photo.fileBase64, index);
- }
- "
- >
- <MdiRotateClockwise />
- <div class="sr-only">{{ $t("components.item.create_modal.rotate_photo") }}</div>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <p>{{ $t("components.item.create_modal.rotate_photo") }}</p>
- </TooltipContent>
- </Tooltip>
- <Tooltip>
- <TooltipTrigger>
- <Button
- size="icon"
- type="button"
- :variant="photo.primary ? 'default' : 'outline'"
- @click.prevent="setPrimary(index)"
- >
- <MdiStar v-if="photo.primary" />
- <MdiStarOutline v-else />
- <div class="sr-only">
- {{ $t("components.item.create_modal.set_as_primary_photo", { isPrimary: photo.primary }) }}
- </div>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <p>
- {{ $t("components.item.create_modal.set_as_primary_photo", { isPrimary: photo.primary }) }}
- </p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
- <p class="mt-1 text-sm" style="overflow-wrap: anywhere">{{ photo.photoName }}</p>
- </div>
- </div>
- </div>
+ <PhotoUploaderPreview
+ :photos="form.photos"
+ @delete="deletePhotoAt"
+ @rotate="rotatePhotoAt"
+ @set-primary="setPrimaryPhotoAt"
+ />
</form>
</BaseModal>
</template>
@@ -289,13 +244,13 @@
import { toast } from "@/components/ui/sonner";
import { Button, ButtonGroup } from "~/components/ui/button";
import BaseModal from "@/components/App/CreateModal.vue";
- import { Label } from "@/components/ui/label";
- import { Input } from "@/components/ui/input";
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import type {
EntityCreate,
EntityTemplateOut,
EntityTemplateSummary,
EntityOut,
+ EntityTypeSummary,
} from "~~/lib/api/types/data-contracts";
import { useTagStore } from "~/stores/tags";
import { useLocationStore } from "~~/stores/locations";
@@ -303,13 +258,10 @@
import MdiBarcodeScan from "~icons/mdi/barcode-scan";
import MdiPackageVariant from "~icons/mdi/package-variant";
import MdiPackageVariantClosed from "~icons/mdi/package-variant-closed";
- import MdiDelete from "~icons/mdi/delete";
- import MdiRotateClockwise from "~icons/mdi/rotate-clockwise";
- import MdiStarOutline from "~icons/mdi/star-outline";
- import MdiStar from "~icons/mdi/star";
import MdiFileDocumentOutline from "~icons/mdi/file-document-outline";
import MdiChevronDown from "~icons/mdi/chevron-down";
import MdiClose from "~icons/mdi/close";
+ import MdiMapMarkerOutline from "~icons/mdi/map-marker-outline";
import { AttachmentTypes } from "~~/lib/api/types/non-generated";
import { useDialog, useDialogHotkey } from "~/components/ui/dialog-provider";
import TagSelector from "~/components/Tag/Selector.vue";
@@ -319,18 +271,28 @@
import LocationSelector from "~/components/Location/Selector.vue";
import FormTextField from "~/components/Form/TextField.vue";
import FormTextArea from "~/components/Form/TextArea.vue";
-
- interface PhotoPreview {
- photoName: string;
- file: File;
- fileBase64: string;
- primary: boolean;
- }
+ import PhotoUploader from "~/components/Form/PhotoUploader.vue";
+ import PhotoUploaderPreview from "~/components/Form/PhotoUploaderPreview.vue";
+ import {
+ deletePhoto,
+ dataURLtoFile,
+ rotatePhotoPreview,
+ setPrimaryPhoto,
+ type PhotoPreview,
+ } from "~/components/Form/photo-uploader";
+ import { useEntityTypeStore } from "~~/stores/entityTypes";
const { t } = useI18n();
const { openDialog, closeDialog, registerOpenDialogCallback } = useDialog();
- useDialogHotkey(DialogID.CreateItem, { code: "Digit1", shift: true });
+ useDialogHotkey(DialogID.CreateEntity, { code: "Digit1", shift: true }, () => ({
+ baseType: "item",
+ }));
+ useDialogHotkey(DialogID.CreateEntity, { code: "Digit2", shift: true }, () => ({
+ baseType: "location",
+ }));
+
+ const entityTypeStore = useEntityTypeStore();
const api = useUserApi();
@@ -341,11 +303,9 @@
const tags = computed(() => tagStore.tags);
const route = useRoute();
- const router = useRouter();
const parent = ref();
const { query, results, isLoading, triggerSearch } = useItemSearch(api, { immediate: false });
- const subItemCreateParam = useRouteQuery("subItemCreate", "n");
const subItemCreate = ref();
const tagId = computed(() => {
@@ -372,27 +332,17 @@
const nameInput = ref<HTMLInputElement | null>(null);
// Entity type selection
- const itemTypes = ref<import("~~/lib/api/types/data-contracts").EntityTypeSummary[]>([]);
- const selectedEntityType = ref<import("~~/lib/api/types/data-contracts").EntityTypeSummary | null>(null);
- const showEntityTypeSelector = computed(() => itemTypes.value.length > 1);
-
- onMounted(async () => {
- const { data, error } = await api.entityTypes.getAll();
- if (!error && data) {
- itemTypes.value = data.filter(et => !et.isLocation);
- // Auto-select first if only one
- if (itemTypes.value.length === 1) {
- selectedEntityType.value = itemTypes.value[0]!;
- }
- }
- });
+ const entityTypes = computed(() => entityTypeStore.allTypes);
+ const selectedEntityType = ref<EntityTypeSummary | null>(null);
async function onEntityTypeChanged(typeId: string) {
- const et = itemTypes.value.find(t => t.id === typeId);
+ const et = entityTypes.value.find(t => t.id === typeId);
selectedEntityType.value = et || null;
- // If the selected type has a default template, auto-apply it
- if (et?.defaultTemplateId && et.defaultTemplate) {
+ // If the selected type has a default template and is not a location, auto-apply it
+ if (et?.isLocation || !et?.defaultTemplateId || !et.defaultTemplate) {
+ clearTemplate();
+ } else {
const { data, error } = await api.templates.get(et.defaultTemplateId);
if (!error && data) {
selectedTemplate.value = {
@@ -535,68 +485,80 @@
);
const { shift } = useMagicKeys();
-
- function deleteImage(index: number) {
- form.photos.splice(index, 1);
+ function appendPhotos(photos: PhotoPreview[]) {
+ form.photos.push(...photos);
}
- function setPrimary(index: number) {
- const primary = form.photos.findIndex(p => p.primary);
+ function deletePhotoAt(index: number) {
+ form.photos = deletePhoto(form.photos, index);
+ }
- if (primary !== -1) form.photos[primary]!.primary = false;
- if (primary !== index) form.photos[index]!.primary = true;
+ function setPrimaryPhotoAt(index: number) {
+ form.photos = setPrimaryPhoto(form.photos, index);
}
- function previewImage(event: Event) {
- const input = event.target as HTMLInputElement;
- if (input.files && input.files.length > 0) {
- for (const file of input.files) {
- const reader = new FileReader();
- reader.onload = e => {
- form.photos.push({
- photoName: file.name,
- fileBase64: e.target?.result as string,
- file,
- primary: form.photos.length === 0,
- });
- };
- reader.readAsDataURL(file);
- }
- input.value = "";
+ async function rotatePhotoAt(index: number) {
+ const photo = form.photos[index];
+ if (!photo) return;
+
+ try {
+ form.photos[index] = await rotatePhotoPreview(photo);
+ } catch (error) {
+ toast.error(t("components.entity.create_modal.toast.rotate_process_failed"));
+ console.error(error);
}
}
onMounted(() => {
- const cleanup = registerOpenDialogCallback(DialogID.CreateItem, async params => {
- // needed since URL will be cleared in the next step => ParentId Selection should stay though
- subItemCreate.value = subItemCreateParam.value === "y";
+ const cleanup = registerOpenDialogCallback(DialogID.CreateEntity, async params => {
+ subItemCreate.value = false;
let parentItemLocationId = null;
-
- if (subItemCreate.value && itemId.value) {
- const itemIdRead = typeof itemId.value === "string" ? (itemId.value as string) : itemId.value[0]!;
- const { data, error } = await api.items.get(itemIdRead);
- if (error || !data) {
- toast.error(t("components.item.create_modal.toast.failed_load_parent"));
- console.error("Parent item fetch error:", error);
+ parent.value = {};
+ form.parentId = null;
+
+ if (params.baseType === "item") {
+ selectedEntityType.value = entityTypes.value.find(t => !t.isLocation) || null;
+
+ subItemCreate.value = params.subItem;
+
+ if (subItemCreate.value && itemId.value) {
+ const itemIdRead = typeof itemId.value === "string" ? (itemId.value as string) : itemId.value[0]!;
+ const { data, error } = await api.items.get(itemIdRead);
+ if (error || !data) {
+ toast.error(t("components.entity.create_modal.toast.failed_load_parent"));
+ console.error("Parent item fetch error:", error);
+ }
+
+ if (data) {
+ parent.value = data;
+ }
+
+ if (data.parent) {
+ const loc = data.parent;
+ parentItemLocationId = loc.id;
+ }
}
- if (data) {
- parent.value = data;
+ if (params.product) {
+ form.name = params.product.item.name;
+ form.description = params.product.item.description;
+
+ if (params.product.imageURL) {
+ appendPhotos([
+ {
+ photoName: "product_view.jpg",
+ fileBase64: params.product.imageBase64,
+ primary: form.photos.length === 0,
+ file: dataURLtoFile(params.product.imageBase64, "product_view.jpg"),
+ },
+ ]);
+ }
}
- if (data.location || data.parent) {
- const loc = data.location || data.parent;
- parentItemLocationId = loc.id;
- }
-
- // clear URL Parameter (subItemCreate) since intention was communicated and received
- const currentQuery = { ...route.query };
- delete currentQuery.subItemCreate;
- await router.push({ query: currentQuery });
+ // Restore last used template if available
+ await restoreLastTemplate();
} else {
- // since Input is hidden in this case, make sure no accidental parent information is sent out
- parent.value = {};
- form.parentId = null;
+ selectedEntityType.value = entityTypes.value.find(t => t.isLocation) || null;
}
const locId = locationId.value ? locationId.value : parentItemLocationId;
@@ -608,26 +570,9 @@
}
}
- if (params?.product) {
- form.name = params.product.item.name;
- form.description = params.product.item.description;
-
- if (params.product.imageURL) {
- form.photos.push({
- photoName: "product_view.jpg",
- fileBase64: params.product.imageBase64,
- primary: form.photos.length === 0,
- file: dataURLtoFile(params.product.imageBase64, "product_view.jpg"),
- });
- }
- }
-
if (tagId.value) {
form.tags = tags.value.filter(l => l.id === tagId.value).map(l => l.id);
}
-
- // Restore last used template if available
- await restoreLastTemplate();
});
onUnmounted(cleanup);
@@ -635,12 +580,16 @@
async function create(close = true) {
if (!form.location?.id) {
- toast.error(t("components.item.create_modal.toast.please_select_location"));
+ toast.error(t("components.entity.create_modal.toast.please_select_location"));
return;
}
if (loading.value) {
- toast.error(t("components.item.create_modal.toast.already_creating"));
+ toast.error(
+ t("components.entity.create_modal.toast.already_creating", {
+ type: t(selectedEntityType.value ? selectedEntityType.value.name : "global.entity"),
+ })
+ );
return;
}
@@ -650,8 +599,20 @@
let error, data;
- // If a template is selected, use the template creation endpoint
- if (templateData.value) {
+ // If the selected entity type is a location, use the location creation endpoint
+ if (selectedEntityType.value?.isLocation) {
+ const result = await api.items.createLocation({
+ name: form.name,
+ description: form.description,
+ parentId: form.location ? form.location.id : null,
+ entityTypeId: selectedEntityType.value?.id || "",
+ quantity: 1,
+ tagIds: form.tags,
+ });
+ error = result.error;
+ data = result.data;
+ } else if (templateData.value) {
+ // If a template is selected, use the template creation endpoint
const templateRequest = {
name: form.name,
description: form.description,
@@ -671,7 +632,7 @@
quantity: form.quantity,
description: form.description,
tagIds: form.tags,
- entityTypeId: selectedEntityType.value?.id,
+ entityTypeId: selectedEntityType.value?.id || "",
};
const result = await api.items.create(out);
@@ -681,14 +642,22 @@
if (error) {
loading.value = false;
- toast.error(t("components.item.create_modal.toast.create_failed"));
+ toast.error(
+ t("components.entity.create_modal.toast.create_failed", {
+ type: t(selectedEntityType.value ? selectedEntityType.value.name : "global.entity"),
+ })
+ );
return;
}
- toast.success(t("components.item.create_modal.toast.create_success"));
+ toast.success(
+ t("components.entity.create_modal.toast.create_success", {
+ type: t(selectedEntityType.value ? selectedEntityType.value.name : "global.entity"),
+ })
+ );
if (form.photos.length > 0) {
- toast.info(t("components.item.create_modal.toast.uploading_photos", { count: form.photos.length }));
+ toast.info(t("components.entity.create_modal.toast.uploading_photos", { count: form.photos.length }));
let uploadError = false;
for (const photo of form.photos) {
const { error: attachError } = await api.items.attachments.add(
@@ -701,14 +670,14 @@
if (attachError) {
uploadError = true;
- toast.error(t("components.item.create_modal.toast.upload_failed", { photoName: photo.photoName }));
+ toast.error(t("components.entity.create_modal.toast.upload_failed", { photoName: photo.photoName }));
console.error(attachError);
}
}
if (uploadError) {
- toast.warning(t("components.item.create_modal.toast.some_photos_failed", { count: form.photos.length }));
+ toast.warning(t("components.entity.create_modal.toast.some_photos_failed", { count: form.photos.length }));
} else {
- toast.success(t("components.item.create_modal.toast.upload_success", { count: form.photos.length }));
+ toast.success(t("components.entity.create_modal.toast.upload_success", { count: form.photos.length }));
}
}
@@ -725,83 +694,12 @@
loading.value = false;
if (close) {
- closeDialog(DialogID.CreateItem);
- navigateTo(`/item/${data.id}`);
- }
- }
-
- function dataURLtoFile(dataURL: string, fileName: string) {
- try {
- const arr = dataURL.split(",");
- const mimeMatch = arr[0]!.match(/:(.*?);/);
- if (!mimeMatch || !mimeMatch[1]) {
- throw new Error("Invalid data URL format");
- }
- const mime = mimeMatch[1];
-
- // Validate mime type is an image
- if (!mime.startsWith("image/")) {
- throw new Error("Invalid mime type, expected image");
- }
-
- const bstr = atob(arr[arr.length - 1]!);
- let n = bstr.length;
- const u8arr = new Uint8Array(n);
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n);
+ closeDialog(DialogID.CreateEntity);
+ if (selectedEntityType.value?.isLocation) {
+ navigateTo(`/location/${data.id}`);
+ } else {
+ navigateTo(`/item/${data.id}`);
}
- return new File([u8arr], fileName, { type: mime });
- } catch (error) {
- console.error("Error converting data URL to file:", error);
- // Return a fallback or rethrow based on your error handling strategy
- throw error;
- }
- }
-
- async function rotateBase64Image90Deg(base64Image: string, index: number) {
- // Create an off-screen canvas
- const offScreenCanvas = document.createElement("canvas");
- const offScreenCanvasCtx = offScreenCanvas.getContext("2d");
-
- if (!offScreenCanvasCtx) {
- toast.error(t("components.item.create_modal.toast.no_canvas_support"));
- return;
- }
-
- // Create an image
- const img = new Image();
-
- // Create a promise to handle the image loading
- await new Promise<void>((resolve, reject) => {
- img.onload = () => resolve();
- img.onerror = () => reject(new Error("Failed to load image"));
- img.src = base64Image;
- }).catch(error => {
- toast.error(t("components.item.create_modal.toast.rotate_failed", { error: error.message }));
- });
-
- // Set its dimensions to rotated size
- offScreenCanvas.height = img.width;
- offScreenCanvas.width = img.height;
-
- // Rotate and draw source image into the off-screen canvas
- offScreenCanvasCtx.rotate((90 * Math.PI) / 180);
- offScreenCanvasCtx.translate(0, -offScreenCanvas.width);
- offScreenCanvasCtx.drawImage(img, 0, 0);
-
- const imageType = base64Image.match(/^data:(.+);base64/)?.[1] || "image/jpeg";
-
- // Encode image to data-uri with base64
- try {
- form.photos[index]!.fileBase64 = offScreenCanvas.toDataURL(imageType, 100);
- form.photos[index]!.file = dataURLtoFile(form.photos[index]!.fileBase64, form.photos[index]!.photoName);
- } catch (error) {
- toast.error(t("components.item.create_modal.toast.rotate_process_failed"));
- console.error(error);
- } finally {
- // Clean up resources
- offScreenCanvas.width = 0;
- offScreenCanvas.height = 0;
}
}
diff --git a/frontend/components/Form/PhotoUploader.vue b/frontend/components/Form/PhotoUploader.vue
new file mode 100644
index 00000000..07f20066
--- /dev/null
+++ b/frontend/components/Form/PhotoUploader.vue
@@ -0,0 +1,70 @@
+<template>
+ <div class="w-full">
+ <div class="flex w-full flex-col gap-1.5">
+ <Label for="photo-uploader" class="flex w-full px-1">
+ {{ label }}
+ </Label>
+
+ <div class="relative inline-block">
+ <Button type="button" variant="outline" class="w-full" aria-hidden="true" @click.prevent="openFilePicker">
+ {{ buttonLabel }}
+ </Button>
+ <Input
+ id="photo-uploader"
+ ref="fileInput"
+ class="absolute left-0 top-0 size-full cursor-pointer opacity-0"
+ type="file"
+ accept="image/png,image/jpeg,image/gif,image/avif,image/webp,android/force-camera-workaround"
+ multiple
+ @change="onFilesSelected"
+ />
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+ import { computed, ref } from "vue";
+ import { useI18n } from "vue-i18n";
+ import { Label } from "~/components/ui/label";
+ import { Input } from "~/components/ui/input";
+ import { Button } from "~/components/ui/button";
+ import { filesToPhotoPreviews, type PhotoPreview } from "./photo-uploader";
+
+ const props = withDefaults(
+ defineProps<{
+ label?: string;
+ buttonLabel?: string;
+ existingCount?: number;
+ }>(),
+ {
+ label: undefined,
+ buttonLabel: undefined,
+ existingCount: 0,
+ }
+ );
+
+ const emit = defineEmits<{
+ (e: "selected", photos: PhotoPreview[]): void;
+ }>();
+
+ const { t } = useI18n();
+ const fileInput = ref<HTMLInputElement | null>(null);
+
+ const label = computed(() => props.label || t("components.entity.create_modal.item_photo"));
+ const buttonLabel = computed(() => props.buttonLabel || t("components.entity.create_modal.upload_photos"));
+
+ function openFilePicker() {
+ fileInput.value?.click();
+ }
+
+ async function onFilesSelected(event: Event) {
+ const input = event.target as HTMLInputElement;
+ if (!input.files || input.files.length === 0) return;
+
+ const photos = await filesToPhotoPreviews(input.files, props.existingCount);
+
+ emit("selected", photos);
+ input.value = "";
+ }
+</script>
diff --git a/frontend/components/Form/PhotoUploaderPreview.vue b/frontend/components/Form/PhotoUploaderPreview.vue
new file mode 100644
index 00000000..7b044880
--- /dev/null
+++ b/frontend/components/Form/PhotoUploaderPreview.vue
@@ -0,0 +1,83 @@
+<template>
+ <div v-if="photos.length > 0" class="mt-4 border-t px-4 pb-4">
+ <div v-for="(photo, index) in photos" :key="index">
+ <div class="mt-8 w-full">
+ <img
+ :src="photo.fileBase64"
+ class="w-full rounded object-fill shadow-sm"
+ :alt="$t('components.entity.create_modal.uploaded')"
+ />
+ </div>
+
+ <div class="mt-2 flex items-center gap-2">
+ <TooltipProvider class="flex gap-2" :delay-duration="0">
+ <Tooltip>
+ <TooltipTrigger>
+ <Button size="icon" type="button" variant="destructive" @click.prevent="emit('delete', index)">
+ <MdiDelete />
+ <div class="sr-only">{{ $t("components.entity.create_modal.delete_photo") }}</div>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{{ $t("components.entity.create_modal.delete_photo") }}</p>
+ </TooltipContent>
+ </Tooltip>
+
+ <Tooltip>
+ <TooltipTrigger>
+ <Button size="icon" type="button" variant="default" @click.prevent="emit('rotate', index)">
+ <MdiRotateClockwise />
+ <div class="sr-only">{{ $t("components.entity.create_modal.rotate_photo") }}</div>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{{ $t("components.entity.create_modal.rotate_photo") }}</p>
+ </TooltipContent>
+ </Tooltip>
+
+ <Tooltip>
+ <TooltipTrigger>
+ <Button
+ size="icon"
+ type="button"
+ :variant="photo.primary ? 'default' : 'outline'"
+ @click.prevent="emit('setPrimary', index)"
+ >
+ <MdiStar v-if="photo.primary" />
+ <MdiStarOutline v-else />
+ <div class="sr-only">
+ {{ $t("components.entity.create_modal.set_as_primary_photo", { isPrimary: photo.primary }) }}
+ </div>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{{ $t("components.entity.create_modal.set_as_primary_photo", { isPrimary: photo.primary }) }}</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+
+ <p class="mt-1 text-sm" style="overflow-wrap: anywhere">{{ photo.photoName }}</p>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+ import { Button } from "~/components/ui/button";
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip";
+ import MdiDelete from "~icons/mdi/delete";
+ import MdiRotateClockwise from "~icons/mdi/rotate-clockwise";
+ import MdiStarOutline from "~icons/mdi/star-outline";
+ import MdiStar from "~icons/mdi/star";
+ import type { PhotoPreview } from "./photo-uploader";
+
+ defineProps<{
+ photos: PhotoPreview[];
+ }>();
+
+ const emit = defineEmits<{
+ (e: "delete", index: number): void;
+ (e: "rotate", index: number): void;
+ (e: "setPrimary", index: number): void;
+ }>();
+</script>
diff --git a/frontend/components/Form/photo-uploader.ts b/frontend/components/Form/photo-uploader.ts
new file mode 100644
index 00000000..c2071a2d
--- /dev/null
+++ b/frontend/components/Form/photo-uploader.ts
@@ -0,0 +1,109 @@
+export interface PhotoPreview {
+ photoName: string;
+ file: File;
+ fileBase64: string;
+ primary: boolean;
+}
+
+export function dataURLtoFile(dataURL: string, fileName: string) {
+ const arr = dataURL.split(",");
+ const mimeMatch = arr[0]!.match(/:(.*?);/);
+ if (!mimeMatch || !mimeMatch[1]) {
+ throw new Error("Invalid data URL format");
+ }
+
+ const mime = mimeMatch[1];
+ if (!mime.startsWith("image/")) {
+ throw new Error("Invalid mime type, expected image");
+ }
+
+ const bstr = atob(arr[arr.length - 1]!);
+ let n = bstr.length;
+ const u8arr = new Uint8Array(n);
+ while (n--) {
+ u8arr[n] = bstr.charCodeAt(n);
+ }
+
+ return new File([u8arr], fileName, { type: mime });
+}
+
+export async function fileToPhotoPreview(file: File, primary = false): Promise<PhotoPreview> {
+ const fileBase64 = await readFileAsDataUrl(file);
+
+ return {
+ photoName: file.name,
+ file,
+ fileBase64,
+ primary,
+ };
+}
+
+export async function filesToPhotoPreviews(files: FileList | File[], existingCount = 0): Promise<PhotoPreview[]> {
+ const nextPhotos: PhotoPreview[] = [];
+
+ for (const file of Array.from(files)) {
+ nextPhotos.push(await fileToPhotoPreview(file, existingCount + nextPhotos.length === 0));
+ }
+
+ return nextPhotos;
+}
+
+export async function rotatePhotoPreview(photo: PhotoPreview): Promise<PhotoPreview> {
+ const offScreenCanvas = document.createElement("canvas");
+ const offScreenCanvasCtx = offScreenCanvas.getContext("2d");
+
+ if (!offScreenCanvasCtx) {
+ throw new Error("Canvas not supported");
+ }
+
+ const img = new Image();
+ await new Promise<void>((resolve, reject) => {
+ img.onload = () => resolve();
+ img.onerror = () => reject(new Error("Failed to load image"));
+ img.src = photo.fileBase64;
+ });
+
+ offScreenCanvas.height = img.width;
+ offScreenCanvas.width = img.height;
+
+ offScreenCanvasCtx.rotate((90 * Math.PI) / 180);
+ offScreenCanvasCtx.translate(0, -offScreenCanvas.width);
+ offScreenCanvasCtx.drawImage(img, 0, 0);
+
+ const imageType = photo.fileBase64.match(/^data:(.+);base64/)?.[1] || "image/jpeg";
+ const fileBase64 = offScreenCanvas.toDataURL(imageType, 1);
+
+ offScreenCanvas.width = 0;
+ offScreenCanvas.height = 0;
+
+ return {
+ ...photo,
+ fileBase64,
+ file: dataURLtoFile(fileBase64, photo.photoName),
+ };
+}
+
+export function setPrimaryPhoto(photos: PhotoPreview[], index: number): PhotoPreview[] {
+ const nextPhotos = photos.map(photo => ({ ...photo, primary: false }));
+ if (nextPhotos[index]) {
+ nextPhotos[index] = { ...nextPhotos[index]!, primary: true };
+ }
+ return nextPhotos;
+}
+
+export function deletePhoto(photos: PhotoPreview[], index: number): PhotoPreview[] {
+ const nextPhotos = photos.filter((_, photoIndex) => photoIndex !== index);
+ if (nextPhotos.length > 0 && !nextPhotos.some(photo => photo.primary)) {
+ nextPhotos[0] = { ...nextPhotos[0]!, primary: true };
+ }
+ return nextPhotos;
+}
+
+async function readFileAsDataUrl(file: File): Promise<string> {
+ return await new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = event => resolve(event.target?.result as string);
+ reader.onerror = () => reject(new Error(`Failed to read file: ${file.name}`));
+ reader.readAsDataURL(file);
+ });
+}
diff --git a/frontend/components/Item/BarcodeModal.vue b/frontend/components/Item/BarcodeModal.vue
index 86bc3cfe..b659b959 100644
--- a/frontend/components/Item/BarcodeModal.vue
+++ b/frontend/components/Item/BarcodeModal.vue
@@ -188,8 +188,11 @@
selectedRow.value < products.value.length
) {
const p = products.value![selectedRow.value];
- openDialog(DialogID.CreateItem, {
- params: { product: p },
+ openDialog(DialogID.CreateEntity, {
+ params: {
+ baseType: "item",
+ product: p,
+ },
});
}
}
diff --git a/frontend/components/Location/CreateModal.vue b/frontend/components/Location/CreateModal.vue
deleted file mode 100644
index b87e2ef7..00000000
--- a/frontend/components/Location/CreateModal.vue
+++ /dev/null
@@ -1,338 +0,0 @@
-<template>
- <BaseModal :dialog-id="DialogID.CreateLocation" :title="$t('components.location.create_modal.title')">
- <form class="flex min-w-0 flex-col gap-2" @submit.prevent="create()">
- <LocationSelector v-model="form.parent" />
-
- <!-- Entity Type selector (shown when multiple location types exist) -->
- <div v-if="showEntityTypeSelector" class="flex w-full flex-col gap-1.5">
- <Label for="location-type-select" class="px-1">Type</Label>
- <select
- id="location-type-select"
- class="w-full rounded-md border bg-background px-3 py-2 text-sm"
- :value="selectedEntityType?.id || ''"
- @change="onEntityTypeChanged(($event.target as HTMLSelectElement).value)"
- >
- <option value="">Select type...</option>
- <option v-for="et in locationTypes" :key="et.id" :value="et.id">{{ et.name }}</option>
- </select>
- </div>
-
- <FormTextField
- ref="locationNameRef"
- v-model="form.name"
- :trigger-focus="focused"
- :autofocus="true"
- :required="true"
- :label="$t('components.location.create_modal.location_name')"
- :max-length="255"
- :min-length="1"
- />
- <FormTextArea
- v-model="form.description"
- :label="$t('components.location.create_modal.location_description')"
- :max-length="1000"
- />
-
- <!-- Photo upload -->
- <div class="flex w-full flex-col gap-1.5">
- <Label for="location-create-photo" class="flex w-full px-1">
- {{ $t("components.location.create_modal.location_photo") }}
- </Label>
- <div class="relative inline-block">
- <Button type="button" variant="outline" class="w-full" aria-hidden="true" @click.prevent="">
- {{ $t("components.item.create_modal.upload_photos") }}
- </Button>
- <Input
- id="location-create-photo"
- ref="fileInput"
- class="absolute left-0 top-0 size-full cursor-pointer opacity-0"
- type="file"
- accept="image/png,image/jpeg,image/gif,image/avif,image/webp,android/force-camera-workaround"
- multiple
- @change="previewImage"
- />
- </div>
- </div>
-
- <!-- Expanded fields (collapsible) -->
- <button
- type="button"
- class="mt-1 flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
- @click="showAdvanced = !showAdvanced"
- >
- <span v-if="!showAdvanced">{{ $t("global.show_more") }}</span>
- <span v-else>{{ $t("global.show_less") }}</span>
- <MdiChevronDown class="size-4 transition-transform" :class="{ 'rotate-180': showAdvanced }" />
- </button>
-
- <template v-if="showAdvanced">
- <TagSelector v-model="form.tags" :tags="tags ?? []" />
- <FormTextArea v-model="form.notes" label="Notes" :max-length="1000" />
- </template>
-
- <div class="mt-4 flex flex-row-reverse">
- <ButtonGroup>
- <Button :disabled="loading" type="submit">{{ $t("global.create") }}</Button>
- <Button variant="outline" :disabled="loading" type="button" @click="create(false)">{{
- $t("global.create_and_add")
- }}</Button>
- </ButtonGroup>
- </div>
-
- <!-- Photo preview (after buttons, like item create modal) -->
- <div v-if="form.photos.length > 0" class="mt-4 border-t px-4 pb-4">
- <div v-for="(photo, index) in form.photos" :key="index">
- <div class="mt-8 w-full">
- <img
- :src="photo.fileBase64"
- class="w-full rounded object-fill shadow-sm"
- :alt="$t('components.item.create_modal.uploaded')"
- />
- </div>
- <div class="mt-2 flex items-center gap-2">
- <TooltipProvider class="flex gap-2" :delay-duration="0">
- <Tooltip>
- <TooltipTrigger>
- <Button size="icon" type="button" variant="destructive" @click.prevent="deleteImage(index)">
- <MdiDelete />
- <div class="sr-only">{{ $t("components.item.create_modal.delete_photo") }}</div>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <p>{{ $t("components.item.create_modal.delete_photo") }}</p>
- </TooltipContent>
- </Tooltip>
- <Tooltip>
- <TooltipTrigger>
- <Button
- size="icon"
- type="button"
- :variant="photo.primary ? 'default' : 'outline'"
- @click.prevent="setPrimary(index)"
- >
- <MdiStar v-if="photo.primary" />
- <MdiStarOutline v-else />
- <div class="sr-only">
- {{ $t("components.item.create_modal.set_as_primary_photo", { isPrimary: photo.primary }) }}
- </div>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <p>{{ $t("components.item.create_modal.set_as_primary_photo", { isPrimary: photo.primary }) }}</p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
- <p class="mt-1 text-sm" style="overflow-wrap: anywhere">{{ photo.photoName }}</p>
- </div>
- </div>
- </div>
- </form>
- </BaseModal>
-</template>
-
-<script setup lang="ts">
- import { useI18n } from "vue-i18n";
- import { DialogID } from "@/components/ui/dialog-provider/utils";
- import { toast } from "@/components/ui/sonner";
- import { Button, ButtonGroup } from "~/components/ui/button";
- import { Label } from "@/components/ui/label";
- import { Input } from "@/components/ui/input";
- import BaseModal from "@/components/App/CreateModal.vue";
- import type { EntityTypeSummary, EntitySummary } from "~~/lib/api/types/data-contracts";
- import { AttachmentTypes } from "~~/lib/api/types/non-generated";
- import { useDialog, useDialogHotkey } from "~/components/ui/dialog-provider";
- import { useTagStore } from "~/stores/tags";
- import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip";
- import LocationSelector from "~/components/Location/Selector.vue";
- import TagSelector from "~/components/Tag/Selector.vue";
- import FormTextField from "~/components/Form/TextField.vue";
- import FormTextArea from "~/components/Form/TextArea.vue";
- import MdiChevronDown from "~icons/mdi/chevron-down";
- import MdiDelete from "~icons/mdi/delete";
- import MdiStar from "~icons/mdi/star";
- import MdiStarOutline from "~icons/mdi/star-outline";
-
- interface PhotoPreview {
- photoName: string;
- file: File;
- fileBase64: string;
- primary: boolean;
- }
-
- const { t } = useI18n();
-
- const { activeDialog, closeDialog } = useDialog();
-
- useDialogHotkey(DialogID.CreateLocation, { code: "Digit3", shift: true });
-
- // Entity type selection
- const locationTypes = ref<import("~~/lib/api/types/data-contracts").EntityTypeSummary[]>([]);
- const selectedEntityType = ref<import("~~/lib/api/types/data-contracts").EntityTypeSummary | null>(null);
- const showEntityTypeSelector = computed(() => locationTypes.value.length > 1);
-
- onMounted(async () => {
- const { data, error } = await api.entityTypes.getAll();
- if (!error && data) {
- locationTypes.value = data.filter(et => et.isLocation);
- if (locationTypes.value.length === 1) {
- selectedEntityType.value = locationTypes.value[0]!;
- }
- }
- });
-
- async function onEntityTypeChanged(typeId: string) {
- const et = locationTypes.value.find(t => t.id === typeId);
- selectedEntityType.value = et || null;
-
- // If the selected type has a default template, auto-apply it
- if (et?.defaultTemplateId && et.defaultTemplate) {
- const { data: tplData, error: tplError } = await api.templates.get(et.defaultTemplateId);
- if (!tplError && tplData) {
- if (tplData.defaultName) form.name = tplData.defaultName;
- if (tplData.defaultDescription) form.description = tplData.defaultDescription;
- if (tplData.defaultTags && tplData.defaultTags.length > 0) {
- form.tags = tplData.defaultTags.map(l => l.id);
- }
- toast.success(t("components.template.toast.applied", { name: tplData.name }));
- }
- }
- }
-
- const loading = ref(false);
- const focused = ref(false);
- const showAdvanced = ref(false);
- const form = reactive({
- name: "",
- description: "",
- parent: null as EntitySummary | null,
- tags: [] as string[],
- notes: "",
- photos: [] as PhotoPreview[],
- });
-
- watch(
- () => activeDialog.value,
- active => {
- if (active && active === DialogID.CreateLocation) {
- if (locationId.value) {
- const found = locations.value.find(l => l.id === locationId.value);
- form.parent = found || null;
- }
- }
- }
- );
-
- function reset() {
- form.name = "";
- form.description = "";
- form.tags = [];
- form.notes = "";
- form.photos = [];
- focused.value = false;
- loading.value = false;
- }
-
- const api = useUserApi();
-
- const locationsStore = useLocationStore();
- const locations = computed(() => locationsStore.allLocations);
-
- const tagStore = useTagStore();
- const tags = computed(() => tagStore.tags);
-
- const route = useRoute();
-
- const { shift } = useMagicKeys();
-
- const locationId = computed(() => {
- if (route.fullPath.includes("/location/")) {
- return route.params.id;
- }
- return null;
- });
-
- function previewImage(event: Event) {
- const input = event.target as HTMLInputElement;
- if (input.files && input.files.length > 0) {
- for (const file of input.files) {
- const reader = new FileReader();
- reader.onload = e => {
- form.photos.push({
- photoName: file.name,
- fileBase64: e.target?.result as string,
- file,
- primary: form.photos.length === 0,
- });
- };
- reader.readAsDataURL(file);
- }
- input.value = "";
- }
- }
-
- function deleteImage(index: number) {
- form.photos.splice(index, 1);
- }
-
- function setPrimary(index: number) {
- const primary = form.photos.findIndex(p => p.primary);
- if (primary !== -1) form.photos[primary]!.primary = false;
- if (primary !== index) form.photos[index]!.primary = true;
- }
-
- async function create(close = true) {
- if (loading.value) {
- toast.error(t("components.location.create_modal.toast.already_creating"));
- return;
- }
- loading.value = true;
-
- if (shift?.value) close = false;
-
- const { data, error } = await api.items.createLocation({
- name: form.name,
- description: form.description,
- parentId: form.parent ? form.parent.id : null,
- entityTypeId: selectedEntityType.value?.id,
- });
-
- if (error) {
- loading.value = false;
- toast.error(t("components.location.create_modal.toast.create_failed"));
- return;
- }
-
- if (data) {
- toast.success(t("components.location.create_modal.toast.create_success"));
- }
-
- // Upload photos if any
- if (form.photos.length > 0 && data) {
- toast.info(t("components.item.create_modal.toast.uploading_photos", { count: form.photos.length }));
- let uploadError = false;
- for (const photo of form.photos) {
- const { error: attachError } = await api.items.attachments.add(
- data.id,
- photo.file,
- photo.photoName,
- AttachmentTypes.Photo,
- photo.primary
- );
- if (attachError) {
- uploadError = true;
- toast.error(t("components.item.create_modal.toast.upload_failed", { photoName: photo.photoName }));
- }
- }
- if (!uploadError) {
- toast.success(t("components.item.create_modal.toast.upload_success", { count: form.photos.length }));
- }
- }
-
- reset();
-
- if (close) {
- closeDialog(DialogID.CreateLocation);
- navigateTo(`/location/${data.id}`);
- }
- }
-</script>
diff --git a/frontend/components/Location/Tree/Root.vue b/frontend/components/Location/Tree/Root.vue
index fd0ac6e4..c5a99e4c 100644
--- a/frontend/components/Location/Tree/Root.vue
+++ b/frontend/components/Location/Tree/Root.vue
@@ -39,10 +39,10 @@
variant="outline"
size="sm"
type="button"
- :aria-label="$t('components.location.create_modal.title') || $t('global.create')"
- @click="openDialog(DialogID.CreateLocation)"
+ :aria-label="$t('global.create')"
+ @click="openDialog(DialogID.CreateEntity, { params: { baseType: 'location' } })"
>
- {{ $t("components.location.create_modal.title") || $t("global.create") }}
+ {{ $t("global.create") }}
</Button>
</div>
diff --git a/frontend/components/Tag/CreateModal.vue b/frontend/components/Tag/CreateModal.vue
index 8b77a127..53de0dbc 100644
--- a/frontend/components/Tag/CreateModal.vue
+++ b/frontend/components/Tag/CreateModal.vue
@@ -53,7 +53,7 @@
const { closeDialog } = useDialog();
const tagStore = useTagStore();
- useDialogHotkey(DialogID.CreateTag, { code: "Digit2", shift: true });
+ useDialogHotkey(DialogID.CreateTag, { code: "Digit3", shift: true });
const loading = ref(false);
const focused = ref(false);
diff --git a/frontend/components/ui/dialog-provider/utils.ts b/frontend/components/ui/dialog-provider/utils.ts
index fed5e5b9..ca60e6c5 100644
--- a/frontend/components/ui/dialog-provider/utils.ts
+++ b/frontend/components/ui/dialog-provider/utils.ts
@@ -14,8 +14,7 @@ export enum DialogID {
ChangePassword = "changePassword",
CreateApiKey = "create-api-key",
CreateApiKeyResult = "create-api-key-result",
- CreateItem = "create-item",
- CreateLocation = "create-location",
+ CreateEntity = "create-entity",
CreateTag = "create-tag",
CreateCollection = "create-collection",
CreateGroupInvite = "create-group-invite",
@@ -64,7 +63,7 @@ export type DialogParamsMap = {
itemId: string;
attachmentId: string;
};
- [DialogID.CreateItem]?: { product?: BarcodeProduct };
+ [DialogID.CreateEntity]: { baseType: "item"; product?: BarcodeProduct; subItem?: true } | { baseType: "location" };
[DialogID.ProductImport]?: { barcode?: string };
[DialogID.EditMaintenance]:
| { type: "create"; itemId: string | string[] }
diff --git a/frontend/composables/use-formatters.ts b/frontend/composables/use-formatters.ts
index cbef77fe..2f44f9f5 100644
--- a/frontend/composables/use-formatters.ts
+++ b/frontend/composables/use-formatters.ts
@@ -92,7 +92,7 @@ export function fmtDate(
return format(dt, "p", localeOptions);
}
- let formatStr = "";
+ let formatStr: string;
switch (fmt) {
case "human":
diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue
index 22a5a229..b8edce70 100644
--- a/frontend/layouts/default.vue
+++ b/frontend/layouts/default.vue
@@ -7,10 +7,9 @@
-->
<ModalConfirm />
<OutdatedModal v-if="status" :status="status" />
- <ItemCreateModal />
+ <EntityCreateModal />
<WipeInventoryDialog />
<TagCreateModal />
- <LocationCreateModal />
<ItemBarcodeModal />
<AppQuickMenuModal :actions="quickMenuActions" />
<AppScannerModal />
@@ -49,7 +48,20 @@
v-for="btn in dropdown"
:key="btn.id"
class="group cursor-pointer text-lg"
- @click="openDialog(btn.dialogId as NoParamDialogIDs)"
+ @click="
+ () => {
+ if (btn.dialogId === DialogID.CreateEntity) {
+ if (btn.id == 0)
+ // create item
+ openDialog(btn.dialogId, { params: { baseType: 'item' } });
+ else if (btn.id == 1)
+ // create location
+ openDialog(btn.dialogId, { params: { baseType: 'location' } });
+ } else {
+ openDialog(btn.dialogId as NoParamDialogIDs);
+ }
+ }
+ "
>
{{ btn.name.value }}
<Shortcut
@@ -227,6 +239,7 @@
import DOMPurify from "dompurify";
import { useTagStore } from "~/stores/tags";
import { useLocationStore } from "~~/stores/locations";
+ import { useEntityTypeStore } from "~~/stores/entityTypes";
import MdiHome from "~icons/mdi/home";
import MdiFileTree from "~icons/mdi/file-tree";
@@ -271,14 +284,12 @@
import { Input } from "~/components/ui/input";
import { Button } from "~/components/ui/button";
import { toast } from "@/components/ui/sonner";
- import { DialogID, type NoParamDialogIDs, type OptionalDialogIDs } from "~/components/ui/dialog-provider/utils";
+ import { DialogID, type NoParamDialogIDs } from "~/components/ui/dialog-provider/utils";
import ModalConfirm from "~/components/ModalConfirm.vue";
import OutdatedModal from "~/components/App/OutdatedModal.vue";
- import ItemCreateModal from "~/components/Item/CreateModal.vue";
+ import EntityCreateModal from "~/components/Entity/CreateModal.vue";
import WipeInventoryDialog from "~/components/WipeInventoryDialog.vue";
-
import TagCreateModal from "~/components/Tag/CreateModal.vue";
- import LocationCreateModal from "~/components/Location/CreateModal.vue";
import ItemBarcodeModal from "~/components/Item/BarcodeModal.vue";
import AppQuickMenuModal from "~/components/App/QuickMenuModal.vue";
import AppScannerModal from "~/components/App/ScannerModal.vue";
@@ -347,7 +358,7 @@
id: number;
name: ComputedRef<string>;
shortcut: string;
- dialogId: NoParamDialogIDs | OptionalDialogIDs;
+ dialogId: DialogID;
};
const dropdown: DropdownItem[] = [
@@ -355,18 +366,18 @@
id: 0,
name: computed(() => t("menu.create_item")),
shortcut: "Shift+1",
- dialogId: DialogID.CreateItem,
+ dialogId: DialogID.CreateEntity,
},
{
id: 1,
name: computed(() => t("menu.create_location")),
- shortcut: "Shift+3",
- dialogId: DialogID.CreateLocation,
+ shortcut: "Shift+2",
+ dialogId: DialogID.CreateEntity,
},
{
id: 2,
name: computed(() => t("menu.create_tag")),
- shortcut: "Shift+2",
+ shortcut: "Shift+3",
dialogId: DialogID.CreateTag,
},
];
@@ -486,8 +497,9 @@
const quickMenuActions = reactive([
...dropdown.map(v => ({
text: computed(() => v.name.value),
- dialogId: v.dialogId as NoParamDialogIDs,
+ dialogId: v.dialogId,
shortcut: v.shortcut.split("+")[1] as string,
+ id: v.id,
type: "create" as const,
})),
...nav.map(v => ({
@@ -503,6 +515,9 @@
const locationStore = useLocationStore();
locationStore.ensureLocationsFetched();
+ const entityTypeStore = useEntityTypeStore();
+ entityTypeStore.ensureFetched();
+
onMounted(() => {
locationStore.refreshParents();
locationStore.refreshTree();
diff --git a/frontend/lib/api/classes/items.ts b/frontend/lib/api/classes/items.ts
index 64fa3f30..5bb28bba 100644
--- a/frontend/lib/api/classes/items.ts
+++ b/frontend/lib/api/classes/items.ts
@@ -203,6 +203,7 @@ export class ItemsApi extends BaseAPI {
return {
...resp,
data: resp.data?.items ?? [],
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
} as { data: EntitySummary[]; error: any; status: number };
}
diff --git a/frontend/lib/utils.ts b/frontend/lib/utils.ts
index 1055b3e5..d8473b3d 100644
--- a/frontend/lib/utils.ts
+++ b/frontend/lib/utils.ts
@@ -72,7 +72,7 @@ export function formatArrayAsString(value: unknown): string {
}
export function formatValueAsCsvField(value: unknown): string {
- let str = "";
+ let str: string;
if (Array.isArray(value)) {
str = formatArrayAsString(value);
diff --git a/frontend/locales/en.json b/frontend/locales/en.json
index 5aac53f0..c3139952 100644
--- a/frontend/locales/en.json
+++ b/frontend/locales/en.json
@@ -176,28 +176,18 @@
"password_strength": "Password Strength"
}
},
- "item": {
- "attachments_list": {
- "download": "Download",
- "open_new_tab": "Open in new tab"
- },
+ "entity": {
"create_modal": {
- "clear_template": "Clear Template",
- "delete_photo": "Delete photo",
- "item_description": "Item Description",
- "item_name": "Item Name",
- "item_photo": "Item Photo 📷",
- "item_quantity": "Item Quantity",
- "parent_item": "Parent Item",
- "product_tooltip_input_barcode": "Autofill with a manually provided barcode",
- "product_tooltip_scan_barcode": "Autofill with a barcode from 📷",
- "rotate_photo": "Rotate photo",
- "set_as_primary_photo": "Set as { isPrimary, select, true {non-} false {} other {}}primary photo",
- "title": "Create Item",
+ "entity_name": "{type} Name",
+ "entity_quantity": "{type} Quantity",
+ "entity_description": "{type} Description",
+ "entity_photo": "{type} Photo 📷",
+ "upload_photos": "Upload Photos",
+ "uploaded": "Uploaded Photo",
"toast": {
- "already_creating": "Already creating an item",
- "create_failed": "Couldn't create item",
- "create_success": "Item created",
+ "already_creating": "Already creating an {type}",
+ "create_failed": "Couldn't create {type}",
+ "create_success": "{type} created",
"failed_load_parent": "Failed to load parent item - please select manually",
"no_canvas_support": "Your browser doesn't support canvas operations",
"please_select_location": "Please select a location.",
@@ -208,8 +198,21 @@
"upload_success": "{count, plural, =0 {No photos uploaded.} =1 {Photo uploaded successfully.} other {All photos uploaded successfully.}}",
"uploading_photos": "{count, plural, =0 {No photos to upload} =1 {Uploading 1 photo…} other {Uploading {count} photos…}}"
},
- "upload_photos": "Upload Photos",
- "uploaded": "Uploaded Photo"
+ "clear_template": "Clear Template",
+ "delete_photo": "Delete photo",
+ "parent_item": "Parent Item",
+ "product_tooltip_input_barcode": "Autofill with a manually provided barcode",
+ "product_tooltip_scan_barcode": "Autofill with a barcode from 📷",
+ "rotate_photo": "Rotate photo",
+ "set_as_primary_photo": "Set as { isPrimary, select, true {non-} false {} other {}}primary photo",
+ "type_selector_placeholder": "Select a type…",
+ "item_selector_no_results_text": "Type to search…"
+ }
+ },
+ "item": {
+ "attachments_list": {
+ "download": "Download",
+ "open_new_tab": "Open in new tab"
},
"product_import": {
"barcode": "Product's barcode",
@@ -280,17 +283,6 @@
}
},
"location": {
- "create_modal": {
- "location_description": "Location Description",
- "location_name": "Location Name",
- "location_photo": "Location Photo 📷",
- "title": "Create Location",
- "toast": {
- "already_creating": "Already creating a location",
- "create_failed": "Couldn't create location",
- "create_success": "Location created"
- }
- },
"selector": {
"clear": "Clear Location Selection",
"no_location_found": "No location found",
@@ -300,7 +292,8 @@
},
"tree": {
"no_locations": "No locations available. Use the Create button to add a new location."
- }
+ },
+ "create_item": "Create Item"
},
"quick_menu": {
"no_results": "No results found.",
@@ -391,6 +384,50 @@
"updated": "Template updated"
},
"using_template": "Using template: {name}"
+ },
+ "entityTypes": {
+ "create_dialog": {
+ "title": "Create Entity Type",
+ "name_label": "Name",
+ "is_container_location_type_label": "Is a container / location type",
+ "button": "Create"
+ },
+ "update_dialog": {
+ "title": "Update Entity Type",
+ "name_label": "Name",
+ "is_container_location_type_label": "Is a container / location type",
+ "button": "Update"
+ },
+ "page": {
+ "title": "Entity Types",
+ "create": "Create",
+ "empty_title": "No entity types defined yet.",
+ "empty_button": "Create Entity Type"
+ },
+ "card": {
+ "default_template": "Default template: {name}",
+ "badge_container": "Container",
+ "tooltip": {
+ "edit": "Edit",
+ "delete": "Delete"
+ },
+ "actions": {
+ "delete": "Delete"
+ }
+ },
+ "toasts": {
+ "name_required": "Name is required",
+ "create_failed": "Failed to create entity type",
+ "create_success": "Entity type created",
+ "update_failed": "Failed to update entity type",
+ "update_success": "Entity type updated",
+ "delete_confirm_failed": "Failed to delete entity type. Make sure no entities are using it.",
+ "delete_success": "Entity type deleted"
+ },
+ "confirm": {
+ "convert_item_to_location": "Converting an item type to a location type will result in a loss of fields for entities using this type. Are you sure you want to continue?",
+ "delete_entity_type": "Are you sure you want to delete \"{name}\"?"
+ }
}
},
"errors": {
@@ -449,7 +486,10 @@
"value": "Value",
"version": "Version: { version }",
"welcome": "Welcome, { username }",
- "yes": "Yes"
+ "yes": "Yes",
+ "item": "Item",
+ "location": "Location",
+ "entity": "Entity"
},
"home": {
"quick_statistics": "Quick Statistics",
diff --git a/frontend/pages/collection/index/entity-types.vue b/frontend/pages/collection/index/entity-types.vue
index 275097e1..1fbe3ea7 100644
--- a/frontend/pages/collection/index/entity-types.vue
+++ b/frontend/pages/collection/index/entity-types.vue
@@ -22,6 +22,7 @@
import FormTextField from "~/components/Form/TextField.vue";
import FormCheckbox from "~/components/Form/Checkbox.vue";
import TemplateSelector from "~/components/Template/Selector.vue";
+ import { useEntityTypeStore } from "~/stores/entityTypes";
const { t } = useI18n();
@@ -30,15 +31,9 @@
const api = useUserApi();
const confirm = useConfirm();
const { openDialog, closeDialog } = useDialog();
+ const entityTypeStore = useEntityTypeStore();
- const { data: entityTypes, refresh } = useAsyncData("entity-types", async () => {
- const { data, error } = await api.entityTypes.getAll();
- if (error) {
- toast.error("Failed to load entity types");
- return [];
- }
- return data;
- });
+ const entityTypes = computed(() => entityTypeStore.allTypes);
// Create form
const createForm = reactive({
@@ -57,7 +52,7 @@
async function create() {
if (!createForm.name.trim()) {
- toast.error("Name is required");
+ toast.error(t("components.entityTypes.toasts.name_required"));
return;
}
@@ -70,14 +65,14 @@
const { error } = await api.entityTypes.create(payload);
if (error) {
- toast.error("Failed to create entity type");
+ toast.error(t("components.entityTypes.toasts.create_failed"));
return;
}
- toast.success("Entity type created");
+ toast.success(t("components.entityTypes.toasts.create_success"));
resetCreateForm();
closeDialog(DialogID.CreateEntityType);
- refresh();
+ entityTypeStore.refresh();
}
// Update form
@@ -86,6 +81,7 @@
name: "",
icon: "",
isLocation: false,
+ originalIsItem: false,
});
const updateTemplate = ref<EntityTemplateSummary | null>(null);
@@ -94,6 +90,7 @@
updateForm.name = et.name;
updateForm.icon = et.icon;
updateForm.isLocation = et.isLocation;
+ updateForm.originalIsItem = !et.isLocation;
updateTemplate.value = et.defaultTemplate
? ({
id: et.defaultTemplate.id,
@@ -106,7 +103,7 @@
async function update() {
if (!updateForm.name.trim()) {
- toast.error("Name is required");
+ toast.error(t("components.entityTypes.toasts.name_required"));
return;
}
@@ -118,31 +115,36 @@
...(updateTemplate.value?.id ? { defaultTemplateId: updateTemplate.value.id } : {}),
} as EntityTypeUpdate;
+ if (updateForm.originalIsItem && updateForm.isLocation) {
+ const { isCanceled } = await confirm.open(t("components.entityTypes.confirm.convert_item_to_location"));
+ if (isCanceled) return;
+ }
+
const { error } = await api.entityTypes.update(updateForm.id, payload);
if (error) {
- toast.error("Failed to update entity type");
+ toast.error(t("components.entityTypes.toasts.update_failed"));
return;
}
- toast.success("Entity type updated");
+ toast.success(t("components.entityTypes.toasts.update_success"));
closeDialog(DialogID.UpdateEntityType);
- refresh();
+ entityTypeStore.refresh();
}
async function deleteEntityType(et: EntityTypeSummary) {
const { isCanceled } = await confirm.open(
- `Are you sure you want to delete "${et.name}"? Entities using this type will need to be reassigned.`
+ t("components.entityTypes.confirm.delete_entity_type", { name: et.name })
);
if (isCanceled) return;
const { error } = await api.entityTypes.delete(et.id);
if (error) {
- toast.error("Failed to delete entity type. Make sure no entities are using it.");
+ toast.error(t("components.entityTypes.toasts.delete_confirm_failed"));
return;
}
- toast.success("Entity type deleted");
- refresh();
+ toast.success(t("components.entityTypes.toasts.delete_success"));
+ entityTypeStore.refresh();
}
</script>
@@ -152,15 +154,24 @@
<Dialog :dialog-id="DialogID.CreateEntityType">
<DialogContent>
<DialogHeader>
- <DialogTitle>Create Entity Type</DialogTitle>
+ <DialogTitle>{{ t("components.entityTypes.create_dialog.title") }}</DialogTitle>
</DialogHeader>
<form class="flex flex-col gap-3" @submit.prevent="create">
- <FormTextField v-model="createForm.name" :autofocus="true" label="Name" :max-length="255" :min-length="1" />
- <FormCheckbox v-model="createForm.isLocation" label="Is a container / location type" />
- <TemplateSelector v-model="createTemplate" />
+ <FormTextField
+ v-model="createForm.name"
+ :autofocus="true"
+ :label="t('components.entityTypes.create_dialog.name_label')"
+ :max-length="255"
+ :min-length="1"
+ />
+ <FormCheckbox
+ v-model="createForm.isLocation"
+ :label="t('components.entityTypes.create_dialog.is_container_location_type_label')"
+ />
+ <TemplateSelector v-if="!createForm.isLocation" v-model="createTemplate" />
<DialogFooter>
- <Button type="submit">Create</Button>
+ <Button type="submit">{{ t("components.entityTypes.create_dialog.button") }}</Button>
</DialogFooter>
</form>
</DialogContent>
@@ -170,15 +181,24 @@
<Dialog :dialog-id="DialogID.UpdateEntityType">
<DialogContent>
<DialogHeader>
- <DialogTitle>Update Entity Type</DialogTitle>
+ <DialogTitle>{{ t("components.entityTypes.update_dialog.title") }}</DialogTitle>
</DialogHeader>
<form class="flex flex-col gap-3" @submit.prevent="update">
- <FormTextField v-model="updateForm.name" :autofocus="true" label="Name" :max-length="255" :min-length="1" />
- <FormCheckbox v-model="updateForm.isLocation" label="Is a container / location type" />
- <TemplateSelector v-model="updateTemplate" />
+ <FormTextField
+ v-model="updateForm.name"
+ :autofocus="true"
+ :label="t('components.entityTypes.update_dialog.name_label')"
+ :max-length="255"
+ :min-length="1"
+ />
+ <FormCheckbox
+ v-model="updateForm.isLocation"
+ :label="t('components.entityTypes.update_dialog.is_container_location_type_label')"
+ />
+ <TemplateSelector v-if="!updateForm.isLocation" v-model="updateTemplate" />
<DialogFooter>
- <Button type="submit">Update</Button>
+ <Button type="submit">{{ t("components.entityTypes.update_dialog.button") }}</Button>
</DialogFooter>
</form>
</DialogContent>
@@ -186,10 +206,10 @@
<!-- Page Content -->
<div class="mb-4 flex items-center justify-between">
- <h3 class="text-lg font-medium">Entity Types</h3>
+ <h3 class="text-lg font-medium">{{ t("components.entityTypes.page.title") }}</h3>
<Button size="sm" @click="openDialog(DialogID.CreateEntityType)">
<MdiPlus class="mr-1 size-4" />
- Create
+ {{ t("components.entityTypes.page.create") }}
</Button>
</div>
@@ -205,11 +225,13 @@
<div class="mr-auto min-w-0">
<div class="flex items-center gap-2">
- <span class="font-medium">{{ et.name }}</span>
- <Badge v-if="et.isLocation" variant="secondary" class="text-xs">Container</Badge>
+ <span class="font-medium">{{ t(et.name) }}</span>
+ <Badge v-if="et.isLocation" variant="secondary" class="text-xs">
+ {{ t("components.entityTypes.card.badge_container") }}
+ </Badge>
</div>
- <p v-if="et.defaultTemplate" class="text-xs text-muted-foreground">
- Default template: {{ et.defaultTemplate.name }}
+ <p v-if="et.defaultTemplate && !et.isLocation" class="text-xs text-muted-foreground">
+ {{ t("components.entityTypes.card.default_template", { name: et.defaultTemplate.name }) }}
</p>
</div>
@@ -221,7 +243,7 @@
<MdiPencil class="size-4" />
</Button>
</TooltipTrigger>
- <TooltipContent>Edit</TooltipContent>
+ <TooltipContent>{{ t("components.entityTypes.card.tooltip.edit") }}</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger as-child>
@@ -229,7 +251,7 @@
<MdiDelete class="size-4" />
</Button>
</TooltipTrigger>
- <TooltipContent>Delete</TooltipContent>
+ <TooltipContent>{{ t("components.entityTypes.card.tooltip.delete") }}</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
@@ -238,10 +260,10 @@
</div>
<div v-else class="flex flex-col items-center justify-center py-12 text-center">
- <p class="mb-4 text-muted-foreground">No entity types defined yet.</p>
+ <p class="mb-4 text-muted-foreground">{{ t("components.entityTypes.page.empty_title") }}</p>
<Button @click="openDialog(DialogID.CreateEntityType)">
<MdiPlus class="mr-2" />
- Create Entity Type
+ {{ t("components.entityTypes.page.empty_button") }}
</Button>
</div>
</div>
diff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vue
index 305039a7..4334790a 100644
--- a/frontend/pages/item/[id]/index.vue
+++ b/frontend/pages/item/[id]/index.vue
@@ -55,7 +55,6 @@
});
const route = useRoute();
- const router = useRouter();
const api = useUserApi();
const itemId = computed<string>(() => route.params.id as string);
@@ -619,14 +618,12 @@
}
async function createSubitem() {
- // setting URL Parameter that is read and immidiately removed in the Item-CreateModal
- await router.push({
- query: {
- subItemCreate: "y",
+ openDialog(DialogID.CreateEntity, {
+ params: {
+ baseType: "item",
+ subItem: true,
},
});
-
- openDialog(DialogID.CreateItem);
}
</script>
diff --git a/frontend/pages/item/[id]/index/edit.vue b/frontend/pages/item/[id]/index/edit.vue
index abb11e1c..4d1298e4 100644
--- a/frontend/pages/item/[id]/index/edit.vue
+++ b/frontend/pages/item/[id]/index/edit.vue
@@ -5,7 +5,6 @@
import type { ItemAttachment, EntityFieldData, EntityOut, EntityUpdate } from "~~/lib/api/types/data-contracts";
import { AttachmentTypes } from "~~/lib/api/types/non-generated";
import { useTagStore } from "~/stores/tags";
- import { useLocationStore } from "~~/stores/locations";
import MdiLoading from "~icons/mdi/loading";
import MdiDelete from "~icons/mdi/delete";
import MdiPencil from "~icons/mdi/pencil";
@@ -47,9 +46,6 @@
const itemId = computed<string>(() => route.params.id as string);
- const locationStore = useLocationStore();
- const locations = computed(() => locationStore.allLocations);
-
const tagStore = useTagStore();
const tags = computed(() => tagStore.tags);
diff --git a/frontend/pages/location/[id]/index/edit.vue b/frontend/pages/location/[id]/index/edit.vue
index 7d2640f8..90413904 100644
--- a/frontend/pages/location/[id]/index/edit.vue
+++ b/frontend/pages/location/[id]/index/edit.vue
@@ -5,7 +5,6 @@
import type { ItemAttachment, EntityFieldData, EntityOut, EntityUpdate } from "~~/lib/api/types/data-contracts";
import { AttachmentTypes } from "~~/lib/api/types/non-generated";
import { useTagStore } from "~/stores/tags";
- import { useLocationStore } from "~~/stores/locations";
import MdiLoading from "~icons/mdi/loading";
import MdiDelete from "~icons/mdi/delete";
import MdiPencil from "~icons/mdi/pencil";
@@ -44,9 +43,6 @@
const locationId = computed<string>(() => route.params.id as string);
- const locationStore = useLocationStore();
- const locations = computed(() => locationStore.allLocations);
-
const tagStore = useTagStore();
const tags = computed(() => tagStore.tags);
diff --git a/frontend/pages/location/[id]/index/index.vue b/frontend/pages/location/[id]/index/index.vue
index cdec53ec..29bcb060 100644
--- a/frontend/pages/location/[id]/index/index.vue
+++ b/frontend/pages/location/[id]/index/index.vue
@@ -4,7 +4,6 @@
import type { AnyDetail, Details } from "~~/components/global/DetailsSection/types";
import { filterZeroValues } from "~~/components/global/DetailsSection/types";
import type { ItemAttachment } from "~~/lib/api/types/data-contracts";
- import { useLocationStore } from "~~/stores/locations";
import MdiPackageVariant from "~icons/mdi/package-variant";
import MdiPlus from "~icons/mdi/plus";
import MdiPencil from "~icons/mdi/pencil";
@@ -49,7 +48,7 @@
const locationId = computed<string>(() => route.params.id as string);
- const { data: location, refresh } = useAsyncData(locationId.value, async () => {
+ const { data: location } = useAsyncData(locationId.value, async () => {
const { data, error } = await api.items.getLocation(locationId.value);
if (error) {
toast.error(t("locations.toast.failed_load_location"));
@@ -79,15 +78,17 @@
}
function openCreateItem() {
- openDialog(DialogID.CreateItem);
+ openDialog(DialogID.CreateEntity, {
+ params: {
+ baseType: "item",
+ },
+ });
}
function goToEdit() {
navigateTo(`/location/${locationId.value}/edit`);
}
- const locationStore = useLocationStore();
-
// Photos
type Photo = {
thumbnailSrc?: string;
@@ -229,7 +230,7 @@
<button
v-for="(photo, i) in photos"
:key="i"
- class="aspect-square group relative overflow-hidden rounded-lg border bg-muted"
+ class="group relative overflow-hidden rounded-lg border bg-muted h-32 aspect-1"
@click="openImageDialog(photo, location.id)"
>
<img
@@ -285,7 +286,7 @@
<Button class="w-9 md:w-auto" @click="openCreateItem">
<MdiPlus name="mdi-plus" />
<span class="hidden md:inline">
- {{ $t("components.item.create_modal.title") }}
+ {{ $t("components.location.create_item") }}
</span>
</Button>
<Button class="w-9 md:w-auto" @click="goToEdit">
diff --git a/frontend/pages/reset-password.vue b/frontend/pages/reset-password.vue
index 94541478..510e3f91 100644
--- a/frontend/pages/reset-password.vue
+++ b/frontend/pages/reset-password.vue
@@ -92,12 +92,7 @@
</CardContent>
<CardFooter class="flex flex-col gap-2">
- <Button
- form="reset-password-form"
- type="submit"
- class="w-full"
- :disabled="loading || !passwordValid || !token"
- >
+ <Button form="reset-password-form" type="submit" class="w-full" :disabled="loading || !passwordValid || !token">
{{ $t("index.reset_password_set") }}
</Button>
<NuxtLink to="/" class="text-sm text-muted-foreground hover:underline">
diff --git a/frontend/stores/entityTypes.ts b/frontend/stores/entityTypes.ts
new file mode 100644
index 00000000..096d87e3
--- /dev/null
+++ b/frontend/stores/entityTypes.ts
@@ -0,0 +1,54 @@
+import { defineStore } from "pinia";
+import type { EntityTypeSummary } from "~~/lib/api/types/data-contracts";
+
+export const useEntityTypeStore = defineStore("entityTypes", {
+ state: () => ({
+ types: null as EntityTypeSummary[] | null,
+ client: useUserApi(),
+ refreshPromise: null as Promise<void> | null,
+ }),
+ getters: {
+ allTypes(state): EntityTypeSummary[] {
+ return state.types ?? [];
+ },
+ locationTypes(state): EntityTypeSummary[] {
+ return (state.types ?? []).filter(t => t.isLocation);
+ },
+ itemTypes(state): EntityTypeSummary[] {
+ return (state.types ?? []).filter(t => !t.isLocation);
+ },
+ },
+ actions: {
+ async ensureFetched() {
+ if (this.types !== null) return;
+
+ if (this.refreshPromise === null) {
+ this.refreshPromise = this.refresh();
+ }
+
+ await this.refreshPromise;
+ },
+
+ async refresh() {
+ if (this.refreshPromise !== null) return this.refreshPromise;
+
+ this.refreshPromise = (async () => {
+ const result = await this.client.entityTypes.getAll();
+ if (result.error) throw result.error;
+ this.types = result.data ?? [];
+ })();
+
+ try {
+ await this.refreshPromise;
+ } finally {
+ this.refreshPromise = null;
+ }
+ },
+
+ findById(id: string) {
+ return (this.types ?? []).find(t => t.id === id) ?? null;
+ },
+ },
+});
+
+export default useEntityTypeStore;