1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-02-01 02:39:26 +00:00

64 lines
1.5 KiB
Svelte
Raw Normal View History

2023-01-10 17:28:27 +01:00
<script>
2023-01-16 20:03:56 +01:00
import { input } from '../../../actions';
2023-01-13 16:56:48 +01:00
import { createEventDispatcher } from 'svelte';
2023-01-17 09:50:15 +01:00
import { InsertItems } from '../../../../wailsjs/go/app/App';
2023-01-10 17:28:27 +01:00
export let collection;
2023-01-13 16:56:48 +01:00
const dispatch = createEventDispatcher();
let json = '';
2023-01-10 17:28:27 +01:00
let insertedIds;
async function insert() {
2023-01-17 09:50:15 +01:00
insertedIds = await InsertItems(collection.hostKey, collection.dbKey, collection.key, json);
2023-01-13 16:56:48 +01:00
}
function showDocs() {
dispatch('performFind', {
query: insertedIds.length === 1
? `{ "_id": ${JSON.stringify(insertedIds[0])} }`
: `{ "_id": { "$in": [ ${insertedIds.map(id => JSON.stringify(id)).join(', ')} ] } }`,
});
2023-01-10 17:28:27 +01:00
}
</script>
<form on:submit|preventDefault={insert}>
<label class="field">
2023-01-13 16:56:48 +01:00
<textarea
cols="30"
rows="10"
placeholder="[]"
class="code"
bind:value={json}
2023-01-17 17:03:11 +01:00
use:input={{ json: true, autofocus: true }}
2023-01-13 16:56:48 +01:00
></textarea>
2023-01-10 17:28:27 +01:00
</label>
<div class="flex">
<div>
{#if insertedIds}
2023-01-13 16:56:48 +01:00
<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>
2023-01-10 17:28:27 +01:00
{/if}
2023-01-13 16:56:48 +01:00
<button type="submit" class="btn" disabled={!json}>Insert</button>
2023-01-10 17:28:27 +01:00
</div>
</div>
</form>
<style>
2023-01-13 16:56:48 +01:00
form {
display: grid;
grid-template-rows: 1fr auto;
gap: 0.5rem;
}
2023-01-10 17:28:27 +01:00
.flex {
display: flex;
justify-content: space-between;
}
</style>