2022-09-06 18:32:13 +00:00
|
|
|
<script setup lang="ts">
|
2023-01-22 06:15:23 +00:00
|
|
|
import { ItemAttachment, ItemField, ItemOut, ItemUpdate } from "~~/lib/api/types/data-contracts";
|
2022-09-24 19:33:38 +00:00
|
|
|
import { AttachmentTypes } from "~~/lib/api/types/non-generated";
|
2022-09-13 03:36:22 +00:00
|
|
|
import { useLabelStore } from "~~/stores/labels";
|
|
|
|
import { useLocationStore } from "~~/stores/locations";
|
2022-09-24 19:33:38 +00:00
|
|
|
import { capitalize } from "~~/lib/strings";
|
2022-10-24 04:54:39 +00:00
|
|
|
import Autocomplete from "~~/components/Form/Autocomplete.vue";
|
2022-09-12 22:47:27 +00:00
|
|
|
|
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
|
|
|
});
|
2022-09-07 05:58:59 +00:00
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
const api = useUserApi();
|
|
|
|
const toast = useNotifier();
|
2022-09-12 22:47:27 +00:00
|
|
|
const preferences = useViewPreferences();
|
2022-09-07 05:58:59 +00:00
|
|
|
|
|
|
|
const itemId = computed<string>(() => route.params.id as string);
|
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
const locationStore = useLocationStore();
|
2022-11-02 19:54:43 +00:00
|
|
|
const locations = computed(() => locationStore.allLocations);
|
2022-09-12 22:47:27 +00:00
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
const labelStore = useLabelStore();
|
|
|
|
const labels = computed(() => labelStore.labels);
|
2022-09-12 22:47:27 +00:00
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
const { data: nullableItem, refresh } = useAsyncData(async () => {
|
2022-09-07 05:58:59 +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-07 05:58:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-09-12 22:47:27 +00:00
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
if (locations && data.location?.id) {
|
|
|
|
// @ts-expect-error - we know the locations is valid
|
2022-10-14 00:45:18 +00:00
|
|
|
const location = locations.value.find(l => l.id === data.location.id);
|
|
|
|
if (location) {
|
|
|
|
data.location = location;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-24 04:54:39 +00:00
|
|
|
if (data.parent) {
|
|
|
|
parent.value = data.parent;
|
|
|
|
}
|
|
|
|
|
2022-09-07 05:58:59 +00:00
|
|
|
return data;
|
|
|
|
});
|
2022-10-24 04:54:39 +00:00
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
const item = computed<ItemOut>(() => nullableItem.value as ItemOut);
|
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
onMounted(() => {
|
|
|
|
refresh();
|
|
|
|
});
|
2022-09-07 05:58:59 +00:00
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
async function saveItem() {
|
2023-02-13 19:43:09 +00:00
|
|
|
if (!item.value.location?.id) {
|
|
|
|
toast.error("Failed to save item: no location selected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
const payload: ItemUpdate = {
|
|
|
|
...item.value,
|
|
|
|
locationId: item.value.location?.id,
|
|
|
|
labelIds: item.value.labels.map(l => l.id),
|
2022-10-24 04:54:39 +00:00
|
|
|
parentId: parent.value ? parent.value.id : null,
|
2023-11-16 02:19:51 +00:00
|
|
|
assetId: item.value.assetId,
|
2022-09-12 22:47:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const { error } = await api.items.update(itemId.value, payload);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
toast.error("Failed to save item");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toast.success("Item saved");
|
|
|
|
navigateTo("/item/" + itemId.value);
|
|
|
|
}
|
2023-06-02 21:56:40 +00:00
|
|
|
type NoUndefinedField<T> = { [P in keyof T]-?: NoUndefinedField<NonNullable<T[P]>> };
|
2022-09-12 22:47:27 +00:00
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
type StringKeys<T> = { [k in keyof T]: T[k] extends string ? k : never }[keyof T];
|
|
|
|
type OnlyString<T> = { [k in StringKeys<T>]: string };
|
|
|
|
|
|
|
|
type NumberKeys<T> = { [k in keyof T]: T[k] extends number ? k : never }[keyof T];
|
|
|
|
type OnlyNumber<T> = { [k in NumberKeys<T>]: number };
|
|
|
|
|
|
|
|
type TextFormField = {
|
|
|
|
type: "text" | "textarea";
|
|
|
|
label: string;
|
|
|
|
// key of ItemOut where the value is a string
|
2023-06-02 21:56:40 +00:00
|
|
|
ref: keyof OnlyString<NoUndefinedField<ItemOut>>;
|
2023-02-13 19:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type NumberFormField = {
|
|
|
|
type: "number";
|
|
|
|
label: string;
|
2023-06-02 21:56:40 +00:00
|
|
|
ref: keyof OnlyNumber<NoUndefinedField<ItemOut>> | keyof OnlyString<NoUndefinedField<ItemOut>>;
|
2023-02-13 19:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/50851263/how-do-i-require-a-keyof-to-be-for-a-property-of-a-specific-type
|
|
|
|
// I don't know why typescript can't just be normal
|
|
|
|
type BooleanKeys<T> = { [k in keyof T]: T[k] extends boolean ? k : never }[keyof T];
|
|
|
|
type OnlyBoolean<T> = { [k in BooleanKeys<T>]: boolean };
|
|
|
|
|
|
|
|
interface BoolFormField {
|
|
|
|
type: "checkbox";
|
|
|
|
label: string;
|
2023-06-02 21:56:40 +00:00
|
|
|
ref: keyof OnlyBoolean<NoUndefinedField<ItemOut>>;
|
2023-02-13 19:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DateKeys<T> = { [k in keyof T]: T[k] extends Date | string ? k : never }[keyof T];
|
|
|
|
type OnlyDate<T> = { [k in DateKeys<T>]: Date | string };
|
|
|
|
|
|
|
|
type DateFormField = {
|
|
|
|
type: "date";
|
2022-09-07 05:58:59 +00:00
|
|
|
label: string;
|
2023-06-02 21:56:40 +00:00
|
|
|
ref: keyof OnlyDate<NoUndefinedField<ItemOut>>;
|
2022-09-07 05:58:59 +00:00
|
|
|
};
|
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
type FormField = TextFormField | BoolFormField | DateFormField | NumberFormField;
|
|
|
|
|
2022-09-07 05:58:59 +00:00
|
|
|
const mainFields: FormField[] = [
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Name",
|
|
|
|
ref: "name",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
2022-09-12 22:47:27 +00:00
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
label: "Quantity",
|
|
|
|
ref: "quantity",
|
|
|
|
},
|
2022-09-07 05:58:59 +00:00
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "textarea",
|
|
|
|
label: "Description",
|
|
|
|
ref: "description",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Serial Number",
|
|
|
|
ref: "serialNumber",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Model Number",
|
|
|
|
ref: "modelNumber",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Manufacturer",
|
|
|
|
ref: "manufacturer",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "textarea",
|
|
|
|
label: "Notes",
|
|
|
|
ref: "notes",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
2022-09-12 22:47:27 +00:00
|
|
|
{
|
|
|
|
type: "checkbox",
|
|
|
|
label: "Insured",
|
|
|
|
ref: "insured",
|
|
|
|
},
|
2022-11-01 07:30:42 +00:00
|
|
|
{
|
|
|
|
type: "checkbox",
|
|
|
|
label: "Archived",
|
|
|
|
ref: "archived",
|
|
|
|
},
|
2022-11-13 23:17:55 +00:00
|
|
|
{
|
|
|
|
type: "text",
|
|
|
|
label: "Asset ID",
|
|
|
|
ref: "assetId",
|
|
|
|
},
|
2022-09-07 05:58:59 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const purchaseFields: FormField[] = [
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Purchased From",
|
|
|
|
ref: "purchaseFrom",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
2022-10-15 05:03:46 +00:00
|
|
|
label: "Purchase Price",
|
2022-09-09 22:46:53 +00:00
|
|
|
ref: "purchasePrice",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "date",
|
2022-10-15 05:03:46 +00:00
|
|
|
label: "Purchase Date",
|
2023-06-02 21:56:40 +00:00
|
|
|
// @ts-expect-error - we know this is a date
|
2022-09-09 22:46:53 +00:00
|
|
|
ref: "purchaseTime",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
const warrantyFields: FormField[] = [
|
|
|
|
{
|
|
|
|
type: "checkbox",
|
|
|
|
label: "Lifetime Warranty",
|
|
|
|
ref: "lifetimeWarranty",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "date",
|
|
|
|
label: "Warranty Expires",
|
2023-06-02 21:56:40 +00:00
|
|
|
// @ts-expect-error - we know this is a date
|
2022-09-12 22:47:27 +00:00
|
|
|
ref: "warrantyExpires",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "textarea",
|
|
|
|
label: "Warranty Notes",
|
|
|
|
ref: "warrantyDetails",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
const soldFields: FormField[] = [
|
2022-09-07 05:58:59 +00:00
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Sold To",
|
|
|
|
ref: "soldTo",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "text",
|
|
|
|
label: "Sold Price",
|
|
|
|
ref: "soldPrice",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
type: "date",
|
|
|
|
label: "Sold At",
|
2023-06-02 21:56:40 +00:00
|
|
|
// @ts-expect-error - we know this is a date
|
2022-09-09 22:46:53 +00:00
|
|
|
ref: "soldTime",
|
2022-09-07 05:58:59 +00:00
|
|
|
},
|
|
|
|
];
|
2022-09-24 19:33:38 +00:00
|
|
|
|
|
|
|
// - Attachments
|
|
|
|
const attDropZone = ref<HTMLDivElement>();
|
|
|
|
const { isOverDropZone: attDropZoneActive } = useDropZone(attDropZone);
|
|
|
|
|
|
|
|
const refAttachmentInput = ref<HTMLInputElement>();
|
|
|
|
|
|
|
|
function clickUpload() {
|
|
|
|
if (!refAttachmentInput.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
refAttachmentInput.value.click();
|
|
|
|
}
|
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
function uploadImage(e: Event) {
|
2022-09-24 19:33:38 +00:00
|
|
|
const files = (e.target as HTMLInputElement).files;
|
2023-01-19 05:44:06 +00:00
|
|
|
if (!files || !files.item(0)) {
|
2022-09-24 19:33:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
const first = files.item(0);
|
|
|
|
if (!first) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-01 17:45:20 +00:00
|
|
|
uploadAttachment([first], null);
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const dropPhoto = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Photo);
|
|
|
|
const dropAttachment = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Attachment);
|
|
|
|
const dropWarranty = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Warranty);
|
|
|
|
const dropManual = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Manual);
|
2022-10-16 03:45:36 +00:00
|
|
|
const dropReceipt = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Receipt);
|
2022-09-24 19:33:38 +00:00
|
|
|
|
2023-12-01 17:45:20 +00:00
|
|
|
async function uploadAttachment(files: File[] | null, type: AttachmentTypes | null) {
|
2023-01-19 05:44:06 +00:00
|
|
|
if (!files || files.length === 0) {
|
2022-09-24 19:33:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:57:57 +00:00
|
|
|
const { data, error } = await api.items.attachments.add(itemId.value, files[0], files[0].name, type);
|
2022-09-24 19:33:38 +00:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
toast.error("Failed to upload attachment");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toast.success("Attachment uploaded");
|
|
|
|
|
|
|
|
item.value.attachments = data.attachments;
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirm = useConfirm();
|
|
|
|
|
|
|
|
async function deleteAttachment(attachmentId: string) {
|
2022-09-25 22:33:13 +00:00
|
|
|
const confirmed = await confirm.open("Are you sure you want to delete this attachment?");
|
2022-09-24 19:33:38 +00:00
|
|
|
|
|
|
|
if (confirmed.isCanceled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:57:57 +00:00
|
|
|
const { error } = await api.items.attachments.delete(itemId.value, attachmentId);
|
2022-09-24 19:33:38 +00:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
toast.error("Failed to delete attachment");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toast.success("Attachment deleted");
|
|
|
|
item.value.attachments = item.value.attachments.filter(a => a.id !== attachmentId);
|
|
|
|
}
|
|
|
|
|
|
|
|
const editState = reactive({
|
|
|
|
modal: false,
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
// Values
|
2022-10-15 21:56:08 +00:00
|
|
|
obj: {},
|
2022-09-24 19:33:38 +00:00
|
|
|
id: "",
|
|
|
|
title: "",
|
|
|
|
type: "",
|
2023-10-07 02:51:08 +00:00
|
|
|
primary: false,
|
2022-09-24 19:33:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const attachmentOpts = Object.entries(AttachmentTypes).map(([key, value]) => ({
|
|
|
|
text: capitalize(key),
|
|
|
|
value,
|
|
|
|
}));
|
|
|
|
|
|
|
|
function openAttachmentEditDialog(attachment: ItemAttachment) {
|
|
|
|
editState.id = attachment.id;
|
|
|
|
editState.title = attachment.document.title;
|
|
|
|
editState.type = attachment.type;
|
2023-10-07 02:51:08 +00:00
|
|
|
editState.primary = attachment.primary;
|
2022-09-24 19:33:38 +00:00
|
|
|
editState.modal = true;
|
2022-10-15 21:56:08 +00:00
|
|
|
|
2023-02-13 19:43:09 +00:00
|
|
|
editState.obj = attachmentOpts.find(o => o.value === attachment.type) || attachmentOpts[0];
|
2022-09-24 19:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function updateAttachment() {
|
|
|
|
editState.loading = true;
|
2022-12-10 05:57:57 +00:00
|
|
|
const { error, data } = await api.items.attachments.update(itemId.value, editState.id, {
|
2022-09-24 19:33:38 +00:00
|
|
|
title: editState.title,
|
|
|
|
type: editState.type,
|
2023-10-07 02:51:08 +00:00
|
|
|
primary: editState.primary,
|
2022-09-24 19:33:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
toast.error("Failed to update attachment");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.value.attachments = data.attachments;
|
|
|
|
|
|
|
|
editState.loading = false;
|
|
|
|
editState.modal = false;
|
|
|
|
|
|
|
|
editState.id = "";
|
|
|
|
editState.title = "";
|
|
|
|
editState.type = "";
|
|
|
|
|
|
|
|
toast.success("Attachment updated");
|
|
|
|
}
|
2022-10-16 05:41:27 +00:00
|
|
|
|
|
|
|
function addField() {
|
|
|
|
item.value.fields.push({
|
|
|
|
id: null,
|
|
|
|
name: "Field Name",
|
|
|
|
type: "text",
|
|
|
|
textValue: "",
|
|
|
|
numberValue: 0,
|
|
|
|
booleanValue: false,
|
|
|
|
timeValue: null,
|
2023-01-19 05:44:06 +00:00
|
|
|
} as unknown as ItemField);
|
2022-10-16 05:41:27 +00:00
|
|
|
}
|
2022-10-24 04:54:39 +00:00
|
|
|
|
|
|
|
const { query, results } = useItemSearch(api, { immediate: false });
|
|
|
|
const parent = ref();
|
2023-07-31 14:57:42 +00:00
|
|
|
|
|
|
|
async function deleteItem() {
|
|
|
|
const confirmed = await confirm.open("Are you sure you want to delete this item?");
|
|
|
|
|
|
|
|
if (!confirmed.data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { error } = await api.items.delete(itemId.value);
|
|
|
|
if (error) {
|
|
|
|
toast.error("Failed to delete item");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
toast.success("Item deleted");
|
|
|
|
navigateTo("/home");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function keyboardSave(e: KeyboardEvent) {
|
|
|
|
// Cmd + S
|
|
|
|
if (e.metaKey && e.key === "s") {
|
|
|
|
e.preventDefault();
|
|
|
|
await saveItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ctrl + S
|
|
|
|
if (e.ctrlKey && e.key === "s") {
|
|
|
|
e.preventDefault();
|
|
|
|
await saveItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
window.addEventListener("keydown", keyboardSave);
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.removeEventListener("keydown", keyboardSave);
|
|
|
|
});
|
2022-09-06 18:32:13 +00:00
|
|
|
</script>
|
|
|
|
|
2022-09-07 05:58:59 +00:00
|
|
|
<template>
|
2023-01-19 05:44:06 +00:00
|
|
|
<div v-if="item" class="pb-8">
|
2022-09-24 19:33:38 +00:00
|
|
|
<BaseModal v-model="editState.modal">
|
|
|
|
<template #title> Attachment Edit </template>
|
|
|
|
|
|
|
|
<FormTextField v-model="editState.title" label="Attachment Title" />
|
2022-10-15 21:56:08 +00:00
|
|
|
<FormSelect
|
|
|
|
v-model:value="editState.type"
|
|
|
|
label="Attachment Type"
|
|
|
|
value-key="value"
|
|
|
|
name="text"
|
|
|
|
:items="attachmentOpts"
|
|
|
|
/>
|
2023-10-07 02:51:08 +00:00
|
|
|
<div v-if="editState.type == 'photo'" class="flex gap-2 mt-3">
|
|
|
|
<input v-model="editState.primary" type="checkbox" class="checkbox" />
|
|
|
|
<p class="text-sm">
|
|
|
|
<span class="font-semibold">Primary Photo</span>
|
|
|
|
This options is only available for photos. Only one photo can be primary. If you select this option, the
|
|
|
|
current primary photo, if any will be unselected.
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-09-24 19:33:38 +00:00
|
|
|
<div class="modal-action">
|
|
|
|
<BaseButton :loading="editState.loading" @click="updateAttachment"> Update </BaseButton>
|
|
|
|
</div>
|
|
|
|
</BaseModal>
|
|
|
|
|
2023-07-31 14:57:42 +00:00
|
|
|
<section class="relative">
|
|
|
|
<div class="my-4 justify-end flex gap-2 items-center sticky z-10 top-1">
|
|
|
|
<div class="mr-auto tooltip tooltip-right" data-tip="Show Advanced View Options">
|
|
|
|
<label class="label cursor-pointer mr-auto">
|
|
|
|
<input v-model="preferences.editorAdvancedView" type="checkbox" class="toggle toggle-primary" />
|
|
|
|
<span class="label-text ml-4"> Advanced </span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<BaseButton size="sm" @click="saveItem">
|
|
|
|
<template #icon>
|
|
|
|
<Icon name="mdi-content-save-outline" />
|
|
|
|
</template>
|
|
|
|
Save
|
|
|
|
</BaseButton>
|
|
|
|
<BaseButton class="btn btn-sm btn-error" @click="deleteItem()">
|
|
|
|
<Icon name="mdi-delete" class="mr-2" />
|
|
|
|
Delete
|
|
|
|
</BaseButton>
|
|
|
|
</div>
|
2023-01-19 05:44:06 +00:00
|
|
|
<div class="space-y-6">
|
2023-02-13 19:43:09 +00:00
|
|
|
<BaseCard class="overflow-visible">
|
|
|
|
<template #title> Edit Details </template>
|
|
|
|
<template #title-actions>
|
2023-07-31 14:57:42 +00:00
|
|
|
<div class="flex flex-wrap justify-between items-center mt-2 gap-4"></div>
|
2023-02-13 19:43:09 +00:00
|
|
|
</template>
|
|
|
|
<div class="px-5 pt-2 border-t mb-6 grid md:grid-cols-2 gap-4">
|
2023-01-28 20:53:00 +00:00
|
|
|
<LocationSelector v-model="item.location" />
|
2022-09-12 22:47:27 +00:00
|
|
|
<FormMultiselect v-model="item.labels" label="Labels" :items="labels ?? []" />
|
2022-10-24 04:54:39 +00:00
|
|
|
<Autocomplete
|
2023-01-22 06:15:23 +00:00
|
|
|
v-if="preferences.editorAdvancedView"
|
2022-10-24 04:54:39 +00:00
|
|
|
v-model="parent"
|
|
|
|
v-model:search="query"
|
|
|
|
:items="results"
|
|
|
|
item-text="name"
|
|
|
|
label="Parent Item"
|
|
|
|
no-results-text="Type to search..."
|
|
|
|
/>
|
2022-09-12 22:47:27 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="border-t border-gray-300 sm:p-0">
|
|
|
|
<div v-for="field in mainFields" :key="field.ref" class="sm:divide-y sm:divide-gray-300 grid grid-cols-1">
|
|
|
|
<div class="pt-2 px-4 pb-4 sm:px-6 border-b border-gray-300">
|
|
|
|
<FormTextArea v-if="field.type === 'textarea'" v-model="item[field.ref]" :label="field.label" inline />
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'text'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'number'"
|
|
|
|
v-model.number="item[field.ref]"
|
|
|
|
type="number"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormDatePicker
|
|
|
|
v-else-if="field.type === 'date'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormCheckbox
|
|
|
|
v-else-if="field.type === 'checkbox'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-07 05:58:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-13 19:43:09 +00:00
|
|
|
</BaseCard>
|
2022-09-07 05:58:59 +00:00
|
|
|
|
2022-10-16 05:41:27 +00:00
|
|
|
<BaseCard>
|
|
|
|
<template #title> Custom Fields </template>
|
2023-02-13 19:43:09 +00:00
|
|
|
<div class="px-5 border-t divide-y divide-gray-300 space-y-4">
|
2022-10-16 05:41:27 +00:00
|
|
|
<div
|
|
|
|
v-for="(field, idx) in item.fields"
|
|
|
|
:key="`field-${idx}`"
|
|
|
|
class="grid grid-cols-2 md:grid-cols-4 gap-2"
|
|
|
|
>
|
|
|
|
<!-- <FormSelect v-model:value="field.type" label="Field Type" :items="fieldTypes" value-key="value" /> -->
|
|
|
|
<FormTextField v-model="field.name" label="Name" />
|
|
|
|
<div class="flex items-end col-span-3">
|
|
|
|
<FormTextField v-model="field.textValue" label="Value" />
|
|
|
|
<div class="tooltip" data-tip="Delete">
|
|
|
|
<button class="btn btn-sm btn-square mb-2 ml-2" @click="item.fields.splice(idx, 1)">
|
|
|
|
<Icon name="mdi-delete" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="px-5 pb-4 mt-4 flex justify-end">
|
|
|
|
<BaseButton size="sm" @click="addField"> Add </BaseButton>
|
|
|
|
</div>
|
|
|
|
</BaseCard>
|
|
|
|
|
2022-09-24 19:33:38 +00:00
|
|
|
<div
|
2023-01-22 06:15:23 +00:00
|
|
|
v-if="preferences.editorAdvancedView"
|
2022-09-24 19:33:38 +00:00
|
|
|
ref="attDropZone"
|
|
|
|
class="overflow-visible card bg-base-100 shadow-xl sm:rounded-lg"
|
|
|
|
>
|
|
|
|
<div class="px-4 py-5 sm:px-6">
|
|
|
|
<h3 class="text-lg font-medium leading-6">Attachments</h3>
|
|
|
|
<p class="text-xs">Changes to attachments will be saved immediately</p>
|
|
|
|
</div>
|
|
|
|
<div class="border-t border-gray-300 p-4">
|
|
|
|
<div v-if="attDropZoneActive" class="grid grid-cols-4 gap-4">
|
|
|
|
<DropZone @drop="dropPhoto"> Photo </DropZone>
|
|
|
|
<DropZone @drop="dropWarranty"> Warranty </DropZone>
|
|
|
|
<DropZone @drop="dropManual"> Manual </DropZone>
|
|
|
|
<DropZone @drop="dropAttachment"> Attachment </DropZone>
|
2022-10-16 03:45:36 +00:00
|
|
|
<DropZone @drop="dropReceipt"> Receipt </DropZone>
|
2022-09-24 19:33:38 +00:00
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
v-else
|
|
|
|
class="h-24 w-full border-2 border-primary border-dashed grid place-content-center"
|
|
|
|
@click="clickUpload"
|
|
|
|
>
|
|
|
|
<input ref="refAttachmentInput" hidden type="file" @change="uploadImage" />
|
|
|
|
<p>Drag and drop files here or click to select files</p>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="border-t border-gray-300 p-4">
|
|
|
|
<ul role="list" class="divide-y divide-gray-400 rounded-md border border-gray-400">
|
|
|
|
<li
|
|
|
|
v-for="attachment in item.attachments"
|
|
|
|
:key="attachment.id"
|
|
|
|
class="grid grid-cols-6 justify-between py-3 pl-3 pr-4 text-sm"
|
|
|
|
>
|
|
|
|
<p class="my-auto col-span-4">
|
|
|
|
{{ attachment.document.title }}
|
|
|
|
</p>
|
|
|
|
<p class="my-auto">
|
|
|
|
{{ capitalize(attachment.type) }}
|
|
|
|
</p>
|
|
|
|
<div class="flex gap-2 justify-end">
|
|
|
|
<div class="tooltip" data-tip="Delete">
|
|
|
|
<button class="btn btn-sm btn-square" @click="deleteAttachment(attachment.id)">
|
|
|
|
<Icon name="mdi-delete" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="tooltip" data-tip="Edit">
|
|
|
|
<button class="btn btn-sm btn-square" @click="openAttachmentEditDialog(attachment)">
|
|
|
|
<Icon name="mdi-pencil" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-01-22 06:15:23 +00:00
|
|
|
<div v-if="preferences.editorAdvancedView" class="overflow-visible card bg-base-100 shadow-xl sm:rounded-lg">
|
2022-09-12 22:47:27 +00:00
|
|
|
<div class="px-4 py-5 sm:px-6">
|
|
|
|
<h3 class="text-lg font-medium leading-6">Purchase Details</h3>
|
|
|
|
</div>
|
|
|
|
<div class="border-t border-gray-300 sm:p-0">
|
|
|
|
<div
|
|
|
|
v-for="field in purchaseFields"
|
|
|
|
:key="field.ref"
|
|
|
|
class="sm:divide-y sm:divide-gray-300 grid grid-cols-1"
|
|
|
|
>
|
|
|
|
<div class="pt-2 px-4 pb-4 sm:px-6 border-b border-gray-300">
|
|
|
|
<FormTextArea v-if="field.type === 'textarea'" v-model="item[field.ref]" :label="field.label" inline />
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'text'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'number'"
|
|
|
|
v-model.number="item[field.ref]"
|
|
|
|
type="number"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormDatePicker
|
|
|
|
v-else-if="field.type === 'date'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormCheckbox
|
|
|
|
v-else-if="field.type === 'checkbox'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-07 05:58:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-01-22 06:15:23 +00:00
|
|
|
<div v-if="preferences.editorAdvancedView" class="overflow-visible card bg-base-100 shadow-xl sm:rounded-lg">
|
2022-09-12 22:47:27 +00:00
|
|
|
<div class="px-4 py-5 sm:px-6">
|
|
|
|
<h3 class="text-lg font-medium leading-6">Warranty Details</h3>
|
|
|
|
</div>
|
|
|
|
<div class="border-t border-gray-300 sm:p-0">
|
|
|
|
<div
|
|
|
|
v-for="field in warrantyFields"
|
|
|
|
:key="field.ref"
|
|
|
|
class="sm:divide-y sm:divide-gray-300 grid grid-cols-1"
|
|
|
|
>
|
|
|
|
<div class="pt-2 px-4 pb-4 sm:px-6 border-b border-gray-300">
|
|
|
|
<FormTextArea v-if="field.type === 'textarea'" v-model="item[field.ref]" :label="field.label" inline />
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'text'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'number'"
|
|
|
|
v-model.number="item[field.ref]"
|
|
|
|
type="number"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormDatePicker
|
|
|
|
v-else-if="field.type === 'date'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormCheckbox
|
|
|
|
v-else-if="field.type === 'checkbox'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-07 05:58:59 +00:00
|
|
|
</div>
|
2022-09-12 22:47:27 +00:00
|
|
|
|
2023-01-22 06:15:23 +00:00
|
|
|
<div v-if="preferences.editorAdvancedView" class="overflow-visible card bg-base-100 shadow-xl sm:rounded-lg">
|
2022-09-12 22:47:27 +00:00
|
|
|
<div class="px-4 py-5 sm:px-6">
|
|
|
|
<h3 class="text-lg font-medium leading-6">Sold Details</h3>
|
|
|
|
</div>
|
|
|
|
<div class="border-t border-gray-300 sm:p-0">
|
|
|
|
<div v-for="field in soldFields" :key="field.ref" class="sm:divide-y sm:divide-gray-300 grid grid-cols-1">
|
|
|
|
<div class="pt-2 pb-4 px-4 sm:px-6 border-b border-gray-300">
|
|
|
|
<FormTextArea v-if="field.type === 'textarea'" v-model="item[field.ref]" :label="field.label" inline />
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'text'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormTextField
|
|
|
|
v-else-if="field.type === 'number'"
|
|
|
|
v-model.number="item[field.ref]"
|
|
|
|
type="number"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormDatePicker
|
|
|
|
v-else-if="field.type === 'date'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
<FormCheckbox
|
|
|
|
v-else-if="field.type === 'checkbox'"
|
|
|
|
v-model="item[field.ref]"
|
|
|
|
:label="field.label"
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-07 05:58:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-12 22:47:27 +00:00
|
|
|
</section>
|
2023-01-19 05:44:06 +00:00
|
|
|
</div>
|
2022-09-07 05:58:59 +00:00
|
|
|
</template>
|