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 11 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
59 changes: 56 additions & 3 deletions app/assets/javascripts/manage/lib/setupDataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var setupDataTables = function () {
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: 'role' },
{ orderable: true, data: 'active' },
Expand Down Expand Up @@ -75,8 +77,59 @@ var setupDataTables = function () {
],
});

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

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

$('.datatable.stats-notscooltravel').DataTable({
columns: [
{ orderable: true, data: 'questionnaire_link' },
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'travel_location' },
{ orderable: true, data: 'acc_status' }
]
});

$('.datatable.stats-attendeeinfo').DataTable({
columns: [
{ 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({
columns: [
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ orderable: true, data: 'school_name' }
]
});

$('.datatable.stats-mlhinfo-checkedin').DataTable({
columns: [
{ orderable: true, data: 'first_name' },
{ orderable: true, data: 'last_name' },
{ orderable: true, data: 'email' },
{ 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
184 changes: 101 additions & 83 deletions app/controllers/manage/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,125 +4,143 @@ def index

def dietary_special_needs
data = Rails.cache.fetch(cache_key_for_questionnaires("dietary_special_needs")) do
select_attributes = [
:first_name,
:last_name,

peterkos marked this conversation as resolved.
Show resolved Hide resolved
# Condition: only retrieve users that have dietary restrictions or special dietary needs
restrictions = "acc_status = 'rsvp_confirmed' AND "\
"dietary_restrictions != '' OR special_needs != ''"

# Filter for the values we want to show to the model
q_attributes = [
:major,
: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
:gender
]
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

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) : '') }
# Generate a full "request" (relation) based on this
q_request = Questionnaire.where(restrictions)
q_json = q_request.select(q_attributes).as_json

for i in 0..q_request.count - 1
peterkos marked this conversation as resolved.
Show resolved Hide resolved
q_json[i]["first_name"] = q_request[i].user.first_name
q_json[i]["last_name"] = q_request[i].user.last_name
q_json[i]["email"] = q_request[i].user.email
end

q_json
end

# Finally, render it out
render json: { data: data }
end

def alt_travel
data = Rails.cache.fetch(cache_key_for_questionnaires("alt_travel")) do
select_attributes = [

peterkos marked this conversation as resolved.
Show resolved Hide resolved
# User info is taken from user model, not from questionnaire query
q_attributes = [
:id,
:first_name,
:last_name,
:travel_location,
:acc_status,
:user_id,
:school_id
:acc_status
]
json_attributes = [

restrictions = "travel_not_from_school = '1'"

q_request = Questionnaire.where(restrictions)
q_json = q_request.select(q_attributes).as_json

for i in 0..q_request.count - 1
peterkos marked this conversation as resolved.
Show resolved Hide resolved
q_json[i]["first_name"] = q_request[i].user.first_name
q_json[i]["last_name"] = q_request[i].user.last_name
q_json[i]["email"] = q_request[i].user.email
q_json[i]["questionnaire_link"] = view_context.link_to("View »".html_safe, manage_questionnaire_path(q_request[i]))
end

q_json
end
render json: { data: data }
end


peterkos marked this conversation as resolved.
Show resolved Hide resolved
def sponsor_info
peterkos marked this conversation as resolved.
Show resolved Hide resolved
data = Rails.cache.fetch(cache_key_for_questionnaires("sponsor_info")) do

peterkos marked this conversation as resolved.
Show resolved Hide resolved
# User info is taken from user model, not from questionnaire query
# (also school name)
q_attributes = [
:id,
:first_name,
:last_name,
:email,
:travel_location,
:acc_status
:vcs_url,
:portfolio_url
]
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 »".html_safe, manage_questionnaire_path(e[0]))

restrictions = "can_share_info = '1' AND checked_in_at != 0"

q_request = Questionnaire.where(restrictions)
q_json = q_request.select(q_attributes).as_json

for i in 0..q_request.count - 1
peterkos marked this conversation as resolved.
Show resolved Hide resolved
q_json[i]["first_name"] = q_request[i].user.first_name
q_json[i]["last_name"] = q_request[i].user.last_name
q_json[i]["email"] = q_request[i].user.email
q_json[i]["school_name"] = q_request[i].school_name
end

q_json
end
render json: { data: data }
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

peterkos marked this conversation as resolved.
Show resolved Hide resolved
# User info is taken from user model, not from questionnaire query
# (also school name)
q_attributes = [
:id
]
data = Questionnaire.joins(:school).select(select_attributes)
to_json_array(data, json_attributes)

q_request = Questionnaire.joins(:school)
q_json = q_request.select(q_attributes).as_json

for i in 0..q_request.count - 1
peterkos marked this conversation as resolved.
Show resolved Hide resolved
q_json[i]["first_name"] = q_request[i].user.first_name
q_json[i]["last_name"] = q_request[i].user.last_name
q_json[i]["email"] = q_request[i].user.email
q_json[i]["school_name"] = q_request[i].school_name
end

q_json
end
render json: { data: data }
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
# User info is taken from user model, not from questionnaire query
# (also school name)
q_attributes = [
: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)

restrictions = "checked_in_at > 0"

q_request = Questionnaire.joins(:school).where(restrictions)
q_json = q_request.select(q_attributes).as_json

for i in 0..q_request.count - 1
peterkos marked this conversation as resolved.
Show resolved Hide resolved
q_json[i]["first_name"] = q_request[i].user.first_name
q_json[i]["last_name"] = q_request[i].user.last_name
q_json[i]["email"] = q_request[i].user.email
q_json[i]["school_name"] = q_request[i].school_name
end

q_json
end
render json: { data: data }
end


private

def to_json_array(data, attributes)
Expand Down
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
4 changes: 1 addition & 3 deletions app/controllers/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def new
if session["devise.provider_data"] && 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"]
Expand Down Expand Up @@ -119,7 +117,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
Loading