2022-02-10 15:47:44 +01:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
import type { Load } from '@sveltejs/kit';
|
|
|
|
export const load: Load = async ({ fetch }) => {
|
|
|
|
const url = `/sources.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 sources;
|
|
|
|
import { session } from '$app/stores';
|
2022-04-08 10:35:16 +02:00
|
|
|
import { post } from '$lib/api';
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
import { getDomain } from '$lib/components/common';
|
2022-04-07 15:23:32 +02:00
|
|
|
const ownSources = sources.filter((source) => {
|
|
|
|
if (source.teams[0].id === $session.teamId) {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const otherSources = sources.filter((source) => {
|
|
|
|
if (source.teams[0].id !== $session.teamId) {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
});
|
2022-04-08 10:35:16 +02:00
|
|
|
async function newSource() {
|
|
|
|
const { id } = await post('/sources/new', {});
|
|
|
|
return await goto(`/sources/${id}`, { replaceState: true });
|
|
|
|
}
|
2022-02-10 15:47:44 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="flex space-x-1 p-6 font-bold">
|
|
|
|
<div class="mr-4 text-2xl tracking-tight">Git Sources</div>
|
|
|
|
{#if $session.isAdmin}
|
2022-04-08 10:35:16 +02:00
|
|
|
<button on:click={newSource} class="add-icon bg-orange-600 hover:bg-orange-500">
|
2022-02-10 15:47:44 +01:00
|
|
|
<svg
|
|
|
|
class="w-6"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
fill="none"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
stroke="currentColor"
|
|
|
|
><path
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
stroke-width="2"
|
|
|
|
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
|
|
|
|
/></svg
|
|
|
|
>
|
2022-04-08 10:35:16 +02:00
|
|
|
</button>
|
2022-02-10 15:47:44 +01:00
|
|
|
{/if}
|
|
|
|
</div>
|
2022-04-08 15:02:48 +02:00
|
|
|
<div class="flex flex-col flex-wrap justify-center">
|
2022-04-08 14:03:21 +02:00
|
|
|
{#if !sources || ownSources.length === 0}
|
2022-02-10 15:47:44 +01:00
|
|
|
<div class="flex-col">
|
|
|
|
<div class="text-center text-xl font-bold">No git sources found</div>
|
|
|
|
</div>
|
2022-04-08 14:12:06 +02:00
|
|
|
{/if}
|
|
|
|
{#if ownSources.length > 0 || otherSources.length > 0}
|
2022-04-07 15:23:32 +02:00
|
|
|
<div class="flex flex-col">
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="flex flex-col flex-wrap justify-center px-2 md:flex-row">
|
2022-04-07 15:23:32 +02:00
|
|
|
{#each ownSources as source}
|
2022-04-08 14:12:06 +02:00
|
|
|
<a href="/sources/{source.id}" class="w-96 p-2 no-underline">
|
2022-04-07 15:23:32 +02:00
|
|
|
<div
|
2022-04-08 14:12:06 +02:00
|
|
|
class="box-selection group hover:bg-orange-600"
|
2022-04-07 15:23:32 +02:00
|
|
|
class:border-red-500={source.gitlabApp && !source.gitlabAppId}
|
|
|
|
class:border-0={source.gitlabApp && !source.gitlabAppId}
|
|
|
|
class:border-l-4={source.gitlabApp && !source.gitlabAppId}
|
|
|
|
>
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="truncate text-center text-xl font-bold">{source.name}</div>
|
2022-04-08 10:35:16 +02:00
|
|
|
{#if $session.teamId === '0' && otherSources.length > 0}
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="truncate text-center">{source.teams[0].name}</div>
|
2022-04-07 15:23:32 +02:00
|
|
|
{/if}
|
|
|
|
{#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)}
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="truncate text-center font-bold text-red-500 group-hover:text-white">
|
2022-04-07 15:23:32 +02:00
|
|
|
Configuration missing
|
|
|
|
</div>
|
|
|
|
{:else}
|
2022-04-08 14:03:21 +02:00
|
|
|
<div class="truncate text-center">{getDomain(source.htmlUrl) || ''}</div>
|
2022-04-07 15:23:32 +02:00
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if otherSources.length > 0 && $session.teamId === '0'}
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="px-6 pb-5 pt-10 text-xl font-bold">Other Sources</div>
|
|
|
|
<div class="flex flex-col flex-wrap justify-center px-2 md:flex-row">
|
2022-04-07 15:23:32 +02:00
|
|
|
{#each otherSources as source}
|
2022-04-08 14:12:06 +02:00
|
|
|
<a href="/sources/{source.id}" class="w-96 p-2 no-underline">
|
2022-04-07 15:23:32 +02:00
|
|
|
<div
|
2022-04-08 14:12:06 +02:00
|
|
|
class="box-selection group hover:bg-orange-600"
|
2022-04-07 15:23:32 +02:00
|
|
|
class:border-red-500={source.gitlabApp && !source.gitlabAppId}
|
|
|
|
class:border-0={source.gitlabApp && !source.gitlabAppId}
|
|
|
|
class:border-l-4={source.gitlabApp && !source.gitlabAppId}
|
|
|
|
>
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="truncate text-center text-xl font-bold">{source.name}</div>
|
2022-04-07 15:23:32 +02:00
|
|
|
{#if $session.teamId === '0'}
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="truncate text-center">{source.teams[0].name}</div>
|
2022-04-07 15:23:32 +02:00
|
|
|
{/if}
|
|
|
|
{#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)}
|
2022-04-08 14:12:06 +02:00
|
|
|
<div class="truncate text-center font-bold text-red-500 group-hover:text-white">
|
2022-04-07 15:23:32 +02:00
|
|
|
Configuration missing
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<div class="truncate text-center">{source.htmlUrl}</div>
|
|
|
|
{/if}
|
2022-02-10 15:47:44 +01:00
|
|
|
</div>
|
2022-04-07 15:23:32 +02:00
|
|
|
</a>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-02-10 15:47:44 +01:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|