2022-07-06 11:02:36 +02:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
import type { Load } from '@sveltejs/kit';
|
|
|
|
|
|
|
|
export const load: Load = async ({}) => {
|
|
|
|
try {
|
|
|
|
const data = await get('/resources');
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
...data
|
|
|
|
},
|
|
|
|
stuff: {
|
|
|
|
...data
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-08-17 10:43:57 +02:00
|
|
|
export let applications: any;
|
|
|
|
export let databases: any;
|
|
|
|
export let services: any;
|
|
|
|
export let settings: any;
|
|
|
|
|
2022-08-12 16:09:52 +02:00
|
|
|
import { get, post } from '$lib/api';
|
2022-07-06 11:02:36 +02:00
|
|
|
import Usage from '$lib/components/Usage.svelte';
|
|
|
|
import { t } from '$lib/translations';
|
2022-08-12 16:14:37 +00:00
|
|
|
import { errorNotification, asyncSleep } from '$lib/common';
|
2022-08-12 16:20:18 +02:00
|
|
|
import { addToast, appSession } from '$lib/store';
|
2022-08-17 10:43:57 +02:00
|
|
|
|
2022-08-12 16:09:52 +02:00
|
|
|
import ApplicationsIcons from '$lib/components/svg/applications/ApplicationIcons.svelte';
|
|
|
|
import DatabaseIcons from '$lib/components/svg/databases/DatabaseIcons.svelte';
|
|
|
|
import ServiceIcons from '$lib/components/svg/services/ServiceIcons.svelte';
|
2022-08-17 10:43:57 +02:00
|
|
|
import { dev } from '$app/env';
|
2022-08-12 16:09:52 +02:00
|
|
|
|
2022-08-17 10:43:57 +02:00
|
|
|
let numberOfGetStatus = 0;
|
|
|
|
|
|
|
|
function getRndInteger(min: number, max: number) {
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
}
|
2022-08-12 16:14:37 +00:00
|
|
|
|
2022-08-12 16:09:52 +02:00
|
|
|
async function getStatus(resources: any) {
|
2022-08-17 10:43:57 +02:00
|
|
|
while (numberOfGetStatus > 1) {
|
|
|
|
await asyncSleep(getRndInteger(100, 200));
|
2022-08-12 16:14:37 +00:00
|
|
|
}
|
2022-08-12 16:09:52 +02:00
|
|
|
try {
|
2022-08-17 10:43:57 +02:00
|
|
|
numberOfGetStatus++;
|
2022-08-12 16:09:52 +02:00
|
|
|
const { id, buildPack, dualCerts } = resources;
|
|
|
|
let isRunning = false;
|
|
|
|
if (buildPack) {
|
|
|
|
const response = await get(`/applications/${id}/status`);
|
|
|
|
isRunning = response.isRunning;
|
|
|
|
} else if (typeof dualCerts !== 'undefined') {
|
|
|
|
const response = await get(`/services/${id}/status`);
|
|
|
|
isRunning = response.isRunning;
|
|
|
|
} else {
|
|
|
|
const response = await get(`/databases/${id}/status`);
|
|
|
|
isRunning = response.isRunning;
|
|
|
|
}
|
|
|
|
if (isRunning) {
|
|
|
|
return 'Running';
|
|
|
|
} else {
|
|
|
|
return 'Stopped';
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
return 'Error';
|
2022-08-12 16:14:37 +00:00
|
|
|
} finally {
|
2022-08-17 10:43:57 +02:00
|
|
|
numberOfGetStatus--;
|
|
|
|
}
|
2022-08-12 16:09:52 +02:00
|
|
|
}
|
2022-07-06 11:02:36 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="flex space-x-1 p-6 font-bold">
|
|
|
|
<div class="mr-4 text-2xl tracking-tight">{$t('index.dashboard')}</div>
|
|
|
|
</div>
|
2022-08-26 01:40:46 +00:00
|
|
|
<div class="container lg:mx-auto lg:p-0 p-5">
|
|
|
|
{#if $appSession.teamId === '0'}
|
|
|
|
<Usage />
|
|
|
|
{/if}
|
|
|
|
{#if applications.length > 0}
|
2022-08-26 10:29:45 +02:00
|
|
|
<h1 class="title text-4xl mt-10">Applications</h1>
|
2022-08-26 01:40:46 +00:00
|
|
|
<div class="divider" />
|
|
|
|
<div class="grid grid-col gap-4 auto-cols-max grid-cols-1 lg:grid-cols-3">
|
|
|
|
{#each applications as application}
|
2022-08-26 10:29:45 +02:00
|
|
|
<a class="no-underline mb-5" href={`/applications/${application.id}`}>
|
2022-08-26 12:46:20 +02:00
|
|
|
<div class="w-full rounded p-5 bg-coolgray-100 hover:bg-coolgray-300 indicator">
|
2022-08-26 10:29:45 +02:00
|
|
|
{#await getStatus(application)}
|
|
|
|
<span class="indicator-item badge bg-yellow-500 badge-xs" />
|
|
|
|
{:then status}
|
|
|
|
{#if status === 'Running'}
|
|
|
|
<span class="indicator-item badge bg-success badge-xs" />
|
|
|
|
{:else}
|
|
|
|
<span class="indicator-item badge bg-error badge-xs" />
|
|
|
|
{/if}
|
|
|
|
{/await}
|
|
|
|
<div class="w-full flex flex-row">
|
|
|
|
<ApplicationsIcons {application} isAbsolute={false} />
|
|
|
|
<div class="w-full flex flex-col ml-5">
|
2022-08-26 12:46:20 +02:00
|
|
|
<h1 class="font-bold text-lg">
|
|
|
|
{application.name}
|
2022-08-26 10:29:45 +02:00
|
|
|
{#if application.settings.isBot}
|
|
|
|
| BOT
|
|
|
|
{/if}
|
2022-08-26 12:46:20 +02:00
|
|
|
</h1>
|
|
|
|
{#if application?.fqdn}
|
|
|
|
<h2>{application?.fqdn}</h2>
|
|
|
|
{:else if !application.settings.isBot && !application?.fqdn}
|
|
|
|
<h2 class="text-red-500">Not configured</h2>
|
|
|
|
{/if}
|
|
|
|
<div class="flex justify-end space-x-2 pt-2">
|
2022-08-26 10:29:45 +02:00
|
|
|
{#if application.fqdn}
|
|
|
|
<a href={application.fqdn} target="_blank" class="icons">
|
|
|
|
<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="M11 7h-5a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-5" />
|
|
|
|
<line x1="10" y1="14" x2="20" y2="4" />
|
|
|
|
<polyline points="15 4 20 4 20 9" />
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
{/if}
|
|
|
|
{#if application.settings.isBot && application.exposePort}
|
|
|
|
<a
|
|
|
|
href={`http://${dev ? 'localhost' : settings.ipv4}:${application.exposePort}`}
|
|
|
|
target="_blank"
|
|
|
|
class="icons"
|
2022-08-17 10:43:57 +02:00
|
|
|
>
|
2022-08-26 10:29:45 +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" />
|
|
|
|
<path d="M11 7h-5a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-5" />
|
|
|
|
<line x1="10" y1="14" x2="20" y2="4" />
|
|
|
|
<polyline points="15 4 20 4 20 9" />
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2022-08-26 01:40:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-26 10:29:45 +02:00
|
|
|
</a>
|
2022-08-26 01:40:46 +00:00
|
|
|
{/each}
|
|
|
|
</div>
|
2022-08-26 12:46:20 +02:00
|
|
|
{/if}
|
|
|
|
{#if services.length > 0}
|
2022-08-26 01:40:46 +00:00
|
|
|
<h1 class="title text-4xl mt-10">Services</h1>
|
|
|
|
<div class="divider" />
|
|
|
|
<div class="grid grid-col gap-4 auto-cols-max grid-cols-1 lg:grid-cols-3">
|
|
|
|
{#each services as service}
|
2022-08-26 10:29:45 +02:00
|
|
|
<a class="no-underline mb-5" href={`/services/${service.id}`}>
|
2022-08-26 12:46:20 +02:00
|
|
|
<div class="w-full rounded p-5 bg-coolgray-100 hover:bg-coolgray-300 indicator">
|
2022-08-26 10:29:45 +02:00
|
|
|
{#await getStatus(service)}
|
|
|
|
<span class="indicator-item badge bg-yellow-500 badge-xs" />
|
|
|
|
{:then status}
|
2022-08-26 12:07:21 +02:00
|
|
|
{#if status === 'Running'}
|
2022-08-26 10:29:45 +02:00
|
|
|
<span class="indicator-item badge bg-success badge-xs" />
|
|
|
|
{:else}
|
|
|
|
<span class="indicator-item badge bg-error badge-xs" />
|
|
|
|
{/if}
|
|
|
|
{/await}
|
|
|
|
<div class="w-full flex flex-row">
|
|
|
|
<ServiceIcons type={service.type} isAbsolute={false} />
|
|
|
|
<div class="w-full flex flex-col ml-5">
|
|
|
|
<h1 class="font-bold text-lg">{service.name}</h1>
|
2022-08-26 12:46:20 +02:00
|
|
|
{#if service?.fqdn}
|
|
|
|
<h2>{service?.fqdn}</h2>
|
|
|
|
{:else}
|
|
|
|
<h2 class="text-red-500">Not configured</h2>
|
|
|
|
{/if}
|
|
|
|
<div class="flex justify-end space-x-2 pt-2">
|
2022-08-26 10:29:45 +02:00
|
|
|
{#if service.fqdn}
|
|
|
|
<a href={service.fqdn} target="_blank" class="icons">
|
|
|
|
<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="M11 7h-5a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-5" />
|
|
|
|
<line x1="10" y1="14" x2="20" y2="4" />
|
|
|
|
<polyline points="15 4 20 4 20 9" />
|
|
|
|
</svg>
|
|
|
|
</a>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2022-08-26 01:40:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-17 10:43:57 +02:00
|
|
|
</div>
|
2022-08-26 10:29:45 +02:00
|
|
|
</a>
|
2022-08-26 01:40:46 +00:00
|
|
|
{/each}
|
2022-08-12 16:09:52 +02:00
|
|
|
</div>
|
2022-08-26 12:46:20 +02:00
|
|
|
{/if}
|
|
|
|
{#if databases.length > 0}
|
2022-08-26 01:40:46 +00:00
|
|
|
<h1 class="title text-4xl mt-10">Databases</h1>
|
|
|
|
<div class="divider" />
|
|
|
|
<div class="grid grid-col gap-4 auto-cols-max grid-cols-1 lg:grid-cols-3">
|
|
|
|
{#each databases as database}
|
2022-08-26 10:29:45 +02:00
|
|
|
<a class="no-underline mb-5" href={`/databases/${database.id}`}>
|
2022-08-26 12:46:20 +02:00
|
|
|
<div class="w-full rounded p-5 bg-coolgray-100 hover:bg-coolgray-300 indicator">
|
2022-08-26 10:29:45 +02:00
|
|
|
{#await getStatus(database)}
|
|
|
|
<span class="indicator-item badge bg-yellow-500 badge-xs" />
|
|
|
|
{:then status}
|
2022-08-26 12:07:21 +02:00
|
|
|
{#if status === 'Running'}
|
2022-08-26 10:29:45 +02:00
|
|
|
<span class="indicator-item badge bg-success badge-xs" />
|
|
|
|
{:else}
|
|
|
|
<span class="indicator-item badge bg-error badge-xs" />
|
|
|
|
{/if}
|
|
|
|
{/await}
|
2022-08-26 12:46:20 +02:00
|
|
|
<div class="w-full flex flex-row pt-2">
|
2022-08-26 10:29:45 +02:00
|
|
|
<DatabaseIcons type={database.type} isAbsolute={false} />
|
|
|
|
<div class="w-full flex flex-col ml-5">
|
|
|
|
<h1 class="font-bold text-lg">{database.name}</h1>
|
2022-08-26 01:40:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-26 10:29:45 +02:00
|
|
|
</a>
|
2022-08-26 01:40:46 +00:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{:else if $appSession.teamId !== '0'}
|
|
|
|
<div class="text-center text-xl font-bold h-screen w-full flex flex-col justify-center">
|
|
|
|
<h1 class="text-5xl">Nothing is configured yet.</h1>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-07-06 11:02:36 +02:00
|
|
|
</div>
|