Marquage Inbox en masse
This commit is contained in:
parent
d9ad6d9cfd
commit
f4784dbdf6
|
@ -16,4 +16,17 @@ class EmailsController < ApplicationController
|
|||
@email.destroy
|
||||
redirect_to emails_url, notice: 'Email was successfully destroyed.'
|
||||
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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">
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<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>
|
||||
<tbody class="text-sm bg-white divide-y divide-gray-200">
|
||||
<% emails.each do |email| %>
|
||||
<%= render partial: "list_row", object: email, as: :email, locals: {form: form} %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<tbody class="text-sm bg-white divide-y divide-gray-200">
|
||||
<% emails.each do |email| %>
|
||||
<%= render partial: "list_row", object: email, as: :email %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6">
|
||||
<div class="flex-1 flex justify-between sm:hidden">
|
||||
<%= link_to_previous_page @emails, 'Previous page', class: "ml-3 paginate-page paginate-page-single" %>
|
||||
<%= link_to_next_page @emails, 'Next Page', class: "paginate-page paginate-page-single" %>
|
||||
</div>
|
||||
<div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-gray-700">
|
||||
Showing
|
||||
<span class="font-medium"><%= @emails.offset_value + 1 %></span>
|
||||
to
|
||||
<span class="font-medium"><%= @emails.offset_value + (@emails.respond_to?(:records) ? @emails.records : @emails.to_a).size %></span>
|
||||
of
|
||||
<span class="font-medium"><%= @emails.total_count %></span>
|
||||
results
|
||||
</p>
|
||||
<div class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6">
|
||||
<div class="flex-1 flex justify-between sm:hidden">
|
||||
<%= link_to_previous_page @emails, 'Previous page', class: "ml-3 paginate-page paginate-page-single" %>
|
||||
<%= link_to_next_page @emails, 'Next Page', class: "paginate-page paginate-page-single" %>
|
||||
</div>
|
||||
<div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<%= form.hidden_field :return_url, value: request.url %>
|
||||
<%= form.select :batch_action, [["Mark not inbox", :mark_not_inbox],["Mark inbox", :mark_inbox]] %>
|
||||
<%= form.submit "Apply" %>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-700">
|
||||
Showing
|
||||
<span class="font-medium"><%= @emails.offset_value + 1 %></span>
|
||||
to
|
||||
<span class="font-medium"><%= @emails.offset_value + (@emails.respond_to?(:records) ? @emails.records : @emails.to_a).size %></span>
|
||||
of
|
||||
<span class="font-medium"><%= @emails.total_count %></span>
|
||||
results
|
||||
</p>
|
||||
</div>
|
||||
<%= paginate @emails %>
|
||||
</div>
|
||||
<%= paginate @emails %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
|
@ -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=""><%= 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>
|
||||
|
|
|
@ -3,7 +3,9 @@ require 'sidekiq/web'
|
|||
Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
|
||||
resources :emails, only: [:index, :show, :destroy]
|
||||
resources :emails, only: [:index, :show, :destroy] do
|
||||
post :batch, on: :collection
|
||||
end
|
||||
|
||||
resources :metadata_mappings
|
||||
|
||||
|
|
Loading…
Reference in New Issue