Marquage Inbox en masse

This commit is contained in:
Jérémy Lecour 2021-03-21 09:24:32 +01:00 committed by Jérémy Lecour
parent d9ad6d9cfd
commit f4784dbdf6
5 changed files with 83 additions and 37 deletions

View file

@ -16,4 +16,17 @@ class EmailsController < ApplicationController
@email.destroy @email.destroy
redirect_to emails_url, notice: 'Email was successfully destroyed.' redirect_to emails_url, notice: 'Email was successfully destroyed.'
end end
def batch
case params[:batch_action]
when "mark_inbox"
Email.where(id: params[:ids]).update_all(inbox: true)
flash[:notice] = "#{helpers.pluralize(params[:ids].count,"email","emails")} have been marked « inbox »"
when "mark_not_inbox"
Email.where(id: params[:ids]).update_all(inbox: false)
flash[:notice] = "#{helpers.pluralize(params[:ids].count,"email","emails")} have been marked « not inbox »"
end
return_url = params[:return_url].presence || emails_url
redirect_to return_url
end
end end

View file

@ -0,0 +1,14 @@
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "checkboxesGroup", "checkboxesItem" ]
syncCheckedState() {
this.checkboxesItemTargets.forEach((element, index) => {
element.checked = this.groupCheckedState
})
}
get groupCheckedState() {
return this.checkboxesGroupTarget.checked
}
}

View file

@ -1,40 +1,51 @@
<%= form_with url: batch_emails_url, method: :post, data: {"turbo-frame": "_top", controller: "checkboxes"} do |form| %>
<div class="shadow overflow-auto border-b border-gray-200 rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="pl-3 pr-1 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">
<%= check_box_tag "foo", "all", false,
class: "focus:ring-gray-500 h-4 w-4 text-gray-600 border-gray-300 rounded",
data: { action: "input->checkboxes#syncCheckedState", "checkboxes-target": "checkboxesGroup" } %>
</th>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">From</th>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Subject</th>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Metadata</th>
</tr>
</thead>
<div class="shadow overflow-auto border-b border-gray-200 rounded-lg"> <tbody class="text-sm bg-white divide-y divide-gray-200">
<table class="min-w-full divide-y divide-gray-200"> <% emails.each do |email| %>
<thead class="bg-gray-50"> <%= render partial: "list_row", object: email, as: :email, locals: {form: form} %>
<tr> <% end %>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th> </tbody>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">From</th> </table>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Subject</th>
<th scope="col" class="px-2 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Metadata</th>
</tr>
</thead>
<tbody class="text-sm bg-white divide-y divide-gray-200"> <div class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6">
<% emails.each do |email| %> <div class="flex-1 flex justify-between sm:hidden">
<%= render partial: "list_row", object: email, as: :email %> <%= link_to_previous_page @emails, 'Previous page', class: "ml-3 paginate-page paginate-page-single" %>
<% end %> <%= link_to_next_page @emails, 'Next Page', class: "paginate-page paginate-page-single" %>
</tbody> </div>
</table> <div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
<div>
<div class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6"> <%= form.hidden_field :return_url, value: request.url %>
<div class="flex-1 flex justify-between sm:hidden"> <%= form.select :batch_action, [["Mark not inbox", :mark_not_inbox],["Mark inbox", :mark_inbox]] %>
<%= link_to_previous_page @emails, 'Previous page', class: "ml-3 paginate-page paginate-page-single" %> <%= form.submit "Apply" %>
<%= link_to_next_page @emails, 'Next Page', class: "paginate-page paginate-page-single" %> </div>
</div> <div>
<div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between"> <p class="text-sm text-gray-700">
<div> Showing
<p class="text-sm text-gray-700"> <span class="font-medium"><%= @emails.offset_value + 1 %></span>
Showing to
<span class="font-medium"><%= @emails.offset_value + 1 %></span> <span class="font-medium"><%= @emails.offset_value + (@emails.respond_to?(:records) ? @emails.records : @emails.to_a).size %></span>
to of
<span class="font-medium"><%= @emails.offset_value + (@emails.respond_to?(:records) ? @emails.records : @emails.to_a).size %></span> <span class="font-medium"><%= @emails.total_count %></span>
of results
<span class="font-medium"><%= @emails.total_count %></span> </p>
results </div>
</p> <%= paginate @emails %>
</div> </div>
<%= paginate @emails %>
</div> </div>
</div> </div>
</div> <% end %>

View file

@ -1,4 +1,10 @@
<tr class="<%= cycle('bg-white', 'bg-gray-50', :name => 'zebra') %>"> <tr class="<%= cycle('bg-white', 'bg-gray-50', :name => 'zebra') %> <%= "text-gray-500 font-light" if !email.inbox? %>">
<td class="text-center pl-3 pr-1">
<%= form.check_box "ids[]",
{class: "focus:ring-gray-500 h-4 w-4 text-gray-600 border-gray-300 rounded",
data: { "checkboxes-target": "checkboxesItem" }},
email.id, nil %>
</td>
<td class=" whitespace-nowrap"><%= link_to email.date.strftime("%Y-%m-%d %H:%M"), email, "data-turbo-frame": "_top", class: "block p-2" %></td> <td class=" whitespace-nowrap"><%= link_to email.date.strftime("%Y-%m-%d %H:%M"), email, "data-turbo-frame": "_top", class: "block p-2" %></td>
<td class=""><%= link_to email.from.join(', '), email, "data-turbo-frame": "_top", class: "block p-2" %></td> <td class=""><%= link_to email.from.join(', '), email, "data-turbo-frame": "_top", class: "block p-2" %></td>
<td class=""><%= link_to email.subject, email, "data-turbo-frame": "_top", class: "block p-2" %></td> <td class=""><%= link_to email.subject, email, "data-turbo-frame": "_top", class: "block p-2" %></td>

View file

@ -3,7 +3,9 @@ require 'sidekiq/web'
Rails.application.routes.draw do Rails.application.routes.draw do
devise_for :users devise_for :users
resources :emails, only: [:index, :show, :destroy] resources :emails, only: [:index, :show, :destroy] do
post :batch, on: :collection
end
resources :metadata_mappings resources :metadata_mappings