1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 21:17:59 +00:00

More UI improvements

This commit is contained in:
Romein van Buren 2023-01-13 16:56:48 +01:00
parent 90ffdc6a8b
commit 516f25801f
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
9 changed files with 84 additions and 17 deletions

View File

@ -105,9 +105,9 @@
<style> <style>
.grid { .grid {
background-color: #fff;
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: #fff;
} }
.grid.contained { .grid.contained {
border: 1px solid #ccc; border: 1px solid #ccc;
@ -152,6 +152,8 @@
button.toggle { button.toggle {
color: inherit; color: inherit;
padding: 0; padding: 0;
margin: 0;
display: contents;
} }
button.toggle :global(svg) { button.toggle :global(svg) {
width: 15px; width: 15px;

View File

@ -28,7 +28,6 @@
} }
else { else {
items = dissectObject(data); items = dissectObject(data);
console.log(items);
} }
} }
@ -55,11 +54,13 @@
} }
function dissectObject(object) { function dissectObject(object) {
return Object.entries(object).map(([ key, value ]) => { const entries = [ ...Array.isArray(object) ? object.entries() : Object.entries(object) ];
return entries.map(([ key, value ]) => {
key = key + '';
const type = getType(value); const type = getType(value);
const child = { key, value, type }; const child = { key, value, type };
if (type.startsWith('object')) { if (type.startsWith('object') || type.startsWith('array')) {
child.children = dissectObject(value); child.children = dissectObject(value);
} }

View File

@ -44,6 +44,7 @@
border-bottom: none; border-bottom: none;
border-radius: 5px 5px 0 0; border-radius: 5px 5px 0 0;
cursor: pointer; cursor: pointer;
background-color: #fff;
} }
.tabs li.active button { .tabs li.active button {
color: #fff; color: #fff;

View File

@ -57,6 +57,7 @@
height: 3rem; height: 3rem;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 10px; border-radius: 10px;
background-color: #fff;
} }
.address .protocol, .address .protocol,

View File

@ -16,7 +16,7 @@
limit: 30, limit: 30,
}; };
const form = { let form = {
query: '{}', query: '{}',
sort: '{ "_id": 1 }', sort: '{ "_id": 1 }',
fields: '{}', fields: '{}',
@ -62,6 +62,12 @@
queryField?.select(); queryField?.select();
} }
export function performQuery(q) {
form = { ...defaults, ...q };
console.log(form);
submitQuery();
}
onMount(resetFocus); onMount(resetFocus);
</script> </script>
@ -110,9 +116,9 @@
<div class="controls"> <div class="controls">
<div> <div>
{#if result} {#key result}
Results: {result.total || 0} <span class="flash-green">Results: {result.total || 0}</span>
{/if} {/key}
</div> </div>
<div> <div>
<button class="btn danger" on:click={remove} disabled={!activeKey}> <button class="btn danger" on:click={remove} disabled={!activeKey}>

View File

@ -1,4 +1,5 @@
<script> <script>
import { tick } from 'svelte';
import TabBar from '../../components/tabbar.svelte'; import TabBar from '../../components/tabbar.svelte';
import Find from './find.svelte'; import Find from './find.svelte';
import Indexes from './indexes.svelte'; import Indexes from './indexes.svelte';
@ -12,12 +13,20 @@
export let collectionKey; export let collectionKey;
let tab = 'find'; let tab = 'find';
let find;
$: if (collection) { $: if (collection) {
collection.hostKey = hostKey; collection.hostKey = hostKey;
collection.dbKey = dbKey; collection.dbKey = dbKey;
collection.key = collectionKey; collection.key = collectionKey;
} }
async function catchQuery(event) {
tab = 'find';
await tick();
console.log(event, find);
find.performQuery(event.detail);
}
</script> </script>
<div class="collection" class:empty={!collection}> <div class="collection" class:empty={!collection}>
@ -34,8 +43,8 @@
<div class="container"> <div class="container">
{#if tab === 'stats'} <Stats {collection} /> {#if tab === 'stats'} <Stats {collection} />
{:else if tab === 'find'} <Find {collection} /> {:else if tab === 'find'} <Find {collection} bind:this={find} />
{:else if tab === 'insert'} <Insert {collection} /> {:else if tab === 'insert'} <Insert {collection} on:performFind={catchQuery} />
{:else if tab === 'remove'} <Remove {collection} /> {:else if tab === 'remove'} <Remove {collection} />
{:else if tab === 'indexes'} <Indexes {collection} /> {:else if tab === 'indexes'} <Indexes {collection} />
{/if} {/if}

View File

@ -1,35 +1,63 @@
<script> <script>
import { input } from '../../actions';
import { createEventDispatcher } from 'svelte';
import { PerformInsert } from '../../../wailsjs/go/main/App'; import { PerformInsert } from '../../../wailsjs/go/main/App';
export let collection; export let collection;
let input = ''; const dispatch = createEventDispatcher();
let json = '';
let insertedIds; let insertedIds;
async function insert() { async function insert() {
insertedIds = await PerformInsert(collection.hostKey, collection.dbKey, collection.key, input); 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> </script>
<form on:submit|preventDefault={insert}> <form on:submit|preventDefault={insert}>
<label class="field"> <label class="field">
<textarea cols="30" rows="10" bind:value={input} placeholder="[]" class="code"></textarea> <textarea
cols="30"
rows="10"
placeholder="[]"
class="code"
bind:value={json}
use:input={{ json: true }}
></textarea>
</label> </label>
<div class="flex"> <div class="flex">
<div> <div>
{#if insertedIds} {#if insertedIds}
Success! {insertedIds.length} document{insertedIds.length > 1 ? 's' : ''} inserted <span class="flash-green">Success! {insertedIds.length} document{insertedIds.length > 1 ? 's' : ''} inserted</span>
{/if} {/if}
</div> </div>
<button type="submit" class="btn" disabled={!input}>Insert</button> <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> </div>
</form> </form>
<style> <style>
form {
display: grid;
grid-template-rows: 1fr auto;
gap: 0.5rem;
}
.flex { .flex {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-top: 0.5rem;
} }
</style> </style>

View File

@ -23,9 +23,14 @@
</form> </form>
<style> <style>
form {
display: grid;
grid-template-rows: auto 1fr auto;
gap: 0.5rem;
}
.flex { .flex {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-top: 0.5rem;
} }
</style> </style>

View File

@ -10,11 +10,17 @@ body {
cursor: default; cursor: default;
font-size: 15px; font-size: 15px;
line-height: 15px; line-height: 15px;
background-color: #eee;
} }
* { * {
vertical-align: middle; vertical-align: middle;
box-sizing: border-box; box-sizing: border-box;
overscroll-behavior: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
touch-action: none;
} }
p { p {
@ -96,3 +102,11 @@ p {
code, .code { code, .code {
font-family: Menlo, monospace; font-family: Menlo, monospace;
} }
@keyframes flashGreen {
0% { color: #0d0; }
100% { color: unset; }
}
.flash-green {
animation: 1s ease-out 0s 1 flashGreen;
}