mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Merge pull request #548 from tabacha/2024-12-15-delete-notifications-on-gui
Feature: Add a "Delete Notifications" button
This commit is contained in:
commit
41ac715fc5
3 changed files with 11 additions and 2 deletions
|
|
@ -15,10 +15,15 @@ class NotificationsController < ApplicationController
|
|||
|
||||
def mark_as_read
|
||||
current_user.notifications.unread.update_all(read_at: Time.zone.now)
|
||||
|
||||
redirect_to notifications_url, notice: 'All notifications marked as read.', status: :see_other
|
||||
end
|
||||
|
||||
|
||||
def destroy_all
|
||||
current_user.notifications.destroy_all
|
||||
redirect_to notifications_url, notice: 'All notifications where successfully destroyed.', status: :see_other
|
||||
end
|
||||
|
||||
def destroy
|
||||
@notification.destroy!
|
||||
redirect_to notifications_url, notice: 'Notification was successfully destroyed.', status: :see_other
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@
|
|||
<h1 class="font-bold text-4xl mb-4">Notifications</h1>
|
||||
<div class="flex items-center justify-center mb-4">
|
||||
<% if @notifications.unread.any? %>
|
||||
<%= link_to "Mark all as read", mark_notifications_as_read_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-primary" %>
|
||||
<%= link_to "Mark all as read", mark_notifications_as_read_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-primary" %>
|
||||
<% end %>
|
||||
<% if @notifications.any? %>
|
||||
<%= link_to "Delete all", delete_all_notifications_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-warning" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
resources :notifications, only: %i[index show destroy]
|
||||
post 'notifications/mark_as_read', to: 'notifications#mark_as_read', as: :mark_notifications_as_read
|
||||
post 'notifications/destroy_all', to: 'notifications#destroy_all', as: :delete_all_notifications
|
||||
resources :stats, only: :index do
|
||||
collection do
|
||||
post :update
|
||||
|
|
|
|||
Loading…
Reference in a new issue