Skip to content

Commit

Permalink
lml#341: Add sidebar nav for assignment exercises.
Browse files Browse the repository at this point in the history
- Add link to the class.
- Add link to the assignment.
- Add a helper class for getting previous and next assignments.
- Add prev / next links in nav.
  • Loading branch information
navilan committed May 20, 2014
1 parent b75051b commit 31283a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/helpers/assignment_exercise_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2011-2014 Rice University. Licensed under the Affero General Public
# License version 3 or later. See the COPYRIGHT file for details.

module AssignmentExerciseHelper

def assignment_exercise_index(assignment_exercise)
assignment_exercise.number - 1
end

def prev_assignment_exercise(assignment_exercise)
index = assignment_exercise_index(assignment_exercise)
if index > 0
assignment_exercise.assignment.assignment_exercises[index-1]
end
end

def next_assignment_exercise(assignment_exercise)
index = assignment_exercise_index(assignment_exercise)
if index < assignment_exercise.assignment.assignment_exercises.count - 1
assignment_exercise.assignment.assignment_exercises[index+1]
end
end

end
15 changes: 14 additions & 1 deletion app/views/assignment_exercises/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</tr>
<thead>
<tbody>
<% all_responses.each_with_index do |se,ii| %>
<% all_responses.each_with_index do |se, ii| %>
<% student = se.student_assignment.student %>
<tr>
<td>
Expand Down Expand Up @@ -72,3 +72,16 @@
</tbody>
</table>
<% end %>

<% prev_ae = prev_assignment_exercise(@assignment_exercise) %>
<% next_ae = next_assignment_exercise(@assignment_exercise) %>
<%
navitem { link_to "Go to Assignment", assignment_path(@assignment_exercise.assignment) }
navitem { link_to "Go to Class", klass_path(@assignment_exercise.assignment.klass) }
if !prev_ae.nil?
navitem { link_to_if !prev_ae.nil?, "Previous Exercise", assignment_exercise_path(prev_ae) }
end
if !next_ae.nil?
navitem { link_to_if !next_ae.nil?, "Next Exercise", assignment_exercise_path(next_ae) }
end
%>

0 comments on commit 31283a5

Please sign in to comment.