Skip to content

Commit

Permalink
hound fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
differentreality committed Jun 30, 2014
1 parent e8990bf commit fc75328
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 144 deletions.
6 changes: 4 additions & 2 deletions app/controllers/admin/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class RegistrationsController < ApplicationController
def index
session[:return_to] ||= request.referer
@pdf_filename = "#{@conference.title}.pdf"
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
@registrations = @conference.registrations.includes(:user)
@registrations = @registrations.order('registrations.created_at ASC')
@attended = @conference.registrations.where('attended = ?', true).count
@headers = %w(name email nickname other_needs arrival departure attended)
end
Expand Down Expand Up @@ -36,7 +37,8 @@ def update
@user.update_attributes!(params[:registration][:user_attributes])
params[:registration].delete :user_attributes
if params[:registration][:supporter_registration]
@registration.supporter_registration.update_attributes(params[:registration][:supporter_registration_attributes])
@registration.supporter_registration.
update_attributes(params[:registration][:supporter_registration_attributes])
params[:registration].delete :supporter_registration_attributes
end
@registration.update_attributes!(params[:registration])
Expand Down
73 changes: 46 additions & 27 deletions app/controllers/admin/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ class StatsController < ApplicationController
before_filter :verify_organizer

def index
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
@registrations = @conference.registrations.includes(:user)
@registrations = @registrations.order('registrations.created_at ASC')
@registered = @conference.registrations.count
@attendees = @conference.registrations.where('attended = ?', true).count
@pre_registered = @conference.registrations.where('created_at < ?', @conference.start_date).count
@pre_registered_attended = @conference.registrations.where('created_at < ? AND attended = ?', @conference.start_date, true).count
@pre_registered = @conference.registrations
@pre_registered = @pre_registered.where('created_at < ?', @conference.start_date).count
@pre_registered_attended = @conference.registrations.where('created_at < ? AND attended = ?',
@conference.start_date, true).count

@registered_with_partner = @conference.registrations.where('attending_with_partner = ?', true).count
@attended_with_partner = @conference.registrations.where('attending_with_partner = ? AND attended = ?', true, true).count
@registered_with_partner = @conference.registrations.where('attending_with_partner = ?',
true).count
@attended_with_partner = @conference.registrations.where(
'attending_with_partner = ? AND attended = ?', true, true).count

@handicapped_access = @conference.registrations.where(handicapped_access_required: true).count
@handicapped_access_attended = @conference.registrations.where(handicapped_access_required: true)
@handicapped_access_attended = @conference.registrations.where(handicapped_access_required:
true)
@handicapped_access_attended = @handicapped_access_attended.where(attended: true).count
@suggested_hotel_stay = @conference.registrations.where('using_affiliated_lodging = ?', true).count
@suggested_hotel_stay = @conference.registrations.where('using_affiliated_lodging = ?',
true).count

@events = @conference.events
# Events charts
@machine_states = [['confirmed'], ['cancelled'], ['rejected'], ['withdrawn'], ['new', 'review'], ['unconfirmed', 'accepted']]
@machine_states = [['confirmed'], ['cancelled'], ['rejected'], ['withdrawn'],
['new', 'review'], ['unconfirmed', 'accepted']]
# Types distribution per state
@type_state = {}
@machine_states.each do |state|
Expand All @@ -40,7 +48,7 @@ def index
if @events.count > 0
start_date = @events.minimum('created_at').strftime('%Y-%m-%d')
end_date = @events.maximum('created_at').strftime('%Y-%m-%d')
if start_date != nil && end_date != nil
unless start_date == nil || end_date == nil
@events_time = var_time(start_date, end_date, @events, 'created_at')
end
end
Expand Down Expand Up @@ -79,16 +87,22 @@ def index
typelength += myevent.event_type.length
@totallength += myevent.event_type.length
end
@eventstats[mytype.title] = { 'count' => events_mytype.count, 'length' => events_mytype.count * mytype.length } if @eventstats[mytype.title] == nil
tmp = { "#{mystate.name}" => { 'type_state_count' => events_mytype_mystate.count, 'type_state_length' => typelength } }
if @eventstats[mytype.title] == nil
@eventstats[mytype.title] = { 'count' => events_mytype.count,
'length' => events_mytype.count * mytype.length }
end

tmp = { "#{mystate.name}" => { 'type_state_count' => events_mytype_mystate.count,
'type_state_length' => typelength } }
@eventstats[mytype.title].merge!(tmp)
end
end
end
@eventstats['totallength'] = @totallength

# SPEAKERS stats
@speakers = User.joins(:events).where('events.conference_id = ? AND events.state LIKE ?', @conference.id, 'confirmed').uniq
@speakers = User.joins(:events).where('events.conference_id = ? AND events.state LIKE ?',
@conference.id, 'confirmed').uniq
@speaker_fields_user = %w(name email affiliation)
@speaker_fields_reg = %w(arrival departure)
# TICKETS stats
Expand All @@ -98,7 +112,7 @@ def index

@tickets_time = []

if @conference.registration_start_date and @conference.end_date and @registered > 0 and @supporter_levels
if @conference.registration_start_date && @conference.end_date && @registered > 0 && @supporter_levels
start_date = @conference.registration_start_date
end_date = @conference.end_date
levels = []
Expand All @@ -108,10 +122,13 @@ def index
end

(start_date..end_date).each do |day|
if @tickets.where('supporter_registrations.created_at LIKE ?', "%#{day}%").where('supporter_levels.title' => levels).count != 0
if @tickets.where('supporter_registrations.created_at LIKE ?', "%#{day}%").where(
'supporter_levels.title' => levels).count != 0
@conference.supporter_levels.each do |level|

day_ticket_count = @tickets.where('supporter_registrations.created_at LIKE ? AND supporter_levels.title LIKE ?', "%#{day}%", "%#{level.title}%").count
day_ticket_count = @tickets.where('supporter_registrations.created_at LIKE ?
AND supporter_levels.title LIKE ?',
"%#{day}%", "%#{level.title}%").count

index = @tickets_time.index { |v| v['key'] == "#{level.title}" }
@tickets_time[index]['values'] << { 'label' => "#{day}", 'value' => day_ticket_count }
Expand All @@ -123,7 +140,8 @@ def index
@tickets_time.each do |ticket|
value = ticket['values'].map { |x| x['value'] }.sum
percent = (value.to_f / @tickets.count * 100).round(2)
@tickets_distribution << { 'status' => ticket['key'], 'value' => value, 'percent' => percent }
@tickets_distribution << { 'status' => ticket['key'],
'value' => value, 'percent' => percent }
end

# OTHER_INFO chart / To be 'Questions'
Expand All @@ -136,7 +154,7 @@ def index
]

# REGISTRATIONS, registered_time
if @conference.registration_start_date and @conference.end_date and @registered > 0
if @conference.registration_start_date && @conference.end_date && @registered > 0
start_date = @conference.registration_start_date
end_date = @conference.end_date
@registered_time = var_time(start_date, end_date, @registrations, 'created_at')
Expand All @@ -156,39 +174,39 @@ def var_time(start_date, end_date, var, field)
result << { 'status' => "#{day}", 'value' => day_var_count }
end
end
return result
result
end

def var_state_func(vars, field, mystate)
result = []

for myvar in vars do
vars.each do |myvar|
# Find events per track and state
value = @conference.events.where("#{field}_id" => myvar.id).where(state: mystate).count
# Find all events in that state
total = @conference.events.where(state: mystate).count
status = "#{myvar.name}"

percent = 0
if value != 0
percent = (value.to_f / total * 100).round(2)
result << { 'status' => status, 'value' => value, 'percent' => percent }
else
percent = 0
end
end
# Get no of events for which the field is not set (Needed so that the pie shows half piece for 50%)
sum = result.inject(0) { |sum, hash| sum + hash['value'] }
value = total - sum if total and sum
# Get no of events for which the field is not set (So that pie shows half piece for 50%)
sum = result.inject(0) { |s, hash| s + hash['value'] }
value = total - sum
if sum != 0 && value != 0
percent = (value.to_f / total * 100).round(2)
result << { 'status' => "no #{field} set", 'value' => value, 'percent' => percent }
end

return result
result
end

def speaker_reg(speaker)
speaker.registrations.where('conference_id = ? AND user_id = ?', @conference.id, speaker.id).first
speaker.registrations.where('conference_id = ? AND user_id = ?',
@conference.id, speaker.id).first
end

def speaker_diet(reg)
Expand All @@ -200,7 +218,8 @@ def diet_count(diet)
end

def social_event_count(event)
@conference.registrations.joins(:social_events).where('registrations_social_events.social_event_id = ?', event).count
@conference.registrations.joins(:social_events).where(
'registrations_social_events.social_event_id = ?', event).count
end

helper_method :speaker_reg
Expand Down
18 changes: 11 additions & 7 deletions app/controllers/api/v1/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class Api::V1::EventsController < Api::BaseController
respond_to :json
module Api
module V1
class EventsController < Api::BaseController
respond_to :json

def index
events = Event.includes(:conference, :track, :room, :event_type, {:event_user => :user})
unless params[:conference_id].blank?
events = events.where("conferences.guid" => params[:conference_id])
def index
events = Event.includes(:conference, :track, :room, :event_type, event_user: :user)
unless params[:conference_id].blank?
events = events.where('conferences.guid' => params[:conference_id])
end
respond_with events.confirmed
end
end
respond_with events.confirmed
end
end
24 changes: 14 additions & 10 deletions app/controllers/api/v1/speakers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
class Api::V1::SpeakersController < Api::BaseController
respond_to :json
module Api
module V1
class SpeakersController < Api::BaseController
respond_to :json

def index
if params[:conference_id].blank?
people = User.joins(:event_users)
else
people = User.joins(:event_users => {:event => :conference})
people = people.where("conferences.guid" => params[:conference_id])
def index
if params[:conference_id].blank?
users = User.joins(:event_users)
else
users = User.joins(event_users: { event: :conference })
users = users.where('conferences.guid' => params[:conference_id])
end
users = users.where('event_users.event_role' => 'speaker')
render json: users, each_serializer: SpeakerSerializer
end
end
people = people.where("event_users.event_role" => "speaker")
render :json => users, :each_serializer => SpeakerSerializer
end
end
44 changes: 26 additions & 18 deletions app/controllers/conference_registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,40 @@ class ConferenceRegistrationController < ApplicationController
def register
# TODO Figure out how to change the route's id from :id to :conference_id
@conference = Conference.find_by(short_title: params[:id])
@workshops = @conference.events.where("require_registration = ? AND state LIKE ?", true, 'confirmed')
@workshops = @conference.events.where('require_registration = ? AND state LIKE ?',
true, 'confirmed')
@user = current_user

@registration = @user.registrations.where(:conference_id => @conference.id).first
@registration = @user.registrations.where(conference_id: @conference.id).first
@registered = true
if @registration.nil?
@registered = false
@registration = @user.registrations.new(:conference_id => @conference.id)
@registration = @user.registrations.new(conference_id: @conference.id)
end

# Check if there's an existing SupporterRegistration for this email and link it when appropriate
@registration.supporter_registration ||= @conference.supporter_registrations.where(:email => @user.email).first
@registration.supporter_registration ||= SupporterRegistration.new(:conference_id => @conference.id)
@registration.supporter_registration ||= @conference.supporter_registrations.where(
email: @user.email).first
@registration.supporter_registration ||= SupporterRegistration.new(conference_id: @conference.id)
end

# TODO this is ugly
def update
conference = Conference.find_by(short_title: params[:id])
user = current_user
registration = user.registrations.where(:conference_id => conference.id).first
registration = user.registrations.where(conference_id: conference.id).first
update_registration = true
# First verify that the supporter code is legit
if !params[:registration][:supporter_registration_attributes].nil? && !params[:registration][:supporter_registration_attributes][:code].empty?
regs = conference.supporter_registrations.where(:code => params[:registration][:supporter_registration_attributes][:code])
if !params[:registration][:supporter_registration_attributes].nil? &&
!params[:registration][:supporter_registration_attributes][:code].empty?
regs = conference.supporter_registrations.where(
code: params[:registration][:supporter_registration_attributes][:code])

if regs.count != 0
if regs.where(:email => user.email).count == 0
redirect_to(register_conference_path(:id => conference.short_title), :alert => "This code is already in use. Please contact #{conference.contact_email} for assistance.")
if regs.where(email: user.email).count == 0
redirect_to(register_conference_path(id: conference.short_title),
alert: "This code is already in use.
Please contact #{conference.contact_email} for assistance.")
return
end
end
Expand All @@ -46,10 +52,10 @@ def update
registration = user.registrations.new(registration_params)
if conference.use_supporter_levels? && !supporter_reg.nil?
if !supporter_reg[:id].blank?
# This means that their supporter registration was entered ahead of time, probably by an admin
# Means that their supporter registration was entered ahead of time, by an admin
registration.supporter_registration = SupporterRegistration.find(supporter_reg[:id])
if registration.supporter_registration.email != user.email
raise "Invalid code"
raise 'Invalid code'
end
else
registration.supporter_registration = conference.
Expand All @@ -63,28 +69,30 @@ def update
registration.update_attributes!(registration_params)
end
rescue Exception => e
Rails.logger.debug e.backtrace.join("\n")
redirect_to(register_conference_path(:id => conference.short_title), :alert => 'Registration failed:' + e.message)
Rails.logger.debug e.backtrace.join('\n')
redirect_to(register_conference_path(id: conference.short_title),
alert: 'Registration failed:' + e.message)
return
end

redirect_message = "You are now registered."
redirect_message = 'You are now registered.'
if update_registration
redirect_message = "Registration updated."
redirect_message = 'Registration updated.'
else
# Track ahoy event
ahoy.track 'Registered', title: 'New registration'
if conference.email_settings.send_on_registration?
Mailbot.registration_mail(conference, current_user).deliver
end
end
redirect_to(register_conference_path(:id => conference.short_title), :notice => redirect_message)
redirect_to(register_conference_path(id: conference.short_title),
notice: redirect_message)
end

def unregister
conference = Conference.find_by(short_title: params[:id])
user = current_user
registration = user.registrations.where(:conference_id => conference.id).first
registration = user.registrations.where(conference_id: conference.id).first
registration.destroy
redirect_to :root
end
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def edit
end

def update
@openids = Openid.where(user_id: current_user.id).order(:provider)
@user = User.find(current_user.id)
email_changed = false

Expand All @@ -20,14 +21,14 @@ def update
password_changed = false
if !params[:user][:password].nil?
if !params[:user][:password].empty?
password_changed = true
password_changed = true
else
params[:user].delete :password
params[:user].delete :password_confirmation
end
end

if email_changed or password_changed
if email_changed || password_changed
successfully_updated = @user.update_with_password(account_update_params)
else
params[:user].delete :current_password
Expand All @@ -36,7 +37,7 @@ def update

if successfully_updated
if email_changed
if !@user.nil?
unless @user.nil?
@user.update_attribute('email', params[:user][:email])
end
set_flash_message :notice, :update_needs_confirmation
Expand Down Expand Up @@ -66,7 +67,8 @@ def after_sign_up_path_for(resource)
def configure_permitted_parameters
devise_parameter_sanitizer.for(:account_update) do |u|
u.
permit(:email, :password, :password_confirmation, :current_password, :name, :biography)
permit(:email, :password, :password_confirmation, :current_password, :name, :biography,
:nickname, :affiliation)
end
devise_parameter_sanitizer.for(:sign_up) do |u|
u.
Expand Down
Loading

0 comments on commit fc75328

Please sign in to comment.