diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb index 7721089..7a5fed7 100644 --- a/app/controllers/emails_controller.rb +++ b/app/controllers/emails_controller.rb @@ -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 diff --git a/app/javascript/controllers/checkboxes_controller.js b/app/javascript/controllers/checkboxes_controller.js new file mode 100644 index 0000000..d901242 --- /dev/null +++ b/app/javascript/controllers/checkboxes_controller.js @@ -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 + } +} diff --git a/app/views/emails/_list.html.erb b/app/views/emails/_list.html.erb index a323d7a..a03b2da 100644 --- a/app/views/emails/_list.html.erb +++ b/app/views/emails/_list.html.erb @@ -1,40 +1,51 @@ +<%= form_with url: batch_emails_url, method: :post, data: {"turbo-frame": "_top", controller: "checkboxes"} do |form| %> +
+ + + + + + + + + + -
-
+ <%= 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" } %> + DateFromSubjectMetadata
- - - - - - - - + + <% emails.each do |email| %> + <%= render partial: "list_row", object: email, as: :email, locals: {form: form} %> + <% end %> + +
DateFromSubjectMetadata
- - <% emails.each do |email| %> - <%= render partial: "list_row", object: email, as: :email %> - <% end %> - - - -
-
- <%= 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" %> -
- +<% end %> \ No newline at end of file diff --git a/app/views/emails/_list_row.html.erb b/app/views/emails/_list_row.html.erb index 6c49adf..22e87ef 100644 --- a/app/views/emails/_list_row.html.erb +++ b/app/views/emails/_list_row.html.erb @@ -1,4 +1,10 @@ - +"> + + <%= 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 %> + <%= link_to email.date.strftime("%Y-%m-%d %H:%M"), email, "data-turbo-frame": "_top", class: "block p-2" %> <%= link_to email.from.join(', '), email, "data-turbo-frame": "_top", class: "block p-2" %> <%= link_to email.subject, email, "data-turbo-frame": "_top", class: "block p-2" %> diff --git a/config/routes.rb b/config/routes.rb index a3080e9..73249d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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