Skip to content

Commit

Permalink
Merge pull request #150 from tesladodger/feat/notify-test
Browse files Browse the repository at this point in the history
Add button to test notifications
  • Loading branch information
aceberg authored Oct 20, 2024
2 parents 53dcf3c + 585ee35 commit 9132401
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
9 changes: 9 additions & 0 deletions internal/web/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/aceberg/WatchYourLAN/internal/db"
"github.com/aceberg/WatchYourLAN/internal/models"
"github.com/aceberg/WatchYourLAN/internal/notify"
"github.com/aceberg/WatchYourLAN/internal/portscan"
)

Expand Down Expand Up @@ -88,3 +89,11 @@ func apiEdit(c *gin.Context) {

c.IndentedJSON(http.StatusOK, "OK")
}

func testNotifyHandler(c *gin.Context) {

msg := "Test notification from WatchYourLAN"
notify.Shout(msg, appConfig.ShoutURL)

c.Status(http.StatusOK)
}
5 changes: 5 additions & 0 deletions internal/web/public/js/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
async function testNotifications() {

const url = '/api/test_notify'
await fetch(url, { method: 'post' })
}
4 changes: 3 additions & 1 deletion internal/web/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</tr>
<tr>
<td><button type="submit" class="btn btn-primary">Save</button></td>
<td><button type="button" style="float: right;" class="btn btn-success" onclick="testNotifications()">Test notifications</button></td>
<td></td>
</tr>
</form>
Expand Down Expand Up @@ -199,6 +200,7 @@
</div>
</div>
</div>
<script src="/fs/public/js/notify.js"></script>

{{ template "footer.html" }}
{{ end }}
{{ end }}
13 changes: 7 additions & 6 deletions internal/web/webgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ func Gui(dirPath, nodePath string) {

router.StaticFS("/fs/", http.FS(pubFS)) // public

router.GET("/api/all", apiAll) // api.go
router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go
router.GET("/api/history/*mac", apiHistory) // api.go
router.GET("/api/host/:id", apiHost) // api.go
router.GET("/api/host/del/:id", apiHostDel) // api.go
router.GET("/api/port/:addr/:port", apiPort) // api.go
router.GET("/api/all", apiAll) // api.go
router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go
router.GET("/api/history/*mac", apiHistory) // api.go
router.GET("/api/host/:id", apiHost) // api.go
router.GET("/api/host/del/:id", apiHostDel) // api.go
router.GET("/api/port/:addr/:port", apiPort) // api.go
router.POST("/api/test_notify", testNotifyHandler) // api.go

router.GET("/", indexHandler) // index.go
router.GET("/history/", historyHandler) // index.go
Expand Down

0 comments on commit 9132401

Please sign in to comment.