arel-ify views and presenters
refs CNVS-4706 Change-Id: I49ef0a651d68de26bb0522d942bec499c300cec1 Reviewed-on: https://gerrit.instructure.com/18701 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
e149fae7bc
commit
6ff362720e
|
@ -89,7 +89,7 @@ class GradeSummaryPresenter
|
|||
def assignments
|
||||
@assignments ||= begin
|
||||
scope = @context.assignments.active.gradeable
|
||||
array = scope.find(:all, :include => [:assignment_overrides]).collect{|a| a.overridden_for(student)}.sort
|
||||
array = scope.includes(:assignment_overrides).collect{|a| a.overridden_for(student)}.sort
|
||||
# pre-cache the assignment group for each assignment object
|
||||
group_index = groups.index_by(&:id)
|
||||
array.each{ |a| a.assignment_group = group_index[a.assignment_group_id] }
|
||||
|
@ -99,7 +99,7 @@ class GradeSummaryPresenter
|
|||
|
||||
def submissions
|
||||
@submissions ||= @context.submissions.
|
||||
scoped(:include => %w(submission_comments rubric_assessments assignment)).
|
||||
includes(:submission_comments, :rubric_assessments, :assignment).
|
||||
find_all_by_user_id(student)
|
||||
end
|
||||
|
||||
|
@ -109,7 +109,7 @@ class GradeSummaryPresenter
|
|||
# Yes, fetch *all* submissions for this course; otherwise the view will end up doing a query for each
|
||||
# assignment in order to calculate grade distributions
|
||||
@context.submissions.
|
||||
all(:select => "submissions.assignment_id, submissions.score, submissions.grade, submissions.quiz_submission_id").
|
||||
select([:assignment_id, :score, :grade, :quiz_submission_id]).
|
||||
group_by(&:assignment_id)
|
||||
else
|
||||
{}
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
<% if context.respond_to?("assignments") %>
|
||||
<a href="<%= context_url(context, :context_assignments_url) %>" class="<%= context.class.to_s.downcase %>_<%= context.id %>_add_assignment_url"> </a>
|
||||
<a href="<%= context_url(context, :context_assignment_url, "{{ id }}") %>" class="<%= context.class.to_s.downcase %>_<%= context.id %>_assignment_url"> </a>
|
||||
<%= select :assignment, :assignment_group_id, (context.assignment_groups.active.scoped(:select => "id, name").map {|g| [g.name, g.id]} << [t('options.new_group', "[ New Group ]"), "new"]), {}, {:class => "assignment_group_id #{context.try_rescue(:weight_assignment_groups) ? 'weight' : ''}", :id => "#{ context.class.to_s.downcase }_#{ context.id }_assignment_groups"} %>
|
||||
<%= select :assignment, :assignment_group_id, (context.assignment_groups.active.select("id, name").map {|g| [g.name, g.id]} << [t('options.new_group', "[ New Group ]"), "new"]), {}, {:class => "assignment_group_id #{context.try_rescue(:weight_assignment_groups) ? 'weight' : ''}", :id => "#{ context.class.to_s.downcase }_#{ context.id }_assignment_groups"} %>
|
||||
<a href="<%= context_url(context, :context_assignment_groups_url) %>" class="<%= context.class.to_s.downcase %>_<%= context.id %>_add_assignment_group_url"> </a>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
if @current_user_submissions
|
||||
submission = @current_user_submissions.detect { |s| s.assignment_id == recent_event.id }
|
||||
elsif @current_user
|
||||
submission = @current_user.submissions.scoped(:select => 'id, assignment_id, score, workflow_state', :conditions => { :assignment_id => recent_event.id }).first
|
||||
submission = @current_user.submissions.select([:id, :assignment_id, :score, :workflow_state]).where(:assignment_id => recent_event).first
|
||||
end
|
||||
|
||||
if is_assignment
|
||||
|
|
|
@ -8,15 +8,16 @@
|
|||
<div style="padding: 0 20px;" id="stats">
|
||||
<h2><%= t 'headings.stats', 'Statistics for %{course}', :course => @context.name %></h2>
|
||||
|
||||
<% active_students = @context.participating_students.scoped(:conditions => "enrollments.type != 'StudentViewEnrollment'").enrolled_before(@range_end).length %>
|
||||
<% active_students = @context.participating_students.where("enrollments.type<>'StudentViewEnrollment'").enrolled_before(@range_end).count %>
|
||||
<% inactive_students = @context.student_enrollments.before(@range_end).select{|e| e.invited? }.length %>
|
||||
|
||||
<% total_topics = @context.discussion_topics.active.before(@range_end).count %>
|
||||
<% total_entries = DiscussionEntry.active.scoped(:conditions => {:discussion_topic_id => @context.discussion_topics.active.before(@range_end).map(&:id)}).count %>
|
||||
<% active_topics = @context.discussion_topics.active.before(@range_end).pluck(:id) %>
|
||||
<% total_topics = active_topics.length %>
|
||||
<% total_entries = DiscussionEntry.active.where(:discussion_topic_id => active_topics).count %>
|
||||
<% new_topics = @context.discussion_topics.active.before(@range_end).select{|t| t.created_at > @range_start}.length %>
|
||||
<% new_entries = DiscussionEntry.active.after(@range_start).scoped(:conditions => {:discussion_topic_id => @context.discussion_topics.active.before(@range_end).map(&:id)}).count %>
|
||||
<% new_entries = DiscussionEntry.active.after(@range_start).where(:discussion_topic_id => active_topics).count %>
|
||||
<% new_assignments = @context.assignments.active.before(@range_end).select{|a| a.expects_submission? && a.created_at > @range_start }.length %>
|
||||
<% new_submissions = @context.submissions.before(@range_end).having_submission.scoped(:conditions => ['submitted_at > ?', @range_start]).count %>
|
||||
<% new_submissions = @context.submissions.before(@range_end).having_submission.where('submitted_at > ?', @range_start).count %>
|
||||
<% total_assignments = @context.assignments.active.before(@range_end).select{|a| a.expects_submission? }.length %>
|
||||
<% total_submissions = @context.submissions.before(@range_end).having_submission.count %>
|
||||
|
||||
|
@ -99,23 +100,23 @@
|
|||
<tr>
|
||||
<td><%= t('file_upload', %{File Upload}) %></td>
|
||||
<td><%= @context.assignments.active.before(@range_end).select{|a| a.submission_types.match(/online_upload/) }.length %></td>
|
||||
<td><%= @context.submissions.before(@range_end).scoped(:conditions => {:submission_type => 'online_upload' }).count %></td>
|
||||
<td><%= @context.submissions.before(@range_end).where(:submission_type => 'online_upload').count %></td>
|
||||
</tr><tr>
|
||||
<td><%= t('text_entry', %{Text Entry}) %></td>
|
||||
<td><%= @context.assignments.active.before(@range_end).select{|a| a.submission_types.match(/online_text_entry/) }.length %></td>
|
||||
<td><%= @context.submissions.before(@range_end).scoped(:conditions => {:submission_type => 'online_text_entry' }).count %></td>
|
||||
<td><%= @context.submissions.before(@range_end).where(:submission_type => 'online_text_entry').count %></td>
|
||||
</tr><tr>
|
||||
<td><%= t('website_url', %{Website URL}) %></td>
|
||||
<td><%= @context.assignments.active.before(@range_end).select{|a| a.submission_types.match(/online_url/) }.length %></td>
|
||||
<td><%= @context.submissions.before(@range_end).scoped(:conditions => {:submission_type => 'online_url' }).count %></td>
|
||||
<td><%= @context.submissions.before(@range_end).where(:submission_type => 'online_url').count %></td>
|
||||
</tr><tr>
|
||||
<td><%= t('quiz', %{Quiz}) %></td>
|
||||
<td><%= @context.assignments.active.before(@range_end).select{|a| a.submission_types.match(/online_quiz/) }.length %></td>
|
||||
<td><%= @context.submissions.before(@range_end).scoped(:conditions => {:submission_type => 'online_quiz' }).count %></td>
|
||||
<td><%= @context.submissions.before(@range_end).where(:submission_type => 'online_quiz').count %></td>
|
||||
</tr><tr>
|
||||
<td><%= t('discussion_topic', %{Discussion Topic}) %></td>
|
||||
<td><%= @context.assignments.active.before(@range_end).select{|a| a.submission_types.match(/discussion_topic/) }.length %></td>
|
||||
<td><%= @context.submissions.before(@range_end).scoped(:conditions => {:submission_type => 'discussion_topic' }).count %></td>
|
||||
<td><%= @context.submissions.before(@range_end).where(:submission_type => 'discussion_topic').count %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div style="clear: left; margin-bottom: 5px;"></div>
|
||||
<% if @messages.blank? %>
|
||||
<b><%= t :all_set, "You're all set up!" %></b>
|
||||
<% if NotificationPolicy.for(@user).find(:first, :conditions => {'communication_channels.path_type' => 'facebook' }) %>
|
||||
<% if NotificationPolicy.for(@user).where('communication_channels.path_type' => 'facebook').first %>
|
||||
<%= t :no_messages_notice, "As things happen in the course you'll start seeing notifications show up here letting you know about things happening in your Canvas account." %>
|
||||
<% else %>
|
||||
<%= t :configure_notification_preferences_notice, "After you *configure your notification preferences* you should start to see notifications show up here letting you know about things happening in your Canvas account.", :wrapper => %{<a href="#{Facebook.app_url}/settings">\1</a>} %>
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
<select class="module_item_select" multiple>
|
||||
<%# cache on the context.wiki instead of just the context because even though it will require a db query, we will get a much better cache hit rate %>
|
||||
<% cache([@context.wiki, 'active_wiki_pages']) do %>
|
||||
<% @context.wiki.wiki_pages.active.scoped({:select => "id, title"}).each do |page| %>
|
||||
<% @context.wiki.wiki_pages.active.select([:id, :title]).each do |page| %>
|
||||
<% if page && !page.new_record? %>
|
||||
<option value="<%= page.id %>"><%= page.title %></option>
|
||||
<% end %>
|
||||
|
@ -144,7 +144,7 @@
|
|||
</div>
|
||||
<div style="margin-top: 5px;">
|
||||
<select class="module_item_select" multiple>
|
||||
<% @context.folders.active.scoped({:limit => 200}).sort_by{|f| f.full_name}.each do |folder| %>
|
||||
<% @context.folders.active.limit(200).sort_by{|f| f.full_name}.each do |folder| %>
|
||||
<optgroup label="<%= folder.full_name %>">
|
||||
<%
|
||||
attachments = if @context.grants_right?(@current_user, session, :manage_files)
|
||||
|
@ -191,7 +191,7 @@
|
|||
</div>
|
||||
<div style="margin-top: 5px;">
|
||||
<select class="module_item_select" multiple>
|
||||
<% @context.quizzes.active.scoped({:limit => 400}).each do |quiz| %>
|
||||
<% @context.quizzes.active.limit(400).each do |quiz| %>
|
||||
<option value="<%= quiz.id %>"><%= quiz.title %></option>
|
||||
<% end %>
|
||||
<option value="new"><%= t :new_quiz_option, "[ New Quiz ]" %></option>
|
||||
|
@ -233,7 +233,7 @@
|
|||
<select class="module_item_select" multiple>
|
||||
<% @context.assignment_groups.active.include_active_assignments.each do |group| %>
|
||||
<optgroup label="<%= group.name %>">
|
||||
<% group.active_assignments.no_graded_quizzes_or_topics.scoped({:limit => 200}).each do |assignment| %>
|
||||
<% group.active_assignments.no_graded_quizzes_or_topics.limit(200).each do |assignment| %>
|
||||
<option value="<%= assignment.id %>"><%= assignment.title %></option>
|
||||
<% end %>
|
||||
</optgroup>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<% cache([@current_user, 'user_dashboard_upcoming_events' ], :expires_in => 3.minutes) do %>
|
||||
<%
|
||||
upcoming_events = @current_user.upcoming_events
|
||||
@current_user_submissions ||= @current_user && @current_user.submissions.scoped(:select => 'id, assignment_id, score, workflow_state', :conditions => {:assignment_id => upcoming_events.select{|e| e.is_a?(Assignment) }.map(&:id)})
|
||||
@current_user_submissions ||= @current_user && @current_user.submissions.select([:id, :assignment_id, :score, :workflow_state]).where(:assignment_id => upcoming_events.select{|e| e.is_a?(Assignment) })
|
||||
%>
|
||||
<%= render :partial => "shared/event_list", :object => upcoming_events, :locals => locals %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue