Merge pull request #150 from tesladodger/feat/notify-test
Add button to test notifications
This commit is contained in:
commit
9132401ce0
4 changed files with 24 additions and 7 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/aceberg/WatchYourLAN/internal/db"
|
"github.com/aceberg/WatchYourLAN/internal/db"
|
||||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||||
|
"github.com/aceberg/WatchYourLAN/internal/notify"
|
||||||
"github.com/aceberg/WatchYourLAN/internal/portscan"
|
"github.com/aceberg/WatchYourLAN/internal/portscan"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -88,3 +89,11 @@ func apiEdit(c *gin.Context) {
|
||||||
|
|
||||||
c.IndentedJSON(http.StatusOK, "OK")
|
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
internal/web/public/js/notify.js
Normal file
5
internal/web/public/js/notify.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
async function testNotifications() {
|
||||||
|
|
||||||
|
const url = '/api/test_notify'
|
||||||
|
await fetch(url, { method: 'post' })
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><button type="submit" class="btn btn-primary">Save</button></td>
|
<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>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -199,6 +200,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/fs/public/js/notify.js"></script>
|
||||||
|
|
||||||
{{ template "footer.html" }}
|
{{ template "footer.html" }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
@ -46,12 +46,13 @@ func Gui(dirPath, nodePath string) {
|
||||||
|
|
||||||
router.StaticFS("/fs/", http.FS(pubFS)) // public
|
router.StaticFS("/fs/", http.FS(pubFS)) // public
|
||||||
|
|
||||||
router.GET("/api/all", apiAll) // api.go
|
router.GET("/api/all", apiAll) // api.go
|
||||||
router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go
|
router.GET("/api/edit/:id/:name/*known", apiEdit) // api.go
|
||||||
router.GET("/api/history/*mac", apiHistory) // api.go
|
router.GET("/api/history/*mac", apiHistory) // api.go
|
||||||
router.GET("/api/host/:id", apiHost) // api.go
|
router.GET("/api/host/:id", apiHost) // api.go
|
||||||
router.GET("/api/host/del/:id", apiHostDel) // api.go
|
router.GET("/api/host/del/:id", apiHostDel) // api.go
|
||||||
router.GET("/api/port/:addr/:port", apiPort) // 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("/", indexHandler) // index.go
|
||||||
router.GET("/history/", historyHandler) // index.go
|
router.GET("/history/", historyHandler) // index.go
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue