Feat: Add clear notification feature
This commit is contained in:
parent
aaa2428f6c
commit
d84eeaae9c
|
|
@ -74,11 +74,19 @@
|
|||
<XButton
|
||||
v-if="notifications.length > 0 && unreadNotifications > 0"
|
||||
variant="tertiary"
|
||||
class="mbs-2 is-fullwidth"
|
||||
class="mbs-2 is-fullwidth"
|
||||
@click="markAllRead"
|
||||
>
|
||||
{{ $t('notification.markAllRead') }}
|
||||
</XButton>
|
||||
<XButton
|
||||
v-if="notifications.length > 0"
|
||||
variant="tertiary"
|
||||
class="mbs-2 is-fullwidth"
|
||||
@click="clearAll"
|
||||
>
|
||||
{{ $t('notification.clearAll') }}
|
||||
</XButton>
|
||||
<p
|
||||
v-if="notifications.length === 0"
|
||||
class="nothing"
|
||||
|
|
@ -246,9 +254,16 @@ async function markAllRead() {
|
|||
const notificationService = new NotificationService()
|
||||
await notificationService.markAllRead()
|
||||
success({message: t('notification.markAllReadSuccess')})
|
||||
|
||||
|
||||
notifications.value.forEach(n => n.readAt = new Date())
|
||||
}
|
||||
|
||||
async function clearAll() {
|
||||
const notificationService = new NotificationService()
|
||||
await notificationService.clearAll()
|
||||
success({message: t('notification.clearAllSuccess')})
|
||||
allNotifications.value = []
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
|
|
@ -1339,7 +1339,9 @@
|
|||
"explainer": "Notifications will appear here when actions, projects or tasks you subscribed to happen.",
|
||||
"markAllRead": "Mark all notifications as read",
|
||||
"markAllReadSuccess": "Successfully marked all notifications as read.",
|
||||
"subscribeFeed": "Subscribe to notifications via Atom feed"
|
||||
"subscribeFeed": "Subscribe to notifications via Atom feed",
|
||||
"clearAll": "Clear notifications",
|
||||
"clearAllSuccess": "All notifications have been cleared."
|
||||
},
|
||||
"quickActions": {
|
||||
"notLoggedIn": "Please log in to the main Vikunja window first.",
|
||||
|
|
|
|||
|
|
@ -29,4 +29,9 @@ export default class NotificationService extends AbstractService<INotification>
|
|||
async markAllRead() {
|
||||
return this.post('/notifications', false)
|
||||
}
|
||||
|
||||
async clearAll() {
|
||||
const {data} = await this.http.delete('/notifications')
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,3 +133,10 @@ func MarkAllNotificationsAsRead(s *xorm.Session, userID int64) (err error) {
|
|||
Update(&DatabaseNotification{ReadAt: time.Now()})
|
||||
return
|
||||
}
|
||||
|
||||
func DeleteAllNotificationsForUser(s *xorm.Session, userID int64) error {
|
||||
_, err := s.
|
||||
Where("notifiable_id = ?", userID).
|
||||
Delete(&DatabaseNotification{})
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,40 @@ import (
|
|||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
// DeleteAllNotifications deletes all notifications for the current user
|
||||
// @Summary Delete all notifications of the current user
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} models.Message "All notifications deleted."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /notifications [delete]
|
||||
func DeleteAllNotifications(c *echo.Context) error {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
a, err := auth.GetAuthFromClaims(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, is := a.(*models.LinkSharing); is {
|
||||
return echo.ErrForbidden
|
||||
}
|
||||
|
||||
err = notifications.DeleteAllNotificationsForUser(s, a.GetID())
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, models.Message{Message: "success"})
|
||||
}
|
||||
|
||||
// MarkAllNotificationsAsRead marks all notifications of a user as read
|
||||
// @Summary Mark all notifications of a user as read
|
||||
// @tags sharing
|
||||
|
|
|
|||
|
|
@ -850,6 +850,7 @@ func registerAPIRoutes(a *echo.Group) {
|
|||
a.GET("/notifications", notificationHandler.ReadAllWeb)
|
||||
a.POST("/notifications/:notificationid", notificationHandler.UpdateWeb)
|
||||
a.POST("/notifications", apiv1.MarkAllNotificationsAsRead)
|
||||
a.DELETE("/notifications", apiv1.DeleteAllNotifications)
|
||||
|
||||
// Migrations
|
||||
m := a.Group("/migration")
|
||||
|
|
|
|||
Loading…
Reference in New Issue