1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 21:17:59 +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} /> <svelte:window on:keydown={keydown} />
{#if show} {#if show}
<div class="modal outer" on:mousedown|self={() => show = false} transition:fade> <div class="modal outer" transition:fade>
<div class="inner" style:max-width={width || '80vw'} transition:fly={{ y: 100 }}> <div class="inner" style:max-width={width || '80vw'} transition:fly={{ y: -100 }}>
{#if title} {#if title}
<header> <header>
<div class="title">{title}</div> <div class="title">{title}</div>
@ -68,7 +68,6 @@
background-color: rgba(0, 0, 0, 0.5); background-color: rgba(0, 0, 0, 0.5);
margin: 0; margin: 0;
padding-top: 50px; padding-top: 50px;
cursor: pointer;
} }
:global(#root.platform-darwin) .outer { :global(#root.platform-darwin) .outer {
margin-top: var(--darwin-titlebar-height); margin-top: var(--darwin-titlebar-height);

View File

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

View File

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

View File

@ -10,24 +10,19 @@ import (
"github.com/wailsapp/wails/v2/pkg/runtime" "github.com/wailsapp/wails/v2/pkg/runtime"
) )
type ExportType string
type FileType string type FileType string
type ExportInfo struct { type ExportInfo struct {
Type ExportType `json:"type"` FileType FileType `json:"fileType"`
FileType FileType `json:"fileType"` OutDir string `json:"outdir"`
OutDir string `json:"outdir"` Filename string `json:"filename"`
Filename string `json:"filename"` HostKey string `json:"hostKey"`
HostKey string `json:"hostKey"` DbKey string `json:"dbKey"`
DbKey string `json:"dbKey"` CollKeys []string `json:"collKeys"`
CollKeys []string `json:"collKeys"`
} }
const ( const (
ExportTypeExport ExportType = "export"
ExportTypeDump ExportType = "dump"
FileTypeJson FileType = "json" FileTypeJson FileType = "json"
FileTypeBson FileType = "bson" FileTypeDump FileType = "dump"
FileTypeCsv FileType = "csv" FileTypeCsv FileType = "csv"
) )
@ -56,19 +51,22 @@ func (a *App) PerformExport(jsonData string) bool {
} }
host := hosts[info.HostKey] host := hosts[info.HostKey]
switch info.Type { switch info.FileType {
case ExportTypeExport: case FileTypeCsv:
if !a.Env.HasMongoExport {
case FileTypeJson:
case FileTypeDump:
if !a.Env.HasMongoDump {
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog, 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 return false
} }
args := make([]string, 0) args := make([]string, 0)
args = append(args, fmt.Sprintf(`--uri="%v"`, host.URI)) args = append(args, fmt.Sprintf(`--uri="%v"`, host.URI))
args = append(args, fmt.Sprintf(`--type="%v"`, info.FileType))
if info.DbKey != "" { if info.DbKey != "" {
args = append(args, fmt.Sprintf(`--db="%v"`, 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)) 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 stdout strings.Builder
var stderr strings.Builder var stderr strings.Builder
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr
err = cmd.Run() err = cmd.Run()
runtime.LogInfo(a.ctx, "Performing export with args: "+strings.Join(args, " ")) runtime.LogInfo(a.ctx, "Performing dump, executing command: mongodump "+strings.Join(args, " "))
runtime.LogInfo(a.ctx, "mongodump stdout: "+stdout.String())
fmt.Println(args) runtime.LogInfo(a.ctx, "mongodump sterr: "+stderr.String())
fmt.Println(stdout.String()) if err != nil {
fmt.Println(stderr.String()) runtime.LogWarning(a.ctx, "Error while executing mongodump: "+err.Error())
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
} }
default: default:
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog, Type: runtime.ErrorDialog,
Title: "Unrecognised export type", Title: "Unrecognised export file type",
Message: string(info.Type), Message: string(info.FileType),
}) })
return false return false
} }