mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Logging
This commit is contained in:
parent
ff3766ad85
commit
126b42d570
@ -1,6 +1,12 @@
|
|||||||
import './reset.css';
|
import './reset.css';
|
||||||
import './style.css';
|
import './style.css';
|
||||||
import App from './app.svelte';
|
import App from './app.svelte';
|
||||||
|
import { LogError } from '../wailsjs/runtime/runtime';
|
||||||
|
|
||||||
|
window.addEventListener('unhandledrejection', event => {
|
||||||
|
LogError('Unhandled Rejection in JS! Reason:');
|
||||||
|
LogError(String(event.reason));
|
||||||
|
});
|
||||||
|
|
||||||
const app = new App({ target: document.getElementById('app') });
|
const app = new App({ target: document.getElementById('app') });
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ export namespace app {
|
|||||||
hasMongoDump: boolean;
|
hasMongoDump: boolean;
|
||||||
homeDirectory: string;
|
homeDirectory: string;
|
||||||
dataDirectory: string;
|
dataDirectory: string;
|
||||||
|
logDirectory: string;
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
static createFrom(source: any = {}) {
|
||||||
return new EnvironmentInfo(source);
|
return new EnvironmentInfo(source);
|
||||||
@ -22,6 +23,7 @@ export namespace app {
|
|||||||
this.hasMongoDump = source["hasMongoDump"];
|
this.hasMongoDump = source["hasMongoDump"];
|
||||||
this.homeDirectory = source["homeDirectory"];
|
this.homeDirectory = source["homeDirectory"];
|
||||||
this.dataDirectory = source["dataDirectory"];
|
this.dataDirectory = source["dataDirectory"];
|
||||||
|
this.logDirectory = source["logDirectory"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class Settings {
|
export class Settings {
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/garraflavatra/rolens/internal/utils/open_file"
|
||||||
"github.com/wailsapp/wails/v2/pkg/menu"
|
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||||
"github.com/wailsapp/wails/v2/pkg/menu/keys"
|
"github.com/wailsapp/wails/v2/pkg/menu/keys"
|
||||||
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
@ -24,6 +25,7 @@ type EnvironmentInfo struct {
|
|||||||
|
|
||||||
HomeDirectory string `json:"homeDirectory"`
|
HomeDirectory string `json:"homeDirectory"`
|
||||||
DataDirectory string `json:"dataDirectory"`
|
DataDirectory string `json:"dataDirectory"`
|
||||||
|
LogDirectory string `json:"logDirectory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
@ -32,16 +34,7 @@ type App struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewApp() *App {
|
func NewApp() *App {
|
||||||
return &App{}
|
a := &App{}
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) Startup(ctx context.Context) {
|
|
||||||
a.ctx = ctx
|
|
||||||
wailsEnv := wailsRuntime.Environment(a.ctx)
|
|
||||||
|
|
||||||
a.Env.Arch = wailsEnv.Arch
|
|
||||||
a.Env.BuildType = wailsEnv.BuildType
|
|
||||||
a.Env.Platform = wailsEnv.Platform
|
|
||||||
|
|
||||||
_, err := exec.LookPath("mongodump")
|
_, err := exec.LookPath("mongodump")
|
||||||
a.Env.HasMongoDump = err == nil
|
a.Env.HasMongoDump = err == nil
|
||||||
@ -57,15 +50,35 @@ func (a *App) Startup(ctx context.Context) {
|
|||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/AppData/Local/Rolens")
|
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/AppData/Local/Rolens")
|
||||||
|
a.Env.LogDirectory = filepath.Join(a.Env.HomeDirectory, "/AppData/Local/Rolens/Logs")
|
||||||
case "darwin":
|
case "darwin":
|
||||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/Library/Application Support/Rolens")
|
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/Library/Application Support/Rolens")
|
||||||
|
a.Env.LogDirectory = filepath.Join(a.Env.HomeDirectory, "/Library/Logs/Rolens")
|
||||||
case "linux":
|
case "linux":
|
||||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/.config/Rolens")
|
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/.config/rolens")
|
||||||
|
a.Env.LogDirectory = filepath.Join(a.Env.HomeDirectory, "/.config/rolens/logs")
|
||||||
default:
|
default:
|
||||||
panic(errors.New("unsupported platform"))
|
panic(errors.New("unsupported platform"))
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = os.MkdirAll(a.Env.DataDirectory, os.ModePerm)
|
os.MkdirAll(a.Env.DataDirectory, os.ModePerm)
|
||||||
|
os.MkdirAll(a.Env.LogDirectory, os.ModePerm)
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Startup(ctx context.Context) {
|
||||||
|
a.ctx = ctx
|
||||||
|
wailsRuntime.LogInfo(a.ctx, "Startup")
|
||||||
|
|
||||||
|
wailsEnv := wailsRuntime.Environment(a.ctx)
|
||||||
|
a.Env.Arch = wailsEnv.Arch
|
||||||
|
a.Env.BuildType = wailsEnv.BuildType
|
||||||
|
a.Env.Platform = wailsEnv.Platform
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Shutdown(ctx context.Context) {
|
||||||
|
wailsRuntime.LogInfo(a.ctx, "Shutdown")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Environment() EnvironmentInfo {
|
func (a *App) Environment() EnvironmentInfo {
|
||||||
@ -109,6 +122,8 @@ func (a *App) Menu() *menu.Menu {
|
|||||||
|
|
||||||
helpMenu := appMenu.AddSubmenu("Help")
|
helpMenu := appMenu.AddSubmenu("Help")
|
||||||
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { wailsRuntime.BrowserOpenURL(a.ctx, "") })
|
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { wailsRuntime.BrowserOpenURL(a.ctx, "") })
|
||||||
|
helpMenu.AddSeparator()
|
||||||
|
helpMenu.AddText("Open log directory", nil, func(cd *menu.CallbackData) { open_file.Reveal(a.Env.LogDirectory) })
|
||||||
|
|
||||||
return appMenu
|
return appMenu
|
||||||
}
|
}
|
||||||
@ -118,6 +133,8 @@ func (a *App) OpenDirectory(id, title string) string {
|
|||||||
title = "Choose a directory"
|
title = "Choose a directory"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wailsRuntime.LogInfo(a.ctx, fmt.Sprintf("Opening directory ('%v')", title))
|
||||||
|
|
||||||
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
|
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
|
||||||
Title: title,
|
Title: title,
|
||||||
CanCreateDirectories: true,
|
CanCreateDirectories: true,
|
||||||
@ -125,7 +142,8 @@ func (a *App) OpenDirectory(id, title string) string {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
wailsRuntime.LogWarning(a.ctx, "Encountered an error while opening directory:")
|
||||||
|
wailsRuntime.LogWarning(a.ctx, err.Error())
|
||||||
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
||||||
Type: wailsRuntime.ErrorDialog,
|
Type: wailsRuntime.ErrorDialog,
|
||||||
Title: "Encountered an error while opening directory",
|
Title: "Encountered an error while opening directory",
|
||||||
@ -133,5 +151,6 @@ func (a *App) OpenDirectory(id, title string) string {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wailsRuntime.LogInfo(a.ctx, "Chosen directory: "+dir)
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -34,7 +33,8 @@ func (a *App) Settings() Settings {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// It's ok if the file cannot be opened, for example if it is not accessible.
|
// It's ok if the file cannot be opened, for example if it is not accessible.
|
||||||
// Therefore no error is returned.
|
// Therefore no error is returned.
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "Cannot open settings.json:")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,8 @@ func (a *App) Settings() Settings {
|
|||||||
err = json.Unmarshal(jsonData, &s)
|
err = json.Unmarshal(jsonData, &s)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Cannot unmarshal settings.json:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not retrieve application settings, using defaults!",
|
Title: "Could not retrieve application settings, using defaults!",
|
||||||
@ -59,6 +60,8 @@ func (a *App) UpdateSettings(jsonData string) Settings {
|
|||||||
s := a.Settings()
|
s := a.Settings()
|
||||||
err := json.Unmarshal([]byte(jsonData), &s)
|
err := json.Unmarshal([]byte(jsonData), &s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.LogError(a.ctx, "Malformed JSON for settings file:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Malformed JSON",
|
Title: "Malformed JSON",
|
||||||
@ -69,6 +72,8 @@ func (a *App) UpdateSettings(jsonData string) Settings {
|
|||||||
|
|
||||||
newJson, err := json.MarshalIndent(s, "", "\t")
|
newJson, err := json.MarshalIndent(s, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.LogError(a.ctx, "Could not marshal settings into JSON:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Could not marshal settings into JSON",
|
Title: "Could not marshal settings into JSON",
|
||||||
@ -80,6 +85,8 @@ func (a *App) UpdateSettings(jsonData string) Settings {
|
|||||||
filePath := path.Join(a.Env.DataDirectory, "settings.json")
|
filePath := path.Join(a.Env.DataDirectory, "settings.json")
|
||||||
err = ioutil.WriteFile(filePath, newJson, os.ModePerm)
|
err = ioutil.WriteFile(filePath, newJson, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.LogError(a.ctx, "Could not update host list:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Could not update host list",
|
Title: "Could not update host list",
|
||||||
|
@ -10,14 +10,14 @@ import (
|
|||||||
func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) {
|
func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
command := bson.M{"collStats": collKey}
|
command := bson.M{"collStats": collKey}
|
||||||
err = client.Database(dbKey).RunCommand(ctx, command).Decode(&result)
|
err = client.Database(dbKey).RunCommand(ctx, command).Decode(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not retrieve collection stats for "+collKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not retrieve collection stats for " + collKey,
|
Title: "Could not retrieve collection stats for " + collKey,
|
||||||
@ -33,7 +33,6 @@ func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) {
|
|||||||
func (a *App) RenameCollection(hostKey, dbKey, collKey, newCollKey string) bool {
|
func (a *App) RenameCollection(hostKey, dbKey, collKey, newCollKey string) bool {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +43,8 @@ func (a *App) RenameCollection(hostKey, dbKey, collKey, newCollKey string) bool
|
|||||||
}
|
}
|
||||||
err = client.Database("admin").RunCommand(ctx, command).Decode(&result)
|
err = client.Database("admin").RunCommand(ctx, command).Decode(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not rename collection "+collKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not rename " + collKey,
|
Title: "Could not rename " + collKey,
|
||||||
@ -71,13 +71,13 @@ func (a *App) TruncateCollection(hostKey, dbKey, collKey string) bool {
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Database(dbKey).Collection(collKey).DeleteMany(ctx, bson.D{})
|
_, err = client.Database(dbKey).Collection(collKey).DeleteMany(ctx, bson.D{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not truncate collection "+collKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not truncate " + collKey,
|
Title: "Could not truncate " + collKey,
|
||||||
@ -104,13 +104,13 @@ func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.Database(dbKey).Collection(collKey).Drop(ctx)
|
err = client.Database(dbKey).Collection(collKey).Drop(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not drop collection "+collKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not drop " + collKey,
|
Title: "Could not drop " + collKey,
|
||||||
|
@ -2,7 +2,6 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
|
|
||||||
@ -27,7 +26,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
err := json.Unmarshal([]byte(formJson), &form)
|
err := json.Unmarshal([]byte(formJson), &form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Could not parse find form:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Couldn't parse form",
|
Title: "Couldn't parse form",
|
||||||
@ -38,7 +38,6 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +48,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
err = bson.UnmarshalExtJSON([]byte(form.Query), true, &query)
|
err = bson.UnmarshalExtJSON([]byte(form.Query), true, &query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "Invalid find query:")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Invalid query",
|
Title: "Invalid query",
|
||||||
@ -60,7 +60,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
err = json.Unmarshal([]byte(form.Fields), &projection)
|
err = json.Unmarshal([]byte(form.Fields), &projection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "Invalid find projection:")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Invalid projection",
|
Title: "Invalid projection",
|
||||||
@ -71,7 +72,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
err = json.Unmarshal([]byte(form.Sort), &sort)
|
err = json.Unmarshal([]byte(form.Sort), &sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "Invalid find sort:")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Invalid sort",
|
Title: "Invalid sort",
|
||||||
@ -89,7 +91,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
total, err := client.Database(dbKey).Collection(collKey).CountDocuments(ctx, query, nil)
|
total, err := client.Database(dbKey).Collection(collKey).CountDocuments(ctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while counting documents:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while counting documents",
|
Title: "Encountered an error while counting documents",
|
||||||
@ -100,7 +103,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
|
|
||||||
cur, err := client.Database(dbKey).Collection(collKey).Find(ctx, query, &opt)
|
cur, err := client.Database(dbKey).Collection(collKey).Find(ctx, query, &opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while performing query:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while performing query",
|
Title: "Encountered an error while performing query",
|
||||||
@ -114,7 +118,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
err = cur.All(ctx, &results)
|
err = cur.All(ctx, &results)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while performing query:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while performing query",
|
Title: "Encountered an error while performing query",
|
||||||
@ -128,7 +133,8 @@ func (a *App) FindItems(hostKey, dbKey, collKey string, formJson string) findRes
|
|||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
marshalled, err := bson.MarshalExtJSON(r, true, true)
|
marshalled, err := bson.MarshalExtJSON(r, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Failed to marshal find BSON:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Failed to marshal BSON",
|
Title: "Failed to marshal BSON",
|
||||||
|
@ -2,7 +2,6 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
@ -14,14 +13,14 @@ import (
|
|||||||
func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer close()
|
defer close()
|
||||||
|
|
||||||
cur, err := client.Database(dbKey).Collection(collKey).Indexes().List(ctx)
|
cur, err := client.Database(dbKey).Collection(collKey).Indexes().List(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while creating index cursor:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while creating index cursor",
|
Title: "Encountered an error while creating index cursor",
|
||||||
@ -33,7 +32,8 @@ func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
|||||||
var results []bson.M
|
var results []bson.M
|
||||||
err = cur.All(ctx, &results)
|
err = cur.All(ctx, &results)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while executing index cursor:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while executing index cursor",
|
Title: "Encountered an error while executing index cursor",
|
||||||
@ -48,7 +48,6 @@ func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
|||||||
func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
defer close()
|
defer close()
|
||||||
@ -69,7 +68,8 @@ func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
|||||||
|
|
||||||
err = json.Unmarshal([]byte(jsonData), &form)
|
err = json.Unmarshal([]byte(jsonData), &form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Could not parse index JSON:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Couldn't parse JSON",
|
Title: "Couldn't parse JSON",
|
||||||
@ -102,7 +102,8 @@ func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
|||||||
|
|
||||||
name, err := client.Database(dbKey).Collection(collKey).Indexes().CreateOne(ctx, indexModel)
|
name, err := client.Database(dbKey).Collection(collKey).Indexes().CreateOne(ctx, indexModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while creating index:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Error while creating index",
|
Title: "Error while creating index",
|
||||||
@ -117,14 +118,14 @@ func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
|||||||
func (a *App) DropIndex(hostKey, dbKey, collKey, indexName string) bool {
|
func (a *App) DropIndex(hostKey, dbKey, collKey, indexName string) bool {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer close()
|
defer close()
|
||||||
|
|
||||||
_, err = client.Database(dbKey).Collection(collKey).Indexes().DropOne(ctx, indexName, &options.DropIndexesOptions{})
|
_, err = client.Database(dbKey).Collection(collKey).Indexes().DropOne(ctx, indexName, &options.DropIndexesOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Encountered an error while creating index drop cursor:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while creating index cursor",
|
Title: "Encountered an error while creating index cursor",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
@ -18,7 +17,8 @@ func (a *App) InsertItems(hostKey, dbKey, collKey, jsonData string) interface{}
|
|||||||
|
|
||||||
err := bson.UnmarshalExtJSON([]byte(jsonData), true, &data)
|
err := bson.UnmarshalExtJSON([]byte(jsonData), true, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Could not parse insert JSON:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Couldn't parse JSON",
|
Title: "Couldn't parse JSON",
|
||||||
@ -29,14 +29,14 @@ func (a *App) InsertItems(hostKey, dbKey, collKey, jsonData string) interface{}
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer close()
|
defer close()
|
||||||
res, err := client.Database(dbKey).Collection(collKey).InsertMany(ctx, data)
|
res, err := client.Database(dbKey).Collection(collKey).InsertMany(ctx, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while performing insert:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while performing query",
|
Title: "Encountered an error while performing query",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
@ -28,7 +27,8 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
|||||||
} else {
|
} else {
|
||||||
err = bson.UnmarshalExtJSON([]byte(jsonData), true, &filter)
|
err = bson.UnmarshalExtJSON([]byte(jsonData), true, &filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Could not parse remove query:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Couldn't parse JSON",
|
Title: "Couldn't parse JSON",
|
||||||
@ -40,7 +40,6 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +54,8 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while performing remove:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while removing items",
|
Title: "Encountered an error while removing items",
|
||||||
@ -70,7 +70,6 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
|||||||
func (a *App) RemoveItemById(hostKey, dbKey, collKey, itemId string) bool {
|
func (a *App) RemoveItemById(hostKey, dbKey, collKey, itemId string) bool {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +79,8 @@ func (a *App) RemoveItemById(hostKey, dbKey, collKey, itemId string) bool {
|
|||||||
err = client.Database(dbKey).Collection(collKey).FindOneAndDelete(ctx, filter).Err()
|
err = client.Database(dbKey).Collection(collKey).FindOneAndDelete(ctx, filter).Err()
|
||||||
|
|
||||||
if err != nil && err != mongo.ErrNoDocuments {
|
if err != nil && err != mongo.ErrNoDocuments {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while performing remove by id:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while removing item" + itemId,
|
Title: "Encountered an error while removing item" + itemId,
|
||||||
|
@ -2,7 +2,6 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
|
|
||||||
@ -24,7 +23,8 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
|||||||
|
|
||||||
err := json.Unmarshal([]byte(formJson), &form)
|
err := json.Unmarshal([]byte(formJson), &form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Could not parse update form:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Couldn't parse form",
|
Title: "Couldn't parse form",
|
||||||
@ -35,7 +35,6 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +44,8 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
|||||||
|
|
||||||
err = bson.UnmarshalExtJSON([]byte(form.Query), true, &query)
|
err = bson.UnmarshalExtJSON([]byte(form.Query), true, &query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Invalid update query:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Invalid query",
|
Title: "Invalid query",
|
||||||
@ -60,7 +60,8 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
update[param.Type] = unmarshalled
|
update[param.Type] = unmarshalled
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Invalid update query:")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Invalid query",
|
Title: "Invalid query",
|
||||||
@ -80,7 +81,8 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Encountered an error while performing update:")
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Encountered an error while updating items",
|
Title: "Encountered an error while updating items",
|
||||||
|
@ -3,7 +3,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
@ -24,6 +23,7 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
|
|||||||
|
|
||||||
h := hosts[hostKey]
|
h := hosts[hostKey]
|
||||||
if len(h.URI) == 0 {
|
if len(h.URI) == 0 {
|
||||||
|
runtime.LogInfo(a.ctx, "Invalid URI (len == 0) for host "+hostKey)
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Invalid uri",
|
Title: "Invalid uri",
|
||||||
@ -35,7 +35,8 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
|
|||||||
client, err := mongo.NewClient(mongoOptions.Client().ApplyURI(h.URI))
|
client, err := mongo.NewClient(mongoOptions.Client().ApplyURI(h.URI))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not connect to host "+hostKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not connect to " + h.Name,
|
Title: "Could not connect to " + h.Name,
|
||||||
@ -55,12 +56,12 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
|
|||||||
func (a *App) OpenConnection(hostKey string) (databases []string) {
|
func (a *App) OpenConnection(hostKey string) (databases []string) {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
databases, err = client.ListDatabaseNames(ctx, bson.M{})
|
databases, err = client.ListDatabaseNames(ctx, bson.M{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not retrieve database names for host "+hostKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not retrieve database list",
|
Title: "Could not retrieve database list",
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
@ -10,13 +8,13 @@ import (
|
|||||||
func (a *App) OpenDatabase(hostKey, dbKey string) (collections []string) {
|
func (a *App) OpenDatabase(hostKey, dbKey string) (collections []string) {
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
collections, err = client.Database(dbKey).ListCollectionNames(ctx, bson.D{})
|
collections, err = client.Database(dbKey).ListCollectionNames(ctx, bson.D{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not retrieve collection list for db "+dbKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not retrieve collection list for " + dbKey,
|
Title: "Could not retrieve collection list for " + dbKey,
|
||||||
@ -43,13 +41,13 @@ func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
|||||||
|
|
||||||
client, ctx, close, err := a.connectToHost(hostKey)
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.Database(dbKey).Drop(ctx)
|
err = client.Database(dbKey).Drop(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogWarning(a.ctx, "Could not drop db "+dbKey)
|
||||||
|
runtime.LogWarning(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not drop " + dbKey,
|
Title: "Could not drop " + dbKey,
|
||||||
|
@ -35,7 +35,8 @@ func (a *App) PerformExport(jsonData string) bool {
|
|||||||
var info ExportInfo
|
var info ExportInfo
|
||||||
err := json.Unmarshal([]byte(jsonData), &info)
|
err := json.Unmarshal([]byte(jsonData), &info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogError(a.ctx, "Could not unmarshal export form")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not unmarshal JSON",
|
Title: "Could not unmarshal JSON",
|
||||||
@ -46,7 +47,6 @@ func (a *App) PerformExport(jsonData string) bool {
|
|||||||
|
|
||||||
hosts, err := a.Hosts()
|
hosts, err := a.Hosts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.ErrorDialog,
|
Type: runtime.ErrorDialog,
|
||||||
Title: "Could not retrieve hosts",
|
Title: "Could not retrieve hosts",
|
||||||
@ -86,6 +86,8 @@ func (a *App) PerformExport(jsonData string) bool {
|
|||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
|
||||||
|
runtime.LogInfo(a.ctx, "Performing export with args: "+strings.Join(args, " "))
|
||||||
|
|
||||||
fmt.Println(args)
|
fmt.Println(args)
|
||||||
fmt.Println(stdout.String())
|
fmt.Println(stdout.String())
|
||||||
fmt.Println(stderr.String())
|
fmt.Println(stderr.String())
|
||||||
|
@ -3,7 +3,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -34,7 +33,8 @@ func (a *App) Hosts() (map[string]Host, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// It's ok if the file cannot be opened, for example if it is not accessible.
|
// It's ok if the file cannot be opened, for example if it is not accessible.
|
||||||
// Therefore no error is returned.
|
// Therefore no error is returned.
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "Could not open hosts.json")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
return make(map[string]Host, 0), nil
|
return make(map[string]Host, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,8 @@ func (a *App) Hosts() (map[string]Host, error) {
|
|||||||
err = json.Unmarshal(jsonData, &hosts)
|
err = json.Unmarshal(jsonData, &hosts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "host.json file contains malformatted JSON data")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
return nil, errors.New("host.json file contains malformatted JSON data")
|
return nil, errors.New("host.json file contains malformatted JSON data")
|
||||||
}
|
}
|
||||||
return hosts, nil
|
return hosts, nil
|
||||||
@ -65,6 +66,8 @@ func (a *App) AddHost(jsonData string) error {
|
|||||||
var newHost Host
|
var newHost Host
|
||||||
err = json.Unmarshal([]byte(jsonData), &newHost)
|
err = json.Unmarshal([]byte(jsonData), &newHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.LogError(a.ctx, "Add host: malformed form")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Malformed JSON",
|
Title: "Malformed JSON",
|
||||||
@ -74,6 +77,8 @@ func (a *App) AddHost(jsonData string) error {
|
|||||||
|
|
||||||
id, err := uuid.NewRandom()
|
id, err := uuid.NewRandom()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.LogError(a.ctx, "Add host: failed to generate a UUID")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Failed to generate a UUID",
|
Title: "Failed to generate a UUID",
|
||||||
@ -107,6 +112,8 @@ func (a *App) UpdateHost(hostKey string, jsonData string) error {
|
|||||||
var host Host
|
var host Host
|
||||||
err = json.Unmarshal([]byte(jsonData), &host)
|
err = json.Unmarshal([]byte(jsonData), &host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.LogError(a.ctx, "Could not parse update host JSON")
|
||||||
|
runtime.LogError(a.ctx, err.Error())
|
||||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Type: runtime.InfoDialog,
|
Type: runtime.InfoDialog,
|
||||||
Title: "Malformed JSON",
|
Title: "Malformed JSON",
|
||||||
|
@ -3,7 +3,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -75,14 +74,16 @@ func (a *App) Views() (ViewStore, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// It's ok if the file cannot be opened, for example if it is not accessible.
|
// It's ok if the file cannot be opened, for example if it is not accessible.
|
||||||
// Therefore no error is returned.
|
// Therefore no error is returned.
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "views.json file cannot be opened")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
return views, nil
|
return views, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(jsonData) > 0 {
|
if len(jsonData) > 0 {
|
||||||
err = json.Unmarshal(jsonData, &views)
|
err = json.Unmarshal(jsonData, &views)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
runtime.LogInfo(a.ctx, "views.json file contains malformatted JSON data")
|
||||||
|
runtime.LogInfo(a.ctx, err.Error())
|
||||||
return nil, errors.New("views.json file contains malformatted JSON data")
|
return nil, errors.New("views.json file contains malformatted JSON data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
internal/utils/open_file/open.go
Normal file
6
internal/utils/open_file/open.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package open_file
|
||||||
|
|
||||||
|
// Reveal reveals the specified file in the Finder.
|
||||||
|
func Reveal(fname string) {
|
||||||
|
reveal(fname)
|
||||||
|
}
|
9
internal/utils/open_file/open_darwin.go
Normal file
9
internal/utils/open_file/open_darwin.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//go:build darwin
|
||||||
|
|
||||||
|
package open_file
|
||||||
|
|
||||||
|
import "os/exec"
|
||||||
|
|
||||||
|
func reveal(fname string) {
|
||||||
|
exec.Command("open", "--reveal", fname).Run()
|
||||||
|
}
|
9
internal/utils/open_file/open_windows.go
Normal file
9
internal/utils/open_file/open_windows.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package open_file
|
||||||
|
|
||||||
|
import "os/exec"
|
||||||
|
|
||||||
|
func reveal(fname string) {
|
||||||
|
exec.Command("explorer", fname).Run()
|
||||||
|
}
|
22
main.go
22
main.go
@ -2,9 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/garraflavatra/rolens/internal/app"
|
"github.com/garraflavatra/rolens/internal/app"
|
||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options/mac"
|
"github.com/wailsapp/wails/v2/pkg/options/mac"
|
||||||
@ -20,17 +22,23 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := app.NewApp()
|
app := app.NewApp()
|
||||||
|
|
||||||
err := wails.Run(&options.App{
|
err := wails.Run(&options.App{
|
||||||
Title: "Rolens",
|
Title: "Rolens",
|
||||||
Width: 1000,
|
|
||||||
Height: 600,
|
Width: 1000,
|
||||||
MinWidth: 1000,
|
Height: 600,
|
||||||
MinHeight: 600,
|
MinWidth: 1000,
|
||||||
|
MinHeight: 600,
|
||||||
|
|
||||||
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 139, A: 1},
|
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 139, A: 1},
|
||||||
OnStartup: app.Startup,
|
|
||||||
Menu: app.Menu(),
|
Menu: app.Menu(),
|
||||||
|
|
||||||
|
OnStartup: app.Startup,
|
||||||
|
OnShutdown: app.Shutdown,
|
||||||
|
Logger: logger.NewFileLogger(path.Join(app.Env.LogDirectory, "rolens.log")),
|
||||||
|
LogLevel: logger.TRACE,
|
||||||
|
LogLevelProduction: logger.INFO,
|
||||||
|
|
||||||
AssetServer: &assetserver.Options{
|
AssetServer: &assetserver.Options{
|
||||||
Assets: assets,
|
Assets: assets,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user