Add attachments to service, maintenance, fuel and parts records
Documents already carried a single optional file: upload, download, detach,
access-checked on every request and proxied through this server, so PocketBase's
files are never public URLs. Service records, workshop visits, refills and
catalog parts all want the same thing — a receipt, an invoice, a photo of the
box — so extend it to them.
Rather than copy the document handlers four more times, lift them into one
shared layer. Every attachable collection has a car relation and a file field,
which is what lets a single set of handlers authorize and serve all of them. An
upload finishes by delegating to the collection's own GET handler, so the
response carries the full record — derived fields and all — exactly as a re-read
would. The web side gets the same treatment: one picker component and one
upload-after-save helper behind all five forms. Net effect is five features for
about the cost of the one that was already there.
Alongside:
- parts gain a notes field
- Reminders moves behind Parts catalog in the car detail tabs
- the changed-part labels spell out in full ("Oil & Oil filter" rather than
"Oil & filter"), and the form and table now agree
The PocketBase schema must be migrated before the new attachments work:
scripts/setup-pocketbase.mjs adds the file fields and parts.notes. It is
additive and safe to re-run.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
e64c89a564
commit
07192f1238
@@ -1,6 +1,8 @@
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import { api } from "../api";
|
||||
import { applyAttachment } from "../lib/attachment.js";
|
||||
import AttachmentField from "./AttachmentField.vue";
|
||||
import Modal from "./Modal.vue";
|
||||
|
||||
const props = defineProps({
|
||||
@@ -16,8 +18,12 @@ const form = ref({
|
||||
name: props.part?.name ?? "",
|
||||
partNumber: props.part?.partNumber ?? "",
|
||||
category: props.part?.category ?? "",
|
||||
notes: props.part?.notes ?? "",
|
||||
});
|
||||
|
||||
const file = ref(null);
|
||||
const removeFile = ref(false);
|
||||
|
||||
async function submit() {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
@@ -27,11 +33,15 @@ async function submit() {
|
||||
name: form.value.name.trim(),
|
||||
partNumber: form.value.partNumber.trim(),
|
||||
category: form.value.category.trim(),
|
||||
notes: form.value.notes.trim(),
|
||||
};
|
||||
const saved = isEdit
|
||||
? await api.updatePart(props.part.id, payload)
|
||||
: await api.createPart(payload);
|
||||
emit("saved", saved);
|
||||
emit("saved", await applyAttachment(api.files.parts, saved, {
|
||||
file: file.value,
|
||||
remove: removeFile.value,
|
||||
}));
|
||||
} catch (e) {
|
||||
error.value = e.message;
|
||||
} finally {
|
||||
@@ -52,6 +62,11 @@ async function submit() {
|
||||
<label class="dh-label">Part number</label>
|
||||
<input v-model="form.partNumber" placeholder="04152-YZZA7" class="dh-input data" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="dh-label">Notes</label>
|
||||
<input v-model="form.notes" placeholder="Fits 2015–2020 · buy in pairs" class="dh-input" />
|
||||
</div>
|
||||
<AttachmentField v-model:file="file" v-model:remove="removeFile" :record="part" legend="Photo or spec sheet" />
|
||||
<div class="mt-4 flex justify-end gap-2">
|
||||
<button type="button" class="dh-btn dh-btn-ghost" @click="emit('close')">Cancel</button>
|
||||
<button type="submit" :disabled="saving" class="dh-btn dh-btn-primary">
|
||||
|
||||
Reference in New Issue
Block a user