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

View File

@@ -31,7 +31,7 @@
export let destinations: any; export let destinations: any;
let filtered: any = setInitials(); let filtered: any = setInitials();
import { get, post } from '$lib/api'; import { del, get, post } from '$lib/api';
import { t } from '$lib/translations'; import { t } from '$lib/translations';
import { asyncSleep, errorNotification, getRndInteger } from '$lib/common'; import { asyncSleep, errorNotification, getRndInteger } from '$lib/common';
import { appSession, search } from '$lib/store'; import { appSession, search } from '$lib/store';
@@ -42,6 +42,7 @@
import { dev } from '$app/env'; import { dev } from '$app/env';
import NewResource from './_NewResource.svelte'; import NewResource from './_NewResource.svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
let numberOfGetStatus = 0; let numberOfGetStatus = 0;
let status: any = {}; let status: any = {};
@@ -432,6 +433,39 @@
return errorNotification(error); 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> </script>
<nav class="header"> <nav class="header">
@@ -749,6 +783,11 @@
</svg> </svg>
</a> </a>
{/if} {/if}
<button
class="icons hover:bg-green-500"
on:click|stopPropagation|preventDefault={() =>
deleteApplication(application.id)}><DeleteIcon /></button
>
</div> </div>
</div> </div>
</div> </div>
@@ -857,6 +896,11 @@
</svg> </svg>
</a> </a>
{/if} {/if}
<button
class="icons hover:bg-green-500"
on:click|stopPropagation|preventDefault={() =>
deleteApplication(application.id)}><DeleteIcon /></button
>
</div> </div>
</div> </div>
</div> </div>
@@ -947,6 +991,11 @@
</svg> </svg>
</a> </a>
{/if} {/if}
<button
class="icons hover:bg-pink-500"
on:click|stopPropagation|preventDefault={() => deleteService(service.id)}
><DeleteIcon /></button
>
</div> </div>
</div> </div>
</div> </div>
@@ -1028,6 +1077,11 @@
</svg> </svg>
</a> </a>
{/if} {/if}
<button
class="icons hover:bg-pink-500"
on:click|stopPropagation|preventDefault={() => deleteService(service.id)}
><DeleteIcon /></button
>
</div> </div>
</div> </div>
</div> </div>
@@ -1119,6 +1173,11 @@
</svg> </svg>
</div> </div>
{/if} {/if}
<button
class="icons hover:bg-databases-100"
on:click|stopPropagation|preventDefault={() => deleteDatabase(database.id)}
><DeleteIcon /></button
>
</div> </div>
</div> </div>
</div> </div>
@@ -1200,6 +1259,11 @@
</svg> </svg>
</div> </div>
{/if} {/if}
<button
class="icons hover:bg-databases"
on:click|stopPropagation|preventDefault={() => deleteDatabase(database.id)}
><DeleteIcon /></button
>
</div> </div>
</div> </div>
</div> </div>

View File

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