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 class NotificationsController < ApplicationController
before_action :require_login 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 # POST /notifications/1/deliver
def deliver def deliver

View File

@ -16,6 +16,7 @@
<ul> <ul>
<li><%= link_to t('navigation.members'), members_path %></li> <li><%= link_to t('navigation.members'), members_path %></li>
<li><%= link_to t('navigation.board'), edit_board_path %></li> <li><%= link_to t('navigation.board'), edit_board_path %></li>
<li><%= link_to t('navigation.notifications'), notifications_path %></li>
<li> <li>
<%= button_to sign_out_path, method: :delete do %> <%= button_to sign_out_path, method: :delete do %>
Sign out of <%= current_user.email %> 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" negative: "Não"
navigation: navigation:
members: "Lista de membros" members: "Lista de membros"
board: "Direcção"
notifications: "Notificações"
members: members:
delete: delete:
confirmation_message: | confirmation_message: |
@ -68,14 +70,6 @@ pt:
unemployed: "Desempregado" unemployed: "Desempregado"
student: "Estudante" student: "Estudante"
retired: "Reformado" retired: "Reformado"
notifications:
attributes:
to_be_sent_on: Data de envio
template: Modelo
status: Estado
status:
sent: Enviada
scheduled: Agendada
contributions: contributions:
attributes: attributes:
amount: Montante amount: Montante
@ -121,3 +115,15 @@ pt:
warning: | warning: |
Atenção: qualquer endereço que ficar omisso verá a sua conta suspensa e Atenção: qualquer endereço que ficar omisso verá a sua conta suspensa e
deixará de poder aceder a este sistema. 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
end end
resources :notifications, only: [] do resources :notifications, only: [:index] do
member do member do
post :deliver post :deliver
end end