switched to js popup to create new watch
This commit is contained in:
parent
974b80567f
commit
04962b1770
7 changed files with 49 additions and 23 deletions
6
main.go
6
main.go
|
@ -70,7 +70,6 @@ func (web *Web) initRouter() {
|
||||||
|
|
||||||
web.router.GET("/watch/view/:id", web.watchView)
|
web.router.GET("/watch/view/:id", web.watchView)
|
||||||
web.router.GET("/watch/edit/:id", web.watchEdit)
|
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/create", web.watchCreatePost)
|
||||||
web.router.POST("/watch/update", web.watchUpdate)
|
web.router.POST("/watch/update", web.watchUpdate)
|
||||||
web.router.POST("/watch/delete", web.deleteWatch)
|
web.router.POST("/watch/delete", web.deleteWatch)
|
||||||
|
@ -84,7 +83,6 @@ func (web *Web) initRouter() {
|
||||||
func (web *Web) initTemplates() {
|
func (web *Web) initTemplates() {
|
||||||
web.templates = multitemplate.NewRenderer()
|
web.templates = multitemplate.NewRenderer()
|
||||||
web.templates.AddFromFiles("index", "templates/base.html", "templates/index.html")
|
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("watchView", "templates/base.html", "templates/watch/view.html")
|
||||||
web.templates.AddFromFiles("watchEdit", "templates/base.html", "templates/watch/edit.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)
|
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) {
|
func (web *Web) watchCreatePost(c *gin.Context) {
|
||||||
var watch Watch
|
var watch Watch
|
||||||
errMap, err := bindAndValidateWatch(&watch, c)
|
errMap, err := bindAndValidateWatch(&watch, c)
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
type Watch struct {
|
type Watch struct {
|
||||||
ID uint `form:"watch_id" yaml:"watch_id"`
|
ID uint `form:"watch_id" yaml:"watch_id"`
|
||||||
Name string `form:"watch_name" yaml:"watch_name" binding:"required" validate:"min=1"`
|
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"`
|
CronEntry *cron.Entry `gorm:"-:all"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
@ -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);
|
|
@ -24,7 +24,7 @@
|
||||||
<a class="nav-link active" aria-current="page" href="/">Home</a>
|
<a class="nav-link active" aria-current="page" href="/">Home</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="/watch/new">New</a>
|
<a class="nav-link" aria-current="page" id="newWatchLink" href="#">New</a>
|
||||||
</li>
|
</li>
|
||||||
{{ template "navbar" .}}
|
{{ template "navbar" .}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
{{define "content"}}
|
|
||||||
<form action="/watch/create" method="post">
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="name" class="form-label">Watch Name</label>
|
|
||||||
<input name="watch_name" type="text" class="form-control" id="name" placeholder="Watch">
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="interval" class="form-label">Interval (seconds) - TODO </label>
|
|
||||||
<input type="number" name="interval" class="form-control" id="interval" value="60">
|
|
||||||
</div>
|
|
||||||
<input type="submit" class="btn btn-primary mb-3" value="Create">
|
|
||||||
</form>
|
|
||||||
{{end}}
|
|
2
todo.md
2
todo.md
|
@ -1,6 +1,4 @@
|
||||||
# Todo
|
# Todo
|
||||||
- remove interval input from new watch page
|
|
||||||
- maybe turn new watch into popup with textbox ?
|
|
||||||
- make generic 'notifier' interface
|
- make generic 'notifier' interface
|
||||||
- telegram
|
- telegram
|
||||||
- discord
|
- discord
|
||||||
|
|
Loading…
Add table
Reference in a new issue