diff --git a/internal/database/create.go b/internal/database/create.go index dce0286..e7d7772 100644 --- a/internal/database/create.go +++ b/internal/database/create.go @@ -13,8 +13,8 @@ import ( // in the session. func CreateConnection(c *gin.Context) { var ( - url string = c.PostForm("db-url") - database string = c.PostForm("db-database") + url string = c.PostForm("db-url") + name string = c.PostForm("db-conn-name") ) session := sessions.Default(c) @@ -30,7 +30,7 @@ func CreateConnection(c *gin.Context) { } } - connections[database] = url + connections[name] = url conn_bytes, err := json.Marshal(connections) if err != nil { @@ -38,9 +38,9 @@ func CreateConnection(c *gin.Context) { } session.Set("connections", []byte(conn_bytes)) - session.Set("current", database) + session.Set("current", name) session.Save() - html := templates.ConnectionsList(connections, database) + html := templates.ConnectionsList(connections, name) c.String(200, html) } diff --git a/internal/database/delete.go b/internal/database/delete.go index b0b7815..073b20e 100644 --- a/internal/database/delete.go +++ b/internal/database/delete.go @@ -11,6 +11,7 @@ import ( func DeleteConnections(c *gin.Context) { session := sessions.Default(c) + current, ok := session.Get("current").(string) connections_bytes, ok := session.Get("connections").([]byte) if !ok { fmt.Println("No connections found") @@ -29,6 +30,21 @@ func DeleteConnections(c *gin.Context) { } } + for name, url := range connections { + newName := c.PostForm(url) + + if name == newName { + continue + } + + delete(connections, name) + connections[newName] = url + + if name == current { + session.Set("current", newName) + } + } + connections_bytes, err := json.Marshal(connections) if err != nil { fmt.Println(err) diff --git a/internal/templates/manager.go b/internal/templates/manager.go index 2a3ffcc..501f0f3 100644 --- a/internal/templates/manager.go +++ b/internal/templates/manager.go @@ -16,7 +16,7 @@ const MANAGER string = `

Manage Stored Connections
- Connection data is stored in the browsers session and can be deleted here. + Connection data is stored in the browsers session and can be renamed or deleted here.

+ + + + +
+ +
+
+

+ database + loading + tables... +

+
-
-
- - +
+
    +
    +
    + + +
    +
    + +
    +
    + +
    + + + + + + + + + + +
    +
    + + + + + + + + + +
    + + +
    +
    +
    +
    +
    +
    +
    + + + - - - - - - - - + + + + + + + +