diff --git a/main.go b/main.go index f41a638..79f2950 100644 --- a/main.go +++ b/main.go @@ -535,9 +535,8 @@ func (web *Web) cacheView(c *gin.Context) { } func (web *Web) cacheClear(c *gin.Context) { - url := c.PostForm("url") - delete(web.urlCache, url) - c.Redirect(http.StatusSeeOther, "/cache/view") + web.urlCache = make(map[string]string, 5) + c.JSON(http.StatusOK, gin.H{"status": "ok"}) } func (web *Web) exportWatch(c *gin.Context) { diff --git a/static/script.js b/static/script.js index e69de29..b8cdedf 100644 --- a/static/script.js +++ b/static/script.js @@ -0,0 +1,22 @@ +function clearCache() { + var confirmed = confirm("Do you want to clear the URL cache?"); + if (!confirmed) { + return; // do nothing + } + var data = new URLSearchParams(); + fetch("/cache/clear", { + method: "POST" + }).then(function (response) { + if (response.ok) { + window.location.reload(); + } + else { + alert("Could not clear cache"); + } + }); +} +function clearCacheButtonInit() { + var clearCacheButton = document.getElementById("clearCacheButton"); + clearCacheButton.onclick = clearCache; +} +document.addEventListener('DOMContentLoaded', clearCacheButtonInit, false); diff --git a/static/script.ts b/static/script.ts index e69de29..a5c16ff 100644 --- a/static/script.ts +++ b/static/script.ts @@ -0,0 +1,21 @@ +function clearCache(){ + let confirmed = confirm("Do you want to clear the URL cache?"); + if (!confirmed){ + return // do nothing + } + let data = new URLSearchParams(); + fetch("/cache/clear", { + method: "POST" + }).then((response) => { + if(response.ok){ + window.location.reload() + } else { + alert("Could not clear cache"); + } + }); +} +function clearCacheButtonInit(){ + let clearCacheButton = document.getElementById("clearCacheButton") as HTMLElement; + clearCacheButton.onclick = clearCache; +} +document.addEventListener('DOMContentLoaded', clearCacheButtonInit, false); \ No newline at end of file diff --git a/templates/watch/edit.html b/templates/watch/edit.html index a131fbf..ec38a85 100644 --- a/templates/watch/edit.html +++ b/templates/watch/edit.html @@ -43,6 +43,11 @@ GoWatch Edit {{ .Watch.Name }} Import Watch + + + View Watch @@ -226,6 +231,5 @@ function canvasInit() { document.addEventListener('DOMContentLoaded', canvasInit, false); var notifiers = {{ .Notifiers }}; - {{ end }} \ No newline at end of file diff --git a/todo.md b/todo.md index 66a818b..f5ea8c7 100644 --- a/todo.md +++ b/todo.md @@ -14,5 +14,4 @@ - walmart - etsy - aliexpress.com -- clear cache button on edit page - add apprise/Shoutrrr ? \ No newline at end of file