This commit is contained in:
Andras Bacsai 2022-03-25 10:36:47 +01:00
parent 767e7b80cb
commit 82bfdb87e3
24 changed files with 81 additions and 317 deletions

1
src/app.d.ts vendored
View File

@ -10,6 +10,7 @@ declare namespace App {
interface Stuff { interface Stuff {
application: any; application: any;
isRunning: boolean; isRunning: boolean;
appId: string;
} }
} }

View File

@ -55,8 +55,7 @@ export default async function (job) {
} = job.data; } = job.data;
const { debug } = settings; const { debug } = settings;
await asyncSleep(1000); await asyncSleep(500);
await db.prisma.build.updateMany({ await db.prisma.build.updateMany({
where: { where: {
status: 'queued', status: 'queued',

View File

@ -88,7 +88,14 @@
try { try {
const { buildId } = await post(`/applications/${id}/deploy.json`, { ...application }); const { buildId } = await post(`/applications/${id}/deploy.json`, { ...application });
toast.push('Deployment queued.'); toast.push('Deployment queued.');
return await goto(`/applications/${id}/logs/build?buildId=${buildId}`); console.log($page.url);
if ($page.url.pathname.startsWith(`/applications/${id}/logs/build`)) {
return window.location.assign(`/applications/${id}/logs/build?buildId=${buildId}`);
} else {
return await goto(`/applications/${id}/logs/build?buildId=${buildId}`, {
replaceState: true
});
}
} catch ({ error }) { } catch ({ error }) {
return errorNotification(error); return errorNotification(error);
} }

View File

@ -151,8 +151,8 @@
<a href={`/sources/${application.gitSource.id}`}><button>Configure it now</button></a> <a href={`/sources/${application.gitSource.id}`}><button>Configure it now</button></a>
</div> </div>
{:else} {:else}
<form on:submit|preventDefault={handleSubmit}> <form on:submit|preventDefault={handleSubmit} class="flex flex-col justify-center text-center">
<div> <div class="flex-col space-y-3 md:space-y-0 space-x-1">
{#if loading.repositories} {#if loading.repositories}
<select name="repository" disabled class="w-96"> <select name="repository" disabled class="w-96">
<option selected value="">Loading repositories...</option> <option selected value="">Loading repositories...</option>

View File

@ -41,7 +41,7 @@
gitlabApp: Prisma.GitlabApp; gitlabApp: Prisma.GitlabApp;
githubApp: Prisma.GithubApp; githubApp: Prisma.GithubApp;
}; };
sources = sources.filter( const filteredSources = sources.filter(
(source) => (source) =>
(source.type === 'github' && source.githubAppId && source.githubApp.installationId) || (source.type === 'github' && source.githubAppId && source.githubApp.installationId) ||
(source.type === 'gitlab' && source.gitlabAppId) (source.type === 'gitlab' && source.gitlabAppId)
@ -59,8 +59,8 @@
<div class="flex space-x-1 p-6 font-bold"> <div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl tracking-tight">Select a Git Source</div> <div class="mr-4 text-2xl tracking-tight">Select a Git Source</div>
</div> </div>
<div class="flex justify-center"> <div class="flex flex-col justify-center">
{#if !sources || sources.length === 0} {#if !filteredSources || filteredSources.length === 0}
<div class="flex-col"> <div class="flex-col">
<div class="pb-2">No configurable Git Source found</div> <div class="pb-2">No configurable Git Source found</div>
<div class="flex justify-center"> <div class="flex justify-center">
@ -83,7 +83,7 @@
</div> </div>
{:else} {:else}
<div class="flex flex-wrap justify-center"> <div class="flex flex-wrap justify-center">
{#each sources as source} {#each filteredSources as source}
<div class="p-2"> <div class="p-2">
<form on:submit|preventDefault={() => handleSubmit(source.id)}> <form on:submit|preventDefault={() => handleSubmit(source.id)}>
<button <button

View File

@ -109,7 +109,7 @@
try { try {
await post(`/applications/${id}/check.json`, { fqdn: application.fqdn, forceSave }); await post(`/applications/${id}/check.json`, { fqdn: application.fqdn, forceSave });
await post(`/applications/${id}.json`, { ...application }); await post(`/applications/${id}.json`, { ...application });
return window.location.reload(); return toast.push('Configurations saved.');
} catch ({ error }) { } catch ({ error }) {
if (error.startsWith('DNS not set')) { if (error.startsWith('DNS not set')) {
forceSave = true; forceSave = true;

View File

@ -84,7 +84,7 @@
<LoadingLogs /> <LoadingLogs />
{/if} {/if}
{#if currentStatus === 'queued'} {#if currentStatus === 'queued'}
<div class="text-center">Queued and waiting for execution.</div> <div class="text-center font-bold text-xl">Queued and waiting for execution.</div>
{:else} {:else}
<div class="flex justify-end sticky top-0 p-2"> <div class="flex justify-end sticky top-0 p-2">
<button <button

View File

@ -54,7 +54,6 @@
return build; return build;
}); });
return window.location.reload();
} catch ({ error }) { } catch ({ error }) {
return errorNotification(error); return errorNotification(error);
} }

View File

@ -1,34 +1,19 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch }) => {
const endpoint = '/applications.json';
const res = await fetch(endpoint);
if (res.ok) {
return {
props: {
...(await res.json())
}
};
}
return {
status: res.status,
error: new Error(`Could not load ${endpoint}`)
};
};
</script>
<script lang="ts"> <script lang="ts">
export let applications: Array<Application>; export let applications: Array<Application>;
import { session } from '$app/stores'; import { session } from '$app/stores';
import Application from './_Application.svelte'; import Application from './_Application.svelte';
import { post } from '$lib/api';
import { goto } from '$app/navigation';
async function newApplication() {
const { id } = await post('/applications/new', {});
return await goto(`/applications/${id}`, { replaceState: true });
}
</script> </script>
<div class="flex space-x-1 p-6 font-bold"> <div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl ">Applications</div> <div class="mr-4 text-2xl ">Applications</div>
{#if $session.isAdmin} {#if $session.isAdmin}
<a href="/new/application" class="add-icon bg-green-600 hover:bg-green-500"> <div on:click={newApplication} class="add-icon cursor-pointer bg-green-600 hover:bg-green-500">
<svg <svg
class="w-6" class="w-6"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -42,7 +27,7 @@
d="M12 6v6m0 0v6m0-6h6m-6 0H6" d="M12 6v6m0 0v6m0-6h6m-6 0H6"
/></svg /></svg
> >
</a> </div>
{/if} {/if}
</div> </div>
<div class="flex flex-wrap justify-center"> <div class="flex flex-wrap justify-center">

View File

@ -6,10 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
export const post: RequestHandler = async (event) => { export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body }; if (status === 401) return { status, body };
const name = uniqueName();
const { name } = await event.request.json();
if (!name) return { status: 400, body: { error: 'Missing name.' } };
try { try {
const { id } = await db.newApplication({ name, teamId }); const { id } = await db.newApplication({ name, teamId });
return { status: 201, body: { id } }; return { status: 201, body: { id } };

View File

@ -8,12 +8,22 @@ export const get: RequestHandler = async (event) => {
if (status === 401) return { status, body }; if (status === 401) return { status, body };
try { try {
const applicationsCount = await (await db.listApplications(teamId)).length; const applicationsCount = await db.prisma.application.count({
const sourcesCount = await (await db.listSources(teamId)).length; where: { teams: { some: { id: teamId } } }
const destinationsCount = await (await db.listDestinations(teamId)).length; });
const teamsCount = await (await db.getMyTeams({ userId })).length; const sourcesCount = await db.prisma.gitSource.count({
const databasesCount = await (await db.listDatabases(teamId)).length; where: { teams: { some: { id: teamId } } }
const servicesCount = await (await db.listServices(teamId)).length; });
const destinationsCount = await db.prisma.destinationDocker.count({
where: { teams: { some: { id: teamId } } }
});
const teamsCount = await db.prisma.permission.count({ where: { userId } });
const databasesCount = await db.prisma.database.count({
where: { teams: { some: { id: teamId } } }
});
const servicesCount = await db.prisma.service.count({
where: { teams: { some: { id: teamId } } }
});
return { return {
body: { body: {
applicationsCount, applicationsCount,

View File

@ -1,24 +1,3 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch }) => {
const url = `/databases.json`;
const res = await fetch(url);
if (res.ok) {
return {
props: {
...(await res.json())
}
};
}
return {
status: res.status,
error: new Error(`Could not load ${url}`)
};
};
</script>
<script lang="ts"> <script lang="ts">
export let databases; export let databases;
import Clickhouse from '$lib/components/svg/databases/Clickhouse.svelte'; import Clickhouse from '$lib/components/svg/databases/Clickhouse.svelte';
@ -27,11 +6,18 @@
import MySQL from '$lib/components/svg/databases/MySQL.svelte'; import MySQL from '$lib/components/svg/databases/MySQL.svelte';
import PostgreSQL from '$lib/components/svg/databases/PostgreSQL.svelte'; import PostgreSQL from '$lib/components/svg/databases/PostgreSQL.svelte';
import Redis from '$lib/components/svg/databases/Redis.svelte'; import Redis from '$lib/components/svg/databases/Redis.svelte';
import { post } from '$lib/api';
import { goto } from '$app/navigation';
async function newDatabase() {
const { id } = await post('/databases/new', {});
return await goto(`/databases/${id}`, { replaceState: true });
}
</script> </script>
<div class="flex space-x-1 p-6 font-bold"> <div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl tracking-tight">Databases</div> <div class="mr-4 text-2xl tracking-tight">Databases</div>
<a href="/new/database" class="add-icon bg-purple-600 hover:bg-purple-500"> <div on:click={newDatabase} class="add-icon cursor-pointer bg-purple-600 hover:bg-purple-500">
<svg <svg
class="w-6" class="w-6"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -45,7 +31,7 @@
d="M12 6v6m0 0v6m0-6h6m-6 0H6" d="M12 6v6m0 0v6m0-6h6m-6 0H6"
/></svg /></svg
> >
</a> </div>
</div> </div>
<div class="flex flex-wrap justify-center"> <div class="flex flex-wrap justify-center">

View File

@ -6,6 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
export const get: RequestHandler = async (event) => { export const get: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body }; if (status === 401) return { status, body };
try { try {
const databases = await db.listDatabases(teamId); const databases = await db.listDatabases(teamId);
return { return {

View File

@ -1,4 +1,4 @@
import { getUserDetails } from '$lib/common'; import { getUserDetails, uniqueName } from '$lib/common';
import * as db from '$lib/database'; import * as db from '$lib/database';
import { ErrorHandler } from '$lib/database'; import { ErrorHandler } from '$lib/database';
import type { RequestHandler } from '@sveltejs/kit'; import type { RequestHandler } from '@sveltejs/kit';
@ -6,9 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
export const post: RequestHandler = async (event) => { export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body }; if (status === 401) return { status, body };
const name = uniqueName();
const { name } = await event.request.json();
try { try {
const { id } = await db.newDatabase({ name, teamId }); const { id } = await db.newDatabase({ name, teamId });
return { status: 201, body: { id } }; return { status: 201, body: { id } };

View File

@ -1,29 +0,0 @@
import { getUserDetails } from '$lib/common';
import * as db from '$lib/database';
import { ErrorHandler } from '$lib/database';
import type { RequestHandler } from '@sveltejs/kit';
export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body };
let { name, fqdn, port, buildCommand, startCommand, installCommand } = await event.request.json();
if (fqdn) fqdn = fqdn.toLowerCase();
if (port) port = Number(port);
try {
const { id } = await db.importApplication({
name,
teamId,
fqdn,
port,
buildCommand,
startCommand,
installCommand
});
return { status: 201, body: { id } };
} catch (error) {
return ErrorHandler(error);
}
};

View File

@ -1,53 +0,0 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch }) => {
const url = `/common/getUniqueName.json`;
const res = await fetch(url);
if (res.ok) {
return {
props: {
...(await res.json())
}
};
}
return {
status: res.status,
error: new Error(`Could not load ${url}`)
};
};
</script>
<script lang="ts">
export let name;
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { post } from '$lib/api';
import { errorNotification } from '$lib/form';
let nameEl: HTMLInputElement;
onMount(() => {
nameEl.focus();
});
async function handleSubmit() {
try {
const { id } = await post('/new/application.json', { name });
return await goto(`/applications/${id}`);
} catch ({ error }) {
return errorNotification(error);
}
}
</script>
<div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl tracking-tight">Add New Application</div>
</div>
<div class="pt-10">
<form on:submit|preventDefault={handleSubmit}>
<div class="flex flex-col items-center space-y-4">
<input name="name" placeholder="Application name" bind:this={nameEl} bind:value={name} />
<button type="submit" class="bg-green-600 hover:bg-green-500">Save</button>
</div>
</form>
</div>

View File

@ -1,59 +0,0 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch, session }) => {
const url = `/common/getUniqueName.json`;
const res = await fetch(url);
if (res.ok) {
return {
props: {
...(await res.json())
}
};
}
return {
status: res.status,
error: new Error(`Could not load ${url}`)
};
};
</script>
<script lang="ts">
export let name;
import { errorNotification } from '$lib/form';
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { post } from '$lib/api';
let autofocus;
onMount(() => {
autofocus.focus();
});
async function handleSubmit() {
try {
const { id } = await post('/new/database.json', { name });
return await goto(`/databases/${id}`);
} catch ({ error }) {
return errorNotification(error);
}
}
</script>
<div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl tracking-tight">Add New Database</div>
</div>
<div class="pt-10">
<form on:submit|preventDefault={handleSubmit}>
<div class="flex flex-col items-center space-y-4">
<input
name="name"
placeholder="Database name"
required
bind:this={autofocus}
bind:value={name}
/>
<button type="submit" class="bg-purple-600 hover:bg-purple-500">Save</button>
</div>
</form>
</div>

View File

@ -1,59 +0,0 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch, session }) => {
const url = `/common/getUniqueName.json`;
const res = await fetch(url);
if (res.ok) {
return {
props: {
...(await res.json())
}
};
}
return {
status: res.status,
error: new Error(`Could not load ${url}`)
};
};
</script>
<script lang="ts">
export let name;
import { enhance, errorNotification } from '$lib/form';
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { post } from '$lib/api';
let autofocus;
onMount(() => {
autofocus.focus();
});
async function handleSubmit() {
try {
const { id } = await post(`/new/service.json`, { name });
return await goto(`/services/${id}`);
} catch ({ error }) {
return errorNotification(error);
}
}
</script>
<div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl tracking-tight">Add New Service</div>
</div>
<div class="pt-10">
<form on:submit|preventDefault={handleSubmit}>
<div class="flex flex-col items-center space-y-4">
<input
name="name"
placeholder="Service name"
required
bind:this={autofocus}
bind:value={name}
/>
<button type="submit" class="bg-pink-600 hover:bg-pink-500">Save</button>
</div>
</form>
</div>

View File

@ -1,24 +1,3 @@
<script context="module" lang="ts">
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch }) => {
const url = `/services.json`;
const res = await fetch(url);
if (res.ok) {
return {
props: {
...(await res.json())
}
};
}
return {
status: res.status,
error: new Error(`Could not load ${url}`)
};
};
</script>
<script lang="ts"> <script lang="ts">
import PlausibleAnalytics from '$lib/components/svg/services/PlausibleAnalytics.svelte'; import PlausibleAnalytics from '$lib/components/svg/services/PlausibleAnalytics.svelte';
import NocoDb from '$lib/components/svg/services/NocoDB.svelte'; import NocoDb from '$lib/components/svg/services/NocoDB.svelte';
@ -27,13 +6,19 @@
import Wordpress from '$lib/components/svg/services/Wordpress.svelte'; import Wordpress from '$lib/components/svg/services/Wordpress.svelte';
import VaultWarden from '$lib/components/svg/services/VaultWarden.svelte'; import VaultWarden from '$lib/components/svg/services/VaultWarden.svelte';
import LanguageTool from '$lib/components/svg/services/LanguageTool.svelte'; import LanguageTool from '$lib/components/svg/services/LanguageTool.svelte';
import { post } from '$lib/api';
import { goto } from '$app/navigation';
export let services; export let services;
async function newService() {
const { id } = await post('/services/new', {});
return await goto(`/services/${id}`, { replaceState: true });
}
</script> </script>
<div class="flex space-x-1 p-6 font-bold"> <div class="flex space-x-1 p-6 font-bold">
<div class="mr-4 text-2xl tracking-tight">Services</div> <div class="mr-4 text-2xl tracking-tight">Services</div>
<a href="/new/service" class="add-icon bg-pink-600 hover:bg-pink-500"> <div on:click={newService} class="add-icon cursor-pointer bg-pink-600 hover:bg-pink-500">
<svg <svg
class="w-6" class="w-6"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -47,7 +32,7 @@
d="M12 6v6m0 0v6m0-6h6m-6 0H6" d="M12 6v6m0 0v6m0-6h6m-6 0H6"
/></svg /></svg
> >
</a> </div>
</div> </div>
<div class="flex flex-wrap justify-center"> <div class="flex flex-wrap justify-center">

View File

@ -6,9 +6,7 @@ import type { RequestHandler } from '@sveltejs/kit';
export const post: RequestHandler = async (event) => { export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body }; if (status === 401) return { status, body };
const name = uniqueName();
const { name } = await event.request.json();
try { try {
const { id } = await db.newService({ name, teamId }); const { id } = await db.newService({ name, teamId });
return { status: 201, body: { id } }; return { status: 201, body: { id } };

View File

@ -91,23 +91,21 @@
</div> </div>
</div> </div>
{/if} {/if}
<div class="mx-auto max-w-2xl"> <div class="flex flex-wrap justify-center">
<div class="flex flex-wrap justify-center"> {#each teams as team}
{#each teams as team} <a href="/teams/{team.teamId}" class="w-96 p-2 no-underline">
<a href="/teams/{team.teamId}" class="w-96 p-2 no-underline"> <div
<div class="box-selection relative"
class="box-selection relative" class:hover:bg-cyan-600={team.team?.id !== '0'}
class:hover:bg-cyan-600={team.team?.id !== '0'} class:hover:bg-red-500={team.team?.id === '0'}
class:hover:bg-red-500={team.team?.id === '0'} >
> <div class="truncate text-center text-xl font-bold">
<div class="truncate text-center text-xl font-bold">{team.team.name}</div> {team.team.name}
<div class="text-center text-xs"> {team.team?.id === '0' ? '(root)' : ''}
({team.team?.id === '0' ? 'root team - ' : ''}{team.permission})
</div>
<div class="mt-1 text-center">{team.team._count.users} member(s)</div>
</div> </div>
</a>
{/each} <div class="mt-1 text-center">{team.team._count.users} member(s)</div>
</div> </div>
</a>
{/each}
</div> </div>

View File

@ -85,7 +85,7 @@ .nav-main {
} }
.nav-side { .nav-side {
@apply relative right-0 top-0 z-50 m-5 flex flex-wrap items-center justify-end space-x-2 bg-coolblack/40 text-white sm:absolute; @apply absolute right-0 top-0 z-50 m-5 flex flex-wrap items-center justify-end space-x-2 bg-coolblack/40 text-white;
} }
.add-icon { .add-icon {