1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-16 13:04:06 +00:00
Files
rolens/frontend/src/organisms/connection/host/dialogs/hostdetail.svelte

92 lines
2.0 KiB
Svelte
Raw Normal View History

2023-01-18 20:59:00 +01:00
<script>
2023-02-15 19:27:51 +01:00
import Modal from '$components/modal.svelte';
2023-08-07 18:21:45 +02:00
import input from '$lib/actions/input.js';
import hostTree from '$lib/stores/hosttree.js';
import { AddHost, UpdateHost } from '$wails/go/app/App.js';
import { createEventDispatcher, onMount } from 'svelte';
2023-01-18 20:59:00 +01:00
2023-01-20 19:08:56 +01:00
export let hostKey = '';
2023-01-18 20:59:00 +01:00
2023-01-20 19:08:56 +01:00
const dispatch = createEventDispatcher();
2023-01-22 21:12:56 +01:00
let form = {};
2023-01-18 20:59:00 +01:00
let error = '';
$: valid = validate(form);
$: host = $hostTree[hostKey];
2023-01-18 20:59:00 +01:00
function validate(form) {
return form.name && form.uri && true;
}
async function submit() {
if (!valid) {
return;
}
try {
2023-01-20 19:08:56 +01:00
if (host && hostKey) {
await UpdateHost(hostKey, JSON.stringify(form));
}
else {
const newHostKey = await AddHost(JSON.stringify(form));
if (newHostKey) {
hostKey = newHostKey;
}
2023-01-20 19:08:56 +01:00
}
dispatch('updated', form);
dispatch('close');
2023-01-18 20:59:00 +01:00
}
catch (e) {
error = e;
}
}
onMount(() => {
form = { ...(host || {}) };
});
2023-01-18 20:59:00 +01:00
</script>
<Modal title={host ? `Edit ${host.name}` : 'Create a new host'} on:close>
2023-01-18 20:59:00 +01:00
<form on:submit|preventDefault={submit}>
<label class="field">
<span class="label">Label</span>
2023-01-20 19:08:56 +01:00
<input type="text" placeholder="mywebsite.com MongoDB" bind:value={form.name} use:input={{ autofocus: true }} />
2023-01-18 20:59:00 +01:00
</label>
<label class="field">
<span class="label">Connection string</span>
2023-08-07 18:21:45 +02:00
<input
type="text"
placeholder="mongodb://..."
bind:value={form.uri}
spellcheck="false"
use:input
/>
2023-01-18 20:59:00 +01:00
</label>
</form>
2023-01-18 20:59:00 +01:00
<div class="result" slot="footer">
<div>
{#if error}
<div class="error">{error}</div>
{/if}
2023-01-18 20:59:00 +01:00
</div>
2023-06-27 17:21:54 +02:00
<button class="button" disabled={!valid} on:click={submit}>
{host ? 'Save' : 'Create'}
</button>
</div>
2023-01-18 20:59:00 +01:00
</Modal>
<style>
form {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.result {
display: flex;
justify-content: space-between;
align-items: center;
}
</style>