2021-05-16 22:25:37 +02:00
|
|
|
<script>
|
|
|
|
import { onMount, onDestroy } from "svelte"
|
|
|
|
import { Button, Modal, notifications, ModalContent } from "@budibase/bbui"
|
|
|
|
import api from "builderStore/api"
|
|
|
|
import analytics from "analytics"
|
|
|
|
|
|
|
|
const DeploymentStatus = {
|
|
|
|
SUCCESS: "SUCCESS",
|
|
|
|
PENDING: "PENDING",
|
|
|
|
FAILURE: "FAILURE",
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:09:57 +02:00
|
|
|
const POLL_INTERVAL = 10000
|
2021-05-16 22:25:37 +02:00
|
|
|
|
|
|
|
let feedbackModal
|
|
|
|
let deployments = []
|
|
|
|
let poll
|
|
|
|
let publishModal
|
|
|
|
|
|
|
|
async function deployApp() {
|
|
|
|
try {
|
|
|
|
const response = await api.post("/api/deploy")
|
|
|
|
if (response.status !== 200) {
|
2021-05-24 15:08:55 +02:00
|
|
|
throw new Error(`status ${response.status}`)
|
2021-05-24 15:08:08 +02:00
|
|
|
} else {
|
|
|
|
notifications.success(`Application published successfully`)
|
2021-05-16 22:25:37 +02:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
analytics.captureException(err)
|
2021-05-24 15:08:08 +02:00
|
|
|
notifications.error(`Error publishing app: ${err}`)
|
2021-05-16 22:25:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchDeployments() {
|
|
|
|
try {
|
|
|
|
const response = await api.get(`/api/deployments`)
|
|
|
|
const json = await response.json()
|
|
|
|
|
|
|
|
if (deployments.length > 0) {
|
|
|
|
checkIncomingDeploymentStatus(deployments, json)
|
|
|
|
}
|
|
|
|
|
|
|
|
deployments = json
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
clearInterval(poll)
|
|
|
|
notifications.error(
|
|
|
|
"Error fetching deployment history. Please try again."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Required to check any updated deployment statuses between polls
|
|
|
|
function checkIncomingDeploymentStatus(current, incoming) {
|
|
|
|
for (let incomingDeployment of incoming) {
|
2021-05-17 22:43:50 +02:00
|
|
|
if (
|
|
|
|
incomingDeployment.status === DeploymentStatus.FAILURE ||
|
|
|
|
incomingDeployment.status === DeploymentStatus.SUCCESS
|
|
|
|
) {
|
2021-05-16 22:25:37 +02:00
|
|
|
const currentDeployment = current.find(
|
|
|
|
deployment => deployment._id === incomingDeployment._id
|
|
|
|
)
|
|
|
|
|
|
|
|
// We have just been notified of an ongoing deployments status change
|
|
|
|
if (
|
|
|
|
!currentDeployment ||
|
|
|
|
currentDeployment.status === DeploymentStatus.PENDING
|
|
|
|
) {
|
|
|
|
if (incomingDeployment.status === DeploymentStatus.FAILURE) {
|
|
|
|
notifications.error(incomingDeployment.err)
|
|
|
|
} else {
|
2021-05-17 22:43:50 +02:00
|
|
|
notifications.send(
|
|
|
|
"Published to Production.",
|
|
|
|
"success",
|
|
|
|
"CheckmarkCircle"
|
|
|
|
)
|
2021-05-16 22:25:37 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-17 22:43:50 +02:00
|
|
|
}
|
2021-05-16 22:25:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
fetchDeployments()
|
|
|
|
poll = setInterval(fetchDeployments, POLL_INTERVAL)
|
|
|
|
})
|
|
|
|
|
|
|
|
onDestroy(() => clearInterval(poll))
|
|
|
|
</script>
|
|
|
|
|
2021-05-17 22:43:50 +02:00
|
|
|
<Button secondary on:click={publishModal.show}>Publish</Button>
|
2021-06-10 13:07:39 +02:00
|
|
|
<Modal bind:this={feedbackModal}>
|
|
|
|
<ModalContent
|
|
|
|
title="Enjoying Budibase?"
|
|
|
|
size="L"
|
|
|
|
showConfirmButton={false}
|
|
|
|
showCancelButton={false}
|
2021-07-21 12:28:38 +02:00
|
|
|
/>
|
2021-06-10 13:07:39 +02:00
|
|
|
</Modal>
|
2021-05-16 22:25:37 +02:00
|
|
|
<Modal bind:this={publishModal}>
|
2021-05-17 22:43:50 +02:00
|
|
|
<ModalContent
|
|
|
|
title="Publish to Production"
|
|
|
|
confirmText="Publish"
|
|
|
|
onConfirm={deployApp}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
>The changes you have made will be published to the production version of
|
|
|
|
the application.</span
|
|
|
|
>
|
|
|
|
</ModalContent>
|
2021-05-16 22:25:37 +02:00
|
|
|
</Modal>
|