mirror of
https://github.com/ershisan99/coolify.git
synced 2026-01-29 05:12:06 +00:00
71
apps/ui/src/routes/destinations/[id]/__layout.svelte
Normal file
71
apps/ui/src/routes/destinations/[id]/__layout.svelte
Normal file
@@ -0,0 +1,71 @@
|
||||
<script context="module" lang="ts">
|
||||
import type { Load } from '@sveltejs/kit';
|
||||
export const load: Load = async ({ fetch, url, params }) => {
|
||||
try {
|
||||
const { id } = params;
|
||||
const response = await get(`/destinations/${id}`);
|
||||
const { destination, settings, state } = response;
|
||||
if (id !== 'new' && (!destination || Object.entries(destination).length === 0)) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/destinations'
|
||||
};
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
destination
|
||||
},
|
||||
stuff: {
|
||||
destination,
|
||||
settings,
|
||||
state
|
||||
}
|
||||
};
|
||||
} catch (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 />
|
||||
Reference in New Issue
Block a user