1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-06-28 05:25:11 +00:00

Implement OOP hosttree (#32)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
2023-06-18 21:31:55 +02:00
committed by GitHub
parent 3fe5f09163
commit a1456b3987
33 changed files with 624 additions and 593 deletions

View File

@ -36,8 +36,6 @@ func (a *App) Menu() *menu.Menu {
fileMenu := appMenu.AddSubmenu("File")
fileMenu.AddText("New host…", keys.CmdOrCtrl("y"), menuCallbackEmit(a, "CreateHost"))
fileMenu.AddText("New database", keys.CmdOrCtrl("y"), menuCallbackEmit(a, "CreateDatabase"))
fileMenu.AddText("New collection…", keys.CmdOrCtrl("i"), menuCallbackEmit(a, "CreateCollection"))
fileMenu.AddSeparator()
fileMenu.AddText("Stats", keys.Combo("h", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "stats"))
fileMenu.AddText("Find", keys.Combo("f", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "find"))

View File

@ -134,9 +134,9 @@ func (a *App) UpdateFoundDocument(hostKey, dbKey, collKey, idJson, newDocJson st
}
defer close()
if _, err := client.Database(dbKey).Collection(collKey).UpdateOne(ctx, id, bson.M{"$set": newDoc}); err != nil {
runtime.LogInfof(a.ctx, "Error while performing find/update: %s", err.Error())
zenity.Error(err.Error(), zenity.Title("Unable to perform update"), zenity.ErrorIcon)
if _, err := client.Database(dbKey).Collection(collKey).ReplaceOne(ctx, id, newDoc); err != nil {
runtime.LogInfof(a.ctx, "Error while replacing document: %s", err.Error())
zenity.Error(err.Error(), zenity.Title("Unable to replace document"), zenity.ErrorIcon)
return false
}

View File

@ -246,7 +246,7 @@ func (a *App) PerformFindExport(hostKey, dbKey, collKey, settingsJson string) bo
continue
}
csvItem = append(csvItem, string(v.(string)))
csvItem = append(csvItem, fmt.Sprintf("%v", v))
}
default:

View File

@ -21,13 +21,14 @@ type HostInfo struct {
func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, func(), error) {
hosts, err := a.Hosts()
if err != nil {
runtime.LogInfof(a.ctx, "Error while getting hosts: %s", err.Error())
zenity.Error(err.Error(), zenity.Title("Error while getting hosts"), zenity.ErrorIcon)
return nil, nil, nil, errors.New("could not retrieve hosts")
}
h := hosts[hostKey]
if len(h.URI) == 0 {
runtime.LogInfo(a.ctx, "Invalid URI (len == 0) for host "+hostKey)
runtime.LogInfof(a.ctx, "Invalid URI (len == 0) for host %s", hostKey)
zenity.Warning("You haven't specified a valid uri for the selected host.", zenity.Title("Invalid query"), zenity.WarningIcon)
return nil, nil, nil, errors.New("invalid uri")
}
@ -35,8 +36,7 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
client, err := mongo.NewClient(mongoOptions.Client().ApplyURI(h.URI))
if err != nil {
runtime.LogWarning(a.ctx, "Could not connect to host "+hostKey)
runtime.LogWarning(a.ctx, err.Error())
runtime.LogWarningf(a.ctx, "Could not connect to host %s: %s", hostKey, err.Error())
zenity.Error(err.Error(), zenity.Title("Error while connecting to "+h.Name), zenity.ErrorIcon)
return nil, nil, nil, errors.New("could not establish a connection with " + h.Name)
}