From 0d0715a3405f959209ebf9a3faee020a04e7df8e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 8 Apr 2022 10:35:16 +0200 Subject: [PATCH] ui/fix: Insane amount --- src/lib/database/applications.ts | 6 +- src/lib/database/gitSources.ts | 35 ++- src/routes/applications/[id]/delete.json.ts | 1 + src/routes/applications/_Application.svelte | 70 ----- src/routes/applications/index.svelte | 117 ++++++- src/routes/databases/index.svelte | 2 +- src/routes/destinations/index.svelte | 2 +- src/routes/iam/index.svelte | 7 +- src/routes/index.svelte | 2 +- src/routes/new/source/_Github.svelte | 96 ------ src/routes/new/source/_Gitlab.svelte | 73 ----- src/routes/new/source/index.svelte | 66 ---- src/routes/services/index.svelte | 9 +- src/routes/sources/[id]/_Github.svelte | 114 +++++-- src/routes/sources/[id]/_Gitlab.svelte | 286 ++++++++++-------- src/routes/sources/[id]/github.json.ts | 18 ++ src/routes/sources/[id]/gitlab.json.ts | 16 +- src/routes/sources/[id]/index.json.ts | 4 +- src/routes/sources/[id]/index.svelte | 53 +++- src/routes/sources/[id]/newGithubApp.svelte | 1 + src/routes/sources/index.svelte | 15 +- .../source/index.json.ts => sources/new.ts} | 6 +- 22 files changed, 509 insertions(+), 490 deletions(-) delete mode 100644 src/routes/applications/_Application.svelte delete mode 100644 src/routes/new/source/_Github.svelte delete mode 100644 src/routes/new/source/_Gitlab.svelte delete mode 100644 src/routes/new/source/index.svelte create mode 100644 src/routes/sources/[id]/github.json.ts rename src/routes/{new/source/index.json.ts => sources/new.ts} (64%) diff --git a/src/lib/database/applications.ts b/src/lib/database/applications.ts index 1c6e172c2..ce53fe709 100644 --- a/src/lib/database/applications.ts +++ b/src/lib/database/applications.ts @@ -73,7 +73,11 @@ export async function removeApplication({ id, teamId }) { await prisma.build.deleteMany({ where: { applicationId: id } }); await prisma.secret.deleteMany({ where: { applicationId: id } }); await prisma.applicationPersistentStorage.deleteMany({ where: { applicationId: id } }); - await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } }); + if (teamId === '0') { + await prisma.application.deleteMany({ where: { id } }); + } else { + await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } }); + } } export async function getApplicationWebhook({ projectId, branch }) { diff --git a/src/lib/database/gitSources.ts b/src/lib/database/gitSources.ts index 0ed6f29b1..b8279c268 100644 --- a/src/lib/database/gitSources.ts +++ b/src/lib/database/gitSources.ts @@ -13,15 +13,11 @@ export async function listSources(teamId) { }); } -export async function newSource({ name, teamId, type, htmlUrl, apiUrl, organization }) { +export async function newSource({ teamId, name }) { return await prisma.gitSource.create({ data: { - teams: { connect: { id: teamId } }, name, - type, - htmlUrl, - apiUrl, - organization + teams: { connect: { id: teamId } } } }); } @@ -55,8 +51,29 @@ export async function getSource({ id, teamId }) { if (body?.gitlabApp?.appSecret) body.gitlabApp.appSecret = decrypt(body.gitlabApp.appSecret); return body; } -export async function addSource({ id, appId, teamId, oauthId, groupName, appSecret }) { +export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }) { + await prisma.gitSource.update({ where: { id }, data: { type, name, htmlUrl, apiUrl } }); + return await prisma.githubApp.create({ + data: { + teams: { connect: { id: teamId } }, + gitSource: { connect: { id } } + } + }); +} +export async function addGitLabSource({ + id, + teamId, + type, + name, + htmlUrl, + apiUrl, + oauthId, + appId, + appSecret, + groupName +}) { const encrptedAppSecret = encrypt(appSecret); + await prisma.gitSource.update({ where: { id }, data: { type, apiUrl, htmlUrl, name } }); return await prisma.gitlabApp.create({ data: { teams: { connect: { id: teamId } }, @@ -75,9 +92,9 @@ export async function configureGitsource({ id, gitSourceId }) { data: { gitSource: { connect: { id: gitSourceId } } } }); } -export async function updateGitsource({ id, name }) { +export async function updateGitsource({ id, name, htmlUrl, apiUrl }) { return await prisma.gitSource.update({ where: { id }, - data: { name } + data: { name, htmlUrl, apiUrl } }); } diff --git a/src/routes/applications/[id]/delete.json.ts b/src/routes/applications/[id]/delete.json.ts index b451728df..03e48a847 100644 --- a/src/routes/applications/[id]/delete.json.ts +++ b/src/routes/applications/[id]/delete.json.ts @@ -14,6 +14,7 @@ export const del: RequestHandler = async (event) => { status: 200 }; } catch (error) { + console.log(error); return ErrorHandler(error); } }; diff --git a/src/routes/applications/_Application.svelte b/src/routes/applications/_Application.svelte deleted file mode 100644 index 8f183eb13..000000000 --- a/src/routes/applications/_Application.svelte +++ /dev/null @@ -1,70 +0,0 @@ - - - -
- {#if buildPack === 'rust'} - - {:else if buildPack === 'node'} - - {:else if buildPack === 'react'} - - {:else if buildPack === 'svelte'} - - {:else if buildPack === 'vuejs'} - - {:else if buildPack === 'php'} - - {:else if buildPack === 'python'} - - {:else if buildPack === 'static'} - - {:else if buildPack === 'nestjs'} - - {:else if buildPack === 'nuxtjs'} - - {:else if buildPack === 'nextjs'} - - {:else if buildPack === 'gatsby'} - - {:else if buildPack === 'docker'} - - {:else if buildPack === 'astro'} - - {:else if buildPack === 'eleventy'} - - {/if} - -
{application.name}
- {#if $session.teamId === '0'} -
Team {application.teams[0].name}
- {/if} - {#if application.fqdn} -
{application.fqdn}
- {/if} - {#if !application.gitSourceId || !application.destinationDockerId} -
- Configuration missing -
- {/if} -
-
diff --git a/src/routes/applications/index.svelte b/src/routes/applications/index.svelte index 547382498..0c69c47fe 100644 --- a/src/routes/applications/index.svelte +++ b/src/routes/applications/index.svelte @@ -1,9 +1,26 @@ - -
-
-
-
-
Configuration
- -
-
- - - -
-
- - -
- -
- - -
-
- - -
-
-
- - -
- -
-
-
-
diff --git a/src/routes/new/source/_Gitlab.svelte b/src/routes/new/source/_Gitlab.svelte deleted file mode 100644 index 219bc56b0..000000000 --- a/src/routes/new/source/_Gitlab.svelte +++ /dev/null @@ -1,73 +0,0 @@ - - -
-
-
-
Configuration
- -
-
- - -
-
- - -
- -
- - -
-
- - -
-
-
diff --git a/src/routes/new/source/index.svelte b/src/routes/new/source/index.svelte deleted file mode 100644 index 73384561a..000000000 --- a/src/routes/new/source/index.svelte +++ /dev/null @@ -1,66 +0,0 @@ - - -
-
Add New Git Source
-
- -
-
Official providers
-
- - - -
-
-
- {#if gitSource.type === 'github'} - - {:else if gitSource.type === 'gitlab'} - - {:else if gitSource.type === 'bitbucket'} -
Not implemented yet
- {/if} -
diff --git a/src/routes/services/index.svelte b/src/routes/services/index.svelte index 06e74873b..389ee8036 100644 --- a/src/routes/services/index.svelte +++ b/src/routes/services/index.svelte @@ -13,6 +13,7 @@ import Ghost from '$lib/components/svg/services/Ghost.svelte'; import MeiliSearch from '$lib/components/svg/services/MeiliSearch.svelte'; import { session } from '$app/stores'; + import { getDomain } from '$lib/components/common'; export let services; async function newService() { @@ -87,9 +88,12 @@
{service.name}
- {#if $session.teamId === '0'} + {#if $session.teamId === '0' && otherServices.length > 0}
{service.teams[0].name}
{/if} + {#if service.fqdn} +
{getDomain(service.fqdn)}
+ {/if} {#if !service.type || !service.fqdn}
Configuration missing @@ -134,6 +138,9 @@ {#if $session.teamId === '0'}
{service.teams[0].name}
{/if} + {#if service.fqdn} +
{getDomain(service.fqdn)}
+ {/if} {#if !service.type || !service.fqdn}
Configuration missing diff --git a/src/routes/sources/[id]/_Github.svelte b/src/routes/sources/[id]/_Github.svelte index 102971353..b2866d195 100644 --- a/src/routes/sources/[id]/_Github.svelte +++ b/src/routes/sources/[id]/_Github.svelte @@ -3,13 +3,19 @@ import { page, session } from '$app/stores'; import { post } from '$lib/api'; import { errorNotification } from '$lib/form'; + import { toast } from '@zerodevx/svelte-toast'; const { id } = $page.params; let loading = false; async function handleSubmit() { loading = true; try { - return await post(`/sources/${id}.json`, { name: source.name }); + await post(`/sources/${id}.json`, { + name: source.name, + htmlUrl: source.htmlUrl, + apiUrl: source.apiUrl + }); + toast.push('Settings saved.'); } catch ({ error }) { return errorNotification(error); } finally { @@ -38,7 +44,18 @@ }, 100); } - function newGithubApp() { + async function newGithubApp() { + loading = true; + try { + await post(`/sources/${id}/github.json`, { + type: 'github', + name: source.name, + htmlUrl: source.htmlUrl, + apiUrl: source.apiUrl + }); + } catch ({ error }) { + return errorNotification(error); + } const left = screen.width / 2 - 1020 / 2; const top = screen.height / 2 - 618 / 2; const newWindow = open( @@ -59,31 +76,72 @@ } -{#if !source.githubAppId} - -{:else if source.githubApp?.installationId} -
-
-
General
- {#if $session.isAdmin} - - - {/if} -
-
-
- - +
+ {#if !source.githubAppId} + +
+
General
+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ {#if source.apiUrl && source.htmlUrl && source.name} +
+ +
+ {/if} + + {:else if source.githubAppId} +
+
+
General
+ {#if $session.isAdmin} + + + {/if} +
+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ {:else} +
+
- -{:else} - -{/if} + {/if} +
diff --git a/src/routes/sources/[id]/_Gitlab.svelte b/src/routes/sources/[id]/_Gitlab.svelte index 7823aebe9..bf3b48733 100644 --- a/src/routes/sources/[id]/_Gitlab.svelte +++ b/src/routes/sources/[id]/_Gitlab.svelte @@ -1,35 +1,73 @@ -{#if !source.gitlabApp?.appId} -
-
-
- - -
- {#if payload.applicationType === 'group'} -
- - -
- {/if} - -
- -
- - - -
-
-
Configuration
+
+ +
+
General
+ {#if $session.isAdmin} -
+ {#if source.gitlabAppId} + + {/if} + {/if} +
+
+ {#if !source.gitlabAppId} +
+ + +
-
-
- - + + +
+ {/if} + {/if} + +
+
+ + +
+
+ {#if source.gitlabApp.groupName} +
+ +
+ {/if} +
+ + +
+
+ + +
+
+
+ + {#if !source.gitlabAppId} + + {/if} +
- {#if payload.applicationType === 'group'} -
- - -
- {/if} +
- - + +
- - Secret +
- -
-{:else} -
-
-
-
General
- {#if $session.isAdmin} - - - {/if} -
-
-
- - -
-
-
-
-{/if} +
+ + {#if !source.gitlabAppId} + + {/if} +
diff --git a/src/routes/sources/[id]/github.json.ts b/src/routes/sources/[id]/github.json.ts new file mode 100644 index 000000000..e0f1d3b61 --- /dev/null +++ b/src/routes/sources/[id]/github.json.ts @@ -0,0 +1,18 @@ +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 }; + const { id } = event.params; + + try { + let { type, name, htmlUrl, apiUrl } = await event.request.json(); + await db.addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }); + return { status: 201 }; + } catch (error) { + return ErrorHandler(error); + } +}; diff --git a/src/routes/sources/[id]/gitlab.json.ts b/src/routes/sources/[id]/gitlab.json.ts index 8420669e6..b1ed314bf 100644 --- a/src/routes/sources/[id]/gitlab.json.ts +++ b/src/routes/sources/[id]/gitlab.json.ts @@ -9,11 +9,23 @@ export const post: RequestHandler = async (event) => { const { id } = event.params; try { - let { oauthId, groupName, appId, appSecret } = await event.request.json(); + let { type, name, htmlUrl, apiUrl, oauthId, appId, appSecret, groupName } = + await event.request.json(); oauthId = Number(oauthId); - await db.addSource({ id, teamId, oauthId, groupName, appId, appSecret }); + await db.addGitLabSource({ + id, + teamId, + type, + name, + htmlUrl, + apiUrl, + oauthId, + appId, + appSecret, + groupName + }); return { status: 201 }; } catch (error) { return ErrorHandler(error); diff --git a/src/routes/sources/[id]/index.json.ts b/src/routes/sources/[id]/index.json.ts index 58fb7008b..cd19e6785 100644 --- a/src/routes/sources/[id]/index.json.ts +++ b/src/routes/sources/[id]/index.json.ts @@ -43,10 +43,10 @@ export const post: RequestHandler = async (event) => { const { id } = event.params; - const { name } = await event.request.json(); + const { name, htmlUrl, apiUrl } = await event.request.json(); try { - await db.updateGitsource({ id, name }); + await db.updateGitsource({ id, name, htmlUrl, apiUrl }); return { status: 201 }; } catch (error) { return ErrorHandler(error); diff --git a/src/routes/sources/[id]/index.svelte b/src/routes/sources/[id]/index.svelte index 83f171412..015c98a1f 100644 --- a/src/routes/sources/[id]/index.svelte +++ b/src/routes/sources/[id]/index.svelte @@ -29,9 +29,41 @@
@@ -40,10 +72,21 @@ {source.name}
-
- {#if source.type === 'github'} - - {:else if source.type === 'gitlab'} - +
+ {#if !source.gitlabAppId && !source.githubAppId} +
+
Select a provider
+
+ + +
+
{/if} +
+ {#if source.type === 'github'} + + {:else if source.type === 'gitlab'} + + {/if} +
diff --git a/src/routes/sources/[id]/newGithubApp.svelte b/src/routes/sources/[id]/newGithubApp.svelte index c8cb4f6f3..b6a74c3ba 100644 --- a/src/routes/sources/[id]/newGithubApp.svelte +++ b/src/routes/sources/[id]/newGithubApp.svelte @@ -36,6 +36,7 @@ export let settings; onMount(() => { const { organization, id, htmlUrl } = source; + console.log(source); const { fqdn } = settings; const host = dev ? 'http://localhost:3000' diff --git a/src/routes/sources/index.svelte b/src/routes/sources/index.svelte index c763e0b58..e07c21973 100644 --- a/src/routes/sources/index.svelte +++ b/src/routes/sources/index.svelte @@ -22,6 +22,9 @@
Git Sources
{#if $session.isAdmin} - + {/if}
@@ -71,7 +78,7 @@ class:border-l-4={source.gitlabApp && !source.gitlabAppId} >
{source.name}
- {#if $session.teamId === '0'} + {#if $session.teamId === '0' && otherSources.length > 0}
{source.teams[0].name}
{/if} {#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)} @@ -79,7 +86,7 @@ Configuration missing
{:else} -
{source.htmlUrl}
+
{getDomain(source.htmlUrl)}
{/if}
diff --git a/src/routes/new/source/index.json.ts b/src/routes/sources/new.ts similarity index 64% rename from src/routes/new/source/index.json.ts rename to src/routes/sources/new.ts index 803b597e9..25943f8bc 100644 --- a/src/routes/new/source/index.json.ts +++ b/src/routes/sources/new.ts @@ -1,4 +1,4 @@ -import { getUserDetails } from '$lib/common'; +import { getUserDetails, uniqueName } from '$lib/common'; import * as db from '$lib/database'; import { ErrorHandler } from '$lib/database'; import type { RequestHandler } from '@sveltejs/kit'; @@ -7,9 +7,9 @@ export const post: RequestHandler = async (event) => { const { teamId, status, body } = await getUserDetails(event); if (status === 401) return { status, body }; - const { name, type, htmlUrl, apiUrl, organization } = await event.request.json(); + const name = uniqueName(); try { - const { id } = await db.newSource({ name, teamId, type, htmlUrl, apiUrl, organization }); + const { id } = await db.newSource({ teamId, name }); return { status: 201, body: { id } }; } catch (e) { return ErrorHandler(e);