fixes for templates, ensured iframetemplate fires ready event

This commit is contained in:
Martin McKeaveney 2021-11-09 17:40:31 +01:00
parent 8b7f3a461f
commit 50b547e0a9
6 changed files with 40 additions and 9 deletions

View File

@ -1,9 +1,16 @@
<script> <script>
import { Icon, Modal, notifications, ModalContent } from "@budibase/bbui" import {
Icon,
Input,
Modal,
notifications,
ModalContent,
} from "@budibase/bbui"
import { store } from "builderStore" import { store } from "builderStore"
import api from "builderStore/api" import api from "builderStore/api"
let revertModal let revertModal
let appName
$: appId = $store.appId $: appId = $store.appId
@ -33,10 +40,17 @@
<Icon name="Revert" hoverable on:click={revertModal.show} /> <Icon name="Revert" hoverable on:click={revertModal.show} />
<Modal bind:this={revertModal}> <Modal bind:this={revertModal}>
<ModalContent title="Revert Changes" confirmText="Revert" onConfirm={revert}> <ModalContent
title="Revert Changes"
confirmText="Revert"
onConfirm={revert}
disabled={appName !== $store.name}
>
<span <span
>The changes you have made will be deleted and the application reverted >The changes you have made will be deleted and the application reverted
back to its production state.</span back to its production state.</span
> >
<span>Please enter your app name to continue.</span>
<Input bind:value={appName} />
</ModalContent> </ModalContent>
</Modal> </Modal>

View File

@ -69,6 +69,7 @@
theme: $store.theme, theme: $store.theme,
customTheme: $store.customTheme, customTheme: $store.customTheme,
previewDevice: $store.previewDevice, previewDevice: $store.previewDevice,
messagePassing: $store.clientFeatures.messagePassing
} }
// Saving pages and screens to the DB causes them to have _revs. // Saving pages and screens to the DB causes them to have _revs.

View File

@ -65,6 +65,7 @@ export default `
theme, theme,
customTheme, customTheme,
previewDevice, previewDevice,
messagePassing
} = parsed } = parsed
// Set some flags so the app knows we're in the builder // Set some flags so the app knows we're in the builder
@ -89,7 +90,11 @@ export default `
throw "The client library couldn't be loaded" throw "The client library couldn't be loaded"
} }
} catch (error) { } catch (error) {
window.parent.postMessage({ type: "error", error }) if (messagePassing) {
window.parent.postMessage({ type: "error", error })
} else {
window.dispatchEvent(new CustomEvent("error", { detail: error }))
}
} }
} }
@ -97,7 +102,9 @@ export default `
window.addEventListener("keydown", evt => { window.addEventListener("keydown", evt => {
window.parent.postMessage({ type: "keydown", key: event.key }) window.parent.postMessage({ type: "keydown", key: event.key })
}) })
window.parent.postMessage({ type: "ready" }) window.parent.postMessage({ type: "ready" })
window.dispatchEvent(new Event("ready"))
</script> </script>
</head> </head>
<body/> <body/>

View File

@ -157,6 +157,11 @@
} }
return title return title
} }
async function onCancel() {
template = null
await auth.setInitInfo({})
}
</script> </script>
{#if showTemplateSelection} {#if showTemplateSelection}
@ -186,7 +191,7 @@
title={getModalTitle()} title={getModalTitle()}
confirmText={template?.fromFile ? "Import app" : "Create app"} confirmText={template?.fromFile ? "Import app" : "Create app"}
onConfirm={createNewApp} onConfirm={createNewApp}
onCancel={inline ? () => (template = null) : null} onCancel={inline ? onCancel : null}
cancelText={inline ? "Back" : undefined} cancelText={inline ? "Back" : undefined}
showCloseIcon={!inline} showCloseIcon={!inline}
disabled={!valid} disabled={!valid}

View File

@ -80,6 +80,10 @@ export function createAuthStore() {
} }
} }
async function setInitInfo(info) {
await api.post(`/api/global/auth/init`, info)
}
return { return {
subscribe: store.subscribe, subscribe: store.subscribe,
setOrganisation: setOrganisation, setOrganisation: setOrganisation,
@ -87,9 +91,7 @@ export function createAuthStore() {
const response = await api.get(`/api/global/auth/init`) const response = await api.get(`/api/global/auth/init`)
return await response.json() return await response.json()
}, },
setInitInfo: async info => { setInitInfo,
await api.post(`/api/global/auth/init`, info)
},
checkQueryString: async () => { checkQueryString: async () => {
const urlParams = new URLSearchParams(window.location.search) const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("tenantId")) { if (urlParams.has("tenantId")) {
@ -129,6 +131,7 @@ export function createAuthStore() {
throw "Unable to create logout" throw "Unable to create logout"
} }
await response.json() await response.json()
await setInitInfo({})
setUser(null) setUser(null)
}, },
updateSelf: async fields => { updateSelf: async fields => {

View File

@ -323,7 +323,7 @@ exports.delete = async ctx => {
ctx.body = result ctx.body = result
} }
exports.sync = async ctx => { exports.sync = async (ctx, next) => {
const appId = ctx.params.appId const appId = ctx.params.appId
if (!isDevAppID(appId)) { if (!isDevAppID(appId)) {
ctx.throw(400, "This action cannot be performed for production apps") ctx.throw(400, "This action cannot be performed for production apps")
@ -336,10 +336,11 @@ exports.sync = async ctx => {
if (info.error) throw info.error if (info.error) throw info.error
} catch (err) { } catch (err) {
// the database doesn't exist. Don't replicate // the database doesn't exist. Don't replicate
ctx.status = 200
ctx.body = { ctx.body = {
message: "App sync not required, app not deployed.", message: "App sync not required, app not deployed.",
} }
return return next()
} }
const replication = new Replication({ const replication = new Replication({