diff --git a/frontend/src/components/grid-items.svelte b/frontend/src/components/grid-items.svelte
index bac58f8..bfe1c7c 100644
--- a/frontend/src/components/grid-items.svelte
+++ b/frontend/src/components/grid-items.svelte
@@ -96,9 +96,12 @@
contextMenu.show(evt, item.menu);
}
- function removeItem(index) {
- items.splice(index, 1);
- items = items;
+ function removeItem(index, itemKey) {
+ if (Array.isArray(items)) {
+ items.splice(index, 1);
+ items = items;
+ }
+ dispatch('removeItem', itemKey);
}
function formatValue(value) {
@@ -167,7 +170,7 @@
{#if canRemoveItems}
- |
diff --git a/frontend/src/components/grid.svelte b/frontend/src/components/grid.svelte
index 71c53a1..a582675 100644
--- a/frontend/src/components/grid.svelte
+++ b/frontend/src/components/grid.svelte
@@ -62,6 +62,7 @@
bind:inputsValid
on:select
on:trigger
+ on:removeItem
/>
@@ -87,6 +88,7 @@
border-collapse: collapse;
width: 100%;
background-color: #fff;
+ table-layout: fixed;
}
table thead {
diff --git a/frontend/src/components/hint.svelte b/frontend/src/components/hint.svelte
index ffeebf5..9371ef7 100644
--- a/frontend/src/components/hint.svelte
+++ b/frontend/src/components/hint.svelte
@@ -9,7 +9,7 @@
diff --git a/frontend/src/components/icon.svelte b/frontend/src/components/icon.svelte
index 85b869e..2511e6b 100644
--- a/frontend/src/components/icon.svelte
+++ b/frontend/src/components/icon.svelte
@@ -81,5 +81,11 @@
{:else if name === 'info'}
+ {:else if name === 'play'}
+
+ {:else if name === 'upload'}
+
+ {:else if name === 'save'}
+
{/if}
diff --git a/frontend/src/lib/stores/queries.js b/frontend/src/lib/stores/queries.js
new file mode 100644
index 0000000..6bc983c
--- /dev/null
+++ b/frontend/src/lib/stores/queries.js
@@ -0,0 +1,45 @@
+import { get, writable } from 'svelte/store';
+import { RemoveQuery, SavedQueries, SaveQuery, UpdateQueries } from '../../../wailsjs/go/app/App';
+
+const { set, subscribe } = writable({});
+let skipUpdate = true;
+
+async function reload() {
+ const newViewStore = await SavedQueries();
+ set(newViewStore);
+ return newViewStore;
+}
+
+function forCollection(hostKey, dbKey, collKey) {
+ const allViews = get({ subscribe });
+ const entries = Object.entries(allViews).filter(v => (
+ v[1].hostKey === hostKey &&
+ v[1].dbKey === dbKey &&
+ v[1].collKey === collKey
+ ));
+
+ return Object.fromEntries(entries);
+}
+
+async function create(query) {
+ const newId = await SaveQuery(JSON.stringify(query));
+ await reload();
+ return newId;
+}
+
+async function remove(id) {
+ await RemoveQuery(id);
+ await reload();
+}
+
+reload();
+subscribe(newViewStore => {
+ if (skipUpdate) {
+ skipUpdate = false;
+ return;
+ }
+ UpdateQueries(JSON.stringify(newViewStore));
+});
+
+const queries = { reload, create, remove, set, subscribe, forCollection };
+export default queries;
diff --git a/frontend/src/organisms/connection/collection/components/querychooser.svelte b/frontend/src/organisms/connection/collection/components/querychooser.svelte
new file mode 100644
index 0000000..88c2558
--- /dev/null
+++ b/frontend/src/organisms/connection/collection/components/querychooser.svelte
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte
index c8ba1f7..1436af5 100644
--- a/frontend/src/organisms/connection/collection/find.svelte
+++ b/frontend/src/organisms/connection/collection/find.svelte
@@ -9,6 +9,8 @@
import Icon from '../../../components/icon.svelte';
import ObjectGrid from '../../../components/objectgrid.svelte';
import views from '../../../lib/stores/views';
+ import QueryChooser from './components/querychooser.svelte';
+ import queries from '../../../lib/stores/queries';
// import ObjectViewer from '../../../components/objectviewer.svelte';
export let collection;
@@ -28,6 +30,9 @@
let queryField;
let activePath = [];
let objectViewerData;
+ let queryToSave;
+ let showQueryChooser = false;
+
$: 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})` : ''};`;
$: lastPage = (submittedForm.limit && result?.results?.length) ? Math.max(0, Math.ceil((result.total - submittedForm.limit) / submittedForm.limit)) : 0;
@@ -50,6 +55,23 @@
}
}
+ function loadQuery() {
+ queryToSave = undefined;
+ showQueryChooser = true;
+ }
+
+ function saveQuery() {
+ queryToSave = form;
+ showQueryChooser = true;
+ }
+
+ function queryChosen(event) {
+ if ($queries[event?.detail]) {
+ form = { ...$queries[event?.detail] };
+ submitQuery();
+ }
+ }
+
function prev() {
form.skip -= form.limit;
if (form.skip < 0) {
@@ -131,13 +153,22 @@
Limit
+
- Run
+
+
+
+
+
+
+
+
+
+ Run
+
-
-
{#key result}
@@ -198,6 +229,12 @@
+
+