mirror of https://github.com/jlelse/GoBlog
Add button to delete all notifications
This commit is contained in:
parent
fae5614838
commit
a576e364bd
|
@ -52,6 +52,11 @@ func (db *database) deleteNotification(id int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *database) deleteAllNotifications() error {
|
||||||
|
_, err := db.exec("delete from notifications")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type notificationsRequestConfig struct {
|
type notificationsRequestConfig struct {
|
||||||
offset, limit int
|
offset, limit int
|
||||||
}
|
}
|
||||||
|
@ -165,15 +170,25 @@ func (a *goBlog) notificationsAdmin(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *goBlog) notificationsAdminDelete(w http.ResponseWriter, r *http.Request) {
|
func (a *goBlog) notificationsAdminDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.Atoi(r.FormValue("notificationid"))
|
if idString := r.FormValue("notificationid"); idString != "" {
|
||||||
if err != nil {
|
// Delete single notification with id
|
||||||
a.serveError(w, r, err.Error(), http.StatusBadRequest)
|
id, err := strconv.Atoi(idString)
|
||||||
return
|
if err != nil {
|
||||||
}
|
a.serveError(w, r, err.Error(), http.StatusBadRequest)
|
||||||
err = a.db.deleteNotification(id)
|
return
|
||||||
if err != nil {
|
}
|
||||||
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
|
err = a.db.deleteNotification(id)
|
||||||
return
|
if err != nil {
|
||||||
|
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Delete all notifications
|
||||||
|
err := a.db.deleteAllNotifications()
|
||||||
|
if err != nil {
|
||||||
|
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, ".", http.StatusFound)
|
http.Redirect(w, r, ".", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ contactagreesend: "Akzeptieren & Senden"
|
||||||
contactsend: "Senden"
|
contactsend: "Senden"
|
||||||
create: "Erstellen"
|
create: "Erstellen"
|
||||||
delete: "Löschen"
|
delete: "Löschen"
|
||||||
|
deleteall: "Alle löschen"
|
||||||
deletedposts: "Gelöschte Posts"
|
deletedposts: "Gelöschte Posts"
|
||||||
deletedpostsdesc: "Gelöschte Posts, die nach 7 Tagen endgültig gelöscht werden."
|
deletedpostsdesc: "Gelöschte Posts, die nach 7 Tagen endgültig gelöscht werden."
|
||||||
docomment: "Kommentieren"
|
docomment: "Kommentieren"
|
||||||
|
|
|
@ -13,6 +13,7 @@ contactagreesend: "Accept & Send"
|
||||||
contactsend: "Send"
|
contactsend: "Send"
|
||||||
create: "Create"
|
create: "Create"
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
|
deleteall: "Delete all"
|
||||||
deletedposts: "Deleted posts"
|
deletedposts: "Deleted posts"
|
||||||
deletedpostsdesc: "Deleted posts that will be permanently deleted after 7 days."
|
deletedpostsdesc: "Deleted posts that will be permanently deleted after 7 days."
|
||||||
docomment: "Comment"
|
docomment: "Comment"
|
||||||
|
|
4
ui.go
4
ui.go
|
@ -1148,6 +1148,10 @@ func (a *goBlog) renderNotificationsAdmin(hb *htmlBuilder, rd *renderData) {
|
||||||
hb.writeElementOpen("h1")
|
hb.writeElementOpen("h1")
|
||||||
hb.writeEscaped(a.ts.GetTemplateStringVariant(rd.Blog.Lang, "notifications"))
|
hb.writeEscaped(a.ts.GetTemplateStringVariant(rd.Blog.Lang, "notifications"))
|
||||||
hb.writeElementClose("h1")
|
hb.writeElementClose("h1")
|
||||||
|
// Delete all form
|
||||||
|
hb.writeElementOpen("form", "class", "actions", "method", "post", "action", "/notifications/delete")
|
||||||
|
hb.writeElementOpen("input", "type", "submit", "value", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "deleteall"))
|
||||||
|
hb.writeElementClose("form")
|
||||||
// Notifications
|
// Notifications
|
||||||
tdLocale := matchTimeDiffLocale(rd.Blog.Lang)
|
tdLocale := matchTimeDiffLocale(rd.Blog.Lang)
|
||||||
for _, n := range nrd.notifications {
|
for _, n := range nrd.notifications {
|
||||||
|
|
Loading…
Reference in New Issue