mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 08:40:28 +00:00
add edit support for maintenance logs
This commit is contained in:
parent
0364e40a58
commit
f8c0fef9b1
1 changed files with 59 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DatePicker from "~~/components/Form/DatePicker.vue";
|
import DatePicker from "~~/components/Form/DatePicker.vue";
|
||||||
import { StatsFormat } from "~~/components/global/StatCard/types";
|
import { StatsFormat } from "~~/components/global/StatCard/types";
|
||||||
import { ItemOut } from "~~/lib/api/types/data-contracts";
|
import { ItemOut, MaintenanceEntry } from "~~/lib/api/types/data-contracts";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
item: ItemOut;
|
item: ItemOut;
|
||||||
|
@ -45,6 +45,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const entry = reactive({
|
const entry = reactive({
|
||||||
|
id: null as string | null,
|
||||||
modal: false,
|
modal: false,
|
||||||
name: "",
|
name: "",
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
|
@ -56,7 +57,21 @@
|
||||||
entry.modal = true;
|
entry.modal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetEntry() {
|
||||||
|
entry.id = null;
|
||||||
|
entry.name = "";
|
||||||
|
entry.date = new Date();
|
||||||
|
entry.description = "";
|
||||||
|
entry.cost = "";
|
||||||
|
}
|
||||||
|
|
||||||
async function createEntry() {
|
async function createEntry() {
|
||||||
|
if (entry.id) {
|
||||||
|
editEntry();
|
||||||
|
resetEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { error } = await api.items.maintenance.create(props.item.id, {
|
const { error } = await api.items.maintenance.create(props.item.id, {
|
||||||
name: entry.name,
|
name: entry.name,
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
|
@ -72,6 +87,7 @@
|
||||||
entry.modal = false;
|
entry.modal = false;
|
||||||
|
|
||||||
refreshLog();
|
refreshLog();
|
||||||
|
resetEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
|
@ -90,6 +106,39 @@
|
||||||
}
|
}
|
||||||
refreshLog();
|
refreshLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openEditDialog(e: MaintenanceEntry) {
|
||||||
|
entry.modal = true;
|
||||||
|
entry.id = e.id;
|
||||||
|
entry.name = e.name;
|
||||||
|
entry.date = new Date(e.date);
|
||||||
|
entry.description = e.description;
|
||||||
|
entry.cost = e.cost;
|
||||||
|
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function editEntry() {
|
||||||
|
if (!entry.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error } = await api.items.maintenance.update(props.item.id, entry.id, {
|
||||||
|
name: entry.name,
|
||||||
|
date: entry.date,
|
||||||
|
description: entry.description,
|
||||||
|
cost: entry.cost,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
toast.error("Failed to update entry");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.modal = false;
|
||||||
|
|
||||||
|
refreshLog();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -102,11 +151,11 @@
|
||||||
<FormTextArea v-model="entry.description" label="Notes" />
|
<FormTextArea v-model="entry.description" label="Notes" />
|
||||||
<FormTextField v-model="entry.cost" autofocus label="Cost" />
|
<FormTextField v-model="entry.cost" autofocus label="Cost" />
|
||||||
<div class="py-2 flex justify-end">
|
<div class="py-2 flex justify-end">
|
||||||
<BaseButton type="submit" class="ml-2">
|
<BaseButton type="submit" class="ml-2 mt-2">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<Icon name="mdi-post" />
|
<Icon name="mdi-post" />
|
||||||
</template>
|
</template>
|
||||||
Create
|
{{ entry.id ? "Update" : "Create" }}
|
||||||
</BaseButton>
|
</BaseButton>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -154,7 +203,13 @@
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<Markdown :source="e.description" />
|
<Markdown :source="e.description" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end p-4">
|
<div class="flex justify-end p-4 gap-1">
|
||||||
|
<BaseButton size="sm" @click="openEditDialog(e)">
|
||||||
|
<template #icon>
|
||||||
|
<Icon name="mdi-edit" />
|
||||||
|
</template>
|
||||||
|
Edit
|
||||||
|
</BaseButton>
|
||||||
<BaseButton size="sm" @click="deleteEntry(e.id)">
|
<BaseButton size="sm" @click="deleteEntry(e.id)">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<Icon name="mdi-delete" />
|
<Icon name="mdi-delete" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue