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

First commit in a long time

This commit is contained in:
2023-05-26 17:21:39 +02:00
parent b15fde11db
commit a84b1498a3
17 changed files with 321 additions and 87 deletions

View File

@ -0,0 +1,61 @@
<script>
import Icon from '$components/icon.svelte';
import Modal from '$components/modal.svelte';
import { startProgress } from '$lib/progress';
import views from '$lib/stores/views';
import { createEventDispatcher } from 'svelte';
export let info;
export let collection;
const dispatch = createEventDispatcher();
let viewKey = collection.viewKey;
$: viewKey = collection.viewKey;
async function performExport() {
const progress = startProgress('Performing export…');
info.view = $views[viewKey];
//...
progress.end();
}
</script>
<Modal bind:show={info} title="Export results" width="400px">
<form on:submit|preventDefault={performExport}>
<label class="field">
<span class="label">Export</span>
<select bind:value={info.contents}>
<option value="all">all records</option>
<option value="query">all records matching query</option>
<option value="querylimitskip">all records matching query, considering limit and skip</option>
</select>
</label>
<label class="field">
<span class="label">Format</span>
<select bind:value={info.format}>
<option value="jsonarray">JSON array</option>
<option value="jsonnewline">JSON: newline-separated objects</option>
<option value="csv">CSV</option>
</select>
</label>
<label class="field">
<span class="label">View to use</span>
<select bind:value={viewKey}>
{#each Object.entries(views.forCollection(collection.hostKey, collection.dbKey, collection.key)) as [key, { name }]}
<option value={key}>{name}</option>
{/each}
</select>
<button class="btn" type="button" on:click={() => dispatch('openViewConfig')} title="Edit view">
<Icon name="cog" />
</button>
</label>
</form>
</Modal>
<style>
form {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
</style>

View File

@ -1,19 +1,18 @@
<script>
// import CodeExample from '$components/code-example.svelte';
import Grid from '$components/grid.svelte';
import Icon from '$components/icon.svelte';
import ObjectGrid from '$components/objectgrid.svelte';
import input from '$lib/actions/input';
import { deepClone } from '$lib/objects';
import busy from '$lib/stores/busy';
import { startProgress } from '$lib/progress';
import queries from '$lib/stores/queries';
import applicationSettings from '$lib/stores/settings';
import views from '$lib/stores/views';
import { FindItems, RemoveItemById } from '$wails/go/app/App';
import { EJSON } from 'bson';
import { createEventDispatcher, onMount } from 'svelte';
import ExportInfo from './components/export.svelte';
import QueryChooser from './components/querychooser.svelte';
// import ObjectViewer from '$components/objectviewer.svelte';
export let collection;
export let hosts = {};
@ -35,6 +34,7 @@
let objectViewerData;
let queryToSave;
let showQueryChooser = false;
let exportInfo;
$: viewsForCollection = views.forCollection(collection.hostKey, collection.dbKey, collection.key);
$: 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})` : ''};`;
@ -42,7 +42,7 @@
$: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0;
async function submitQuery() {
busy.start();
const progress = startProgress('Performing query…');
activePath = [];
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
if (newResult) {
@ -50,7 +50,7 @@
result = newResult;
submittedForm = deepClone(form);
}
busy.end();
progress.end();
resetFocus();
}
@ -168,7 +168,7 @@
<button class="btn" type="button" on:click={saveQuery}>
<Icon name="save" /> Save as…
</button>
<button class="btn" type="button" on:click={saveQuery}>
<button class="btn" type="button" on:click={() => exportInfo = {}}>
<Icon name="save" /> Export results…
</button>
<button type="submit" class="btn" title="Run query">
@ -245,6 +245,8 @@
{collection}
/>
<ExportInfo on:openViewConfig bind:collection bind:info={exportInfo} />
<!-- <ObjectViewer bind:data={objectViewerData} /> -->
<datalist id="limits">

View File

@ -1,5 +1,4 @@
<script>
// import CodeExample from '$components/code-example.svelte';
import Icon from '$components/icon.svelte';
import input from '$lib/actions/input';
import { RemoveItems } from '$wails/go/app/App';

View File

@ -1,5 +1,4 @@
<script>
// import CodeExample from '$components/code-example.svelte';
import ObjectGrid from '$components/objectgrid.svelte';
export let collection;

View File

@ -1,5 +1,4 @@
<script>
// import CodeExample from '$components/code-example.svelte';
import Icon from '$components/icon.svelte';
import input from '$lib/actions/input';
import { atomicUpdateOperators } from '$lib/mongo';

View File

@ -2,7 +2,7 @@
import DirectoryChooser from '$components/directorychooser.svelte';
import Grid from '$components/grid.svelte';
import Modal from '$components/modal.svelte';
import busy from '$lib/stores/busy';
import { startProgress } from '$lib/progress';
import { connections } from '$lib/stores/connections';
import applicationSettings from '$lib/stores/settings';
import { OpenConnection, OpenDatabase, PerformDump } from '$wails/go/app/App';
@ -21,7 +21,7 @@
info.collKeys = [];
if (hostKey) {
busy.start();
const progress = startProgress(`Opening connection to host "${hostKey}"`);
const databases = await OpenConnection(hostKey);
if (databases && !$connections[hostKey]) {
@ -31,7 +31,7 @@
});
}
busy.end();
progress.end();
}
}
@ -40,14 +40,14 @@
info.dbKey = dbKey;
if (dbKey) {
busy.start();
const progress = startProgress(`Opening database "${dbKey}"`);
const collections = await OpenDatabase(info.hostKey, dbKey);
for (const collKey of collections?.sort() || []) {
$connections[info.hostKey].databases[dbKey].collections[collKey] = {};
}
busy.end();
progress.end();
}
}

View File

@ -1,6 +1,6 @@
<script>
import Grid from '$components/grid.svelte';
import busy from '$lib/stores/busy';
import { startProgress } from '$lib/progress';
import { connections } from '$lib/stores/connections';
import { WindowSetTitle } from '$wails/runtime/runtime';
import { createEventDispatcher } from 'svelte';
@ -28,7 +28,7 @@
}
async function openConnection(hostKey) {
busy.start();
const progress = startProgress(`Connecting to "${hostKey}"…`);
const databases = await OpenConnection(hostKey);
if (databases) {
@ -41,47 +41,47 @@
WindowSetTitle(`${hosts[activeHostKey].name} - Rolens`);
}
busy.end();
progress.end();
}
async function openDatabase(dbKey) {
busy.start();
const progress = startProgress(`Opening database "${dbKey}"…`);
const collections = await OpenDatabase(activeHostKey, dbKey);
for (const collKey of collections || []) {
$connections[activeHostKey].databases[dbKey].collections[collKey] = {};
}
busy.end();
progress.end();
}
async function dropDatabase(dbKey) {
busy.start();
const progress = startProgress(`Dropping database "${dbKey}"…`);
await DropDatabase(activeHostKey, dbKey);
await reload();
busy.end();
progress.end();
}
async function openCollection(collKey) {
busy.start();
const progress = startProgress(`Opening collection "${collKey}"…`);
const stats = await OpenCollection(activeHostKey, activeDbKey, collKey);
$connections[activeHostKey].databases[activeDbKey].collections[collKey] = $connections[activeHostKey].databases[activeDbKey].collections[collKey] || {};
$connections[activeHostKey].databases[activeDbKey].collections[collKey].stats = stats;
busy.end();
progress.end();
}
async function truncateCollection(dbKey, collKey) {
busy.start();
const progress = startProgress(`Truncating collection "${collKey}"…`);
await TruncateCollection(activeHostKey, dbKey, collKey);
await reload();
busy.end();
progress.end();
}
async function dropCollection(dbKey, collKey) {
busy.start();
const progress = startProgress(`Dropping collection "${collKey}"…`);
await DropCollection(activeHostKey, dbKey, collKey);
await reload();
busy.end();
progress.end();
}
</script>

View File

@ -1,5 +1,5 @@
<script>
import busy from '$lib/stores/busy';
import { startProgress } from '$lib/progress';
import { connections } from '$lib/stores/connections';
import { Hosts, RenameCollection } from '$wails/go/app/App';
import { EnterText } from '$wails/go/ui/UI';
@ -44,13 +44,13 @@
async function renameCollection(oldCollKey) {
const newCollKey = await EnterText('Rename collection', `Enter a new name for collection ${oldCollKey}.`, oldCollKey);
if (newCollKey && (newCollKey !== oldCollKey)) {
busy.start();
const progress = startProgress(`Renaming collection "${oldCollKey}" to "${newCollKey}"…`);
const ok = await RenameCollection(activeHostKey, activeDbKey, oldCollKey, newCollKey);
if (ok) {
activeCollKey = newCollKey;
await hostTree.reload();
}
busy.end();
progress.end();
}
}