fix: delete resource on dashboard

This commit is contained in:
Andras Bacsai 2022-12-07 15:27:26 +01:00
parent 132707caa7
commit 2e3c815e53
3 changed files with 74 additions and 9 deletions

View File

@ -495,9 +495,9 @@
{#if !isSimpleDockerfile}
<div class="grid grid-cols-2 items-center">
<label for="gitSource">{$t('application.git_source')}</label>
{#if isDisabled || application.settings.isPublicRepository}
{#if isDisabled || application.settings?.isPublicRepository}
<input
disabled={isDisabled || application.settings.isPublicRepository}
disabled={isDisabled || application.settings?.isPublicRepository}
class="w-full"
value={application.gitSource?.name}
/>
@ -526,7 +526,7 @@
/>
<a
href="{application.gitSource
.htmlUrl}/{application.repository}/commits/{application.branch}"
?.htmlUrl}/{application.repository}/commits/{application.branch}"
target="_blank noreferrer"
class="btn btn-primary text-xs"
>Commits<svg
@ -548,10 +548,10 @@
</div>
<div class="grid grid-cols-2 items-center">
<label for="repository">{$t('application.git_repository')}</label>
{#if isDisabled || application.settings.isPublicRepository}
{#if isDisabled || application.settings?.isPublicRepository}
<input
class="w-full"
disabled={isDisabled || application.settings.isPublicRepository}
disabled={isDisabled || application.settings?.isPublicRepository}
value="{application.repository}/{application.branch}"
/>
{:else}
@ -633,7 +633,7 @@
<label for="destination">{$t('application.destination')}</label>
<div class="no-underline">
<input
value={application.destinationDocker.name}
value={application.destinationDocker?.name}
id="destination"
disabled
class="bg-transparent w-full"
@ -880,7 +880,7 @@
/>
</div>
<div class="text-center bg-green-600 rounded">
Connected to {application.connectedDatabase.databaseId}
Connected to {application.connectedDatabase?.databaseId}
</div>
{/if}
{/if}
@ -1230,7 +1230,7 @@
readonly={!$appSession.isAdmin}
name="port"
id="port"
required={!!dockerComposeConfiguration[service.name].fqdn}
required={!!dockerComposeConfiguration[service.name]?.fqdn}
bind:value={dockerComposeConfiguration[service.name].port}
/>
</div>

View File

@ -31,7 +31,7 @@
export let destinations: any;
let filtered: any = setInitials();
import { get, post } from '$lib/api';
import { del, get, post } from '$lib/api';
import { t } from '$lib/translations';
import { asyncSleep, errorNotification, getRndInteger } from '$lib/common';
import { appSession, search } from '$lib/store';
@ -42,6 +42,7 @@
import { dev } from '$app/env';
import NewResource from './_NewResource.svelte';
import { onMount } from 'svelte';
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
let numberOfGetStatus = 0;
let status: any = {};
@ -432,6 +433,39 @@
return errorNotification(error);
}
}
async function deleteApplication(id: string) {
try {
const sure = confirm('Are you sure? This will delete this application!');
if (sure) {
await del(`/applications/${id}`, { force: true });
return window.location.reload();
}
} catch (error) {
return errorNotification(error);
}
}
async function deleteService(id: string) {
try {
const sure = confirm('Are you sure? This will delete this service!');
if (sure) {
await del(`/services/${id}`, {});
return window.location.reload();
}
} catch (error) {
return errorNotification(error);
}
}
async function deleteDatabase(id: string) {
try {
const sure = confirm('Are you sure? This will delete this database!');
if (sure) {
await del(`/databases/${id}`, { force: true });
return window.location.reload();
}
} catch (error) {
return errorNotification(error);
}
}
</script>
<nav class="header">
@ -749,6 +783,11 @@
</svg>
</a>
{/if}
<button
class="icons hover:bg-green-500"
on:click|stopPropagation|preventDefault={() =>
deleteApplication(application.id)}><DeleteIcon /></button
>
</div>
</div>
</div>
@ -857,6 +896,11 @@
</svg>
</a>
{/if}
<button
class="icons hover:bg-green-500"
on:click|stopPropagation|preventDefault={() =>
deleteApplication(application.id)}><DeleteIcon /></button
>
</div>
</div>
</div>
@ -947,6 +991,11 @@
</svg>
</a>
{/if}
<button
class="icons hover:bg-pink-500"
on:click|stopPropagation|preventDefault={() => deleteService(service.id)}
><DeleteIcon /></button
>
</div>
</div>
</div>
@ -1028,6 +1077,11 @@
</svg>
</a>
{/if}
<button
class="icons hover:bg-pink-500"
on:click|stopPropagation|preventDefault={() => deleteService(service.id)}
><DeleteIcon /></button
>
</div>
</div>
</div>
@ -1119,6 +1173,11 @@
</svg>
</div>
{/if}
<button
class="icons hover:bg-databases-100"
on:click|stopPropagation|preventDefault={() => deleteDatabase(database.id)}
><DeleteIcon /></button
>
</div>
</div>
</div>
@ -1200,6 +1259,11 @@
</svg>
</div>
{/if}
<button
class="icons hover:bg-databases"
on:click|stopPropagation|preventDefault={() => deleteDatabase(database.id)}
><DeleteIcon /></button
>
</div>
</div>
</div>

View File

@ -42,6 +42,7 @@ module.exports = {
colors: {
"applications": "#16A34A",
"databases": "#9333EA",
"databases-100": "#9b46ea",
"destinations": "#0284C7",
"sources": "#EA580C",
"services": "#DB2777",