mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-21 06:48:04 +00:00
Added functionality to save and import shell scripts (#37)
This commit is contained in:
@ -12,6 +12,8 @@
|
||||
import Stats from './stats.svelte';
|
||||
import Update from './update.svelte';
|
||||
|
||||
export let host;
|
||||
export let database;
|
||||
export let collection;
|
||||
export let tab = 'stats';
|
||||
|
||||
@ -47,6 +49,8 @@
|
||||
this={view.component}
|
||||
visible={tab === view.key}
|
||||
on:performFind={catchQuery}
|
||||
{host}
|
||||
{database}
|
||||
{collection}
|
||||
/>
|
||||
</div>
|
||||
|
@ -6,6 +6,7 @@
|
||||
import Shell from '../shell.svelte';
|
||||
import Stats from './stats.svelte';
|
||||
|
||||
export let host;
|
||||
export let database;
|
||||
export let tab = 'stats';
|
||||
|
||||
@ -28,7 +29,7 @@
|
||||
|
||||
{#each Object.values(tabs) as view}
|
||||
<div class="container" class:hidden={tab !== view.key}>
|
||||
<svelte:component this={view.component} visible={tab === view.key} {database} />
|
||||
<svelte:component this={view.component} visible={tab === view.key} {host} {database} />
|
||||
</div>
|
||||
{/each}
|
||||
{/key}
|
||||
|
@ -64,11 +64,20 @@
|
||||
|
||||
{#if activeCollKey}
|
||||
{#key activeCollKey}
|
||||
<CollectionView collection={$hostTree[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]} bind:tab={collTab} />
|
||||
<CollectionView
|
||||
host={$hostTree[activeHostKey]}
|
||||
database={$hostTree[activeHostKey]?.databases[activeDbKey]}
|
||||
collection={$hostTree[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]}
|
||||
bind:tab={collTab}
|
||||
/>
|
||||
{/key}
|
||||
{:else if activeDbKey}
|
||||
{#key activeDbKey}
|
||||
<DatabaseView database={$hostTree[activeHostKey]?.databases[activeDbKey]} bind:tab={dbTab} />
|
||||
<DatabaseView
|
||||
host={$hostTree[activeHostKey]}
|
||||
database={$hostTree[activeHostKey]?.databases[activeDbKey]}
|
||||
bind:tab={dbTab}
|
||||
/>
|
||||
{/key}
|
||||
{:else if activeHostKey}
|
||||
{#key activeHostKey}
|
||||
|
@ -2,6 +2,7 @@
|
||||
import BlankState from '$components/blankstate.svelte';
|
||||
import CodeEditor from '$components/codeeditor.svelte';
|
||||
import Icon from '$components/icon.svelte';
|
||||
import { OpenShellScript, SaveShellScript } from '$wails/go/app/App';
|
||||
import { javascript } from '@codemirror/lang-javascript';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
|
||||
@ -19,7 +20,7 @@
|
||||
let busy = false;
|
||||
let editor;
|
||||
|
||||
async function run() {
|
||||
async function runScript() {
|
||||
busy = true;
|
||||
|
||||
if (collection) {
|
||||
@ -35,6 +36,36 @@
|
||||
busy = false;
|
||||
}
|
||||
|
||||
async function loadScript() {
|
||||
const _script = await OpenShellScript();
|
||||
if (_script) {
|
||||
script = _script;
|
||||
editor.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: editor.state.doc.length,
|
||||
insert: script,
|
||||
},
|
||||
selection: {
|
||||
from: 0,
|
||||
anchor: 0,
|
||||
to: 0,
|
||||
head: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function saveScript() {
|
||||
await SaveShellScript(
|
||||
host?.key || '',
|
||||
database?.key || '',
|
||||
collection?.key || '',
|
||||
script,
|
||||
false // not temporary
|
||||
);
|
||||
}
|
||||
|
||||
async function copyErrorDescription() {
|
||||
await navigator.clipboard.writeText(result.errorDescription);
|
||||
copySucceeded = true;
|
||||
@ -86,10 +117,19 @@
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<button class="button" on:click={run}>
|
||||
<button class="button" on:click={runScript}>
|
||||
<Icon name="play" /> Run
|
||||
</button>
|
||||
|
||||
<div class="field inline">
|
||||
<button class="button secondary" on:click={loadScript}>
|
||||
<Icon name="upload" /> Load script…
|
||||
</button>
|
||||
<button class="button secondary" on:click={saveScript}>
|
||||
<Icon name="save" /> Save as…
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#key result}
|
||||
<div class="status flash-green">
|
||||
{#if result?.status}
|
||||
@ -145,6 +185,7 @@
|
||||
.controls {
|
||||
margin-top: 0.5rem;
|
||||
display: flex;
|
||||
gap: 0.2rem;
|
||||
align-items: center;
|
||||
grid-column: 1 / 3;
|
||||
}
|
||||
|
Reference in New Issue
Block a user