Finishing UI - getting API ready.
This commit is contained in:
parent
bd197bee9e
commit
e8e4dd5c90
|
@ -1,5 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { ModalContent, Toggle, Input, Layout, Dropzone } from "@budibase/bbui"
|
import { ModalContent, Toggle, Input, Layout, Dropzone, notifications } from "@budibase/bbui"
|
||||||
|
import { API } from "api"
|
||||||
|
import { automationStore, store } from "../../builderStore"
|
||||||
|
|
||||||
export let app
|
export let app
|
||||||
|
|
||||||
|
@ -8,8 +10,22 @@
|
||||||
password
|
password
|
||||||
let file
|
let file
|
||||||
|
|
||||||
function updateApp() {
|
async function updateApp() {
|
||||||
console.log("confirm")
|
try {
|
||||||
|
let data = new FormData()
|
||||||
|
data.append("appExport", file)
|
||||||
|
if (encrypted) {
|
||||||
|
data.append("encryptionPassword", password.trim())
|
||||||
|
}
|
||||||
|
const appId = app.devId
|
||||||
|
await API.updateAppFromExport(appId, data)
|
||||||
|
const pkg = await API.fetchAppPackage(appId)
|
||||||
|
await store.actions.initialise(pkg)
|
||||||
|
await automationStore.actions.fetch()
|
||||||
|
notifications.success("App updated successfully")
|
||||||
|
} catch (err) {
|
||||||
|
notifications.error(`Failed to update app - ${err.message || err}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { sdk } from "@budibase/shared-core"
|
||||||
|
|
||||||
export const buildAppEndpoints = API => ({
|
export const buildAppEndpoints = API => ({
|
||||||
/**
|
/**
|
||||||
* Fetches screen definition for an app.
|
* Fetches screen definition for an app.
|
||||||
|
@ -81,6 +83,22 @@ export const buildAppEndpoints = API => ({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an application using an export - the body
|
||||||
|
* should be of type FormData, with a "file" and a "password" if encrypted.
|
||||||
|
* @param appId The ID of the app to update - this will always be
|
||||||
|
* converted to development ID.
|
||||||
|
* @param body a FormData body with a file and password.
|
||||||
|
*/
|
||||||
|
updateAppFromExport: async (appId, body) => {
|
||||||
|
const devId = sdk.applications.getDevAppID(appId)
|
||||||
|
return await API.post({
|
||||||
|
url: `/api/applications/${devId}/import`,
|
||||||
|
body,
|
||||||
|
json: false,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports an export of all apps.
|
* Imports an export of all apps.
|
||||||
* @param apps the FormData containing the apps to import
|
* @param apps the FormData containing the apps to import
|
||||||
|
|
|
@ -575,7 +575,16 @@ export async function sync(ctx: UserCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateWithExport(ctx: UserCtx) {}
|
export async function importToApp(ctx: UserCtx) {
|
||||||
|
const { appId } = ctx.params
|
||||||
|
const appExport = ctx.request.files?.appExport
|
||||||
|
const password = ctx.request.body.encryptionPassword
|
||||||
|
if (!appExport) {
|
||||||
|
ctx.throw(400, "Must supply app export to import")
|
||||||
|
}
|
||||||
|
console.log(appExport)
|
||||||
|
ctx.body = { message: "app updated" }
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateAppPackage(appPackage: any, appId: any) {
|
export async function updateAppPackage(appPackage: any, appId: any) {
|
||||||
return context.doInAppContext(appId, async () => {
|
return context.doInAppContext(appId, async () => {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import * as deploymentController from "../controllers/deploy"
|
||||||
import authorized from "../../middleware/authorized"
|
import authorized from "../../middleware/authorized"
|
||||||
import { permissions } from "@budibase/backend-core"
|
import { permissions } from "@budibase/backend-core"
|
||||||
import { applicationValidator } from "./utils/validators"
|
import { applicationValidator } from "./utils/validators"
|
||||||
|
import { importToApp } from "../controllers/application"
|
||||||
|
|
||||||
const router: Router = new Router()
|
const router: Router = new Router()
|
||||||
|
|
||||||
|
@ -59,9 +60,9 @@ router
|
||||||
controller.destroy
|
controller.destroy
|
||||||
)
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/applications/:appId/update",
|
"/api/applications/:appId/import",
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
controller.updateWithExport
|
controller.importToApp
|
||||||
)
|
)
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|
Loading…
Reference in New Issue