Browse Source

Icons, identify device by index, launch.json

master
adro 2 years ago
parent
commit
ed9d9474e3
  1. 1
      .gitignore
  2. 15
      .vscode/launch.json
  3. 15
      web/device.go
  4. 12
      web/template/device.html
  5. 2
      web/template/page.html

1
.gitignore vendored

@ -26,3 +26,4 @@ config.toml @@ -26,3 +26,4 @@ config.toml
miniwol
!example/**
__debug_bin

15
.vscode/launch.json vendored

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}"
}
]
}

15
web/device.go

@ -3,6 +3,7 @@ package web @@ -3,6 +3,7 @@ package web
import (
"errors"
"net/http"
"strconv"
"strings"
"git.ulra.eu/adro/miniwol/config"
@ -27,13 +28,12 @@ func add(c echo.Context) error { @@ -27,13 +28,12 @@ func add(c echo.Context) error {
}
func wake(c echo.Context) error {
_device := config.Device{}
err := c.Bind(&_device)
index, err := strconv.Atoi(c.FormValue("Index"))
if err != nil {
return err
}
for _, device := range config.Config.Devices {
if device == _device {
for i, device := range config.Config.Devices {
if i == index {
if !strings.Contains(device.IP, ":") {
device.IP += ":9"
}
@ -49,13 +49,12 @@ func wake(c echo.Context) error { @@ -49,13 +49,12 @@ func wake(c echo.Context) error {
}
func remove(c echo.Context) error {
_device := config.Device{}
err := c.Bind(&_device)
index, err := strconv.Atoi(c.FormValue("Index"))
if err != nil {
return err
}
for i, device := range config.Config.Devices {
if device == _device {
for i := range config.Config.Devices {
if i == index {
config.Config.Devices = append(config.Config.Devices[:i], config.Config.Devices[i+1:]...)
err := config.Save()
if err != nil {

12
web/template/device.html

@ -27,16 +27,12 @@ @@ -27,16 +27,12 @@
<td>
<div class="actions">
<form action="/wake" method="post">
<input type="text" name="Alias" value="{{$d.Alias}}" hidden>
<input type="text" name="MAC" value="{{$d.MAC}}" hidden>
<input type="text" name="IP" value="{{$d.IP}}" hidden>
<input type="submit" value="Wake">
<input type="number" name="Index" value="{{$i}}" hidden>
<input type="submit" value="&#x23FB;" title="Wake">
</form>
<form action="/remove" method="post">
<input type="text" name="Alias" value="{{$d.Alias}}" hidden>
<input type="text" name="MAC" value="{{$d.MAC}}" hidden>
<input type="text" name="IP" value="{{$d.IP}}" hidden>
<input type="submit" value="Remove">
<input type="number" name="Index" value="{{$i}}" hidden>
<input type="submit" value="&#x1F5D1;" title="Delete">
</form>
</div>
</td>

2
web/template/page.html

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
<div style="flex-grow: 1;"></div>
{{ if .Auth }}
<form action="/deauth" method="post">
<input type="submit" value="Logout">
<input type="submit" value="&#x23FB;">
</form>
{{ end }}
</nav>

Loading…
Cancel
Save