126 lines
4.0 KiB
Svelte
Raw Normal View History

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>
<div class="flex justify-center">
{#if !sources || sources.length === 0}
<div class="flex-col">
<div class="text-center text-xl font-bold">No git sources found</div>
</div>
{:else}
2022-04-07 15:23:32 +02:00
<div class="flex flex-col">
2022-04-07 15:50:57 +02:00
<div class="flex flex-col md:flex-row flex-wrap px-2 justify-center">
2022-04-07 15:23:32 +02:00
{#each ownSources as source}
<a href="/sources/{source.id}" class="no-underline p-2 w-96">
<div
class="box-selection hover:bg-orange-600 group"
class:border-red-500={source.gitlabApp && !source.gitlabAppId}
class:border-0={source.gitlabApp && !source.gitlabAppId}
class:border-l-4={source.gitlabApp && !source.gitlabAppId}
>
<div class="font-bold text-xl text-center truncate">{source.name}</div>
2022-04-08 10:35:16 +02:00
{#if $session.teamId === '0' && otherSources.length > 0}
2022-04-07 19:17:03 +02:00
<div class="text-center truncate">{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)}
<div class="font-bold text-center truncate text-red-500 group-hover:text-white">
Configuration missing
</div>
{:else}
2022-04-08 10:35:16 +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-07 23:26:06 +02:00
<div class="text-xl font-bold pb-5 pt-10 px-6">Other Srouces</div>
2022-04-07 15:50:57 +02:00
<div class="flex flex-col md:flex-row flex-wrap px-2 justify-center">
2022-04-07 15:23:32 +02:00
{#each otherSources as source}
<a href="/sources/{source.id}" class="no-underline p-2 w-96">
<div
class="box-selection hover:bg-orange-600 group"
class:border-red-500={source.gitlabApp && !source.gitlabAppId}
class:border-0={source.gitlabApp && !source.gitlabAppId}
class:border-l-4={source.gitlabApp && !source.gitlabAppId}
>
<div class="font-bold text-xl text-center truncate">{source.name}</div>
{#if $session.teamId === '0'}
2022-04-07 19:17:03 +02:00
<div class="text-center truncate">{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)}
<div class="font-bold text-center truncate text-red-500 group-hover:text-white">
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>