2022-07-06 11:02:36 +02:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
import type { Load } from '@sveltejs/kit';
|
|
|
|
function checkConfiguration(database: any): any {
|
|
|
|
let configurationPhase = null;
|
|
|
|
if (!database.type) {
|
|
|
|
configurationPhase = 'type';
|
|
|
|
} else if (!database.version) {
|
|
|
|
configurationPhase = 'version';
|
|
|
|
} else if (!database.destinationDockerId) {
|
|
|
|
configurationPhase = 'destination';
|
|
|
|
}
|
|
|
|
return configurationPhase;
|
|
|
|
}
|
|
|
|
export const load: Load = async ({ fetch, url, params }) => {
|
|
|
|
try {
|
|
|
|
const { id } = params;
|
|
|
|
const response = await get(`/databases/${id}`);
|
|
|
|
const { database, versions, privatePort, settings } = response;
|
|
|
|
if (id !== 'new' && (!database || Object.entries(database).length === 0)) {
|
|
|
|
return {
|
|
|
|
status: 302,
|
2022-09-22 09:04:32 +02:00
|
|
|
redirect: '/'
|
2022-07-06 11:02:36 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
const configurationPhase = checkConfiguration(database);
|
|
|
|
if (
|
|
|
|
configurationPhase &&
|
|
|
|
url.pathname !== `/databases/${params.id}/configuration/${configurationPhase}`
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
status: 302,
|
|
|
|
redirect: `/databases/${params.id}/configuration/${configurationPhase}`
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
database,
|
|
|
|
versions,
|
|
|
|
privatePort
|
|
|
|
},
|
|
|
|
stuff: {
|
|
|
|
database,
|
|
|
|
versions,
|
|
|
|
privatePort,
|
|
|
|
settings
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
return handlerNotFoundLoad(error, url);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export let database: any;
|
|
|
|
import { del, get, post } from '$lib/api';
|
|
|
|
import { t } from '$lib/translations';
|
|
|
|
import { page } from '$app/stores';
|
|
|
|
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
|
2022-09-07 11:40:52 +02:00
|
|
|
import { appSession, status, isDeploymentEnabled } from '$lib/store';
|
2022-07-06 11:02:36 +02:00
|
|
|
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
|
|
|
|
import { onDestroy, onMount } from 'svelte';
|
2022-09-01 11:20:22 +02:00
|
|
|
import Tooltip from '$lib/components/Tooltip.svelte';
|
2022-09-10 00:05:19 +00:00
|
|
|
import DatabaseLinks from './_DatabaseLinks.svelte';
|
2022-07-06 11:02:36 +02:00
|
|
|
const { id } = $page.params;
|
|
|
|
|
2022-09-08 10:54:24 +02:00
|
|
|
$status.database.isPublic = database.settings.isPublic || false;
|
2022-07-06 11:02:36 +02:00
|
|
|
let statusInterval: any = false;
|
2022-09-01 13:58:44 +02:00
|
|
|
let forceDelete = false;
|
2022-07-21 12:43:53 +00:00
|
|
|
|
2022-09-07 11:40:52 +02:00
|
|
|
$isDeploymentEnabled = !$appSession.isAdmin;
|
2022-07-21 12:43:53 +00:00
|
|
|
|
2022-09-01 13:58:44 +02:00
|
|
|
async function deleteDatabase(force: boolean) {
|
2022-07-06 11:02:36 +02:00
|
|
|
const sure = confirm(`Are you sure you would like to delete '${database.name}'?`);
|
|
|
|
if (sure) {
|
2022-08-31 15:03:36 +02:00
|
|
|
$status.database.initialLoading = true;
|
2022-07-06 11:02:36 +02:00
|
|
|
try {
|
2022-09-01 13:58:44 +02:00
|
|
|
await del(`/databases/${database.id}`, { id: database.id, force });
|
2022-09-10 07:58:56 +00:00
|
|
|
return await window.location.assign('/');
|
2022-07-08 14:11:18 +02:00
|
|
|
} catch (error) {
|
2022-07-06 11:02:36 +02:00
|
|
|
return errorNotification(error);
|
|
|
|
} finally {
|
2022-08-31 15:03:36 +02:00
|
|
|
$status.database.initialLoading = false;
|
2022-07-06 11:02:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async function stopDatabase() {
|
|
|
|
const sure = confirm($t('database.confirm_stop', { name: database.name }));
|
|
|
|
if (sure) {
|
2022-08-31 15:03:36 +02:00
|
|
|
$status.database.initialLoading = true;
|
2022-09-07 09:45:16 +02:00
|
|
|
$status.database.loading = true;
|
2022-07-06 11:02:36 +02:00
|
|
|
try {
|
|
|
|
await post(`/databases/${database.id}/stop`, {});
|
2022-09-08 10:54:24 +02:00
|
|
|
$status.database.isPublic = false;
|
2022-07-08 14:11:18 +02:00
|
|
|
} catch (error) {
|
2022-07-06 11:02:36 +02:00
|
|
|
return errorNotification(error);
|
2022-08-31 15:03:36 +02:00
|
|
|
} finally {
|
|
|
|
$status.database.initialLoading = false;
|
2022-09-07 09:45:16 +02:00
|
|
|
$status.database.loading = false;
|
|
|
|
await getStatus();
|
2022-07-06 11:02:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async function startDatabase() {
|
2022-08-31 15:03:36 +02:00
|
|
|
$status.database.initialLoading = true;
|
|
|
|
$status.database.loading = true;
|
2022-07-06 11:02:36 +02:00
|
|
|
try {
|
|
|
|
await post(`/databases/${database.id}/start`, {});
|
2022-07-08 14:11:18 +02:00
|
|
|
} catch (error) {
|
2022-07-06 11:02:36 +02:00
|
|
|
return errorNotification(error);
|
2022-08-31 15:03:36 +02:00
|
|
|
} finally {
|
|
|
|
$status.database.initialLoading = false;
|
|
|
|
$status.database.loading = false;
|
|
|
|
await getStatus();
|
2022-07-06 11:02:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
async function getStatus() {
|
|
|
|
if ($status.database.loading) return;
|
|
|
|
$status.database.loading = true;
|
2022-07-20 13:35:26 +00:00
|
|
|
const data = await get(`/databases/${id}/status`);
|
2022-07-06 11:02:36 +02:00
|
|
|
$status.database.isRunning = data.isRunning;
|
|
|
|
$status.database.initialLoading = false;
|
|
|
|
$status.database.loading = false;
|
|
|
|
}
|
|
|
|
onDestroy(() => {
|
|
|
|
$status.database.initialLoading = true;
|
2022-09-02 14:11:36 +02:00
|
|
|
$status.database.isRunning = false;
|
|
|
|
$status.database.isExited = false;
|
|
|
|
$status.database.loading = false;
|
2022-07-06 11:02:36 +02:00
|
|
|
clearInterval(statusInterval);
|
|
|
|
});
|
|
|
|
onMount(async () => {
|
|
|
|
$status.database.isRunning = false;
|
|
|
|
$status.database.loading = false;
|
|
|
|
if (
|
|
|
|
database.type &&
|
|
|
|
database.destinationDockerId &&
|
|
|
|
database.version &&
|
|
|
|
database.defaultDatabase
|
|
|
|
) {
|
|
|
|
await getStatus();
|
|
|
|
statusInterval = setInterval(async () => {
|
|
|
|
await getStatus();
|
|
|
|
}, 2000);
|
2022-07-06 15:52:00 +02:00
|
|
|
} else {
|
|
|
|
$status.database.initialLoading = false;
|
2022-07-06 11:02:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if id !== 'new'}
|
2022-09-19 12:05:47 +02:00
|
|
|
<nav class="header lg:flex-row flex-col-reverse">
|
|
|
|
<div class="flex flex-row space-x-2 font-bold pt-10 lg:pt-0">
|
|
|
|
<div class="flex flex-col items-center justify-center">
|
|
|
|
<div class="title">
|
|
|
|
{#if $page.url.pathname === `/databases/${id}`}
|
|
|
|
Configurations
|
|
|
|
{:else if $page.url.pathname === `/databases/${id}/logs`}
|
|
|
|
Database Logs
|
|
|
|
{:else if $page.url.pathname === `/databases/${id}/configuration/type`}
|
|
|
|
Select a Database Type
|
|
|
|
{:else if $page.url.pathname === `/databases/${id}/configuration/version`}
|
|
|
|
Select a Database Version
|
|
|
|
{:else if $page.url.pathname === `/databases/${id}/configuration/destination`}
|
|
|
|
Select a Destination
|
|
|
|
{/if}
|
2022-09-07 00:16:57 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<DatabaseLinks {database} />
|
|
|
|
</div>
|
2022-09-19 12:05:47 +02:00
|
|
|
<div class="lg:block hidden flex-1" />
|
|
|
|
<div class="flex flex-row flex-wrap space-x-3 justify-center lg:justify-start lg:py-0">
|
2022-09-10 00:05:19 +00:00
|
|
|
{#if database.type && database.destinationDockerId && database.version}
|
2022-09-07 00:16:57 +00:00
|
|
|
{#if $status.database.isExited}
|
|
|
|
<a
|
|
|
|
id="exited"
|
2022-09-10 00:05:19 +00:00
|
|
|
href={!$status.database.isRunning ? `/databases/${id}/logs` : null}
|
2022-09-19 12:05:47 +02:00
|
|
|
class="icons bg-transparent text-red-500 tooltip-error"
|
2022-09-07 00:16:57 +00:00
|
|
|
sveltekit:prefetch
|
2022-07-06 11:02:36 +02:00
|
|
|
>
|
2022-09-07 00:16:57 +00:00
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
class="w-6 h-6"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentcolor"
|
|
|
|
fill="none"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
>
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path
|
|
|
|
d="M8.7 3h6.6c.3 0 .5 .1 .7 .3l4.7 4.7c.2 .2 .3 .4 .3 .7v6.6c0 .3 -.1 .5 -.3 .7l-4.7 4.7c-.2 .2 -.4 .3 -.7 .3h-6.6c-.3 0 -.5 -.1 -.7 -.3l-4.7 -4.7c-.2 -.2 -.3 -.4 -.3 -.7v-6.6c0 -.3 .1 -.5 .3 -.7l4.7 -4.7c.2 -.2 .4 -.3 .7 -.3z"
|
|
|
|
/>
|
|
|
|
<line x1="12" y1="8" x2="12" y2="12" />
|
|
|
|
<line x1="12" y1="16" x2="12.01" y2="16" />
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
<Tooltip triggeredBy="#exited">{'Service exited with an error!'}</Tooltip>
|
|
|
|
{/if}
|
|
|
|
{#if $status.database.initialLoading}
|
2022-09-19 12:05:47 +02:00
|
|
|
<button class="icons flex animate-spin duration-500 ease-in-out">
|
2022-09-07 00:16:57 +00:00
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
class="h-6 w-6"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentColor"
|
|
|
|
fill="none"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
>
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M9 4.55a8 8 0 0 1 6 14.9m0 -4.45v5h5" />
|
|
|
|
<line x1="5.63" y1="7.16" x2="5.63" y2="7.17" />
|
|
|
|
<line x1="4.06" y1="11" x2="4.06" y2="11.01" />
|
|
|
|
<line x1="4.63" y1="15.1" x2="4.63" y2="15.11" />
|
|
|
|
<line x1="7.16" y1="18.37" x2="7.16" y2="18.38" />
|
|
|
|
<line x1="11" y1="19.94" x2="11" y2="19.95" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
{:else if $status.database.isRunning}
|
|
|
|
<button
|
|
|
|
id="stop"
|
|
|
|
on:click={stopDatabase}
|
|
|
|
type="submit"
|
|
|
|
disabled={!$appSession.isAdmin}
|
2022-09-19 12:05:47 +02:00
|
|
|
class="icons bg-transparent text-red-500"
|
2022-09-07 00:16:57 +00:00
|
|
|
>
|
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
class="w-6 h-6"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentColor"
|
|
|
|
fill="none"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
>
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<rect x="6" y="5" width="4" height="14" rx="1" />
|
|
|
|
<rect x="14" y="5" width="4" height="14" rx="1" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
<Tooltip triggeredBy="#stop">{'Stop'}</Tooltip>
|
|
|
|
{:else}
|
|
|
|
<button
|
|
|
|
id="start"
|
|
|
|
on:click={startDatabase}
|
|
|
|
type="submit"
|
|
|
|
disabled={!$appSession.isAdmin}
|
|
|
|
class="icons bg-transparent text-sm flex items-center space-x-2 text-green-500"
|
|
|
|
><svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
class="w-6 h-6"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentColor"
|
|
|
|
fill="none"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
>
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M7 4v16l13 -8z" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
<Tooltip triggeredBy="#start">{'Start'}</Tooltip>
|
|
|
|
{/if}
|
2022-07-06 11:02:36 +02:00
|
|
|
{/if}
|
2022-09-07 00:16:57 +00:00
|
|
|
<div class="border border-stone-700 h-8" />
|
|
|
|
<a
|
|
|
|
id="configuration"
|
|
|
|
href="/databases/{id}"
|
|
|
|
sveltekit:prefetch
|
|
|
|
class="hover:text-yellow-500 rounded"
|
|
|
|
class:text-yellow-500={$page.url.pathname === `/databases/${id}`}
|
|
|
|
class:bg-coolgray-500={$page.url.pathname === `/databases/${id}`}
|
|
|
|
>
|
|
|
|
<button class="icons bg-transparent m text-sm disabled:text-red-500">
|
2022-07-06 11:02:36 +02:00
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
class="h-6 w-6"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentColor"
|
|
|
|
fill="none"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
>
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
2022-09-07 00:16:57 +00:00
|
|
|
<rect x="4" y="8" width="4" height="4" />
|
|
|
|
<line x1="6" y1="4" x2="6" y2="8" />
|
|
|
|
<line x1="6" y1="12" x2="6" y2="20" />
|
|
|
|
<rect x="10" y="14" width="4" height="4" />
|
|
|
|
<line x1="12" y1="4" x2="12" y2="14" />
|
|
|
|
<line x1="12" y1="18" x2="12" y2="20" />
|
|
|
|
<rect x="16" y="5" width="4" height="4" />
|
|
|
|
<line x1="18" y1="4" x2="18" y2="5" />
|
|
|
|
<line x1="18" y1="9" x2="18" y2="20" />
|
|
|
|
</svg></button
|
|
|
|
></a
|
|
|
|
>
|
|
|
|
<Tooltip triggeredBy="#configuration">{'Configuration'}</Tooltip>
|
|
|
|
<div class="border border-stone-700 h-8" />
|
|
|
|
<a
|
|
|
|
id="databaselogs"
|
|
|
|
href={$status.database.isRunning ? `/databases/${id}/logs` : null}
|
|
|
|
sveltekit:prefetch
|
|
|
|
class="hover:text-pink-500 rounded"
|
|
|
|
class:text-pink-500={$page.url.pathname === `/databases/${id}/logs`}
|
|
|
|
class:bg-coolgray-500={$page.url.pathname === `/databases/${id}/logs`}
|
|
|
|
>
|
|
|
|
<button disabled={!$status.database.isRunning} class="icons bg-transparent text-sm">
|
2022-07-06 11:02:36 +02:00
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
2022-09-07 00:16:57 +00:00
|
|
|
class="h-6 w-6"
|
2022-08-31 15:03:36 +02:00
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5"
|
|
|
|
stroke="currentColor"
|
|
|
|
fill="none"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
>
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
2022-09-07 00:16:57 +00:00
|
|
|
<path d="M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0" />
|
|
|
|
<path d="M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0" />
|
|
|
|
<line x1="3" y1="6" x2="3" y2="19" />
|
|
|
|
<line x1="12" y1="6" x2="12" y2="19" />
|
|
|
|
<line x1="21" y1="6" x2="21" y2="19" />
|
|
|
|
</svg></button
|
|
|
|
></a
|
|
|
|
>
|
|
|
|
<Tooltip triggeredBy="#databaselogs">{'Logs'}</Tooltip>
|
|
|
|
{#if forceDelete}
|
2022-08-31 15:03:36 +02:00
|
|
|
<button
|
2022-09-07 00:16:57 +00:00
|
|
|
on:click={() => deleteDatabase(true)}
|
2022-08-31 15:03:36 +02:00
|
|
|
type="submit"
|
|
|
|
disabled={!$appSession.isAdmin}
|
2022-09-07 00:16:57 +00:00
|
|
|
class:hover:text-red-500={$appSession.isAdmin}
|
|
|
|
class="icons bg-transparent text-sm"
|
2022-08-31 15:03:36 +02:00
|
|
|
>
|
2022-09-07 00:16:57 +00:00
|
|
|
Force Delete</button
|
|
|
|
>{:else}
|
|
|
|
<button
|
|
|
|
id="delete"
|
|
|
|
on:click={() => deleteDatabase(false)}
|
|
|
|
type="submit"
|
|
|
|
disabled={!$appSession.isAdmin}
|
|
|
|
class:hover:text-red-500={$appSession.isAdmin}
|
|
|
|
class="icons bg-transparent text-sm"><DeleteIcon /></button
|
2022-08-31 15:03:36 +02:00
|
|
|
>
|
2022-09-07 00:16:57 +00:00
|
|
|
{/if}
|
2022-09-01 13:58:44 +02:00
|
|
|
|
2022-09-19 12:05:47 +02:00
|
|
|
<Tooltip triggeredBy="#delete" placement="left">Delete</Tooltip>
|
2022-09-07 00:16:57 +00:00
|
|
|
</div>
|
2022-07-06 11:02:36 +02:00
|
|
|
</nav>
|
|
|
|
{/if}
|
|
|
|
<slot />
|