diff --git a/admin/app/admin/email_batch.rb b/admin/app/admin/email_batch.rb index bd934f6da..3f15aadd3 100644 --- a/admin/app/admin/email_batch.rb +++ b/admin/app/admin/email_batch.rb @@ -17,42 +17,54 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do column 'Test Emails' do |pp| pp.test_emails end column 'Email Count' do |pp| pp.qualified_count end column 'Send Count' do |pp| pp.sent_count end - column 'Started At' do |pp| pp.started_at end - column 'Completed At' do |pp| pp.completed_at end + column 'Started' do |pp| pp.started_at end + column 'Completed' do |pp| pp.completed_at end + column 'Send Test' do |pp| + link_to("Test Batch (#{pp.test_count})", + batch_test_admin_batch_email_path(pp.id), + :confirm => "Run test batch with #{pp.test_count} emails?") + end + column 'Send Live' do |pp| + link_to("Live Batch (#{User.email_opt_in.count})", + batch_send_admin_batch_email_path(pp.id), + :confirm => "Run LIVE batch with #{User.email_opt_in.count} emails?") + end default_actions end action_item :only => :show do - link_to("Run Test Batch (#{resource.test_count})", - "/admin/batch_emails/#{resource.id}/batch_test", + link_to("Send Test Batch (#{resource.test_count})", + batch_test_admin_batch_email_path(resource.id), :confirm => "Run test batch with #{resource.test_count} emails?") end action_item :only => :show do - link_to("Run Live Batch (#{User.email_opt_in.count})", - "/admin/batch_emails/#{resource.id}/batch_send", + link_to("Send Live Batch (#{User.email_opt_in.count})", + batch_send_admin_batch_email_path(resource.id), :confirm => "Run LIVE batch with #{User.email_opt_in.count} emails?") end show :title => 'Batch Email' do |obj| panel 'Email Contents' do attributes_table_for obj do - row 'Subject' do |obj| obj.subject end row 'From' do |obj| obj.from_email end row 'Test Emails' do |obj| obj.test_emails end + row 'Subject' do |obj| obj.subject end row 'Body' do |obj| obj.body end - row 'State' do |obj| obj.aasm_state end end end columns do column do panel 'Sending Parameters' do attributes_table_for obj do - row 'Opt-in User Count' do |obj| User.email_opt_in.count end + row 'State' do |obj| obj.aasm_state end + row 'User Count' do |obj| + obj.qualified_count ? obj.qualified_count : User.email_opt_in.count + end row 'Sent Count' do |obj| obj.sent_count end - row 'Started At' do |obj| obj.started_at end - row 'Completed At' do |obj| obj.completed_at end + row 'Started' do |obj| obj.started_at end + row 'Completed' do |obj| obj.completed_at end row 'Updated' do |obj| obj.updated_at end end end @@ -67,8 +79,9 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do controller do def create - EmailBatch.create_with_params(params[:jam_ruby_email_batch]) - redirect_to admin_batch_emails_path + batch = EmailBatch.create_with_params(params[:jam_ruby_email_batch]) + redirect_to admin_batch_email_path(batch.id) + # redirect_to admin_batch_emails_path end def update diff --git a/db/up/emails.sql b/db/up/emails.sql index 9c68b643e..86f8b4f6f 100644 --- a/db/up/emails.sql +++ b/db/up/emails.sql @@ -20,19 +20,19 @@ CREATE TABLE email_batches ( updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -CREATE TABLE email_batch_results ( - id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), - email_batch_id VARCHAR(64) REFERENCES email_batches(id) ON DELETE CASCADE, - user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, +-- CREATE TABLE email_batch_results ( +-- id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), +-- email_batch_id VARCHAR(64) REFERENCES email_batches(id) ON DELETE CASCADE, +-- user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, - error_type VARCHAR(32), - email_address VARCHAR(256), +-- error_type VARCHAR(32), +-- email_address VARCHAR(256), - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); +-- created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +-- ); -ALTER TABLE email_batch_results ADD CONSTRAINT email_batch_uniqkey UNIQUE (email_batch_id); -ALTER TABLE email_batch_results ADD CONSTRAINT email_user_uniqkey UNIQUE (user_id); +-- ALTER TABLE email_batch_results ADD CONSTRAINT email_batch_uniqkey UNIQUE (email_batch_id); +-- ALTER TABLE email_batch_results ADD CONSTRAINT email_user_uniqkey UNIQUE (user_id); -ALTER TABLE users ADD COLUMN opt_out_email_batch boolean DEFAULT false; +ALTER TABLE users ALTER COLUMN subscribe_email SET DEFAULT true; diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 76af3a456..11e21efd2 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -1,12 +1,12 @@ module JamRuby class BatchMailer < JamRuby::AsyncMailer - layout "batch_mailer" + layout "user_mailer" sendgrid_category :use_subject_lines sendgrid_unique_args :env => Environment.mode def _send_batch(batch, users) - @body = batch.body + @batch_body = batch.body emails = users.map(&:email) sendgrid_recipients(emails) diff --git a/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb b/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb index 6fcd69d53..1198a26f4 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb @@ -24,13 +24,11 @@
<%= yield %>
+<%= @batch_body ? @batch_body.html_safe : yield %>
This email was sent to you because you have an account at JamKazam. Click here to unsubscribe and update your profile settings.
-This email was sent to you because you have an account at JamKazam.