1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-19 22:18:03 +00:00

Added a JSON viewer for items

This commit is contained in:
2023-01-15 12:02:17 +01:00
parent 6931e63f47
commit 5297f00635
10 changed files with 118 additions and 10 deletions

View File

@ -5,6 +5,7 @@
import { input } from '../../actions';
import ObjectGrid from '../../components/objectgrid.svelte';
import Icon from '../../components/icon.svelte';
import JsonViewer from '../../components/jsonviewer.svelte';
export let collection;
@ -21,6 +22,7 @@
let submittedForm = {};
let queryField;
let activeKey = '';
let json = '';
$: code = `db.${collection.key}.find(${form.query || '{}'}${form.fields && form.fields !== '{}' ? `, ${form.fields}` : ''}).sort(${form.sort})${form.skip ? `.skip(${form.skip})` : ''}${form.limit ? `.limit(${form.limit})` : ''};`;
async function submitQuery() {
@ -55,6 +57,12 @@
queryField?.select();
}
function openJson(itemId) {
const item = result?.results?.filter(i => i._id == itemId);
console.log(item);
json = JSON.stringify(item, undefined, 2);
}
export function performQuery(q) {
form = { ...defaults, ...q };
console.log(form);
@ -103,7 +111,7 @@
<div class="result">
<div class="grid">
{#key result}
<ObjectGrid data={result.results} bind:activeKey />
<ObjectGrid data={result.results} bind:activeKey on:trigger={e => openJson(e.detail)} />
{/key}
</div>
@ -128,6 +136,8 @@
</div>
</div>
<JsonViewer bind:json />
<style>
.find {
display: grid;