diff --git a/app/controllers/candidate_controller.rb b/app/controllers/candidate_controller.rb index bb9de97..bf63951 100644 --- a/app/controllers/candidate_controller.rb +++ b/app/controllers/candidate_controller.rb @@ -9,6 +9,14 @@ def is_candidate? end def portal + @events = Event.with_permission(current_user).where('end_time >= ? AND end_time <= ?', Time.now, Time.now + 7.days).order(:start_time) + @challenges = Challenge.where(candidate_id: current_user.id) + @announcements = Announcement.all.limit(10) + set_up_status_and_my_events + set_up_done + end + + def set_up_status_and_my_events req = Hash.new { |h,k| 0 } req["Mandatory for Candidates"] = 3 req["Fun"] = 3 @@ -17,14 +25,14 @@ def portal @my_events = current_user.events.group_by(&:event_type) @my_confirmed_events = current_user.events.joins(:rsvps).where('rsvps.confirmed = ?', 't').group_by(&:event_type) @status = {} - req.each do |x, y| - @my_events[x] ||= [] - @my_confirmed_events[x] ||= [] - @status[x] = (@my_confirmed_events[x].count >= y) + req.each do |event_type, count_required| + @my_events[event_type] ||= [] + @my_confirmed_events[event_type] ||= [] # prevent nil exceptions + @status[event_type] = (@my_confirmed_events[event_type].count >= count_required) end - @events = Event.with_permission(current_user).where('end_time >= ? AND end_time <= ?', Time.now, Time.now + 7.days).order(:start_time) - @challenges = Challenge.where(candidate_id: current_user.id) - @announcements = Announcement.all.limit(10) + end + + def set_up_done @done = Hash.new(false) @done["events"] = !@status.has_value?(false) @done["challenges"] = @challenges.where(confirmed: true).count >= 5 diff --git a/app/views/candidate/portal.html.erb b/app/views/candidate/portal.html.erb index 238377b..342ddb9 100644 --- a/app/views/candidate/portal.html.erb +++ b/app/views/candidate/portal.html.erb @@ -4,7 +4,7 @@