Skip to content
This repository has been archived by the owner on Dec 10, 2017. It is now read-only.

Commit

Permalink
tried to clean up controller for candidate portal
Browse files Browse the repository at this point in the history
  • Loading branch information
kacasey8 committed Jan 16, 2014
1 parent 92dda97 commit 3c12f42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions app/controllers/candidate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/candidate/portal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<h2>Important Information</h2>
[Coming Soon]

<h2>Additional Forms</h2>
[Coming Soon]
</div>
Expand All @@ -26,7 +26,7 @@

<div id="checklist" style="float:left">
<h2>Checklist</h2>

<div style="float:left; width: 45%;">
<h3>
<span class="<%= "req_status " + (@done["events"] ? "status_done" : "status_notdone") %>"></span>
Expand Down

0 comments on commit 3c12f42

Please sign in to comment.