mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Removed export functionality. Only dumping for now
This commit is contained in:
parent
5dd9e0573d
commit
b15fde11db
@ -160,7 +160,7 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-row three">
|
||||
<div class="form-row actions">
|
||||
<!-- <CodeExample {code} /> -->
|
||||
<button class="btn" type="button" on:click={loadQuery}>
|
||||
<Icon name="upload" /> Load query…
|
||||
@ -168,6 +168,9 @@
|
||||
<button class="btn" type="button" on:click={saveQuery}>
|
||||
<Icon name="save" /> Save as…
|
||||
</button>
|
||||
<button class="btn" type="button" on:click={saveQuery}>
|
||||
<Icon name="save" /> Export results…
|
||||
</button>
|
||||
<button type="submit" class="btn" title="Run query">
|
||||
<Icon name="play" /> Run
|
||||
</button>
|
||||
@ -276,10 +279,10 @@
|
||||
.form-row.two {
|
||||
grid-template: 1fr / 5fr 1fr 1fr;
|
||||
}
|
||||
.form-row.three {
|
||||
.form-row.actions {
|
||||
margin-bottom: 0rem;
|
||||
grid-template: 1fr / repeat(3, auto);
|
||||
justify-content: end;
|
||||
grid-template: 1fr / repeat(4, auto);
|
||||
justify-content: start;
|
||||
}
|
||||
|
||||
.result {
|
||||
|
@ -5,26 +5,14 @@
|
||||
import busy from '$lib/stores/busy';
|
||||
import { connections } from '$lib/stores/connections';
|
||||
import applicationSettings from '$lib/stores/settings';
|
||||
import { OpenConnection, OpenDatabase, PerformExport } from '$wails/go/app/App';
|
||||
import { OpenConnection, OpenDatabase, PerformDump } from '$wails/go/app/App';
|
||||
|
||||
export let info;
|
||||
export let hosts = {};
|
||||
|
||||
const actionLabel = {
|
||||
export: 'Perform export',
|
||||
dump: 'Perform dump',
|
||||
};
|
||||
|
||||
$: if (info) {
|
||||
info.outdir = info.outdir || $applicationSettings.defaultExportDirectory;
|
||||
info.filename = info.filename || `Export ${new Date().getTime()}`;
|
||||
|
||||
if (info.filetype === 'bson') {
|
||||
info.type = 'dump';
|
||||
}
|
||||
else {
|
||||
info.type = 'export';
|
||||
}
|
||||
info.filename = info.filename || `Dump ${new Date().getTime()}`;
|
||||
}
|
||||
|
||||
async function selectHost(hostKey) {
|
||||
@ -63,8 +51,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function performExport() {
|
||||
await PerformExport(JSON.stringify(info));
|
||||
async function performDump() {
|
||||
const ok = await PerformDump(JSON.stringify(info));
|
||||
if (ok) {
|
||||
info = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function selectCollection(collKey) {
|
||||
@ -72,38 +63,16 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:show={info} title={actionLabel[info?.type]}>
|
||||
<form on:submit|preventDefault={performExport}>
|
||||
<Modal bind:show={info} title="Perform dump">
|
||||
<form on:submit|preventDefault={performDump}>
|
||||
<!-- svelte-ignore a11y-label-has-associated-control - input is in DirectoryChooser -->
|
||||
<label class="field">
|
||||
<span class="label">Output destination:</span>
|
||||
<DirectoryChooser bind:value={info.outdir} />
|
||||
<span class="label">/</span>
|
||||
<input type="text" bind:value={info.filename} />
|
||||
<span class="label">.</span>
|
||||
<select bind:value={info.filetype} class="filetype">
|
||||
<optgroup label="Dump (via mongodump)">
|
||||
<option value="bson">bson</option>
|
||||
</optgroup>
|
||||
<optgroup label="Export">
|
||||
<option value="csv">csv</option>
|
||||
<option value="json">json</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<div class="options">
|
||||
{#if info.filetype === 'json'}
|
||||
<label class="field">
|
||||
<span class="label">Separate items using:</span>
|
||||
<select bind:value={info.jsonType}>
|
||||
<option value="newline">Newline</option>
|
||||
<option value="array">JSON array</option>
|
||||
</select>
|
||||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="location">
|
||||
<div class="grid">
|
||||
<Grid
|
||||
@ -156,7 +125,7 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button type="submit" class="btn">{actionLabel[info.type]}</button>
|
||||
<button type="submit" class="btn">Perform dump</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
@ -164,7 +133,7 @@
|
||||
<style>
|
||||
form {
|
||||
display: grid;
|
||||
grid-template: auto auto 1fr auto / 1fr;
|
||||
grid-template: auto 1fr auto / 1fr;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.location {
|
||||
@ -176,8 +145,4 @@
|
||||
border: 1px solid #ccc;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
select.filetype {
|
||||
flex: 0 1;
|
||||
}
|
||||
</style>
|
@ -6,7 +6,7 @@
|
||||
import { EventsOn } from '$wails/runtime/runtime';
|
||||
import { onMount } from 'svelte';
|
||||
import CollectionDetail from './collection/index.svelte';
|
||||
import Export from './export/export.svelte';
|
||||
import DumpInfo from './dump.svelte';
|
||||
import HostDetail from './hostdetail.svelte';
|
||||
import HostTree from './hosttree.svelte';
|
||||
|
||||
@ -119,7 +119,7 @@
|
||||
{hosts}
|
||||
/>
|
||||
|
||||
<Export bind:info={exportInfo} {hosts} />
|
||||
<DumpInfo bind:info={exportInfo} {hosts} />
|
||||
|
||||
<style>
|
||||
.tree {
|
||||
|
2
frontend/wailsjs/go/app/App.d.ts
vendored
2
frontend/wailsjs/go/app/App.d.ts
vendored
@ -37,7 +37,7 @@ export function OpenConnection(arg1:string):Promise<Array<string>>;
|
||||
|
||||
export function OpenDatabase(arg1:string,arg2:string):Promise<Array<string>>;
|
||||
|
||||
export function PerformExport(arg1:string):Promise<boolean>;
|
||||
export function PerformDump(arg1:string):Promise<boolean>;
|
||||
|
||||
export function PurgeLogDirectory():Promise<void>;
|
||||
|
||||
|
@ -62,8 +62,8 @@ export function OpenDatabase(arg1, arg2) {
|
||||
return window['go']['app']['App']['OpenDatabase'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function PerformExport(arg1) {
|
||||
return window['go']['app']['App']['PerformExport'](arg1);
|
||||
export function PerformDump(arg1) {
|
||||
return window['go']['app']['App']['PerformDump'](arg1);
|
||||
}
|
||||
|
||||
export function PurgeLogDirectory() {
|
||||
|
@ -1,90 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
type FileType string
|
||||
type ExportInfo struct {
|
||||
FileType FileType `json:"fileType"`
|
||||
OutDir string `json:"outdir"`
|
||||
Filename string `json:"filename"`
|
||||
HostKey string `json:"hostKey"`
|
||||
DbKey string `json:"dbKey"`
|
||||
CollKeys []string `json:"collKeys"`
|
||||
}
|
||||
|
||||
const (
|
||||
FileTypeJson FileType = "json"
|
||||
FileTypeDump FileType = "dump"
|
||||
FileTypeCsv FileType = "csv"
|
||||
)
|
||||
|
||||
func (a *App) PerformExport(jsonData string) bool {
|
||||
var info ExportInfo
|
||||
err := json.Unmarshal([]byte(jsonData), &info)
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not unmarshal export form")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
zenity.Error(err.Error(), zenity.Title("Error while getting hosts"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
host := hosts[info.HostKey]
|
||||
|
||||
switch info.FileType {
|
||||
case FileTypeCsv:
|
||||
|
||||
case FileTypeJson:
|
||||
|
||||
case FileTypeDump:
|
||||
if !a.Env.HasMongoDump {
|
||||
zenity.Error("You need to install mongodump to perform a dump.", zenity.Title("Additional tooling required"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
args := make([]string, 0)
|
||||
args = append(args, fmt.Sprintf(`--uri="%v"`, host.URI))
|
||||
|
||||
if info.DbKey != "" {
|
||||
args = append(args, fmt.Sprintf(`--db="%v"`, info.DbKey))
|
||||
|
||||
if info.CollKeys != nil {
|
||||
args = append(args, fmt.Sprintf(`--collection="%v"`, info.CollKeys[0]))
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, fmt.Sprintf(`--out="%v.%v"`, path.Join(info.OutDir, info.Filename), info.FileType))
|
||||
cmd := exec.Command("mongodump", args...)
|
||||
var stdout strings.Builder
|
||||
var stderr strings.Builder
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err = cmd.Run()
|
||||
|
||||
runtime.LogInfo(a.ctx, "Performing dump, executing command: mongodump "+strings.Join(args, " "))
|
||||
runtime.LogInfo(a.ctx, "mongodump stdout: "+stdout.String())
|
||||
runtime.LogInfo(a.ctx, "mongodump sterr: "+stderr.String())
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Error while executing mongodump: "+err.Error())
|
||||
}
|
||||
|
||||
default:
|
||||
zenity.Error(fmt.Sprintf("File type '%v' is not known.", info.FileType), zenity.Title("Unrecognised file type"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
return err == nil
|
||||
}
|
71
internal/app/dump.go
Normal file
71
internal/app/dump.go
Normal file
@ -0,0 +1,71 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
type DumpInfo struct {
|
||||
OutDir string `json:"outdir"`
|
||||
Filename string `json:"filename"`
|
||||
HostKey string `json:"hostKey"`
|
||||
DbKey string `json:"dbKey"`
|
||||
CollKeys []string `json:"collKeys"`
|
||||
}
|
||||
|
||||
func (a *App) PerformDump(jsonData string) bool {
|
||||
var info DumpInfo
|
||||
err := json.Unmarshal([]byte(jsonData), &info)
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not unmarshal dump form")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
zenity.Error(err.Error(), zenity.Title("Error while getting hosts"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
host := hosts[info.HostKey]
|
||||
|
||||
if !a.Env.HasMongoDump {
|
||||
zenity.Error("You need to install mongodump to perform a dump.", zenity.Title("Additional tooling required"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
args := make([]string, 0)
|
||||
args = append(args, fmt.Sprintf(`--uri="%v"`, host.URI))
|
||||
|
||||
if info.DbKey != "" {
|
||||
args = append(args, fmt.Sprintf(`--db="%v"`, info.DbKey))
|
||||
|
||||
if info.CollKeys != nil {
|
||||
args = append(args, fmt.Sprintf(`--collection="%v"`, info.CollKeys[0]))
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, fmt.Sprintf(`--out="%v"`, path.Join(info.OutDir, info.Filename)))
|
||||
cmd := exec.Command("mongodump", args...)
|
||||
var stdout strings.Builder
|
||||
var stderr strings.Builder
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err = cmd.Run()
|
||||
|
||||
runtime.LogInfo(a.ctx, "Performing dump, executing command: mongodump "+strings.Join(args, " "))
|
||||
runtime.LogInfo(a.ctx, "mongodump stdout: "+stdout.String())
|
||||
runtime.LogInfo(a.ctx, "mongodump sterr: "+stderr.String())
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Error while executing mongodump: "+err.Error())
|
||||
}
|
||||
|
||||
return err == nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user