From 36f7b9fe391421f22df6894e2f0227a8ead20091 Mon Sep 17 00:00:00 2001
From: Azpect3120 <104033825+Azpect3120@users.noreply.github.com>
Date: Thu, 15 Aug 2024 09:07:12 -0700
Subject: [PATCH] FEAT: Connection manager changes!
Can now edit the connection names when creating a connection and the
connection manager can now edit those names! Much better ease of use.
---
internal/database/create.go | 10 +-
internal/database/delete.go | 16 ++
internal/templates/manager.go | 12 +-
web/static/scripts/modal.js | 23 +-
web/static/styles/main.css | 40 ++--
web/templates/index.html | 412 ++++++++++++++++++----------------
6 files changed, 273 insertions(+), 240 deletions(-)
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.