2022-09-06 18:32:13 +00:00
|
|
|
<script setup lang="ts">
|
2022-11-01 07:30:42 +00:00
|
|
|
import { CustomDetail, Detail, Details } from "~~/components/global/DetailsSection/types";
|
2022-09-24 19:33:38 +00:00
|
|
|
import { ItemAttachment } from "~~/lib/api/types/data-contracts";
|
|
|
|
|
2022-09-06 18:32:13 +00:00
|
|
|
definePageMeta({
|
2022-10-15 20:15:55 +00:00
|
|
|
middleware: ["auth"],
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
const api = useUserApi();
|
|
|
|
const toast = useNotifier();
|
|
|
|
|
|
|
|
const itemId = computed<string>(() => route.params.id as string);
|
|
|
|
const preferences = useViewPreferences();
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
const { data: item, refresh } = useAsyncData(itemId.value, async () => {
|
2022-09-06 18:32:13 +00:00
|
|
|
const { data, error } = await api.items.get(itemId.value);
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Failed to load item");
|
|
|
|
navigateTo("/home");
|
2022-09-06 18:32:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
});
|
2022-09-12 22:47:27 +00:00
|
|
|
onMounted(() => {
|
|
|
|
refresh();
|
|
|
|
});
|
|
|
|
|
2022-09-24 19:33:38 +00:00
|
|
|
type FilteredAttachments = {
|
|
|
|
photos: ItemAttachment[];
|
|
|
|
attachments: ItemAttachment[];
|
|
|
|
warranty: ItemAttachment[];
|
|
|
|
manuals: ItemAttachment[];
|
2022-10-16 03:45:36 +00:00
|
|
|
receipts: ItemAttachment[];
|
2022-09-24 19:33:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const attachments = computed<FilteredAttachments>(() => {
|
|
|
|
if (!item.value) {
|
|
|
|
return {
|
|
|
|
photos: [],
|
|
|
|
attachments: [],
|
|
|
|
manuals: [],
|
|
|
|
warranty: [],
|
2022-10-16 03:45:36 +00:00
|
|
|
receipts: [],
|
2022-09-24 19:33:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return item.value.attachments.reduce(
|
|
|
|
(acc, attachment) => {
|
|
|
|
if (attachment.type === "photo") {
|
|
|
|
acc.photos.push(attachment);
|
|
|
|
} else if (attachment.type === "warranty") {
|
|
|
|
acc.warranty.push(attachment);
|
|
|
|
} else if (attachment.type === "manual") {
|
|
|
|
acc.manuals.push(attachment);
|
2022-10-16 03:45:36 +00:00
|
|
|
} else if (attachment.type === "receipt") {
|
|
|
|
acc.receipts.push(attachment);
|
2022-09-24 19:33:38 +00:00
|
|
|
} else {
|
|
|
|
acc.attachments.push(attachment);
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
photos: [] as ItemAttachment[],
|
|
|
|
attachments: [] as ItemAttachment[],
|
|
|
|
warranty: [] as ItemAttachment[],
|
|
|
|
manuals: [] as ItemAttachment[],
|
2022-10-16 03:45:36 +00:00
|
|
|
receipts: [] as ItemAttachment[],
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-11-13 22:59:05 +00:00
|
|
|
const assetID = computed<Details>(() => {
|
|
|
|
if (item.value?.assetId === "000-000") {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: "Asset ID",
|
|
|
|
text: item.value?.assetId,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2022-11-01 07:30:42 +00:00
|
|
|
const itemDetails = computed<Details>(() => {
|
2022-10-07 02:54:09 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: "Description",
|
|
|
|
text: item.value?.description,
|
|
|
|
},
|
2022-10-24 04:54:39 +00:00
|
|
|
{
|
|
|
|
name: "Quantity",
|
|
|
|
text: item.value?.quantity,
|
|
|
|
},
|
2022-10-07 02:54:09 +00:00
|
|
|
{
|
|
|
|
name: "Serial Number",
|
|
|
|
text: item.value?.serialNumber,
|
|
|
|
},
|
|
|
|
{
|
2022-10-14 16:30:23 +00:00
|
|
|
name: "Model Number",
|
2022-10-07 02:54:09 +00:00
|
|
|
text: item.value?.modelNumber,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Manufacturer",
|
|
|
|
text: item.value?.manufacturer,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Insured",
|
|
|
|
text: item.value?.insured ? "Yes" : "No",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Notes",
|
|
|
|
text: item.value?.notes,
|
|
|
|
},
|
2022-11-13 22:59:05 +00:00
|
|
|
...assetID.value,
|
2022-10-20 05:31:08 +00:00
|
|
|
...item.value.fields.map(field => {
|
|
|
|
/**
|
|
|
|
* Support Special URL Syntax
|
|
|
|
*/
|
|
|
|
const url = maybeUrl(field.textValue);
|
|
|
|
if (url.isUrl) {
|
|
|
|
return {
|
2022-11-01 07:30:42 +00:00
|
|
|
type: "link",
|
2022-10-20 05:31:08 +00:00
|
|
|
name: field.name,
|
|
|
|
text: url.text,
|
|
|
|
href: url.url,
|
2022-11-01 07:30:42 +00:00
|
|
|
} as CustomDetail;
|
2022-10-20 05:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: field.name,
|
|
|
|
text: field.textValue,
|
|
|
|
};
|
|
|
|
}),
|
2022-10-07 02:54:09 +00:00
|
|
|
];
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
|
|
|
|
2022-09-24 19:33:38 +00:00
|
|
|
const showAttachments = computed(() => {
|
|
|
|
if (preferences.value?.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
attachments.value.photos.length > 0 ||
|
|
|
|
attachments.value.attachments.length > 0 ||
|
|
|
|
attachments.value.warranty.length > 0 ||
|
2022-10-16 03:45:36 +00:00
|
|
|
attachments.value.manuals.length > 0 ||
|
|
|
|
attachments.value.receipts.length > 0
|
2022-09-24 19:33:38 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
const attachmentDetails = computed(() => {
|
|
|
|
const details: Detail[] = [];
|
2022-09-24 19:33:38 +00:00
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
const push = (name: string) => {
|
|
|
|
details.push({
|
|
|
|
name,
|
|
|
|
text: "",
|
|
|
|
slot: name.toLowerCase(),
|
|
|
|
});
|
|
|
|
};
|
2022-09-24 19:33:38 +00:00
|
|
|
|
|
|
|
if (attachments.value.photos.length > 0) {
|
2022-10-07 02:54:09 +00:00
|
|
|
push("Photos");
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
if (attachments.value.attachments.length > 0) {
|
|
|
|
push("Attachments");
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attachments.value.warranty.length > 0) {
|
2022-10-07 02:54:09 +00:00
|
|
|
push("Warranty");
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
if (attachments.value.manuals.length > 0) {
|
|
|
|
push("Manuals");
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 03:45:36 +00:00
|
|
|
if (attachments.value.receipts.length > 0) {
|
|
|
|
push("Receipts");
|
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
return details;
|
2022-09-24 19:33:38 +00:00
|
|
|
});
|
|
|
|
|
2022-09-09 18:20:38 +00:00
|
|
|
const showWarranty = computed(() => {
|
|
|
|
if (preferences.value.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-12 22:47:27 +00:00
|
|
|
return validDate(item.value?.warrantyExpires);
|
2022-09-09 18:20:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const warrantyDetails = computed(() => {
|
2022-10-15 20:15:55 +00:00
|
|
|
const details: Details = [
|
2022-10-07 02:54:09 +00:00
|
|
|
{
|
|
|
|
name: "Lifetime Warranty",
|
|
|
|
text: item.value?.lifetimeWarranty ? "Yes" : "No",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (item.value?.lifetimeWarranty) {
|
|
|
|
details.push({
|
|
|
|
name: "Warranty Expires",
|
|
|
|
text: "N/A",
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
details.push({
|
|
|
|
name: "Warranty Expires",
|
|
|
|
text: item.value?.warrantyExpires,
|
|
|
|
type: "date",
|
|
|
|
});
|
2022-09-09 18:20:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
details.push({
|
|
|
|
name: "Warranty Details",
|
|
|
|
text: item.value?.warrantyDetails || "",
|
|
|
|
});
|
2022-09-09 18:20:38 +00:00
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
return details;
|
2022-09-09 18:20:38 +00:00
|
|
|
});
|
|
|
|
|
2022-09-06 18:32:13 +00:00
|
|
|
const showPurchase = computed(() => {
|
|
|
|
if (preferences.value.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-09 13:03:24 +00:00
|
|
|
return item.value?.purchaseFrom || item.value?.purchasePrice !== "0";
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
|
|
|
|
2022-10-15 20:15:55 +00:00
|
|
|
const purchaseDetails = computed<Details>(() => {
|
2022-10-07 02:54:09 +00:00
|
|
|
return [
|
|
|
|
{
|
2022-10-15 05:03:46 +00:00
|
|
|
name: "Purchased From",
|
2022-10-09 13:03:24 +00:00
|
|
|
text: item.value?.purchaseFrom || "",
|
2022-10-07 02:54:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Purchase Price",
|
2022-10-15 20:15:55 +00:00
|
|
|
text: item.value?.purchasePrice || "",
|
|
|
|
type: "currency",
|
2022-10-07 02:54:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Purchase Date",
|
|
|
|
text: item.value.purchaseTime,
|
2022-10-09 13:03:24 +00:00
|
|
|
type: "date",
|
2022-10-07 02:54:09 +00:00
|
|
|
},
|
2022-10-09 13:03:24 +00:00
|
|
|
];
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const showSold = computed(() => {
|
|
|
|
if (preferences.value.showEmpty) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-09 13:03:24 +00:00
|
|
|
return item.value?.soldTo || item.value?.soldPrice !== "0";
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
|
|
|
|
2022-10-15 20:15:55 +00:00
|
|
|
const soldDetails = computed<Details>(() => {
|
2022-10-07 02:54:09 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: "Sold To",
|
|
|
|
text: item.value?.soldTo || "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Sold Price",
|
2022-10-15 20:15:55 +00:00
|
|
|
text: item.value?.soldPrice || "",
|
|
|
|
type: "currency",
|
2022-10-07 02:54:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Sold At",
|
|
|
|
text: item.value?.soldTime || "",
|
2022-10-09 13:03:24 +00:00
|
|
|
type: "date",
|
2022-10-07 02:54:09 +00:00
|
|
|
},
|
2022-10-09 13:03:24 +00:00
|
|
|
];
|
2022-09-06 18:32:13 +00:00
|
|
|
});
|
2022-09-09 06:05:23 +00:00
|
|
|
|
|
|
|
const confirm = useConfirm();
|
|
|
|
|
|
|
|
async function deleteItem() {
|
2022-09-25 22:33:13 +00:00
|
|
|
const confirmed = await confirm.open("Are you sure you want to delete this item?");
|
2022-09-09 06:05:23 +00:00
|
|
|
|
|
|
|
if (!confirmed.data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { error } = await api.items.delete(itemId.value);
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Failed to delete item");
|
2022-09-09 06:05:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.success("Item deleted");
|
|
|
|
navigateTo("/home");
|
2022-09-09 06:05:23 +00:00
|
|
|
}
|
2022-09-06 18:32:13 +00:00
|
|
|
</script>
|
|
|
|
|
2022-09-09 06:05:23 +00:00
|
|
|
<template>
|
2022-09-12 22:47:27 +00:00
|
|
|
<BaseContainer v-if="item" class="pb-8">
|
2022-09-09 06:05:23 +00:00
|
|
|
<section class="px-3">
|
|
|
|
<div class="flex justify-between items-center">
|
|
|
|
<div class="form-control"></div>
|
|
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 gap-3">
|
2022-10-07 02:54:09 +00:00
|
|
|
<BaseCard>
|
2022-09-09 06:05:23 +00:00
|
|
|
<template #title>
|
2022-10-07 02:54:09 +00:00
|
|
|
<BaseSectionHeader>
|
|
|
|
<Icon name="mdi-package-variant" class="mr-2 -mt-1 text-base-content" />
|
|
|
|
<span class="text-base-content">
|
|
|
|
{{ item ? item.name : "" }}
|
2022-09-09 06:05:23 +00:00
|
|
|
</span>
|
2022-10-24 04:54:39 +00:00
|
|
|
<div v-if="item.parent" class="text-sm breadcrumbs pb-0">
|
|
|
|
<ul class="text-base-content/70">
|
|
|
|
<li>
|
|
|
|
<NuxtLink :to="`/item/${item.parent.id}`"> {{ item.parent.name }}</NuxtLink>
|
|
|
|
</li>
|
|
|
|
<li>{{ item.name }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2022-10-07 02:54:09 +00:00
|
|
|
<template #description>
|
2022-10-24 04:54:39 +00:00
|
|
|
<div class="flex flex-wrap gap-2 mt-3">
|
|
|
|
<NuxtLink ref="badge" class="badge p-3" :to="`/location/${item.location.id}`">
|
|
|
|
<Icon name="heroicons-map-pin" class="mr-2 swap-on"></Icon>
|
|
|
|
{{ item.location.name }}
|
|
|
|
</NuxtLink>
|
|
|
|
<template v-if="item.labels && item.labels.length > 0">
|
|
|
|
<LabelChip v-for="label in item.labels" :key="label.id" class="badge-primary" :label="label" />
|
|
|
|
</template>
|
2022-09-09 06:05:23 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</BaseSectionHeader>
|
|
|
|
</template>
|
2022-10-07 02:54:09 +00:00
|
|
|
<template #title-actions>
|
|
|
|
<div class="modal-action mt-0">
|
|
|
|
<label class="label cursor-pointer mr-auto">
|
|
|
|
<input v-model="preferences.showEmpty" type="checkbox" class="toggle toggle-primary" />
|
|
|
|
<span class="label-text ml-4"> Show Empty </span>
|
|
|
|
</label>
|
|
|
|
<BaseButton size="sm" :to="`/item/${itemId}/edit`">
|
|
|
|
<template #icon>
|
|
|
|
<Icon name="mdi-pencil" />
|
|
|
|
</template>
|
|
|
|
Edit
|
|
|
|
</BaseButton>
|
|
|
|
<BaseButton size="sm" @click="deleteItem">
|
|
|
|
<template #icon>
|
|
|
|
<Icon name="mdi-delete" />
|
|
|
|
</template>
|
|
|
|
Delete
|
|
|
|
</BaseButton>
|
|
|
|
</div>
|
2022-09-12 22:47:27 +00:00
|
|
|
</template>
|
2022-10-07 02:54:09 +00:00
|
|
|
|
|
|
|
<DetailsSection :details="itemDetails" />
|
|
|
|
</BaseCard>
|
|
|
|
|
|
|
|
<BaseCard v-if="showAttachments">
|
|
|
|
<template #title> Attachments </template>
|
|
|
|
<DetailsSection :details="attachmentDetails">
|
|
|
|
<template #manuals>
|
|
|
|
<ItemAttachmentsList
|
|
|
|
v-if="attachments.manuals.length > 0"
|
|
|
|
:attachments="attachments.manuals"
|
|
|
|
:item-id="item.id"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #attachments>
|
|
|
|
<ItemAttachmentsList
|
|
|
|
v-if="attachments.attachments.length > 0"
|
|
|
|
:attachments="attachments.attachments"
|
|
|
|
:item-id="item.id"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #warranty>
|
|
|
|
<ItemAttachmentsList
|
|
|
|
v-if="attachments.warranty.length > 0"
|
|
|
|
:attachments="attachments.warranty"
|
|
|
|
:item-id="item.id"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #photos>
|
|
|
|
<ItemAttachmentsList
|
|
|
|
v-if="attachments.photos.length > 0"
|
|
|
|
:attachments="attachments.photos"
|
|
|
|
:item-id="item.id"
|
|
|
|
/>
|
|
|
|
</template>
|
2022-10-16 03:45:36 +00:00
|
|
|
<template #receipts>
|
|
|
|
<ItemAttachmentsList
|
|
|
|
v-if="attachments.receipts.length > 0"
|
|
|
|
:attachments="attachments.receipts"
|
|
|
|
:item-id="item.id"
|
|
|
|
/>
|
|
|
|
</template>
|
2022-10-07 02:54:09 +00:00
|
|
|
</DetailsSection>
|
|
|
|
</BaseCard>
|
|
|
|
|
|
|
|
<BaseCard v-if="showPurchase">
|
2022-10-15 05:03:46 +00:00
|
|
|
<template #title> Purchase Details </template>
|
2022-10-07 02:54:09 +00:00
|
|
|
<DetailsSection :details="purchaseDetails" />
|
|
|
|
</BaseCard>
|
|
|
|
|
|
|
|
<BaseCard v-if="showWarranty">
|
2022-10-15 05:03:46 +00:00
|
|
|
<template #title> Warranty Details </template>
|
2022-10-07 02:54:09 +00:00
|
|
|
<DetailsSection :details="warrantyDetails" />
|
|
|
|
</BaseCard>
|
|
|
|
|
|
|
|
<BaseCard v-if="showSold">
|
2022-10-15 05:03:46 +00:00
|
|
|
<template #title> Sold Details </template>
|
2022-10-07 02:54:09 +00:00
|
|
|
<DetailsSection :details="soldDetails" />
|
|
|
|
</BaseCard>
|
2022-09-09 06:05:23 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
2022-10-24 04:54:39 +00:00
|
|
|
|
|
|
|
<section class="my-6 px-3">
|
|
|
|
<BaseSectionHeader v-if="item && item.children && item.children.length > 0"> Child Items </BaseSectionHeader>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
|
|
<ItemCard v-for="child in item.children" :key="child.id" :item="child" />
|
|
|
|
</div>
|
|
|
|
</section>
|
2022-09-09 06:05:23 +00:00
|
|
|
</BaseContainer>
|
|
|
|
</template>
|