mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-19 22:18:03 +00:00
Split app.svelte
This commit is contained in:
63
frontend/src/organisms/connection/collection/insert.svelte
Normal file
63
frontend/src/organisms/connection/collection/insert.svelte
Normal file
@ -0,0 +1,63 @@
|
||||
<script>
|
||||
import { input } from '../../../actions';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { PerformInsert } from '../../../../wailsjs/go/app/App';
|
||||
|
||||
export let collection;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
let json = '';
|
||||
let insertedIds;
|
||||
|
||||
async function insert() {
|
||||
insertedIds = await PerformInsert(collection.hostKey, collection.dbKey, collection.key, json);
|
||||
}
|
||||
|
||||
function showDocs() {
|
||||
dispatch('performFind', {
|
||||
query: insertedIds.length === 1
|
||||
? `{ "_id": ${JSON.stringify(insertedIds[0])} }`
|
||||
: `{ "_id": { "$in": [ ${insertedIds.map(id => JSON.stringify(id)).join(', ')} ] } }`,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<form on:submit|preventDefault={insert}>
|
||||
<label class="field">
|
||||
<textarea
|
||||
cols="30"
|
||||
rows="10"
|
||||
placeholder="[]"
|
||||
class="code"
|
||||
bind:value={json}
|
||||
use:input={{ json: true }}
|
||||
></textarea>
|
||||
</label>
|
||||
|
||||
<div class="flex">
|
||||
<div>
|
||||
{#if insertedIds}
|
||||
<span class="flash-green">Success! {insertedIds.length} document{insertedIds.length > 1 ? 's' : ''} inserted</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div>
|
||||
{#if insertedIds}
|
||||
<button class="btn" type="button" on:click={showDocs}>View inserted docs</button>
|
||||
{/if}
|
||||
<button type="submit" class="btn" disabled={!json}>Insert</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
form {
|
||||
display: grid;
|
||||
grid-template-rows: 1fr auto;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user