mirror of https://github.com/jlelse/GoBlog
Allow to delete notifications
This commit is contained in:
parent
1b2eed9897
commit
1898536bf1
1
http.go
1
http.go
|
@ -212,6 +212,7 @@ func buildStaticHandlersRouters() error {
|
||||||
notificationsRouter.Use(authMiddleware)
|
notificationsRouter.Use(authMiddleware)
|
||||||
notificationsRouter.Get("/", notificationsAdmin)
|
notificationsRouter.Get("/", notificationsAdmin)
|
||||||
notificationsRouter.Get(paginationPath, notificationsAdmin)
|
notificationsRouter.Get(paginationPath, notificationsAdmin)
|
||||||
|
notificationsRouter.Post("/delete", notificationsAdminDelete)
|
||||||
|
|
||||||
if ap := appConfig.ActivityPub; ap != nil && ap.Enabled {
|
if ap := appConfig.ActivityPub; ap != nil && ap.Enabled {
|
||||||
activitypubRouter = chi.NewRouter()
|
activitypubRouter = chi.NewRouter()
|
||||||
|
|
|
@ -46,6 +46,11 @@ func saveNotification(n *notification) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteNotification(id int) error {
|
||||||
|
_, err := appDbExec("delete from notifications where id = @id", sql.Named("id", id))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type notificationsRequestConfig struct {
|
type notificationsRequestConfig struct {
|
||||||
offset, limit int
|
offset, limit int
|
||||||
}
|
}
|
||||||
|
@ -157,3 +162,17 @@ func notificationsAdmin(w http.ResponseWriter, r *http.Request) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func notificationsAdminDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id, err := strconv.Atoi(r.FormValue("notificationid"))
|
||||||
|
if err != nil {
|
||||||
|
serveError(w, r, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = deleteNotification(id)
|
||||||
|
if err != nil {
|
||||||
|
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Redirect(w, r, ".", http.StatusFound)
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,18 @@ func initTemplateStrings() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTemplateStringVariant(lang, name string) (result string) {
|
func getTemplateStringVariant(input ...string) (result string) {
|
||||||
|
var lang, name string
|
||||||
|
if l := len(input); l == 1 {
|
||||||
|
lang = appConfig.Blogs[appConfig.DefaultBlog].Lang
|
||||||
|
name = input[0]
|
||||||
|
} else if l == 2 {
|
||||||
|
lang = input[0]
|
||||||
|
name = input[1]
|
||||||
|
} else {
|
||||||
|
// Wrong number of input strings
|
||||||
|
return ""
|
||||||
|
}
|
||||||
m, ok := templateStrings[lang]
|
m, ok := templateStrings[lang]
|
||||||
if !ok {
|
if !ok {
|
||||||
m = templateStrings[defaultStrings]
|
m = templateStrings[defaultStrings]
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
{{ define "title" }}
|
{{ define "title" }}
|
||||||
<title>{{ string .Blog.Lang "notifications" }} - {{ .Blog.Title }}</title>
|
<title>{{ string "notifications" }} - {{ .Blog.Title }}</title>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "main" }}
|
{{ define "main" }}
|
||||||
<main>
|
<main>
|
||||||
<h1>{{ string .Blog.Lang "notifications" }}</h1>
|
<h1>{{ string "notifications" }}</h1>
|
||||||
{{ range $i, $notification := .Data.Notifications }}
|
{{ range $i, $notification := .Data.Notifications }}
|
||||||
<p>
|
<div class="p">
|
||||||
ID: {{ $notification.ID }}<br/>
|
<p><i>{{ unixtodate $notification.Time }}</i></p>
|
||||||
Time: {{ unixtodate $notification.Time }}<br/>
|
{{ md $notification.Text }}
|
||||||
Text: {{ $notification.Text }}
|
<form method="post">
|
||||||
</p>
|
<input type="hidden" name="notificationid" value="{{ $notification.ID }}">
|
||||||
|
<input type="submit" formaction="/notifications/delete" value="{{ string "delete" }}">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .Data.HasPrev }}
|
{{ if .Data.HasPrev }}
|
||||||
<p><a href="{{ .Data.Prev }}">{{ string .Blog.Lang "prev" }}</a></p>
|
<p><a href="{{ .Data.Prev }}">{{ string "prev" }}</a></p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .Data.HasNext }}
|
{{ if .Data.HasNext }}
|
||||||
<p><a href="{{ .Data.Next }}">{{ string .Blog.Lang "next" }}</a></p>
|
<p><a href="{{ .Data.Next }}">{{ string "next" }}</a></p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in New Issue