Extraction de partiels et activiation des turbo-frames sur la liste

This commit is contained in:
Jérémy Lecour 2021-01-31 12:34:01 +01:00 committed by Jérémy Lecour
parent e0912ee7af
commit ef83920479
6 changed files with 136 additions and 128 deletions

View file

@ -18,6 +18,7 @@ class Email < ApplicationRecord
validates :from, presence: true
validates :headers, presence: true
paginates_per 10
def postponed?
postponed_until.present? && postponed_until > DateTime.now

View file

@ -0,0 +1,81 @@
<div id="<%= dom_id email %>" class="email_container">
<table class="email_content">
<thead class="email_main_headers">
<tr>
<th>Date</th>
<td><%= email.date %></td>
</tr>
<tr>
<th>From</th>
<td><%= email.from.join(', ') %></td>
</tr>
<tr>
<th>To</th>
<td><%= email.to.join(', ') %></td>
</tr>
<tr>
<th>Delivered-To</th>
<td><%= email.delivered_to.join(', ') %></td>
</tr>
<tr>
<th>Subject</th>
<td><%= email.subject %></td>
</tr>
<% if email.organisations.present? %>
<tr>
<th>Clients</th>
<td>
<% email.organisations.presence.each do |organisation| %>
<span class="email_attribute_organisation"><%= organisation %></span>
<% end %>
</td>
</tr>
<% end %>
<% if email.servers.present? %>
<tr>
<th>Servers</th>
<td>
<% email.servers.presence.each do |server| %>
<span class="email_attribute_server"><%= server %></span>
<% end %>
</td>
</tr>
<% end %>
<% if email.issues.present? %>
<tr>
<th>Issues</th>
<td>
<% email.issues.presence.each do |issue| %>
<span class="email_attribute_issue"><%= issue %></span>
<% end %>
</td>
</tr>
<% end %>
<tr>
<th>From Cron</th>
<td>
<span class="<%= email.cron? ? "email_attribute_cron" : "" %>"><%= email.cron? ? "Yes" : "No" %></span>
</td>
</tr>
</thead>
<thead class="email_additional_headers">
<% email.headers.each do |header| %>
<tr>
<th><%= header["name"] %></th>
<td><%= header["value"] %><td>
</tr>
<% end %>
</thead>
<tbody>
<tr>
<td colspan="2">
<% if email.plain_body.present? %>
<pre><%= email.plain_body %></pre>
<% else %>
<i>Empty body</i>
<% end %>
</td>
</tr>
</tbody>
</table>
</div>

View file

@ -0,0 +1,41 @@
<table>
<thead>
<tr>
<th>Date</th>
<th>Subject</th>
<th>Metadata</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @emails.each do |email| %>
<tr>
<td><%= email.date %></td>
<td><%= email.subject %></td>
<td>
<% email.organisations.each do |organisation| %>
<span class="email_attribute_organisation"><%= organisation %></span>
<% end if email.organisations %>
<% email.servers.each do |server| %>
<span class="email_attribute_server"><%= server %></span>
<% end if email.servers %>
<% if email.cron? %>
<span class="email_attribute_cron">cron</span>
<% end %>
<% if email.mailing_list? %>
<span class="email_attribute_mailing_list">list</span>
<% end %>
<% if email.junk? %>
<span class="email_attribute_junk">junk</span>
<% end %>
</td>
<td><%= link_to 'Show', email, "data-turbo-frame": "_top" %></td>
<td><%= link_to 'Edit', edit_email_path(email), "data-turbo-frame": "_top" %></td>
<td><%= link_to 'Destroy', email, method: :delete, data: { confirm: 'Are you sure?' }, "data-turbo-frame": "_top" %></td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @emails %>

View file

@ -2,48 +2,6 @@
<h1>Emails</h1>
<table>
<thead>
<tr>
<th>Date</th>
<th>Subject</th>
<th>Metadata</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @emails.each do |email| %>
<tr>
<td><%= email.date %></td>
<td><%= email.subject %></td>
<td>
<% email.organisations.each do |organisation| %>
<span class="email_attribute_organisation"><%= organisation %></span>
<% end if email.organisations %>
<% email.servers.each do |server| %>
<span class="email_attribute_server"><%= server %></span>
<% end if email.servers %>
<% if email.cron? %>
<span class="email_attribute_cron">cron</span>
<% end %>
<% if email.mailing_list? %>
<span class="email_attribute_mailing_list">list</span>
<% end %>
<% if email.junk? %>
<span class="email_attribute_junk">junk</span>
<% end %>
</td>
<td><%= link_to 'Show', email %></td>
<td><%= link_to 'Edit', edit_email_path(email) %></td>
<td><%= link_to 'Destroy', email, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @emails %>
<br>
<%= link_to 'New Email', new_email_path %>
<%= turbo_frame_tag "emails" do %>
<%= render partial: "list", object: @emails %>
<% end %>

View file

@ -1,86 +1,12 @@
<p id="notice"><%= notice %></p>
<div class="email_container">
<table class="email_content">
<thead class="email_main_headers">
<tr>
<th>Date</th>
<td><%= @email.date %></td>
</tr>
<tr>
<th>From</th>
<td><%= @email.from.join(', ') %></td>
</tr>
<tr>
<th>To</th>
<td><%= @email.to.join(', ') %></td>
</tr>
<tr>
<th>Delivered-To</th>
<td><%= @email.delivered_to.join(', ') %></td>
</tr>
<tr>
<th>Subject</th>
<td><%= @email.subject %></td>
</tr>
<% if @email.organisations.present? %>
<tr>
<th>Clients</th>
<td>
<% @email.organisations.presence.each do |organisation| %>
<span class="email_attribute_organisation"><%= organisation %></span>
<% end %>
</td>
</tr>
<% end %>
<% if @email.servers.present? %>
<tr>
<th>Servers</th>
<td>
<% @email.servers.presence.each do |server| %>
<span class="email_attribute_server"><%= server %></span>
<% end %>
</td>
</tr>
<% end %>
<% if @email.issues.present? %>
<tr>
<th>Issues</th>
<td>
<% @email.issues.presence.each do |issue| %>
<span class="email_attribute_issue"><%= issue %></span>
<% end %>
</td>
</tr>
<% end %>
<tr>
<th>From Cron</th>
<td>
<span class="<%= @email.cron? ? "email_attribute_cron" : "" %>"><%= @email.cron? ? "Yes" : "No" %></span>
</td>
</tr>
</thead>
<thead class="email_additional_headers">
<% @email.headers.each do |header| %>
<tr>
<th><%= header["name"] %></th>
<td><%= header["value"] %><td>
</tr>
<% end %>
</thead>
<tbody>
<tr>
<td colspan="2">
<% if @email.plain_body.present? %>
<pre><%= @email.plain_body %></pre>
<% else %>
<i>Empty body</i>
<% end %>
</td>
</tr>
</tbody>
</table>
</div>
<%= turbo_stream_from @email %>
<%= link_to 'Edit', edit_email_path(@email) %> |
<%= link_to 'Back', emails_path %>
<%= turbo_frame_tag "room" do %>
<%= render @email %>
<p>
<%= link_to 'Edit', edit_email_path(@email) %> |
<%= link_to 'Back', emails_path, "data-turbo-frame": "_top" %>
</p>
<% end %>

View file

@ -14,6 +14,7 @@
</head>
<body>
<%= Time.now %>
<%= yield %>
</body>
</html>