1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-19 22:18:03 +00:00

Loose JSON parsing. Many UI improvements.

This commit is contained in:
2023-02-19 17:26:32 +01:00
parent 7ac1587c95
commit 78540622ee
25 changed files with 211 additions and 130 deletions

View File

@ -86,6 +86,34 @@ func (a *App) Environment() EnvironmentInfo {
return a.Env
}
func (a *App) PurgeLogDirectory() {
sure, _ := wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
Title: "Are you sure you want to remove all logfiles?",
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: wailsRuntime.QuestionDialog,
})
if sure != "Yes" {
return
}
err := os.RemoveAll(a.Env.LogDirectory)
if err == nil {
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
Title: "Successfully purged log directory.",
Type: wailsRuntime.InfoDialog,
})
} else {
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
Title: "Encountered an error while purging log directory.",
Message: err.Error(),
Type: wailsRuntime.WarningDialog,
})
}
}
func menuEventEmitter(a *App, eventName string, data ...interface{}) func(cd *menu.CallbackData) {
return func(cd *menu.CallbackData) {
wailsRuntime.EventsEmit(a.ctx, eventName, data...)
@ -99,6 +127,9 @@ func (a *App) Menu() *menu.Menu {
aboutMenu.AddText("About…", nil, menuEventEmitter(a, "OpenAboutModal"))
aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), menuEventEmitter(a, "OpenPrefrences"))
aboutMenu.AddSeparator()
aboutMenu.AddText("Open log directory…", nil, func(cd *menu.CallbackData) { open_file.Reveal(a.Env.LogDirectory) })
aboutMenu.AddText("Purge logs", nil, func(cd *menu.CallbackData) { a.PurgeLogDirectory() })
aboutMenu.AddSeparator()
aboutMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
if runtime.GOOS == "darwin" {
@ -123,8 +154,6 @@ func (a *App) Menu() *menu.Menu {
helpMenu := appMenu.AddSubmenu("Help")
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
}

View File

@ -64,6 +64,7 @@ func (a *App) TruncateCollection(hostKey, dbKey, collKey string) bool {
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: runtime.WarningDialog,
})
if sure != "Yes" {
return false
@ -97,6 +98,7 @@ func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: runtime.WarningDialog,
})
if sure != "Yes" {
return false

View File

@ -20,6 +20,7 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: runtime.WarningDialog,
})
if sure != "Yes" {
return 0

View File

@ -44,11 +44,12 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
err = bson.UnmarshalExtJSON([]byte(form.Query), true, &query)
if err != nil {
runtime.LogError(a.ctx, "Invalid update query:")
runtime.LogError(a.ctx, err.Error())
runtime.LogWarning(a.ctx, "Invalid update query:")
runtime.LogWarning(a.ctx, form.Query)
runtime.LogWarning(a.ctx, err.Error())
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "Invalid query",
Title: "Invalid update query",
Message: err.Error(),
})
return 0
@ -60,11 +61,12 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
if err == nil {
update[param.Type] = unmarshalled
} else {
runtime.LogError(a.ctx, "Invalid update query:")
runtime.LogError(a.ctx, err.Error())
runtime.LogWarning(a.ctx, "Invalid update parameter value:")
runtime.LogWarning(a.ctx, param.Value)
runtime.LogWarning(a.ctx, err.Error())
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "Invalid query",
Title: "Invalid update query",
Message: err.Error(),
})
return 0

View File

@ -34,6 +34,7 @@ func (a *App) DropDatabase(hostKey, dbKey string) bool {
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: runtime.WarningDialog,
})
if sure != "Yes" {
return false

View File

@ -150,6 +150,7 @@ func (a *App) RemoveHost(key string) error {
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: runtime.WarningDialog,
})
if sure != "Yes" {
return errors.New("operation aborted")

View File

@ -135,6 +135,7 @@ func (a *App) RemoveView(viewKey string) error {
Buttons: []string{"Yes", "No"},
DefaultButton: "Yes",
CancelButton: "No",
Type: runtime.WarningDialog,
})
if sure != "Yes" {
return errors.New("operation aborted")