wip: add record saving functionality
This commit is contained in:
parent
2df74f1b99
commit
38a2d9df14
2 changed files with 24 additions and 3 deletions
|
@ -37,7 +37,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@beyonk/svelte-googlemaps": "^2.2.0",
|
"@beyonk/svelte-googlemaps": "^2.2.0",
|
||||||
"@budibase/bbui": "^1.34.6",
|
"@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",
|
"@fortawesome/fontawesome-free": "^5.14.0",
|
||||||
"@svelteschool/svelte-forms": "^0.7.0",
|
"@svelteschool/svelte-forms": "^0.7.0",
|
||||||
"britecharts": "^2.16.1",
|
"britecharts": "^2.16.1",
|
||||||
|
@ -48,4 +48,4 @@
|
||||||
"svelte-flatpickr": "^2.4.0",
|
"svelte-flatpickr": "^2.4.0",
|
||||||
"svelte-fusioncharts": "^1.0.0"
|
"svelte-fusioncharts": "^1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
import AgGrid from "@budibase/svelte-ag-grid"
|
import AgGrid from "@budibase/svelte-ag-grid"
|
||||||
import InputForm from "./InputForm.svelte"
|
import InputForm from "./InputForm.svelte"
|
||||||
|
|
||||||
|
export let _bb
|
||||||
export let datasource = {}
|
export let datasource = {}
|
||||||
|
|
||||||
let dataLoaded = false
|
let dataLoaded = false
|
||||||
|
@ -13,6 +14,10 @@
|
||||||
let columnDefs
|
let columnDefs
|
||||||
|
|
||||||
onMount(async () => {
|
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)) {
|
if (!isEmpty(datasource)) {
|
||||||
data = await fetchData(datasource)
|
data = await fetchData(datasource)
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -45,14 +50,30 @@
|
||||||
// Send off data here and update to display in grid component
|
// Send off data here and update to display in grid component
|
||||||
console.log("Submitting:", e.detail)
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{#if dataLoaded}
|
{#if dataLoaded}
|
||||||
<AgGrid bind:data {columnDefs} />
|
<AgGrid {data} {columnDefs} on:update={handleUpdate} />
|
||||||
<InputForm fields={columnDefs} on:submit={handleSubmit} />
|
<InputForm fields={columnDefs} on:submit={handleSubmit} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
<pre>{JSON.stringify(data, 0, 2)}</pre>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.container {
|
.container {
|
||||||
|
|
Loading…
Reference in a new issue