diff --git a/internal/database/delete.go b/internal/database/delete.go new file mode 100644 index 0000000..b0b7815 --- /dev/null +++ b/internal/database/delete.go @@ -0,0 +1,40 @@ +package database + +import ( + "encoding/json" + "fmt" + + "github.com/Azpect3120/Web-Database-Viewer/internal/templates" + "github.com/gin-contrib/sessions" + "github.com/gin-gonic/gin" +) + +func DeleteConnections(c *gin.Context) { + session := sessions.Default(c) + connections_bytes, ok := session.Get("connections").([]byte) + if !ok { + fmt.Println("No connections found") + } + + var connections map[string]string + if err := json.Unmarshal(connections_bytes, &connections); err != nil { + fmt.Println(err) + } + + for _, conn := range c.PostFormArray("connections") { + for name, url := range connections { + if conn == url { + delete(connections, name) + } + } + } + + connections_bytes, err := json.Marshal(connections) + if err != nil { + fmt.Println(err) + } + session.Set("connections", connections_bytes) + session.Save() + + c.String(200, templates.MANAGER_CLOSED) +} diff --git a/internal/http/router.go b/internal/http/router.go index adb5993..35076ca 100644 --- a/internal/http/router.go +++ b/internal/http/router.go @@ -50,6 +50,7 @@ func populate(web, api *gin.RouterGroup) { "status": 200, }) }) + api.POST("/connections/delete", database.DeleteConnections) web.GET("/connections", func(c *gin.Context) { session := sessions.Default(c) connections_bytes, conn_ok := session.Get("connections").([]byte) @@ -73,7 +74,9 @@ func populate(web, api *gin.RouterGroup) { c.String(200, database.TableTree(c)) }) - // This should return an HTML template which will be used to auto or not - // auto send the query to the server. web.GET("/query/auto", templates.ToggleQueryType) + + web.GET("/manager/open", templates.OpenManager) + web.GET("/manager/hide", templates.HideManager) + } diff --git a/internal/templates/connections.go b/internal/templates/connections.go index 0390a3f..b185372 100644 --- a/internal/templates/connections.go +++ b/internal/templates/connections.go @@ -3,7 +3,7 @@ package templates import "fmt" // List item templates -const LIST_OPEN string = `` const LIST_ITEM string = `` const LIST_CLOSE string = `` diff --git a/internal/templates/manager.go b/internal/templates/manager.go new file mode 100644 index 0000000..2a3ffcc --- /dev/null +++ b/internal/templates/manager.go @@ -0,0 +1,88 @@ +package templates + +import ( + "encoding/json" + "fmt" + + "github.com/gin-contrib/sessions" + "github.com/gin-gonic/gin" +) + +const MANAGER string = ` +
+
+
+
+

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

+ +
+
+ + + + + + + + + + + %s + +
DeleteNameDriverURL
+
+
+ +
+
+
+
+` + +const MANAGER_ENTRY string = ` + + + + + %s + %s + %s + +` + +const MANAGER_CLOSED string = ` + +` + +func OpenManager(c *gin.Context) { + session := sessions.Default(c) + connections_bytes, ok := session.Get("connections").([]byte) + if !ok { + fmt.Println("No connections found") + } + + var connections map[string]string + if err := json.Unmarshal(connections_bytes, &connections); err != nil { + fmt.Println(err) + } + + var entries string + for name, url := range connections { + entries += fmt.Sprintf(MANAGER_ENTRY, url, name, "PostgreSQL", url) + } + + c.String(200, fmt.Sprintf(MANAGER, entries)) +} + +func HideManager(c *gin.Context) { + c.String(200, MANAGER_CLOSED) +} diff --git a/web/static/scripts/modal.js b/web/static/scripts/modal.js index 7efd47e..bd12ae9 100644 --- a/web/static/scripts/modal.js +++ b/web/static/scripts/modal.js @@ -75,3 +75,5 @@ for (const key in input) { }) } } + + diff --git a/web/static/styles/main.css b/web/static/styles/main.css index 824eeb0..c0f8439 100644 --- a/web/static/styles/main.css +++ b/web/static/styles/main.css @@ -710,10 +710,27 @@ video { width: 100%; } +.w-fit { + width: -moz-fit-content; + width: fit-content; +} + .min-w-full { min-width: 100%; } +.max-w-\[50\%\] { + max-width: 50%; +} + +.max-w-\[50\%\%\] { + max-width: 50%%; +} + +.max-w-full { + max-width: 100%; +} + .flex-grow { flex-grow: 1; } @@ -738,6 +755,10 @@ video { flex-wrap: wrap; } +.items-start { + align-items: flex-start; +} + .items-center { align-items: center; } @@ -803,6 +824,10 @@ video { overflow-x: auto; } +.overflow-x-hidden { + overflow-x: hidden; +} + .overflow-y-hidden { overflow-y: hidden; } @@ -840,6 +865,10 @@ video { border-bottom-width: 1px; } +.border-t { + border-top-width: 1px; +} + .border-gray-300 { --tw-border-opacity: 1; border-color: rgb(209 213 219 / var(--tw-border-opacity)); @@ -885,6 +914,21 @@ video { background-color: rgb(234 179 8 / var(--tw-bg-opacity)); } +.bg-red-500 { + --tw-bg-opacity: 1; + background-color: rgb(239 68 68 / var(--tw-bg-opacity)); +} + +.bg-red-600 { + --tw-bg-opacity: 1; + background-color: rgb(220 38 38 / var(--tw-bg-opacity)); +} + +.bg-red-300 { + --tw-bg-opacity: 1; + background-color: rgb(252 165 165 / var(--tw-bg-opacity)); +} + .bg-opacity-50 { --tw-bg-opacity: 0.5; } @@ -940,10 +984,18 @@ video { padding-bottom: 0.5rem; } +.pt-4 { + padding-top: 1rem; +} + .text-left { text-align: left; } +.text-center { + text-align: center; +} + .text-2xl { font-size: 1.5rem; line-height: 2rem; diff --git a/web/templates/index.html b/web/templates/index.html index 71d11c3..b5d3351 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -32,6 +32,9 @@ + @@ -71,7 +74,7 @@
- +
@@ -199,6 +202,10 @@
+ + + +