Permalink
Browse files

Course Optimizations

 * really optimized the controller find()s
 * tweaked the views a bit to clean them up and make them more pretty
  • Loading branch information...
1 parent 2d3559a commit 0244803f332e248595304ef6af7bff98574ef429 @rnhurt committed Jan 13, 2010
@@ -10,9 +10,11 @@ def new
end
def edit
- @course = Course.find(params[:id])
+ @course = Course.find(params[:id], :include => [:enrollments, :students])
+ @course_terms = CourseTerm.find_all_by_course_id(@course,
+ :include => [:supporting_skills, :term], :order => "date_ranges.end_date")
@homerooms = Student.find_homerooms()
- @skill_cats = SupportingSkillCategory.active
+ @skill_cats = SupportingSkillCategory.active.all( :include => :supporting_skills )
respond_to do |format|
format.html
@@ -32,7 +34,8 @@ def edit
render :partial => "student_list"
}
- end end
+ end
+ end
def create
@course = Course.new(params[:course])
@@ -1,42 +1,37 @@
-<%# FIXME: This is completely yucky and should be pretty easy to clean up. %>
-<% students = @course.students.sort_by &:last_name if @course %>
-<% students ||= [] %>
-<% enrollments = @course.enrollments %>
+<table class='master'>
+ <thead>
+ <tr>
+ <th width='1px'><acronym title="This student has an accommodation in this course">Acm?</acronym></th>
+ <th colspan='0'>Enrolled Students (<%= @course.enrollments.size %>)</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% if @course.enrollments.blank? %>
+ <tr class='help'><td colspan='0'>Add students to this course from the list of students &nbsp;--></td></tr>
+ <% else %>
+ <% @course.enrollments.sort_by{|e| e.student.last_name}.each do |enrollment| %>
+ <tr class="<%= cycle('odd', 'even') %>" id="<%= enrollment.student.id %>">
+ <td>
+ <%= check_box_tag enrollment.id, enrollment.id, enrollment.accommodation,
+ :onclick => remote_function(
+ :url => { :action => :toggle_accommodation, :id => enrollment.id },
+ :loading => "Element.show('spinner')",
+ :complete => "Element.hide('spinner')" ) %>
+ </td>
+ <%= content_tag :td, enrollment.student.full_name %>
+ <td>
+ <% form_remote_tag :url => { :action => 'remove_student', :student_id => enrollment.student.id },
+ :method => :delete,
+ :confirm => "Are you sure you want to remove this '#{enrollment.student.full_name}' from this course?",
+ :loading => "Element.show('spinner')",
+ :complete => "Element.hide('spinner')" do %>
+ <%= submit_tag 'Remove', :class => 'smallbtn negative' %>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ <% end %>
+ </tbody>
+</table>
- <table class='master'>
- <thead>
- <tr>
- <th width='1px'><acronym title="This student has an accommodation in this course">Acm?</acronym></th>
- <th colspan='0'>Enrolled Students (<%= enrollments.size %>)</th>
- </tr>
- </thead>
- <tbody>
- <% if enrollments.blank? %>
- <tr class='help'><td colspan='0'>Add students to this course from the list of students &nbsp;--></td></tr>
- <% else %>
- <% for enrollment in enrollments %>
- <tr class="<%= cycle('odd', 'even') %>" id="<%= enrollment.student.id %>">
- <td>
- <%= check_box_tag enrollment.id, enrollment.id, enrollment.accommodation,
- :onclick => remote_function(
- :url => { :action => :toggle_accommodation, :id => enrollment.id },
- :loading => "Element.show('spinner')",
- :complete => "Element.hide('spinner')" ) %>
- </td>
- <%= content_tag :td, enrollment.student.full_name %>
- <td>
- <% form_remote_tag :url => { :action => 'remove_student', :student_id => enrollment.student.id },
- :method => :delete,
- :confirm => "Are you sure you want to remove this '#{enrollment.student.full_name}' from this course?",
- :loading => "Element.show('spinner')",
- :complete => "Element.hide('spinner')" do %>
- <%= submit_tag 'Remove', :class => 'smallbtn negative' %>
- <% end %>
- </td>
- </tr>
- <% end %>
- <% end %>
- </tbody>
- </table>
-
@@ -1,8 +1,8 @@
<div class="box span-14 last">
<ul class="checklist">
- <% for category in @skill_cats %>
+ <% @skill_cats.each do |category| %>
<%= content_tag :li, category.name, :class=>"category" %>
- <% for skill in category.supporting_skills.active %>
+ <% category.supporting_skills.each do |skill| %>
<li>
<label for="<%= "#{skill.id}-#{course_term.id}" -%>">
<%= check_box_tag skill.id, "1", course_term.supporting_skills.include?(skill),
@@ -12,7 +12,6 @@
:action => "update"
), :id => "#{skill.id}-#{course_term.id}" %>
<%= h skill.description %>
- <%#= debug course_term %>
</label>
</li>
<% end %>
@@ -1,31 +1,31 @@
<% params[:value] ||= '||Students' %>
- <table id='students' class='master'>
- <thead>
- <th>
- <%= params[:value].split('||')[1] %> <%= "(#{@students.length})" unless @students.blank? %></th>
- <th><%= link_to_remote( "Add All",
- {:url => { :action => 'add_student', :students => @students },
- :loading => "Element.show('spinner')",
- :complete => "Element.hide('spinner')"},
- {:class => 'btn sml positive'}) unless @students.blank? %>
- </th>
- </thead>
- <tbody>
- <% if @students.blank? %>
- <tr class='help'><td colspan='0'>Choose from a <br /><em>'Class Of'</em><br /> or a <br /><em>'Home Room'</em><br /> above.</td></tr>
- <% else %>
- <% students = @students.sort_by &:last_name %>
- <% for student in students %>
- <tr class="<%= cycle('odd', 'even') %>">
- <td colspan='2'><%= link_to_remote student.full_name,
- :url => { :action => 'add_student', :student_id => student.id },
- :loading => "Element.show('spinner')",
- :complete => "Element.hide('spinner')"
- %></td>
- </tr>
- <% end %>
- <% end %>
- </tbody>
- </table>
+<table id='students' class='master'>
+ <thead>
+ <th>
+ <%= params[:value].split('||')[1] %> <%= "(#{@students.length})" unless @students.blank? %></th>
+ <th><%= link_to_remote( "Add All",
+ {:url => { :action => 'add_student', :students => @students },
+ :loading => "Element.show('spinner')",
+ :complete => "Element.hide('spinner')"},
+ {:class => 'btn sml positive'}) unless @students.blank? %>
+ </th>
+</thead>
+<tbody>
+ <% if @students.blank? %>
+ <tr class='help'><td colspan='0'>Choose from a <br /><em>'Class Of'</em><br /> or a <br /><em>'Home Room'</em><br /> above.</td></tr>
+ <% else %>
+ <% students = @students.sort_by &:last_name %>
+ <% for student in students %>
+ <tr class="<%= cycle('odd', 'even') %>">
+ <td colspan='2'><%= link_to_remote student.full_name,
+ :url => { :action => 'add_student', :student_id => student.id },
+ :loading => "Element.show('spinner')",
+ :complete => "Element.hide('spinner')"
+ %></td>
+ </tr>
+ <% end %>
+ <% end %>
+</tbody>
+</table>
@@ -5,7 +5,6 @@
<%= error_messages_for :course, :header_message => "Please Try Again!", :message => "We had some problems saving your changes:" %>
<div class='box span-14'>
-<%# form_for( @course, :url => {}, :html => {:id => 'edit_course'} ) do |f| %>
<% form_for @course do |f| %>
<fieldset>
<%= f.label :name, {}, :class => 'req' %>
@@ -22,28 +21,22 @@
<%= submit_tag 'Save', :class=> 'btn positive' %>
<%= link_to 'Cancel', courses_path, :class => 'btn standard' %>
<%= button_to 'Delete Course', @course,
- :method => :delete,
- # :disabled => !@course.course_terms.assignments.empty?,
- # :class => "btn negative " + (@course.assignments.empty? ? '' : 'disabled'),
- :class => "btn negative",
+ :method => :delete, :class => "btn negative",
:confirm => "Are you sure you want to delete the '#{@course.name}' course?" %>
</div>
</fieldset>
-<%#= observe_form "edit_course_#{@course.id}", :url => {:action => :update} %>
</div>
<div id="students"><%= render :partial => "students_tab" %></div>
-<% @course.course_terms.sort!{ |a,b| a.term.end_date <=> b.term.end_date } %>
-
<ul id="course_tabs" class="subsection_tabs">
- <% @course.course_terms.each do |course_term| %>
+ <% @course_terms.each do |course_term| %>
<li class="tab"><%= link_to course_term.term.name, "\##{course_term.term.name}" %></li>
<% end %>
</ul>
-<% @course.course_terms.each do |course_term| %>
+<% @course_terms.each do |course_term| %>
<div id="<%= course_term.term.name %>">
<%= render :partial => "skills_tab", :locals => {:course_term => course_term} %>
</div>

0 comments on commit 0244803

Please sign in to comment.