From 3f8f6aa81a378a9bdfa2b46c2483000e16760808 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 2 Jan 2023 12:33:31 +0000 Subject: [PATCH] added notifiers page, with test button --- main.go | 20 ++++++++++++++++++++ templates/base.html | 3 +++ templates/notifiers.html | 27 +++++++++++++++++++++++++++ todo.md | 3 --- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 templates/notifiers.html diff --git a/main.go b/main.go index a9fc182..e0dff78 100644 --- a/main.go +++ b/main.go @@ -131,6 +131,9 @@ func (web *Web) initRouter() { web.router.GET("/cache/view", web.cacheView) web.router.POST("/cache/clear", web.cacheClear) + web.router.GET("/notifiers/view", web.notifiersView) + web.router.POST("/notifiers/test", web.notifiersTest) + web.router.SetTrustedProxies(nil) } @@ -150,6 +153,8 @@ func (web *Web) initTemplates() { web.templates.Add("cacheView", template.Must(template.ParseFS(templatesFS, "base.html", "cache/view.html"))) + web.templates.Add("notifiersView", template.Must(template.ParseFS(templatesFS, "base.html", "notifiers.html"))) + web.templates.Add("500", template.Must(template.ParseFS(templatesFS, "base.html", "500.html"))) } @@ -317,6 +322,21 @@ func (web *Web) index(c *gin.Context) { }) } +func (web *Web) notifiersView(c *gin.Context) { + c.HTML(http.StatusOK, "notifiersView", web.notifiers) +} + +func (web *Web) notifiersTest(c *gin.Context) { + notifierName := c.PostForm("notifier_name") + notifier, exists := web.notifiers[notifierName] + if !exists { + c.Redirect(http.StatusSeeOther, "/notifiers/view") + return + } + notifier.Message("GoWatch Test") + c.Redirect(http.StatusSeeOther, "/notifiers/view") +} + func (web *Web) watchCreate(c *gin.Context) { templateFiles, err := EMBED_FS.ReadDir("watchTemplates") if err != nil { diff --git a/templates/base.html b/templates/base.html index ac9fd7e..0eda59f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -23,6 +23,9 @@ + diff --git a/templates/notifiers.html b/templates/notifiers.html new file mode 100644 index 0000000..9132308 --- /dev/null +++ b/templates/notifiers.html @@ -0,0 +1,27 @@ +{{define "title"}} +GoWatch +{{end}} + +{{define "content"}} + + + + + + + + + {{ range $name, $notifier := . }} + + + + + {{ end }} + +
NameTest
{{ $name }} +
+ + +
+
+{{end}} \ No newline at end of file diff --git a/todo.md b/todo.md index 181f891..4d27b5e 100644 --- a/todo.md +++ b/todo.md @@ -11,7 +11,4 @@ - organize docs? - disable gin debug - add favicon -- notifiers overview page - - with test for notifier - - last success/error message - db prune readme \ No newline at end of file