Add notification index page

This commit is contained in:
Hugo Peixoto 2022-10-06 15:50:38 +01:00
parent e0f76c7aba
commit abaf80e5c4
5 changed files with 76 additions and 10 deletions

View File

@ -1,6 +1,12 @@
class NotificationsController < ApplicationController
before_action :require_login
before_action :set_notification
before_action :set_notification, only: [:deliver]
# GET /notifications
def index
@scheduled = Notification.where(status: 'scheduled').order(to_be_sent_on: :asc)
@sent = Notification.where(status: 'sent').order(sent_at: :desc)
end
# POST /notifications/1/deliver
def deliver

View File

@ -16,6 +16,7 @@
<ul>
<li><%= link_to t('navigation.members'), members_path %></li>
<li><%= link_to t('navigation.board'), edit_board_path %></li>
<li><%= link_to t('navigation.notifications'), notifications_path %></li>
<li>
<%= button_to sign_out_path, method: :delete do %>
Sign out of <%= current_user.email %>

View File

@ -0,0 +1,53 @@
<h1><%= t('notifications.index.title') %></h1>
<details>
<summary><h2 style="display: inline"><%= t('notifications.index.scheduled') %></h2></summary>
<table class='zebra'>
<tr>
<th><%= t('notifications.attributes.to_be_sent_on') %></th>
<th><%= t('notifications.attributes.template') %></th>
<th><%= t('notifications.attributes.member') %></th>
<th><%= t('members.show.contribution_actions') %></th>
</tr>
<% @scheduled.each do |notification| %>
<tr>
<td><%= notification.to_be_sent_on %></td>
<td><code><%= notification.template %></code></td>
<td><%= link_to notification.member do %><%= notification.member.display_name %> &lt;<%= notification.member.email %>&gt;<% end %></td>
<td>
<% if notification.status == 'scheduled' %>
<%= form_with url: deliver_notification_path(notification) do |form| %>
<%= form.submit t('members.show.actions.deliver_notification') %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</table>
</details>
<details>
<summary><h2 style="display: inline"><%= t('notifications.index.sent') %></h2></summary>
<table class='zebra'>
<tr>
<th><%= t('notifications.attributes.to_be_sent_on') %></th>
<th><%= t('notifications.attributes.template') %></th>
<th><%= t('notifications.attributes.status') %></th>
<th><%= t('members.show.contribution_actions') %></th>
</tr>
<% @sent.each do |notification| %>
<tr>
<td><%= notification.to_be_sent_on %></td>
<td><code><%= notification.template %></code></td>
<td><%= notification_status(notification.status) %></td>
<td>
<% if notification.status == 'scheduled' %>
<%= form_with url: deliver_notification_path(notification) do |form| %>
<%= form.submit t('members.show.actions.deliver_notification') %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</table>
</details>

View File

@ -4,6 +4,8 @@ pt:
negative: "Não"
navigation:
members: "Lista de membros"
board: "Direcção"
notifications: "Notificações"
members:
delete:
confirmation_message: |
@ -68,14 +70,6 @@ pt:
unemployed: "Desempregado"
student: "Estudante"
retired: "Reformado"
notifications:
attributes:
to_be_sent_on: Data de envio
template: Modelo
status: Estado
status:
sent: Enviada
scheduled: Agendada
contributions:
attributes:
amount: Montante
@ -121,3 +115,15 @@ pt:
warning: |
Atenção: qualquer endereço que ficar omisso verá a sua conta suspensa e
deixará de poder aceder a este sistema.
notifications:
index:
title: "Notificações"
scheduled: "Agendadas"
sent: "Enviadas"
attributes:
to_be_sent_on: Data de envio
template: Modelo
status: Estado
status:
sent: Enviada
scheduled: Agendada

View File

@ -19,7 +19,7 @@ Rails.application.routes.draw do
end
end
resources :notifications, only: [] do
resources :notifications, only: [:index] do
member do
post :deliver
end