From ce9cad33622ee4aeccdb28d1eb4cea780c9bdd56 Mon Sep 17 00:00:00 2001 From: arashsheyda Date: Fri, 21 Apr 2023 12:56:59 +0300 Subject: [PATCH] feat: create document --- client/components/DatabaseDetail.vue | 58 ++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/client/components/DatabaseDetail.vue b/client/components/DatabaseDetail.vue index c0c44b0..8e57b53 100644 --- a/client/components/DatabaseDetail.vue +++ b/client/components/DatabaseDetail.vue @@ -13,11 +13,22 @@ const documents = computedAsync(async () => { const fields = computed(() => { if (documents.value && documents.value.length > 0) return Object.keys(documents.value[0]) + return [] }) const editing = ref(false) const selectedDocument = ref() +function addDocument() { + editing.value = true + // add newDocument with fields as keys + selectedDocument.value = {} + for (const field of fields.value) { + if (field !== '_id') + selectedDocument.value[field] = '' + } +} + function editDocument(document: any) { if (editing.value) return @@ -26,6 +37,13 @@ function editDocument(document: any) { } async function saveDocument() { + await rpc.createDocument(props.collection, selectedDocument.value) + editing.value = false + selectedDocument.value = undefined + documents.value = await rpc.listDocuments(props.collection) +} + +async function updateDocument() { // TODO: validate & show errors await rpc.updateDocument(props.collection, selectedDocument.value) editing.value = false @@ -46,10 +64,10 @@ async function deleteDocument(document: any) {