mirror of
https://github.com/ershisan99/coolify.git
synced 2026-01-08 05:02:21 +00:00
91 lines
2.4 KiB
Svelte
91 lines
2.4 KiB
Svelte
<script context="module" lang="ts">
|
|
import type { Load } from '@sveltejs/kit';
|
|
function checkConfiguration(destination: any): string | null {
|
|
let configurationPhase = null;
|
|
if (!destination?.remoteEngine) return configurationPhase;
|
|
if (!destination?.sshKey) {
|
|
configurationPhase = 'sshkey';
|
|
}
|
|
return configurationPhase;
|
|
}
|
|
export const load: Load = async ({ url, params }) => {
|
|
try {
|
|
const { id } = params;
|
|
const response = await get(`/destinations/${id}`);
|
|
const { destination, settings } = response;
|
|
if (id !== 'new' && (!destination || Object.entries(destination).length === 0)) {
|
|
return {
|
|
status: 302,
|
|
redirect: '/destinations'
|
|
};
|
|
}
|
|
const configurationPhase = checkConfiguration(destination);
|
|
if (
|
|
configurationPhase &&
|
|
url.pathname !== `/destinations/${params.id}/configuration/${configurationPhase}`
|
|
) {
|
|
return {
|
|
status: 302,
|
|
redirect: `/destinations/${params.id}/configuration/${configurationPhase}`
|
|
};
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
destination
|
|
},
|
|
stuff: {
|
|
destination,
|
|
settings
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.log(error)
|
|
return handlerNotFoundLoad(error, url);
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
export let destination: any;
|
|
|
|
import { del, get } from '$lib/api';
|
|
import { t } from '$lib/translations';
|
|
import { goto } from '$app/navigation';
|
|
import { page } from '$app/stores';
|
|
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
|
|
import { appSession } from '$lib/store';
|
|
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
|
|
|
|
const { id } = $page.params;
|
|
|
|
async function deleteDestination(destination: any) {
|
|
const sure = confirm($t('application.confirm_to_delete', { name: destination.name }));
|
|
if (sure) {
|
|
try {
|
|
await del(`/destinations/${destination.id}`, { id: destination.id });
|
|
return await goto('/destinations');
|
|
} catch (error) {
|
|
return errorNotification(error);
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
{#if id !== 'new'}
|
|
<nav class="nav-side">
|
|
<button
|
|
on:click={() => deleteDestination(destination)}
|
|
title={$t('source.delete_git_source')}
|
|
type="submit"
|
|
disabled={!$appSession.isAdmin}
|
|
class:hover:text-red-500={$appSession.isAdmin}
|
|
class="icons tooltip-bottom bg-transparent text-sm"
|
|
data-tooltip={$appSession.isAdmin
|
|
? $t('destination.delete_destination')
|
|
: $t('destination.permission_denied_delete_destination')}><DeleteIcon /></button
|
|
>
|
|
</nav>
|
|
{/if}
|
|
<slot />
|