Search index page
This commit is contained in:
parent
8542417d40
commit
95e2f2a4de
8 changed files with 125 additions and 51 deletions
|
|
@ -21,6 +21,10 @@ func Get(path string) (config models.Conf) {
|
||||||
viper.SetDefault("TIMEOUT", 60)
|
viper.SetDefault("TIMEOUT", 60)
|
||||||
viper.SetDefault("TRIM_HIST", 48)
|
viper.SetDefault("TRIM_HIST", 48)
|
||||||
viper.SetDefault("SHOUTRRR_URL", "")
|
viper.SetDefault("SHOUTRRR_URL", "")
|
||||||
|
|
||||||
|
viper.SetDefault("USE_DB", "sqlite")
|
||||||
|
viper.SetDefault("PG_CONNECT", "")
|
||||||
|
|
||||||
viper.SetDefault("INFLUX_ENABLE", false)
|
viper.SetDefault("INFLUX_ENABLE", false)
|
||||||
|
|
||||||
viper.SetConfigFile(path)
|
viper.SetConfigFile(path)
|
||||||
|
|
@ -42,6 +46,9 @@ func Get(path string) (config models.Conf) {
|
||||||
config.TrimHist = viper.GetInt("TRIM_HIST")
|
config.TrimHist = viper.GetInt("TRIM_HIST")
|
||||||
config.ShoutURL = viper.Get("SHOUTRRR_URL").(string)
|
config.ShoutURL = viper.Get("SHOUTRRR_URL").(string)
|
||||||
|
|
||||||
|
config.UseDB = viper.Get("USE_DB").(string)
|
||||||
|
config.PGConnect = viper.Get("PG_CONNECT").(string)
|
||||||
|
|
||||||
config.InfluxEnable = viper.GetBool("INFLUX_ENABLE")
|
config.InfluxEnable = viper.GetBool("INFLUX_ENABLE")
|
||||||
config.InfluxSkipTLS = viper.GetBool("INFLUX_SKIP_TLS")
|
config.InfluxSkipTLS = viper.GetBool("INFLUX_SKIP_TLS")
|
||||||
config.InfluxAddr, _ = viper.Get("INFLUX_ADDR").(string)
|
config.InfluxAddr, _ = viper.Get("INFLUX_ADDR").(string)
|
||||||
|
|
@ -70,6 +77,9 @@ func Write(config models.Conf) {
|
||||||
viper.Set("TRIM_HIST", config.TrimHist)
|
viper.Set("TRIM_HIST", config.TrimHist)
|
||||||
viper.Set("SHOUTRRR_URL", config.ShoutURL)
|
viper.Set("SHOUTRRR_URL", config.ShoutURL)
|
||||||
|
|
||||||
|
viper.Set("USE_DB", config.UseDB)
|
||||||
|
viper.Set("PG_CONNECT", config.PGConnect)
|
||||||
|
|
||||||
viper.Set("influx_enable", config.InfluxEnable)
|
viper.Set("influx_enable", config.InfluxEnable)
|
||||||
viper.Set("influx_skip_tls", config.InfluxSkipTLS)
|
viper.Set("influx_skip_tls", config.InfluxSkipTLS)
|
||||||
viper.Set("influx_addr", config.InfluxAddr)
|
viper.Set("influx_addr", config.InfluxAddr)
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,24 @@ package models
|
||||||
|
|
||||||
// Conf - app config
|
// Conf - app config
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
Host string
|
Host string
|
||||||
Port string
|
Port string
|
||||||
Theme string
|
Theme string
|
||||||
Color string
|
Color string
|
||||||
DirPath string
|
DirPath string
|
||||||
ConfPath string
|
ConfPath string
|
||||||
DBPath string
|
DBPath string
|
||||||
NodePath string
|
NodePath string
|
||||||
LogLevel string
|
LogLevel string
|
||||||
Ifaces string
|
Ifaces string
|
||||||
ArpArgs string
|
ArpArgs string
|
||||||
Timeout int
|
Timeout int
|
||||||
TrimHist int
|
TrimHist int
|
||||||
ShoutURL string
|
ShoutURL string
|
||||||
|
// PostgreSQL
|
||||||
|
UseDB string
|
||||||
|
PGConnect string
|
||||||
|
// InfluxDB
|
||||||
InfluxEnable bool
|
InfluxEnable bool
|
||||||
InfluxAddr string
|
InfluxAddr string
|
||||||
InfluxToken string
|
InfluxToken string
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@ func saveConfigHandler(c *gin.Context) {
|
||||||
appConfig.Ifaces = c.PostForm("ifaces")
|
appConfig.Ifaces = c.PostForm("ifaces")
|
||||||
appConfig.ShoutURL = c.PostForm("shout")
|
appConfig.ShoutURL = c.PostForm("shout")
|
||||||
|
|
||||||
|
appConfig.UseDB = c.PostForm("usedb")
|
||||||
|
appConfig.PGConnect = c.PostForm("pgconnect")
|
||||||
|
|
||||||
timeout := c.PostForm("timeout")
|
timeout := c.PostForm("timeout")
|
||||||
trimHist := c.PostForm("trim")
|
trimHist := c.PostForm("trim")
|
||||||
appConfig.Timeout, _ = strconv.Atoi(timeout)
|
appConfig.Timeout, _ = strconv.Atoi(timeout)
|
||||||
|
|
|
||||||
68
internal/web/public/js/filter-search.js
Normal file
68
internal/web/public/js/filter-search.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
let oldFilter = '';
|
||||||
|
let bkpArray;
|
||||||
|
|
||||||
|
function filterFunc(field, value) {
|
||||||
|
|
||||||
|
if (oldFilter == field) {
|
||||||
|
addrsArray = bkpArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (field) {
|
||||||
|
case 'iface':
|
||||||
|
addrsArray = addrsArray.filter((item) => item.Iface == value);
|
||||||
|
break;
|
||||||
|
case 'known':
|
||||||
|
addrsArray = addrsArray.filter((item) => item.Known == value);
|
||||||
|
break;
|
||||||
|
case 'line':
|
||||||
|
addrsArray = addrsArray.filter((item) => item.Now == value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log("Filter error");
|
||||||
|
}
|
||||||
|
|
||||||
|
oldFilter = field;
|
||||||
|
|
||||||
|
displayArrayData(addrsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetFilter() {
|
||||||
|
addrsArray = bkpArray;
|
||||||
|
displayArrayData(addrsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchFunc() {
|
||||||
|
const s = document.getElementById('search').value;
|
||||||
|
|
||||||
|
if (s != "") {
|
||||||
|
|
||||||
|
const sl = s.toLowerCase();
|
||||||
|
|
||||||
|
let newArray = [];
|
||||||
|
|
||||||
|
for (let item of addrsArray) {
|
||||||
|
|
||||||
|
if (searchItem(item, sl)) {
|
||||||
|
newArray.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addrsArray = newArray;
|
||||||
|
} else {
|
||||||
|
addrsArray = bkpArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
displayArrayData(addrsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchItem(item, sl) {
|
||||||
|
|
||||||
|
const name = item.Name.toLowerCase();
|
||||||
|
const hw = item.Hw.toLowerCase();
|
||||||
|
const mac = item.Mac.toLowerCase();
|
||||||
|
|
||||||
|
if ((name.includes(sl)) || (item.Iface.includes(sl)) || (item.IP.includes(sl)) || (mac.includes(sl)) || (hw.includes(sl)) || (item.Date.includes(sl))) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
let oldFilter = '';
|
|
||||||
let bkpArray;
|
|
||||||
|
|
||||||
function filterFunc(field, value) {
|
|
||||||
|
|
||||||
if (oldFilter == field) {
|
|
||||||
addrsArray = bkpArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (field) {
|
|
||||||
case 'iface':
|
|
||||||
addrsArray = addrsArray.filter((item) => item.Iface == value);
|
|
||||||
break;
|
|
||||||
case 'known':
|
|
||||||
addrsArray = addrsArray.filter((item) => item.Known == value);
|
|
||||||
break;
|
|
||||||
case 'line':
|
|
||||||
addrsArray = addrsArray.filter((item) => item.Now == value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log("Filter error");
|
|
||||||
}
|
|
||||||
|
|
||||||
oldFilter = field;
|
|
||||||
|
|
||||||
displayArrayData(addrsArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetFilter() {
|
|
||||||
addrsArray = bkpArray;
|
|
||||||
displayArrayData(addrsArray);
|
|
||||||
}
|
|
||||||
|
|
@ -44,6 +44,20 @@
|
||||||
<textarea name="shout" class="form-control" style="width: 100%;" rows="3" wrap="soft">{{ .Config.ShoutURL }}</textarea>
|
<textarea name="shout" class="form-control" style="width: 100%;" rows="3" wrap="soft">{{ .Config.ShoutURL }}</textarea>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Use DB</td>
|
||||||
|
<td><select name="usedb" class="form-select">
|
||||||
|
<option selected>{{ .Config.UseDB }}</option>
|
||||||
|
<option value="sqlite">sqlite</option>
|
||||||
|
<option value="postgres">postgres</option>
|
||||||
|
</select></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>PG Connect URL</td>
|
||||||
|
<td>
|
||||||
|
<textarea name="pgconnect" class="form-control" style="width: 100%;" rows="3" wrap="soft">{{ .Config.PGConnect }}</textarea>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Log level</td>
|
<td>Log level</td>
|
||||||
<td><select name="log" class="form-select">
|
<td><select name="log" class="form-select">
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,17 @@
|
||||||
</head>
|
</head>
|
||||||
<script src="/fs/public/js/index.js"></script>
|
<script src="/fs/public/js/index.js"></script>
|
||||||
<script src="/fs/public/js/sort.js"></script>
|
<script src="/fs/public/js/sort.js"></script>
|
||||||
<script src="/fs/public/js/filter.js"></script>
|
<script src="/fs/public/js/filter-search.js"></script>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-lg">
|
<div class="container-lg">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md mt-4 mb-4">
|
<div class="col-md mt-4 mb-4">
|
||||||
<div class="card border-primary">
|
<div class="card border-primary">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="d-flex justify-content-between">
|
<!-- <div class="d-flex justify-content-between">
|
||||||
<div class="d-flex justify-content-left gap-3">
|
<div class="d-flex justify-content-left gap-3"> -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md mt-1 mb-1">
|
||||||
<button class="btn btn-outline-primary" disabled>Filter by</button>
|
<button class="btn btn-outline-primary" disabled>Filter by</button>
|
||||||
<button class="btn btn-outline-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Iface</button>
|
<button class="btn btn-outline-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Iface</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
|
|
@ -30,7 +32,12 @@
|
||||||
</ul>
|
</ul>
|
||||||
<button class="btn btn-outline-primary" onclick="resetFilter()">Reset filter</button>
|
<button class="btn btn-outline-primary" onclick="resetFilter()">Reset filter</button>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-outline-primary" id="edit" onclick="editClick()">Edit names</button>
|
<div class="col-md mt-1 mb-1">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<input class="form-control" id="search" oninput="searchFunc()" placeholder="Search" style="max-width: 10em;">
|
||||||
|
<button class="btn btn-outline-primary" id="edit" onclick="editClick()">Edit names</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body table-responsive">
|
<div class="card-body table-responsive">
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func Gui(dirPath, nodePath string) {
|
||||||
quitScan = make(chan bool)
|
quitScan = make(chan bool)
|
||||||
updateRoutines() // routines-upd.go
|
updateRoutines() // routines-upd.go
|
||||||
|
|
||||||
slog.Info("config", "path", appConfig.DirPath)
|
slog.Info("Config dir", "path", appConfig.DirPath)
|
||||||
|
|
||||||
address := appConfig.Host + ":" + appConfig.Port
|
address := appConfig.Host + ":" + appConfig.Port
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue