Skip to content

Commit

Permalink
Rake Task and UI changes
Browse files Browse the repository at this point in the history
- Add rake task to check and update user status to Subscribe and Unsubscribed
- UI fix the navigation bar, paignation and button alignments
- Fix the rake task for Blocked users
  • Loading branch information
Ashish944 committed Jun 16, 2020
1 parent 0e6bf7b commit 3e21bcb
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 11 deletions.
22 changes: 22 additions & 0 deletions app/assets/stylesheets/light/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,25 @@
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

.badge-users-count {
margin-top: 10px;
}

.btn-mail {
margin-top: 5px;
}

#users_per_page {
width: 50px;
height: 30px;
}

#searchbox {
height: 30px;
}

.brand {
font-weight: bold !important;
margin-top: 5px !important;
}
4 changes: 2 additions & 2 deletions app/models/light/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class User
end
end

scope :subscribed_users, -> { where is_subscribed: true }
scope :unsubscribed_users, -> { where is_subscribed: false }
scope :subscribed_users, -> { where(is_subscribed: true, sidekiq_status: 'Subscribed') }
scope :unsubscribed_users, -> { where(is_subscribed: false, sidekiq_status: 'Unsubscribed') }
scope :new_users, -> { where(is_subscribed: false, sidekiq_status: NEW_USER) }
scope :blocked_users, -> { where(is_subscribed: false, sidekiq_status: 'Block') }
scope :bounced_users, -> { where(is_subscribed: false, sidekiq_status: 'Bounced') }
Expand Down
7 changes: 4 additions & 3 deletions app/views/light/newsletters/_top_navbar.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= nav_bar :brand => "Newsletters", :responsive => true, :static => :top, :fluid => :true do
= nav_bar :brand => 'Newsletters', :responsive => true, :static => :top, :fluid => :true do
= menu_group do
= menu_item "Add Newsletter", new_newsletter_path
= menu_item "Opt in letters", opt_in_newsletters_path
Expand All @@ -10,6 +10,7 @@

= menu_item "Show Users", users_path, ({:method => 'get'} if params[:controller] == 'light/users' && params[:action].in?(['new', 'create']))
= menu_group :pull => :right do
= content_tag :a, "Send Mail", :href => sendmailer_path, :class => 'btn btn-danger', :data => { :confirm => 'Are you sure ?'}
= content_tag :a, "Test Mail", :href => testmail_path, :class => "btn btn-success"
.btn-mail
= content_tag :a, "Send Mail", :href => sendmailer_path, :class => 'btn btn-danger', :data => { :confirm => 'Are you sure ?'}
= content_tag :a, "Test Mail", :href => testmail_path, :class => 'btn btn-success'
%br
12 changes: 6 additions & 6 deletions app/views/light/users/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
%option{:value => 'Opt in mail sent'} Opt in Mail Sent: #{Light::User.opt_in_users.count}

%ul.nav.navbar-nav.pull-right
%li
%h5= raw ("Subscribers: #{badge(Light::User.subscribed_users.count)}")
%li.badge-users-count
%h5= raw ("Subscribed users: #{badge(Light::User.subscribed_users.count)}")

%li
%li.badge-users-count
%h5= raw ("New users: #{badge(Light::User.new_users.count)}")

.row
Expand Down Expand Up @@ -55,13 +55,13 @@

%a{ :href => "/newsletter/users/{{_id.$oid}}", data:{ :confirm => 'Are you sure?', method: 'delete'}, :class => 'btn btn-sm btn-danger' } Delete

.col-lg-12.padding_none.text-center
.col-lg-12.padding_none.pull-right
#user_pagination.col-lg-12
.col-lg-6.content

:javascript
var users_data = #{@users.to_json}
var total_count = #{@users.count}
$('#searchbox').css('height',30)
$('.per-page').css('width',90)
initialize_filterjs_table('#users tbody', users_data, '#user-template', '', [], '#user_pagination', '#users_per_page')
$('.per-page').css('width',90)
$('.per-page').css('height',30)
57 changes: 57 additions & 0 deletions lib/tasks/update_user_status.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace :light do
desc 'Checking and updating the User status (Subscribed and Unsubscribed)'
task :update_user_status => :environment do

# setting status to Unsubscribed for users whose flag 'is_subscribed' is false
# and status is nil
puts "\n\n Unsubscribed Update Status : "
puts Light::User.where(is_subscribed: false, sidekiq_status: nil, is_blocked: false)
.update_all(sidekiq_status: 'Unsubscribed')
puts Light::User.where(is_subscribed: false, sidekiq_status: nil, is_blocked: true)
.update_all(sidekiq_status: 'Unsubscribed')

# setting status to Subscribed for users whose flag 'is_subscribed' is true
# and status is nil
puts "\n\n Subscribed Update Status : "
puts Light::User.where(is_subscribed: true, sidekiq_status: nil)
.update_all(sidekiq_status: 'Subscribed')

# change 'web subscription request' status to 'Unsubscribed'
# 1. add previous status into source field
puts "\n\n Change 'web subscription request' status to 'Unsubscribed' : "
web_subscription = Light::User.where(sidekiq_status: 'web subscription request')
puts web_subscription.update_all(source: 'web subscription request')

# 2. change status to 'Unsubscribed'
puts web_subscription.update_all(sidekiq_status: 'Unsubscribed')


# Fix flag 'is_subscribed' and 'is_blocked' for Blocked Users
puts "\n\n Fix flag is_subscribed : "
puts Light::User.where(sidekiq_status: 'Block')
.update_all(is_subscribed: false, is_blocked: true)

puts Light::User.where(is_subscribed: true, is_blocked: true)
.update_all(is_subscribed: false, sidekiq_status: 'Block')

puts "\n\n Fix flag is_blocked :"
puts Light::User.where(is_blocked: nil)
.update_all(is_blocked: false)

def check_status(status)
Light::User.where(sidekiq_status: status).count
end

# Status wise count of User
puts "\n\n Total no of User Status : " +
"\n Subscribed : #{check_status('Subscribed')}" +
"\n Unsubscribed : #{check_status('Unsubscribed')}" +
"\n New User : #{check_status('new user')}" +
"\n Invalid : #{check_status('Invalid')}" +
"\n Spam : #{check_status('Spam')}" +
"\n Blocked : #{check_status('Block')}" +
"\n Bounced : #{check_status('Bounced')}" +
"\n Opt in User: #{check_status('Opt in mail sent')}"
end
end

0 comments on commit 3e21bcb

Please sign in to comment.