1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Export refinements

This commit is contained in:
Romein van Buren 2023-02-16 20:19:04 +01:00
parent 38ef130684
commit 715519b06d
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
4 changed files with 58 additions and 67 deletions

View File

@ -36,8 +36,8 @@
<svelte:window on:keydown={keydown} />
{#if show}
<div class="modal outer" on:mousedown|self={() => show = false} transition:fade>
<div class="inner" style:max-width={width || '80vw'} transition:fly={{ y: 100 }}>
<div class="modal outer" transition:fade>
<div class="inner" style:max-width={width || '80vw'} transition:fly={{ y: -100 }}>
{#if title}
<header>
<div class="title">{title}</div>
@ -68,7 +68,6 @@
background-color: rgba(0, 0, 0, 0.5);
margin: 0;
padding-top: 50px;
cursor: pointer;
}
:global(#root.platform-darwin) .outer {
margin-top: var(--darwin-titlebar-height);

View File

@ -74,26 +74,36 @@
<Modal bind:show={info} title={actionLabel[info?.type]}>
<form on:submit|preventDefault={performExport}>
<div class="meta">
<!-- svelte-ignore a11y-label-has-associated-control - input is in DirectoryChooser -->
<label class="field">
<span class="label">Output directory</span>
<DirectoryChooser bind:value={info.outdir} />
</label>
<label class="field">
<span class="label">Filename</span>
<input type="text" bind:value={info.filename} />
<select bind:value={info.filetype} class="filetype">
<optgroup label="Dump (mongodump)">
<option value="bson">.bson</option>
</optgroup>
<optgroup label="Export (mongoexport)">
<option value="csv">.csv</option>
<option value="json">.json</option>
</optgroup>
</select>
</label>
<!-- 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
@ -154,7 +164,8 @@
<style>
form {
display: grid;
grid-template: auto / 1fr;
grid-template: auto auto 1fr auto / 1fr;
gap: 0.5rem;
}
.location {
display: grid;
@ -163,17 +174,9 @@
}
.location .grid {
border: 1px solid #ccc;
padding: 0.3rem;
overflow-y: auto;
}
.meta {
display: grid;
grid-template: 1fr / 1fr 1fr;
gap: 0.5rem;
margin-bottom: 0.5rem;
}
select.filetype {
flex: 0 1;
}

View File

@ -102,8 +102,8 @@
name: collKey,
icon: 'list',
menu: [
{ label: 'Export collection (JSON/CSV, mongoexport)…', fn: () => dispatch('exportCollection', collKey) },
{ label: 'Dump collection (BSON, mongodump)…', fn: () => dispatch('dumpCollection', collKey) },
{ label: 'Export collection (JSON, CSV)…', fn: () => dispatch('exportCollection', collKey) },
{ label: 'Dump collection (BSON via mongodump)…', fn: () => dispatch('dumpCollection', collKey) },
{ separator: true },
{ label: 'Rename collection…', fn: () => dispatch('renameCollection', collKey) },
{ label: 'Truncate collection…', fn: () => truncateCollection(dbKey, collKey) },

View File

@ -10,24 +10,19 @@ import (
"github.com/wailsapp/wails/v2/pkg/runtime"
)
type ExportType string
type FileType string
type ExportInfo struct {
Type ExportType `json:"type"`
FileType FileType `json:"fileType"`
OutDir string `json:"outdir"`
Filename string `json:"filename"`
HostKey string `json:"hostKey"`
DbKey string `json:"dbKey"`
CollKeys []string `json:"collKeys"`
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 (
ExportTypeExport ExportType = "export"
ExportTypeDump ExportType = "dump"
FileTypeJson FileType = "json"
FileTypeBson FileType = "bson"
FileTypeDump FileType = "dump"
FileTypeCsv FileType = "csv"
)
@ -56,19 +51,22 @@ func (a *App) PerformExport(jsonData string) bool {
}
host := hosts[info.HostKey]
switch info.Type {
case ExportTypeExport:
if !a.Env.HasMongoExport {
switch info.FileType {
case FileTypeCsv:
case FileTypeJson:
case FileTypeDump:
if !a.Env.HasMongoDump {
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "You need to install mongoexport to perform an export.",
Title: "You need to install mongodump to perform a dump.",
})
return false
}
args := make([]string, 0)
args = append(args, fmt.Sprintf(`--uri="%v"`, host.URI))
args = append(args, fmt.Sprintf(`--type="%v"`, info.FileType))
if info.DbKey != "" {
args = append(args, fmt.Sprintf(`--db="%v"`, info.DbKey))
@ -79,34 +77,25 @@ func (a *App) PerformExport(jsonData string) bool {
}
args = append(args, fmt.Sprintf(`--out="%v.%v"`, path.Join(info.OutDir, info.Filename), info.FileType))
cmd := exec.Command("mongoexport", args...)
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 export with args: "+strings.Join(args, " "))
fmt.Println(args)
fmt.Println(stdout.String())
fmt.Println(stderr.String())
fmt.Println(err)
case ExportTypeDump:
if !a.Env.HasMongoDump {
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "You need to install mongodump to perform a dump.",
})
return false
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:
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "Unrecognised export type",
Message: string(info.Type),
Title: "Unrecognised export file type",
Message: string(info.FileType),
})
return false
}