From 04962b1770decae548a584365567e6aafbf4aa91 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sat, 17 Dec 2022 10:11:33 +0000 Subject: [PATCH] switched to js popup to create new watch --- main.go | 6 ------ models.go | 1 - static/script.js | 23 +++++++++++++++++++++++ static/script.ts | 25 +++++++++++++++++++++++++ templates/base.html | 2 +- templates/watch/create.html | 13 ------------- todo.md | 2 -- 7 files changed, 49 insertions(+), 23 deletions(-) delete mode 100644 templates/watch/create.html diff --git a/main.go b/main.go index 8eaa02d..5a3b154 100644 --- a/main.go +++ b/main.go @@ -70,7 +70,6 @@ func (web *Web) initRouter() { web.router.GET("/watch/view/:id", web.watchView) web.router.GET("/watch/edit/:id", web.watchEdit) - web.router.GET("/watch/new", web.watchCreate) web.router.POST("/watch/create", web.watchCreatePost) web.router.POST("/watch/update", web.watchUpdate) web.router.POST("/watch/delete", web.deleteWatch) @@ -84,7 +83,6 @@ func (web *Web) initRouter() { func (web *Web) initTemplates() { web.templates = multitemplate.NewRenderer() web.templates.AddFromFiles("index", "templates/base.html", "templates/index.html") - web.templates.AddFromFiles("watchCreate", "templates/base.html", "templates/watch/create.html") web.templates.AddFromFiles("watchView", "templates/base.html", "templates/watch/view.html") web.templates.AddFromFiles("watchEdit", "templates/base.html", "templates/watch/edit.html") @@ -167,10 +165,6 @@ func (web *Web) index(c *gin.Context) { c.HTML(http.StatusOK, "index", watches) } -func (web *Web) watchCreate(c *gin.Context) { - c.HTML(http.StatusOK, "watchCreate", gin.H{}) -} - func (web *Web) watchCreatePost(c *gin.Context) { var watch Watch errMap, err := bindAndValidateWatch(&watch, c) diff --git a/models.go b/models.go index 1411a76..76234cb 100644 --- a/models.go +++ b/models.go @@ -11,7 +11,6 @@ import ( type Watch struct { ID uint `form:"watch_id" yaml:"watch_id"` Name string `form:"watch_name" yaml:"watch_name" binding:"required" validate:"min=1"` - Interval int `form:"interval" yaml:"interval" binding:"required"` CronEntry *cron.Entry `gorm:"-:all"` } diff --git a/static/script.js b/static/script.js index e69de29..16c60b5 100644 --- a/static/script.js +++ b/static/script.js @@ -0,0 +1,23 @@ +function newWatch() { + var response = prompt("Name of new Watch", ""); + if (response == null || response == "") { + return; // do nothing + } + var data = new URLSearchParams(); + data.append("watch_name", response); + fetch("/watch/create", { + method: "POST", + body: data + }).then(function (response) { + if (!response.ok) { + alert("Could not create watch"); + return; + } + window.location.href = response.url; + }); +} +function newWatchLinkInit() { + var newWatchLink = document.getElementById("newWatchLink"); + newWatchLink.onclick = newWatch; +} +document.addEventListener('DOMContentLoaded', newWatchLinkInit, false); diff --git a/static/script.ts b/static/script.ts index e69de29..5197776 100644 --- a/static/script.ts +++ b/static/script.ts @@ -0,0 +1,25 @@ +function newWatch(){ + let response = prompt("Name of new Watch", ""); + if (response == null || response == ""){ + return // do nothing + } + let data = new URLSearchParams(); + data.append("watch_name", response); + fetch("/watch/create", { + method: "POST", + body: data, + }).then((response) => { + if(!response.ok){ + alert("Could not create watch"); + return; + } + window.location.href = response.url; + }); +} + +function newWatchLinkInit(){ + let newWatchLink = document.getElementById("newWatchLink") as HTMLElement; + newWatchLink.onclick = newWatch; +} + +document.addEventListener('DOMContentLoaded', newWatchLinkInit, false); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 4b73110..1a6e5df 100644 --- a/templates/base.html +++ b/templates/base.html @@ -24,7 +24,7 @@ Home {{ template "navbar" .}} diff --git a/templates/watch/create.html b/templates/watch/create.html deleted file mode 100644 index 68d34f8..0000000 --- a/templates/watch/create.html +++ /dev/null @@ -1,13 +0,0 @@ -{{define "content"}} -
-
- - -
-
- - -
- -
-{{end}} \ No newline at end of file diff --git a/todo.md b/todo.md index 8e9e87f..cdfe6ce 100644 --- a/todo.md +++ b/todo.md @@ -1,6 +1,4 @@ # Todo -- remove interval input from new watch page - - maybe turn new watch into popup with textbox ? - make generic 'notifier' interface - telegram - discord