Clear table button
This commit is contained in:
parent
b05ca57cbe
commit
201250e3db
4 changed files with 23 additions and 1 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,11 @@
|
|||
<div class="alert alert-info" role="alert">
|
||||
<h4 class="alert-heading">Warning!</h4>
|
||||
<p>After changing <b>Host</b> or <b>Port</b> you need to restart the app</p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<form action="/clear/" method="post">
|
||||
<button type="submit" class="btn btn-danger">Clear table</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func Gui(configPath string) {
|
|||
log.Println("=================================== ")
|
||||
|
||||
http.HandleFunc("/", indexHandler)
|
||||
http.HandleFunc("/clear/", clearHandler)
|
||||
http.HandleFunc("/config/", configHandler)
|
||||
http.HandleFunc("/del_host/", delHandler)
|
||||
http.HandleFunc("/home/", homeHandler)
|
||||
|
|
|
|||
Loading…
Reference in a new issue