diff --git a/api.go b/api.go index 9d54148..befe1c9 100644 --- a/api.go +++ b/api.go @@ -57,7 +57,10 @@ func API_Connect(c *gin.Context) { info, err := client.Info() if err == nil { - dbClient.db.Close() + if dbClient != nil { + dbClient.db.Close() + } + dbClient = client } @@ -135,6 +138,11 @@ func API_History(c *gin.Context) { } func API_Info(c *gin.Context) { + if dbClient == nil { + c.JSON(400, Error{"Not connected"}) + return + } + res, err := dbClient.Info() if err != nil { diff --git a/main.go b/main.go index fe8f907..b001e7a 100644 --- a/main.go +++ b/main.go @@ -17,11 +17,11 @@ var options struct { Version bool `short:"v" long:"version" description:"Print version"` Debug bool `short:"d" long:"debug" description:"Enable debugging mode" default:"false"` Url string `long:"url" description:"Database connection string"` - Host string `long:"host" description:"Server hostname or IP" default:"localhost"` + Host string `long:"host" description:"Server hostname or IP"` Port int `long:"port" description:"Server port" default:"5432"` - User string `long:"user" description:"Database user" default:"postgres"` + User string `long:"user" description:"Database user"` Pass string `long:"pass" description:"Password for user"` - DbName string `long:"db" description:"Database name" default:"postgres"` + DbName string `long:"db" description:"Database name"` Ssl string `long:"ssl" description:"SSL option" default:"disable"` HttpHost string `long:"bind" description:"HTTP server host" default:"localhost"` HttpPort uint `long:"listen" description:"HTTP server listen port" default:"8080"` @@ -62,7 +62,18 @@ func getConnectionString() string { return str } +func connectionSettingsBlank() bool { + return options.Host == "" && + options.User == "" && + options.DbName == "" && + options.Url == "" +} + func initClient() { + if connectionSettingsBlank() { + return + } + client, err := NewClient() if err != nil { exitWithMessage(err.Error()) @@ -158,7 +169,9 @@ func main() { initOptions() initClient() - defer dbClient.db.Close() + if dbClient != nil { + defer dbClient.db.Close() + } if !options.Debug { gin.SetMode("release") diff --git a/static/css/app.css b/static/css/app.css index 2ef23e5..3f1ef53 100644 --- a/static/css/app.css +++ b/static/css/app.css @@ -1,3 +1,7 @@ +#main { + display: none; +} + #nav { position: fixed; top: 0; @@ -13,6 +17,7 @@ padding: 0px; height: 50px; display: block; + width: 550px; } #nav ul li { @@ -331,4 +336,40 @@ #custom_query { height: 205px; +} + +#connection_window { + z-index: 2; + position: fixed; + background: #ebeef0; + top: 0px; + left: 0px; + bottom: 0px; + right: 0px; + display: none; +} + +#connection_error { + display: none; +} + +.connection-settings { + width: 500px; + margin: 0px auto; + margin-top: 50px; +} + +.connection-settings h1 { + text-align: center; + margin-bottom: 25px; + color: #95A7B7; + font-weight: normal; +} + +.connection-settings form { + background: #fff; + padding: 40px 25px; + border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; } \ No newline at end of file diff --git a/static/index.html b/static/index.html index 62ab987..03c05bc 100644 --- a/static/index.html +++ b/static/index.html @@ -13,52 +13,79 @@ - -