1
0
Fork 0
mirror of synced 2024-06-16 09:25:12 +12:00

adds functionality to update name and description of app

This commit is contained in:
kevmodrome 2020-06-29 17:18:43 +02:00
parent 712e3ffea0
commit 4f6283eef2
No known key found for this signature in database
GPG key ID: E8F9CD141E63BF38
3 changed files with 45 additions and 2 deletions

View file

@ -1,15 +1,39 @@
<script>
import { Input, TextArea, Button } from "@budibase/bbui"
import { store } from "builderStore"
import api from "builderStore/api"
import Title from "../TabTitle.svelte"
async function updateApplication(data) {
const response = await api.put(`/api/${$store.appId}/appPackage`, data)
const app = await response.json()
store.update(state => {
state = {
...state,
...data,
}
return state
})
}
</script>
<Title>General</Title>
<div class="container">
<div class="background">
<Input thin edit placeholder="Enter your name" label="Name" />
<Input
on:save={e => updateApplication({ name: e.detail })}
thin
edit
value={$store.name}
label="Name" />
</div>
<div class="background">
<TextArea thin edit placeholder="Enter your name" label="Name" />
<TextArea
on:save={e => updateApplication({ description: e.detail })}
thin
edit
value={$store.description}
label="Name" />
</div>
</div>

View file

@ -18,6 +18,8 @@ exports.fetch = async function(ctx) {
key: ["app"],
})
console.log("Apps: ", body)
ctx.body = body.rows.map(row => row.doc)
}
@ -90,6 +92,22 @@ exports.create = async function(ctx) {
ctx.message = `Application ${ctx.request.body.name} created successfully`
}
exports.update = async function(ctx) {
const clientId = await lookupClientId(ctx.params.applicationId)
const db = new CouchDB(ClientDb.name(clientId))
const application = await db.get(ctx.params.applicationId)
const data = ctx.request.body
const newData = { ...application, ...data }
const response = await db.put(newData)
data._rev = response.rev
ctx.status = 200
ctx.message = `Application ${application.name} updated successfully.`
ctx.body = response
}
const createEmptyAppPackage = async (ctx, app) => {
const templateFolder = resolve(
__dirname,

View file

@ -12,6 +12,7 @@ router
authorized(BUILDER),
controller.fetchAppPackage
)
.put("/api/:applicationId/appPackage", authorized(BUILDER), controller.update)
.post("/api/applications", authorized(BUILDER), controller.create)
module.exports = router