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> <script>
import { Input, TextArea, Button } from "@budibase/bbui" import { Input, TextArea, Button } from "@budibase/bbui"
import { store } from "builderStore"
import api from "builderStore/api"
import Title from "../TabTitle.svelte" 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> </script>
<Title>General</Title> <Title>General</Title>
<div class="container"> <div class="container">
<div class="background"> <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>
<div class="background"> <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>
</div> </div>

View File

@ -18,6 +18,8 @@ exports.fetch = async function(ctx) {
key: ["app"], key: ["app"],
}) })
console.log("Apps: ", body)
ctx.body = body.rows.map(row => row.doc) 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` 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 createEmptyAppPackage = async (ctx, app) => {
const templateFolder = resolve( const templateFolder = resolve(
__dirname, __dirname,

View File

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