Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: first_name and last_name move from questionnaire to user #241

Merged
merged 30 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dd63c2f
Initial move: first/last name; user->quesitonnaire
peterkos May 26, 2020
c8571f3
refactor: Attempt to fix backend params
peterkos May 26, 2020
5032247
refactor: Make HoundBot a little happier
peterkos May 26, 2020
1362047
feat: Admin list shows first/last names
peterkos May 27, 2020
a098e1a
inprog on stats page
peterkos May 29, 2020
8be1aa6
Refactored stats datatable and controller
peterkos May 30, 2020
0f1b0ae
Migration is now backwards compatible with pre-2.0
peterkos May 30, 2020
890a753
4space->2space :rage: #downwith2spaces
peterkos May 30, 2020
ce3ade8
Merge branch '2.0' into issue-222
peterkos Jun 8, 2020
f79be12
Fix various first_name/last_name bugs
peterkos Jun 9, 2020
c2bacfa
Fixed remainder of tests for name refactor
peterkos Jun 9, 2020
334eadc
Fix datatable style and count ranges
peterkos Jun 9, 2020
a25e69c
Fix some more style bugs
peterkos Jun 9, 2020
5be9b1f
Viewing bus list w/ passengers now works
peterkos Jun 18, 2020
7869dfb
Adds Users & Staff support for #222
cbaudouinjr Jun 19, 2020
9b0bc4d
Adds #222 support to stats, fixes stats layout
cbaudouinjr Jun 28, 2020
de98e6f
Fixes Hound issues
cbaudouinjr Jun 28, 2020
4de5632
Removes Hound whitespace issues
cbaudouinjr Jun 28, 2020
d791024
History audit bugfix
peterkos Jun 30, 2020
5350fcb
Add nil check back, whoops. This works better.
peterkos Jun 30, 2020
6556b17
Squashed commit of the following:
peterkos Jul 2, 2020
df42cf6
Merge branch '2.0' into issue-222
cbaudouinjr Jul 2, 2020
2b2cec1
Fix undefined err on bus list info
peterkos Jul 18, 2020
900a0a8
Fix bus captain bug, update schema
peterkos Aug 29, 2020
5c3dff5
Squashed commit of the following:
peterkos Aug 30, 2020
eadaddd
Actually assign current_user
peterkos Aug 30, 2020
6f72d89
mymlh working
peterkos Aug 30, 2020
33e3c65
Refactor questionnnaire new to be nicer to read
peterkos Aug 30, 2020
8012b30
Patch condition error for info refactor
peterkos Aug 30, 2020
8f6e894
Merge branch '2.0' into issue-222
peterkos Aug 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 79 additions & 9 deletions app/assets/javascripts/manage/lib/setupDataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ var setupDataTables = function () {
});

$('.datatable.users').DataTable({
order: [5, 'desc'],
order: [8, 'desc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'email' },
{ orderable: false, data: 'link' },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email', visible: false },
{ orderable: true, data: 'role' },
{ orderable: false, data: 'questionnaire'},
{ orderable: true, data: 'active' },
Expand All @@ -34,15 +37,18 @@ var setupDataTables = function () {
});

$('.datatable.admins').DataTable({
order: [1, 'asc'],
order: [2, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'email' },
{ orderable: false, data: 'link' },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email', visible: false },
{ orderable: true, data: 'role' },
{ orderable: true, data: 'active' },
{ orderable: true, data: 'receive_weekly_report' },
{ orderable: true, data: 'created_at' },
{ orderable: true, data: 'current_sign_in_at' },
{ orderable: true, data: 'created_at', visible: false },
{ orderable: true, data: 'current_sign_in_at', visible: false },
{ orderable: true, data: 'last_sign_in_at', visible: false },
{ orderable: true, data: 'current_sign_in_ip', visible: false },
{ orderable: true, data: 'last_sign_in_ip', visible: false },
Expand Down Expand Up @@ -75,8 +81,72 @@ var setupDataTables = function () {
],
});

$('.datatable.stats').DataTable({
processing: false,
serverSide: false,
// MARK: Datatables for the stats

$('.datatable.stats-dietary').DataTable({
order: [1, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'phone', visible: false },
{ orderable: false, data: 'questionnaire' },
{ orderable: true, data: 'checked_in_at', visible: false },
{ orderable: true, data: 'dietary_restrictions' },
{ orderable: true, data: 'special_needs' }
]
});

$('.datatable.stats-notschooltravel').DataTable({
order: [1, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'phone', visible: false },
{ orderable: false, data: 'questionnaire' },
{ orderable: true, data: 'travel_location' },
{ orderable: true, data: 'acc_status' }
]
});

$('.datatable.stats-attendeeinfo').DataTable({
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'school_name' },
{ orderable: true, data: 'vcs_url' },
{ orderable: true, data: 'portfolio_url' }
]
});

$('.datatable.stats-mlhinfo-applied').DataTable({
order: [1, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'phone', visible: false },
{ orderable: true, data: 'school_name' }
]
});

$('.datatable.stats-mlhinfo-checkedin').DataTable({
order: [1, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'phone' },
{ orderable: true, data: 'school_name' }
]
});


};
4 changes: 2 additions & 2 deletions app/controllers/manage/bus_lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def toggle_bus_captain
is_bus_captain = params[:bus_captain] == "1"
@questionnaire.update_attribute(:is_bus_captain, is_bus_captain)
if @questionnaire.reload.is_bus_captain
flash[:notice] = "#{@questionnaire.full_name} has been promoted to a bus captain."
flash[:notice] = "#{@questionnaire.user.full_name} has been promoted to a bus captain."
Message.queue_for_trigger("bus_list.new_captain_confirmation", @questionnaire.user.id)
else
flash[:notice] = "#{@questionnaire.full_name} has been removed as a bus captain."
flash[:notice] = "#{@questionnaire.user.full_name} has been removed as a bus captain."
end
redirect_to [:manage, @bus_list]
end
Expand Down
14 changes: 11 additions & 3 deletions app/controllers/manage/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def create
def update
update_params = questionnaire_params
email = update_params.delete(:email)
# Take our nested user object out as a whole
user_params = params[:questionnaire][:user]
if user_params
@questionnaire.user.update_attributes(first_name: user_params[:first_name])
@questionnaire.user.update_attributes(last_name: user_params[:last_name])
end
@questionnaire.user.update_attributes(email: email) if email.present?
update_params = convert_school_name_to_id(update_params)
update_params = convert_boarded_bus_param(update_params, @questionnaire)
Expand All @@ -76,11 +82,11 @@ def check_in
end
@questionnaire.update_attribute(:checked_in_at, Time.now)
@questionnaire.update_attribute(:checked_in_by_id, current_user.id)
flash[:notice] = "Checked in #{@questionnaire.full_name}."
flash[:notice] = "Checked in #{@questionnaire.user.full_name}."
elsif params[:check_in] == "false"
@questionnaire.update_attribute(:checked_in_at, nil)
@questionnaire.update_attribute(:checked_in_by_id, current_user.id)
flash[:notice] = "#{@questionnaire.full_name} no longer checked in."
flash[:notice] = "#{@questionnaire.user.full_name} no longer checked in."
else
flash[:alert] = "No check-in action provided!"
redirect_to show_redirect_path
Expand Down Expand Up @@ -147,8 +153,10 @@ def message_events
private

def questionnaire_params
# Note that this ONLY considers parameters for the questionnaire, not the user.
# TODO: Refactor "email" out to user as first_name and last_name were
params.require(:questionnaire).permit(
:email, :experience, :first_name, :last_name, :gender,
:email, :experience, :gender,
:date_of_birth, :interest, :school_id, :school_name, :major, :level_of_study,
:shirt_size, :dietary_restrictions, :special_needs, :international,
:portfolio_url, :vcs_url, :agreement_accepted, :bus_captain_interest,
Expand Down
134 changes: 11 additions & 123 deletions app/controllers/manage/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -1,137 +1,25 @@
class Manage::StatsController < Manage::ApplicationController
def index
end

def dietary_special_needs
data = Rails.cache.fetch(cache_key_for_questionnaires("dietary_special_needs")) do
select_attributes = [
:first_name,
:last_name,
:phone,
:checked_in_at,
:dietary_restrictions,
:special_needs,
:user_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:phone,
:checked_in_at,
:dietary_restrictions,
:special_needs
]
data = Questionnaire.where("dietary_restrictions != '' AND acc_status = 'rsvp_confirmed' OR special_needs != '' AND acc_status = 'rsvp_confirmed'").select(select_attributes)
to_json_array(data, json_attributes)
end
render json: { data: data }
end
respond_to :html, :json

def sponsor_info
data = Rails.cache.fetch(cache_key_for_questionnaires("sponsor_info")) do
select_attributes = [
:id,
:first_name,
:last_name,
:vcs_url,
:portfolio_url,
:user_id,
:school_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:school_name,
:vcs_url,
:portfolio_url
]
data = Questionnaire.where("can_share_info = '1' AND checked_in_at != 0").joins(:resume_attachment).select(select_attributes)
json = to_json_array(data, json_attributes)
json.map.with_index { |item, index| item.insert(6, data[index].resume.attached? ? url_for(data[index].resume) : '') }
end
render json: { data: data }
def dietary_restrictions_special_needs_datatable
render json: DietarySpecialNeedsDatatable.new(params, view_context: view_context)
end

def alt_travel
data = Rails.cache.fetch(cache_key_for_questionnaires("alt_travel")) do
select_attributes = [
:id,
:first_name,
:last_name,
:travel_location,
:acc_status,
:user_id,
:school_id
]
json_attributes = [
:id,
:first_name,
:last_name,
:email,
:travel_location,
:acc_status
]
data = Questionnaire.where("travel_not_from_school = '1'").select(select_attributes)
json = to_json_array(data, json_attributes)
json.each do |e|
e[0] = view_context.link_to("View &raquo;".html_safe, manage_questionnaire_path(e[0]))
end
end
render json: { data: data }
def alt_travel_datatable
render json: AltTravelDatatable.new(params, view_context: view_context)
end

def mlh_info_applied
data = Rails.cache.fetch(cache_key_for_questionnaires("mlh_info_applied")) do
select_attributes = [
:first_name,
:last_name,
:user_id,
:school_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:school_name
]
data = Questionnaire.joins(:school).select(select_attributes)
to_json_array(data, json_attributes)
end
render json: { data: data }
def attendee_sponsor_info_datatable
render json: AttendeeSponsorInfoDatatable.new(params, view_context: view_context)
end

def mlh_info_checked_in
data = Rails.cache.fetch(cache_key_for_questionnaires("mlh_info_checked_in")) do
select_attributes = [
:first_name,
:last_name,
:user_id,
:school_id
]
json_attributes = [
:first_name,
:last_name,
:email,
:school_name
]
data = Questionnaire.joins(:school).select(select_attributes).where('checked_in_at > 0')
to_json_array(data, json_attributes)
end
render json: { data: data }
def mlh_applied_datatable
render json: MLHAppliedDatatable.new(params, view_context: view_context)
end


private

def to_json_array(data, attributes)
data.map { |e| attributes.map { |a| e.send(a) } }
def mlh_checked_in_datatable
render json: MLHCheckedInDatatable.new(params, view_context: view_context)
end

def cache_key_for_questionnaires(id)
count = Questionnaire.count
max_updated_at = Questionnaire.maximum(:updated_at).try(:utc).try(:to_s, :number)
"stats/all-#{count}-#{max_updated_at}-#{id}"
end
end
2 changes: 1 addition & 1 deletion app/controllers/manage/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def destroy

def user_params
params.require(:user).permit(
:email, :password, :password_confirmation, :remember_me, :role, :is_active, :receive_weekly_report
:first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :role, :is_active, :receive_weekly_report
)
end

Expand Down
15 changes: 7 additions & 8 deletions app/controllers/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ def new
@questionnaire = Questionnaire.new

if session["devise.provider_data"] && session["devise.provider_data"]["info"]
info = session["devise.provider_data"]["info"]
@skip_my_mlh_fields = true
@questionnaire.tap do |q|
q.first_name = session["devise.provider_data"]["info"]["first_name"]
q.last_name = session["devise.provider_data"]["info"]["last_name"]
q.phone = session["devise.provider_data"]["info"]["phone_number"]
q.level_of_study = session["devise.provider_data"]["info"]["level_of_study"]
q.major = session["devise.provider_data"]["info"]["major"]
q.date_of_birth = session["devise.provider_data"]["info"]["date_of_birth"]
q.gender = session["devise.provider_data"]["info"]["gender"]
q.phone = info["phone_number"]
q.level_of_study = info["level_of_study"]
q.major = info["major"]
q.date_of_birth = info["date_of_birth"]
q.gender = info["gender"]

school = School.where(name: session["devise.provider_data"]["info"]["school"]["name"]).first_or_create do |s|
s.name = session["devise.provider_data"]["info"]["school"]["name"]
Expand Down Expand Up @@ -116,7 +115,7 @@ def schools

def questionnaire_params
params.require(:questionnaire).permit(
:email, :experience, :first_name, :last_name, :gender,
:email, :experience, :gender,
:date_of_birth, :interest, :school_id, :school_name, :major, :level_of_study,
:shirt_size, :dietary_restrictions, :special_needs, :international,
:portfolio_url, :vcs_url, :agreement_accepted, :bus_captain_interest,
Expand Down
25 changes: 13 additions & 12 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Users::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
before_action :configure_sign_up_params, only: [:create]
before_action :configure_account_update_params, only: [:update]

# GET /resource/sign_up
def new
Expand Down Expand Up @@ -28,6 +28,17 @@ def destroy
super
end

# Permit adding custom parameters for sign up
# (Devise gives us email and password by default, but we want some more.)
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
end

# Permit updating custom parameters for sign up
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name])
end

# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
Expand All @@ -39,16 +50,6 @@ def destroy

# protected

# You can put the params you want to permit in the empty array.
# def configure_sign_up_params
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end

# You can put the params you want to permit in the empty array.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end

# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
Expand Down
Loading