1
0
Fork 0
mirror of synced 2024-07-16 19:56:10 +12:00

wip: add record saving functionality

This commit is contained in:
kevmodrome 2020-09-28 09:09:08 +02:00
parent 2df74f1b99
commit 38a2d9df14
2 changed files with 24 additions and 3 deletions

View file

@ -37,7 +37,7 @@
"dependencies": {
"@beyonk/svelte-googlemaps": "^2.2.0",
"@budibase/bbui": "^1.34.6",
"@budibase/svelte-ag-grid": "^0.0.6",
"@budibase/svelte-ag-grid": "^0.0.8",
"@fortawesome/fontawesome-free": "^5.14.0",
"@svelteschool/svelte-forms": "^0.7.0",
"britecharts": "^2.16.1",
@ -48,4 +48,4 @@
"svelte-flatpickr": "^2.4.0",
"svelte-fusioncharts": "^1.0.0"
}
}
}

View file

@ -6,6 +6,7 @@
import AgGrid from "@budibase/svelte-ag-grid"
import InputForm from "./InputForm.svelte"
export let _bb
export let datasource = {}
let dataLoaded = false
@ -13,6 +14,10 @@
let columnDefs
onMount(async () => {
console.log(datasource)
const jsonModel = await _bb.api.get(`/api/models/${datasource.modelId}`)
const model = await jsonModel.json()
console.log(model)
if (!isEmpty(datasource)) {
data = await fetchData(datasource)
if (data) {
@ -45,14 +50,30 @@
// Send off data here and update to display in grid component
console.log("Submitting:", e.detail)
}
const handleUpdate = ({ detail }) => {
console.log(detail)
data[detail.row] = detail.data
updateRecord(detail.data)
}
const updateRecord = async record => {
const response = await _bb.api.patch(
`/api/${record.modelId}/records/${record._id}`,
record
)
const json = await response.json()
console.log(json)
}
</script>
<div class="container">
{#if dataLoaded}
<AgGrid bind:data {columnDefs} />
<AgGrid {data} {columnDefs} on:update={handleUpdate} />
<InputForm fields={columnDefs} on:submit={handleSubmit} />
{/if}
</div>
<pre>{JSON.stringify(data, 0, 2)}</pre>
<style>
.container {