From 201250e3dbe2b1fd5875425aaddd9bd541e4c4ed Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Tue, 3 Jan 2023 00:17:35 +0700 Subject: [PATCH] Clear table button --- internal/db/db-edit.go | 6 ++++++ internal/web/config.go | 11 +++++++++++ internal/web/templates/config.html | 6 +++++- internal/web/webgui.go | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/db/db-edit.go b/internal/db/db-edit.go index 7480c10..e9cfb5b 100644 --- a/internal/db/db-edit.go +++ b/internal/db/db-edit.go @@ -64,3 +64,9 @@ func Delete(path string, id uint16) { sqlStatement = fmt.Sprintf(sqlStatement, id) dbExec(path, sqlStatement) } + +// Clear - delete all hosts from table +func Clear(path string) { + sqlStatement := `DELETE FROM "now";` + dbExec(path, sqlStatement) +} diff --git a/internal/web/config.go b/internal/web/config.go index c996017..77f2972 100644 --- a/internal/web/config.go +++ b/internal/web/config.go @@ -2,11 +2,13 @@ package web import ( "html/template" + "log" "net/http" "strconv" "github.com/aceberg/WatchYourLAN/internal/check" "github.com/aceberg/WatchYourLAN/internal/conf" + "github.com/aceberg/WatchYourLAN/internal/db" "github.com/aceberg/WatchYourLAN/internal/models" "github.com/aceberg/WatchYourLAN/internal/scan" ) @@ -50,3 +52,12 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, r.Header.Get("Referer"), 302) } + +func clearHandler(w http.ResponseWriter, r *http.Request) { + + log.Println("INFO: delting all hosts from DB") + + db.Clear(AppConfig.DbPath) + + http.Redirect(w, r, r.Header.Get("Referer"), 302) +} diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html index 5aacd38..8637ccc 100644 --- a/internal/web/templates/config.html +++ b/internal/web/templates/config.html @@ -50,7 +50,11 @@
After changing Host or Port you need to restart the app
-