diff --git a/web/html/feed.html b/web/html/feed.html
index e7580d6..1aa62ce 100644
--- a/web/html/feed.html
+++ b/web/html/feed.html
@@ -14,7 +14,11 @@
{{ end }}
-
+
{{ else }}
diff --git a/web/html/html.go b/web/html/html.go
index 1b1b3e5..c4fda1d 100644
--- a/web/html/html.go
+++ b/web/html/html.go
@@ -2,8 +2,10 @@ package html
import (
"embed"
+ "encoding/json"
"html/template"
"io"
+ "log"
"time"
"github.com/Jaculabilis/intake/core"
@@ -18,9 +20,25 @@ func tsToDate(t int) string {
return tm.Format(time.DateTime)
}
+func massDeactivateVals(items []core.Item) string {
+ var shorts []string
+ for _, item := range items {
+ shorts = append(shorts, core.FormatAsShort(item))
+ }
+ massDeac := struct {
+ Items []string `json:"items"`
+ }{shorts}
+ vals, err := json.Marshal(massDeac)
+ if err != nil {
+ log.Printf("error serializing mass deactivate list: %v", err)
+ }
+ return string(vals)
+}
+
var funcs = template.FuncMap{
- "raw": rawHtml,
- "tsToDate": tsToDate,
+ "raw": rawHtml,
+ "tsToDate": tsToDate,
+ "massDeacVars": massDeactivateVals,
}
//go:embed intake.css
diff --git a/web/item.go b/web/item.go
index 4a2ad34..c7347fc 100644
--- a/web/item.go
+++ b/web/item.go
@@ -2,7 +2,9 @@ package web
import (
"encoding/json"
+ "log"
"net/http"
+ "strings"
"time"
"github.com/Jaculabilis/intake/core"
@@ -85,3 +87,33 @@ func (env *Env) doAction(writer http.ResponseWriter, req *http.Request) {
html.Item(writer, html.ItemData{Item: newItem})
}
+
+func (env *Env) massDeactivate(writer http.ResponseWriter, req *http.Request) {
+ if err := req.ParseForm(); err != nil {
+ log.Printf("error parsing form data: %v", err)
+ http.Error(writer, "", http.StatusBadRequest)
+ return
+ }
+ for _, item := range req.PostForm["items"] {
+ i := strings.Index(item, "/")
+ if i == -1 {
+ log.Printf("error: invalid source/item: %s", item)
+ http.Error(writer, "", http.StatusBadRequest)
+ return
+ }
+ }
+ for _, item := range req.PostForm["items"] {
+ i := strings.Index(item, "/")
+ source := item[:i]
+ id := item[i+1:]
+ active, err := core.DeactivateItem(env.db, source, id)
+ if err != nil {
+ log.Printf("error: failed to deactivate %s/%s: %v", source, id, err)
+ }
+ if active {
+ log.Printf("deactivated %s/%s", source, id)
+ }
+ }
+ writer.Header()["HX-Refresh"] = []string{"true"}
+ http.Error(writer, "ok", http.StatusNoContent)
+}
diff --git a/web/main.go b/web/main.go
index cb978f6..cf5cd2f 100644
--- a/web/main.go
+++ b/web/main.go
@@ -34,6 +34,7 @@ func RunServer(db *core.DB, addr string, port string) {
handleFunc("GET /item/{source}/{id}", env.getItem)
handleFunc("DELETE /item/{source}/{id}", env.deleteItem)
handleFunc("POST /item/{source}/{id}/action/{action}", env.doAction)
+ handleFunc("POST /mass-deactivate", env.massDeactivate)
log.Fatal(http.ListenAndServe(bind, nil))
}