Class: Admin::GmailSignaturesController

Inherits:
CrmController
  • Object
show all
Defined in:
app/controllers/admin/gmail_signatures_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
9
10
11
12
# File 'app/controllers/admin/gmail_signatures_controller.rb', line 6

def index
  @pusher = GmailSignaturePusher.new
  @employees = Employee.active_employees
                       .sorted
                       .includes(:employee_record, :contact_points)
  @batch_result = load_batch_result
end

#previewObject



58
59
60
61
# File 'app/controllers/admin/gmail_signatures_controller.rb', line 58

def preview
  employee = Employee.find(params[:id])
  render partial: 'communications/signature', locals: { sender_party: employee, theme: :gmail }, layout: false
end

#push_allObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/gmail_signatures_controller.rb', line 28

def push_all
  pusher = GmailSignaturePusher.new
  employees = Employee.active_employees
                      .sorted
                      .includes(:employee_record, :contact_points)
  batch_result = pusher.push_all(employees)
  store_batch_result(batch_result)

  flash[:success] = "Pushed #{batch_result.succeeded.size}/#{batch_result.total} signatures"
  flash[:error] = "#{batch_result.failed.size} failed" if batch_result.failed.any?
  redirect_to admin_gmail_signatures_path
end

#push_oneObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/admin/gmail_signatures_controller.rb', line 14

def push_one
  employee = Employee.find(params[:id])
  pusher = GmailSignaturePusher.new
  result = pusher.push_one(employee)
  store_batch_result(GmailSignaturePusher::BatchResult.new(results: [result]))

  if result.success
    flash[:success] = "Signature pushed to #{result.email}"
  else
    flash[:error] = "Failed to push to #{result.email}: #{result.error}"
  end
  redirect_to admin_gmail_signatures_path
end

#push_selectedObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/admin/gmail_signatures_controller.rb', line 41

def push_selected
  ids = params[:employee_ids].to_s.split(",").map(&:to_i).reject(&:zero?)
  if ids.empty?
    flash[:error] = "No employees selected."
    return redirect_to admin_gmail_signatures_path
  end

  pusher = GmailSignaturePusher.new
  employees = Employee.where(id: ids).includes(:employee_record, :contact_points)
  batch_result = pusher.push_all(employees)
  store_batch_result(batch_result)

  flash[:success] = "Pushed #{batch_result.succeeded.size}/#{batch_result.total} signatures"
  flash[:error] = "#{batch_result.failed.size} failed" if batch_result.failed.any?
  redirect_to admin_gmail_signatures_path
end