Skip to content

Commit

Permalink
Add notifcaion preferences to teammates
Browse files Browse the repository at this point in the history
- manage preferences for all events from profile form
- Add tooltip info toggled to show preferences explanations
- Add decorator for teammate

Improve notifications settings flow for team members (rubycentral#259)
  • Loading branch information
jonsgreen committed Jan 15, 2018
1 parent df9367a commit c9cedd8
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 31 deletions.
5 changes: 5 additions & 0 deletions app/assets/javascripts/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(document).ready(function () {
if ($('#notification-preferences-toggle').length) {
$('#notification-preferences-toggle').on("click", function(e) { e.preventDefault() })
}
})
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
@import "modules/event-teammate-invitations";
@import "modules/program-session";
@import "modules/proposal";
@import "modules/profile";
@import "modules/ratings";
@import "modules/schedule";
@import "modules/selection";
Expand Down
12 changes: 12 additions & 0 deletions app/assets/stylesheets/modules/_profile.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#profiles_edit {
.user_teammates_notification_preference {
margin-bottom: 40px;
span.radio {
display: inline-block;
margin: 0px 10px 10px 0px;
label {
text-transform: capitalize;
}
}
}
}
4 changes: 3 additions & 1 deletion app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def update
private

def user_params
params.require(:user).permit(:bio, :gender, :ethnicity, :country, :name, :email, :password, :password_confirmation)
params.require(:user).permit(:bio, :gender, :ethnicity, :country, :name,
:email, :password, :password_confirmation,
teammates_attributes: [:id, :notification_preference])
end

def incomplete_profile_msg
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/staff/teammates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Staff::TeammatesController < Staff::ApplicationController
respond_to :html, :json

def index
@staff = current_event.teammates.accepted.alphabetize
@staff = TeammateDecorator.decorate_collection(current_event.teammates.accepted.alphabetize)
@invitations = current_event.teammates.invitations

@staff_count = group_count(@staff)
Expand Down
7 changes: 7 additions & 0 deletions app/decorators/teammate_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TeammateDecorator < ApplicationDecorator
delegate_all

def notification_preference
Teammate::NOTIFICATION_PREFERENCES[teammate.notification_preference]
end
end
12 changes: 12 additions & 0 deletions app/helpers/profiles_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ProfilesHelper

def notification_preferences_tooltip
<<-HTML
<p><strong>Notification Preferences</strong></p>
<p><b>All Via Email</b> - You will receive emails for all public and internal comments. You will also receive in-app notications for all public and internal comments. </p>
<p><b>Mention Only Via Email</b> - You will only receive emails for every public and internal comment that directly mentions your @shortname. You will also receive in-app notications for all public and internal comments.</p>
<p><b>In App Only</b> - You will not receive any email notifications and only receive in-app notifications for all public and internal comments.</p>
HTML
end

end
12 changes: 11 additions & 1 deletion app/models/teammate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ class Teammate < ApplicationRecord

STAFF_ROLES = ['reviewer', 'program team', 'organizer']

ALL = 'all'
MENTIONS = 'mentions'
IN_APP_ONLY = 'in_app_only'

NOTIFICATION_PREFERENCES = {
ALL => 'All Via Email',
MENTIONS => 'Mention Only Via Email',
IN_APP_ONLY => 'In App Only'
}

belongs_to :event
belongs_to :user

Expand Down Expand Up @@ -83,13 +93,13 @@ def comment_notifications
# email :string
# state :string
# token :string
# notifications :boolean default(TRUE)
# invited_at :datetime
# accepted_at :datetime
# declined_at :datetime
# created_at :datetime
# updated_at :datetime
# mention_name :string
# notification_preference :string default("all")
#
# Indexes
#
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class User < ApplicationRecord

before_create :check_pending_invite_email

accepts_nested_attributes_for :teammates

attr_accessor :pending_invite_email

def self.from_omniauth(auth, invitation_email=nil)
Expand Down
21 changes: 19 additions & 2 deletions app/views/profiles/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%h1
Edit Your Profile

= form_for current_user, url: profile_path, html: {role: 'form'} do |f|
= simple_form_for current_user, url: profile_path, html: {role: 'form'} do |f|
.row
%fieldset.col-md-6
.widget
Expand All @@ -30,7 +30,7 @@
%fieldset.col-md-6
.widget
.widget-header
%i.fa.fa-envelope
%i.fa.fa-lock
- if current_user.provider.present?
%i.fa{class: "fa-#{current_user.provider.downcase}"}
%h3 Identity Services
Expand All @@ -56,6 +56,23 @@
| Connected via
= current_user.provider

.widget
.widget-header
%i.fa.fa-envelope
%h3
Notifications
= link_to "#", id: "notification-preferences-toggle",
data: { container: 'body', toggle: 'popover', placement: "left",
content: notification_preferences_tooltip, html: true } do
%i.fa.fa-question-circle
.widget-content
= f.simple_fields_for :teammates do |fields|
- teammate = fields.object
%b= teammate.event.name
= fields.input :notification_preference,
collection: Teammate::NOTIFICATION_PREFERENCES.invert,
as: :radio_buttons, wrapper: 'horizontal_radio_and_checkboxes', label: false

.row
.col-md-12.form-submit
%button.pull-right.btn.btn-success.btn-lg{type: "submit"} Save
14 changes: 0 additions & 14 deletions app/views/staff/events/_teammate_notifications.html.haml

This file was deleted.

7 changes: 2 additions & 5 deletions app/views/staff/teammates/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
%th Mention Name
%th Rated Proposals
%th Role
%th Email Notifications
%th Notification Preference
- if current_user.organizer_for_event?(current_event)
%th
%tbody
Expand All @@ -44,10 +44,7 @@
%td.mention-name= render partial: 'mention_name_controls', locals: { teammate: teammate }
%td= teammate.ratings_count(current_event)
%td.role= render partial: 'role_controls', locals: { teammate: teammate }
%td.notifications.text-center
%span= teammate.comment_notifications
- if teammate.user == current_user
= render partial: "staff/events/teammate_notifications", locals: {teammate: teammate}
%td= teammate.notification_preference
- if current_user.organizer_for_event?(current_event)
%td.text-center{ id: "teammate-role-#{teammate.id}" }
- unless teammate.user == current_user
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/simple_form_bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@
b.use :html5
b.use :placeholder

b.use :label, class: 'col-sm-3 control-label'
b.use :label, class: 'col-sm-12 control-label'

b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
b.wrapper tag: 'div', class: 'col-sm-12' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddNotificationPreferenceToTeammates < ActiveRecord::Migration[5.1]
def change
add_column :teammates, :notification_preference, :string, default: Teammate::ALL
remove_column :teammates, :notifications, :boolean
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180111175100) do
ActiveRecord::Schema.define(version: 20180106144145) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -181,13 +181,13 @@
t.string "email"
t.string "state"
t.string "token"
t.boolean "notifications", default: true
t.datetime "invited_at"
t.datetime "accepted_at"
t.datetime "declined_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "mention_name"
t.string "notification_preference", default: "all"
t.index ["event_id"], name: "index_teammates_on_event_id"
t.index ["user_id"], name: "index_teammates_on_user_id"
end
Expand Down
3 changes: 1 addition & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def create_seed_data
email: organizer.email,
role: "organizer",
mention_name: "organizer",
state: Teammate::ACCEPTED,
notifications: false
state: Teammate::ACCEPTED
)
seed_event.teammates.create(
user: track_director,
Expand Down
13 changes: 12 additions & 1 deletion spec/features/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@
end

scenario "A user attempts to save their bio without email", js: true do
visit (edit_profile_path)
visit(edit_profile_path)
fill_in('Email', with: '')
click_button 'Save'
expect(page).to have_content("Unable to save profile. Please correct the following: Email can't be blank")
end

scenario 'A user updates their event email preference' do
teammate = create(:teammate, role: 'organizer', user: user, state: Teammate::ACCEPTED)
visit(event_path(teammate.event))
visit(edit_profile_path)
choose(Teammate::NOTIFICATION_PREFERENCES[Teammate::MENTIONS])
click_button 'Save'
click_link 'Dashboard'
click_link 'Team'
expect(page).to have_content(Teammate::NOTIFICATION_PREFERENCES[Teammate::MENTIONS])
end
end

0 comments on commit c9cedd8

Please sign in to comment.