Add Preview Pending action to Admin System Emails

Some system emails need to be manually reviewed before being sent. This
new action allows admins to see a preview of all Pending to be sent
Proposal Notification Digest messages.
This commit is contained in:
Bertocq
2018-04-18 16:12:38 +02:00
committed by decabeza
parent 5c726e0949
commit eb0919d978
8 changed files with 123 additions and 10 deletions

View File

@@ -1,9 +1,11 @@
class Admin::SystemEmailsController < Admin::BaseController
before_action :load_system_email, only: [:view]
before_action :load_system_email, only: [:view, :preview_pending]
def index
@system_emails = %w(proposal_notification_digest)
@system_emails = {
proposal_notification_digest: %w(view preview_pending)
}
end
def view
@@ -14,9 +16,22 @@ class Admin::SystemEmailsController < Admin::BaseController
end
end
def preview_pending
case @system_email
when "proposal_notification_digest"
@previews = ProposalNotification.where(id: unsent_proposal_notifications_ids)
.page(params[:page])
end
end
private
def load_system_email
@system_email = params[:system_email_id]
end
def unsent_proposal_notifications_ids
Notification.where(notifiable_type: "ProposalNotification", emailed_at: nil)
.group(:notifiable_id).count.keys
end
end

View File

@@ -9,17 +9,24 @@
</tr>
</thead>
<tbody>
<% @system_emails.each do |system_email| %>
<tr id="<%= system_email %>" class="system_email">
<% @system_emails.each do |system_email_title, system_email_actions| %>
<tr id="<%= system_email_title %>" class="system_email">
<td>
<%= t("admin.system_emails.#{system_email}.title") %>
<%= t("admin.system_emails.#{system_email_title}.title") %>
</td>
<td>
<%= t("admin.system_emails.#{system_email}.description") %>
<%= t("admin.system_emails.#{system_email_title}.description") %>
</td>
<td class="text-right">
<%= link_to t("admin.shared.view"), admin_system_email_view_path(system_email),
class: "button hollow" %>
<% if system_email_actions.include?('view') %>
<%= link_to t("admin.shared.view"), admin_system_email_view_path(system_email_title),
class: "button hollow" %>
<% end %>
<% if system_email_actions.include?('preview_pending') %>
<%= link_to t("admin.system_emails.preview_pending.action"),
admin_system_email_preview_pending_path(system_email_title),
class: "button" %>
<% end %>
</td>
</tr>
<% end %>

View File

@@ -0,0 +1,16 @@
<%= back_link_to admin_system_emails_path %>
<% system_email_name = t("admin.system_emails.#{@system_email}.title") %>
<h2><%= t("admin.system_emails.preview_pending.preview_of", name: system_email_name) %></h2>
<div class="small-12 column">
<h4><%= t("admin.system_emails.preview_pending.pending_to_be_sent") %></h4>
<p><%= t("admin.system_emails.#{@system_email}.preview_detail") %></p>
<% @previews.each do |preview| %>
<%= render partial: "admin/system_emails/preview_pending/#{@system_email}",
locals: { preview: preview } %>
<% end %>
</div>
<%= paginate @previews %>

View File

@@ -0,0 +1,33 @@
<% if preview.proposal.present? %>
<div class="callout highlight">
<div class="row">
<div class="small-12 medium-6 column">
<strong><%= t("admin.shared.proposal") %></strong><br>
<%= link_to preview.proposal.title, proposal_url(preview.proposal) %>
</div>
<div class="small-12 medium-6 column">
<strong><%= t("admin.shared.title") %></strong><br>
<%= link_to preview.title, proposal_url(preview.proposal, anchor: "tab-notifications") %>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 column">
<strong><%= t("admin.shared.author") %></strong><br>
<%= preview.proposal.author&.username || '-' %>
</div>
<div class="small-12 medium-6 column">
<strong><%= t("admin.shared.created_at") %></strong><br>
<%= l(preview.created_at, format: :datetime) %>
</div>
</div>
</div>
<div class="row">
<div class="column">
<strong><%= t("admin.shared.content") %></strong>
<p class="help-text" id="phase-description-help-text">
<%= preview.body %>
</p>
</div>
</div>
<% end %>