add restore funtionality
This commit is contained in:
parent
32ef7ff1a9
commit
2a430468f6
|
@ -1,5 +1,12 @@
|
||||||
<script>
|
<script>
|
||||||
import { ActionButton, ActionMenu, MenuItem, Icon } from "@budibase/bbui"
|
import {
|
||||||
|
ActionButton,
|
||||||
|
ActionMenu,
|
||||||
|
MenuItem,
|
||||||
|
Icon,
|
||||||
|
Heading,
|
||||||
|
Body,
|
||||||
|
} from "@budibase/bbui"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
|
@ -7,13 +14,16 @@
|
||||||
|
|
||||||
let deleteDialog
|
let deleteDialog
|
||||||
let restoreDialog
|
let restoreDialog
|
||||||
let editDialog
|
|
||||||
|
let restoreBackupName
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
const onClickRestore = () => {
|
const onClickRestore = () => {
|
||||||
dispatch("buttonclick", {
|
dispatch("buttonclick", {
|
||||||
type: "backupRestore",
|
type: "backupRestore",
|
||||||
backupId: row._id,
|
backupId: row._id,
|
||||||
|
restoreBackupName,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +43,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MenuItem on:click={deleteDialog.show} icon="Delete">Delete</MenuItem>
|
<MenuItem on:click={deleteDialog.show} icon="Delete">Delete</MenuItem>
|
||||||
<MenuItem on:click={editDialog.show} icon="Edit">Edit</MenuItem>
|
<MenuItem icon="Edit">Edit</MenuItem>
|
||||||
|
<MenuItem icon="Edit">Download</MenuItem>
|
||||||
</ActionMenu>
|
</ActionMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -55,8 +66,8 @@
|
||||||
title="Confirm Restore"
|
title="Confirm Restore"
|
||||||
warning={false}
|
warning={false}
|
||||||
>
|
>
|
||||||
Are you sure you wish to restore this backup
|
<Heading size="S">{row.name}</Heading>
|
||||||
<i>{row.name}</i>. This action cannot be undone.
|
<Body size="S">{new Date(row.timestamp).toLocaleString()}</Body>
|
||||||
</ConfirmDialog>
|
</ConfirmDialog>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -80,9 +80,21 @@
|
||||||
|
|
||||||
function flattenBackups(backups) {
|
function flattenBackups(backups) {
|
||||||
let flattened = backups.map(backup => {
|
let flattened = backups.map(backup => {
|
||||||
|
if (!backup.name) {
|
||||||
|
if (backup.trigger === "publish") {
|
||||||
|
backup.name = "Published Backup"
|
||||||
|
} else if (backup.trigger === "scheduled") {
|
||||||
|
backup.name = "Scheduled Backup"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backup.type === "restore") {
|
||||||
|
backup.trigger = "restore"
|
||||||
|
backup.name = "Restored"
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...backup,
|
...backup,
|
||||||
days: getDaysBetween(backup.createdAt),
|
days: getDaysBetween(backup.timestamp),
|
||||||
...backup?.contents,
|
...backup?.contents,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -123,19 +135,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectBackup({ detail }) {
|
|
||||||
console.log(detail)
|
|
||||||
}
|
|
||||||
async function deleteBackup(backupId) {
|
async function deleteBackup(backupId) {
|
||||||
await backups.deleteBackup({ appId: app.instance._id, backupId })
|
await backups.deleteBackup({ appId: app.instance._id, backupId })
|
||||||
await fetchBackups(app.instance._id, trigger, page)
|
await fetchBackups(app.instance._id, trigger, page)
|
||||||
}
|
}
|
||||||
async function restoreBackup(backupId) {
|
async function restoreBackup(backupId) {
|
||||||
console.log(backupId)
|
backups.restoreBackup({ appId: app.instance._id, backupId })
|
||||||
//backups.restoreBackup(app.instance._id, backupId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleButtonClick({ detail }) {
|
function handleButtonClick({ detail }) {
|
||||||
if (detail.type === "backupDelete") {
|
if (detail.type === "backupDelete") {
|
||||||
deleteBackup(detail.backupId)
|
deleteBackup(detail.backupId)
|
||||||
} else if (detail.type === "backupRestore") {
|
} else if (detail.type === "backupRestore") {
|
||||||
|
@ -152,6 +160,7 @@
|
||||||
placeholder="All"
|
placeholder="All"
|
||||||
label="Trigger"
|
label="Trigger"
|
||||||
options={Object.values(triggers)}
|
options={Object.values(triggers)}
|
||||||
|
bind:value={trigger}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -167,7 +176,6 @@
|
||||||
{#if backupData}
|
{#if backupData}
|
||||||
<div>
|
<div>
|
||||||
<Table
|
<Table
|
||||||
on:click={selectBackup}
|
|
||||||
{schema}
|
{schema}
|
||||||
allowSelectRows={false}
|
allowSelectRows={false}
|
||||||
allowEditColumns={false}
|
allowEditColumns={false}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
import { Icon } from "@budibase/bbui"
|
import { Icon } from "@budibase/bbui"
|
||||||
|
|
||||||
export let value
|
export let value
|
||||||
|
$: console.log(value)
|
||||||
let trigger = value.charAt(0).toUpperCase() + value.slice(1)
|
let trigger = value?.charAt(0).toUpperCase() + value?.slice(1)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="cell">
|
<div class="cell">
|
||||||
|
@ -16,6 +16,9 @@
|
||||||
{:else if value === "scheduled"}
|
{:else if value === "scheduled"}
|
||||||
<Icon name="Clock" />
|
<Icon name="Clock" />
|
||||||
<div>{trigger}</div>
|
<div>{trigger}</div>
|
||||||
|
{:else if value === "restore"}
|
||||||
|
<Icon name="Refresh" />
|
||||||
|
<div>{trigger}</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,17 @@ export const buildBackupsEndpoints = API => ({
|
||||||
/**
|
/**
|
||||||
* Gets a list of users in the current tenant.
|
* Gets a list of users in the current tenant.
|
||||||
*/
|
*/
|
||||||
searchBackups: async ({ appId, page }) => {
|
searchBackups: async ({ appId, trigger, page }) => {
|
||||||
|
const opts = {}
|
||||||
|
if (page) {
|
||||||
|
opts.page = page
|
||||||
|
}
|
||||||
|
if (trigger) {
|
||||||
|
opts.trigger = trigger.toLowerCase()
|
||||||
|
}
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: `/api/apps/${appId}/backups/search`,
|
url: `/api/apps/${appId}/backups/search`,
|
||||||
body: {
|
body: opts,
|
||||||
page,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -26,7 +31,13 @@ export const buildBackupsEndpoints = API => ({
|
||||||
|
|
||||||
updateBackup: async ({ appId, backupId }) => {
|
updateBackup: async ({ appId, backupId }) => {
|
||||||
return await API.patch({
|
return await API.patch({
|
||||||
url: `/api/apps/${appId}/backups/${backupId}}`,
|
url: `/api/apps/${appId}/backups/${backupId}`,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
restoreBackup: async ({ appId, backupId }) => {
|
||||||
|
return await API.post({
|
||||||
|
url: `/api/apps/${appId}/backups/${backupId}/import`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue