Skip to content

Commit

Permalink
Search index page
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Aug 26, 2024
1 parent 8542417 commit 95e2f2a
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 51 deletions.
10 changes: 10 additions & 0 deletions internal/conf/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func Get(path string) (config models.Conf) {
viper.SetDefault("TIMEOUT", 60)
viper.SetDefault("TRIM_HIST", 48)
viper.SetDefault("SHOUTRRR_URL", "")

viper.SetDefault("USE_DB", "sqlite")
viper.SetDefault("PG_CONNECT", "")

viper.SetDefault("INFLUX_ENABLE", false)

viper.SetConfigFile(path)
Expand All @@ -42,6 +46,9 @@ func Get(path string) (config models.Conf) {
config.TrimHist = viper.GetInt("TRIM_HIST")
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.InfluxSkipTLS = viper.GetBool("INFLUX_SKIP_TLS")
config.InfluxAddr, _ = viper.Get("INFLUX_ADDR").(string)
Expand Down Expand Up @@ -70,6 +77,9 @@ func Write(config models.Conf) {
viper.Set("TRIM_HIST", config.TrimHist)
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_skip_tls", config.InfluxSkipTLS)
viper.Set("influx_addr", config.InfluxAddr)
Expand Down
32 changes: 18 additions & 14 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package models

// Conf - app config
type Conf struct {
Host string
Port string
Theme string
Color string
DirPath string
ConfPath string
DBPath string
NodePath string
LogLevel string
Ifaces string
ArpArgs string
Timeout int
TrimHist int
ShoutURL string
Host string
Port string
Theme string
Color string
DirPath string
ConfPath string
DBPath string
NodePath string
LogLevel string
Ifaces string
ArpArgs string
Timeout int
TrimHist int
ShoutURL string
// PostgreSQL
UseDB string
PGConnect string
// InfluxDB
InfluxEnable bool
InfluxAddr string
InfluxToken string
Expand Down
3 changes: 3 additions & 0 deletions internal/web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func saveConfigHandler(c *gin.Context) {
appConfig.Ifaces = c.PostForm("ifaces")
appConfig.ShoutURL = c.PostForm("shout")

appConfig.UseDB = c.PostForm("usedb")
appConfig.PGConnect = c.PostForm("pgconnect")

timeout := c.PostForm("timeout")
trimHist := c.PostForm("trim")
appConfig.Timeout, _ = strconv.Atoi(timeout)
Expand Down
68 changes: 68 additions & 0 deletions internal/web/public/js/filter-search.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 0 additions & 32 deletions internal/web/public/js/filter.js

This file was deleted.

14 changes: 14 additions & 0 deletions internal/web/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
<textarea name="shout" class="form-control" style="width: 100%;" rows="3" wrap="soft">{{ .Config.ShoutURL }}</textarea>
</td>
</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>
<td>Log level</td>
<td><select name="log" class="form-select">
Expand Down
15 changes: 11 additions & 4 deletions internal/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
</head>
<script src="/fs/public/js/index.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>
<div class="container-lg">
<div class="row">
<div class="col-md mt-4 mb-4">
<div class="card border-primary">
<div class="card-header">
<div class="d-flex justify-content-between">
<div class="d-flex justify-content-left gap-3">
<!-- <div class="d-flex justify-content-between">
<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 dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Iface</button>
<ul class="dropdown-menu">
Expand All @@ -30,7 +32,12 @@
</ul>
<button class="btn btn-outline-primary" onclick="resetFilter()">Reset filter</button>
</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 class="card-body table-responsive">
Expand Down
2 changes: 1 addition & 1 deletion internal/web/webgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Gui(dirPath, nodePath string) {
quitScan = make(chan bool)
updateRoutines() // routines-upd.go

slog.Info("config", "path", appConfig.DirPath)
slog.Info("Config dir", "path", appConfig.DirPath)

address := appConfig.Host + ":" + appConfig.Port

Expand Down

0 comments on commit 95e2f2a

Please sign in to comment.