Skip to content

Instantly share code, notes, and snippets.

@benjaminvialle
Created November 11, 2012 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminvialle/4055226 to your computer and use it in GitHub Desktop.
Save benjaminvialle/4055226 to your computer and use it in GitHub Desktop.
Diff from RB for issue 523
diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb
--- a/app/controllers/submissions_controller.rb
+++ b/app/controllers/submissions_controller.rb
@@ -269,24 +269,48 @@ class SubmissionsController < ApplicationController
params[:sort_by] = 'group_name'
end
@assignment = Assignment.find(params[:assignment_id])
- @groupings, @groupings_total = handle_paginate_event(
- S_TABLE_PARAMS, # the data structure to handle filtering and sorting
- { :assignment => @assignment, # the assignment to filter by
- :user_id => current_user.id}, # the submissions accessable by the current user
- params) # additional parameters that affect things like sorting
-
- #Eager load all data only for those groupings that will be displayed
- sorted_groupings = @groupings
- @groupings = Grouping.find(:all, :conditions => {:id => sorted_groupings},
- :include => [:assignment, :group, :grace_period_deductions,
- {:current_submission_used => :result},
- {:accepted_student_memberships => :user}])
-
- #re-sort @groupings by the previous order, because eager loading query
- #messed up the grouping order
- @groupings = sorted_groupings.map do |sorted_grouping|
- @groupings.detect do |unsorted_grouping|
- unsorted_grouping == sorted_grouping
+
+ if params[:search] == nil or params[:search].blank?
+ @groupings, @groupings_total = handle_paginate_event(
+ S_TABLE_PARAMS, # the data structure to handle filtering and sorting
+ { :assignment => @assignment, # the assignment to filter by
+ :user_id => current_user.id}, # the submissions accessable by the current user
+ params) # additional parameters that affect things like sorting
+
+ #Eager load all data only for those groupings that will be displayed
+ sorted_groupings = @groupings
+ @groupings = Grouping.find(:all, :conditions => {:id => sorted_groupings},
+ :include => [:assignment, :group, :grace_period_deductions,
+ {:current_submission_used => :result},
+ {:accepted_student_memberships => :user}])
+
+ #re-sort @groupings by the previous order, because eager loading query
+ #messed up the grouping order
+ @groupings = sorted_groupings.map do |sorted_grouping|
+ @groupings.detect do |unsorted_grouping|
+ unsorted_grouping == sorted_grouping
+ end
+ end
+ else
+ if (current_user.admin?)
+ # Show all of the groupings for this assignment
+ @groupings = Grouping.joins(:student_memberships => :user).where(
+ 'users.user_name LIKE ? AND assignment_id = ?',
+ '%' + params[:search] + '%', @assignment.id).uniq
+ else
+ # TA - Show only groupings for this assignment assigned to this TA
+ @groupings = Grouping.joins('
+ LEFT JOIN memberships ta on ta.grouping_id = groupings.id
+ LEFT JOIN memberships s on s.grouping_id = groupings.id
+ LEFT JOIN users students on s.user_id = students.id').where("
+ students.user_name LIKE ?
+ AND ta.user_id = ?
+ AND assignment_id = ?
+ AND s.type = 'StudentMembership'
+ AND ta.type = 'TAMembership'",
+ '%' + params[:search] + '%',
+ current_user.id,
+ @assignment.id).uniq
end
end
@@ -297,6 +321,7 @@ class SubmissionsController < ApplicationController
@desc = params[:desc]
@filter = params[:filter]
@sort_by = params[:sort_by]
+ @search = params[:search]
end
def index
diff --git a/app/views/submissions/_submissions_table_sorting_links.html.erb b/app/views/submissions/_submissions_table_sorting_links.html.erb
--- a/app/views/submissions/_submissions_table_sorting_links.html.erb
+++ b/app/views/submissions/_submissions_table_sorting_links.html.erb
@@ -1,6 +1,7 @@
<tr>
<th>
</th>
+ <% if @search == nil or @search.blank? %>
<th class="<%="ap_sorting_by" if (sort_by == 'group_name')%>
<%="ap_sorting_by_desc" if (sort_by == 'group_name' && !desc.blank?)%>">
<%= link_to I18n.t("browse_submissions.group_name"),
@@ -78,6 +79,17 @@
:desc => (sort_by == 'section' && desc.blank?) %>
</th>
<% end %>
+ <% else %>
+ <th><%= I18n.t("browse_submissions.group_name") %></th>
+ <th><%= I18n.t("browse_submissions.repository") %></th>
+ <th><%= I18n.t("browse_submissions.commit_date") %></th>
+ <th><%= I18n.t("browse_submissions.marking_state") %></th>
+ <th><%= I18n.t("browse_submissions.grace_credits_used") %></th>
+ <th><%= I18n.t("browse_submissions.final_grade") %></th>
+ <% if assignment.section_groups_only %>
+ <th><%= I18n.t("browse_submissions.section") %></th>
+ <% end %>
+ <% end %>
<th>
<%= I18n.t("browse_submissions.can_begin_grading") %>
</th>
diff --git a/app/views/submissions/browse.html.erb b/app/views/submissions/browse.html.erb
--- a/app/views/submissions/browse.html.erb
+++ b/app/views/submissions/browse.html.erb
@@ -70,6 +70,24 @@
</div>
<% end %>
+ <%= label_tag "search", I18n.t("browse_submissions.search_by_student"), :class => "inline_label" %>
+ <%= text_field_tag "search", params[:search], {:id => "submissionSearch"} %>
+ <% if @search != nil and !@search.blank? %>
+ <div class="search_results">
+ <%=h I18n.t("browse_submissions.search_count", :count => h(@groupings.length)) %>&nbsp;
+ <%= link_to I18n.t("browse_submissions.clear_search"), browse_assignment_submissions_path() %>
+ </div>
+ <% end %>
+
+ <script type="text/javascript">
+ $('submissionSearch').observe('keypress', function(e) {
+ var search = e.element().value;
+ if(e.keyCode == Event.KEY_RETURN && search.length > 0) {
+ top.location.href = "<%= browse_assignment_submissions_path() %>" + '?search=' + search;
+ }
+ });
+ </script>
+
<div class="clear"></div>
<%= form_tag update_submissions_assignment_submissions_path(@assignment) %>
@@ -86,6 +104,7 @@
<% end %>
</div>
<% end %>
+ <% if @search == nil or @search.blank? %>
<div class="ap_filters" id="ap_filters_1">
<%= render :partial => 'submissions_table_filters',
:locals => {
@@ -122,6 +141,7 @@
:locals => {:page_items => @groupings.size,
:total_items => @groupings_total} %>
</div>
+ <% end %>
<table>
<thead id="submissions_table_head">
@@ -134,7 +154,6 @@
:sort_by => @sort_by,
:desc => @desc } %>
</thead>
-
<%= render :partial => 'submissions_table_body',
:locals => {
:groupings => @groupings,
@@ -152,7 +171,7 @@
</tfoot>
</table>
-
+ <% if @search == nil or @search.blank? %>
<div class="ap_nav_box">
<div class="ap_page_links" id="ap_page_links_2">
<%= render :partial => 'ajax_paginate/initial_paginate_links',
@@ -169,6 +188,7 @@
<div id="ap_selector">
<%= render :partial => 'ajax_paginate/selector' %>
</div>
+ <% end %>
<div class="clear"></div>
@@ -180,6 +200,7 @@
:name => "unrelease_results" %>
<% end %>
</div>
+ <% if @search == nil or @search.blank? %>
<div class="ap_filters" id="ap_filters_2">
<%= render :partial => 'submissions_table_filters',
:locals => {
@@ -192,6 +213,7 @@
:per_page => @per_page,
:per_pages => @per_pages } %>
</div>
+ <% end %>
<div class="clear"></div>
</div>
</form>
diff --git a/config/locales/en.yml b/config/locales/en.yml
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -342,6 +342,9 @@ en:
find_by_revision_timestamp: "Find by Revision Timestamp"
find_by_revision_number: "Find by Revision Number"
viewing_revision: "Viewing Revision: #<span id=\"current_revision_number_display\">%{revision_number}</span>"
+ search_by_student: "Search by Student ID:"
+ search_count: "Search returned %{count} result(s)"
+ clear_search: "Clear Search"
current_path: "Current Path:"
root: "[root]"
collect_and_grab: "Collect and Grade This Revision"
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
--- a/public/stylesheets/main.css
+++ b/public/stylesheets/main.css
@@ -870,6 +870,14 @@ input#extra_mark_description{
margin: 5px;
}
+.search_results {
+ display: inline-block;
+ border: 1px solid #E6DB55;
+ padding: 3px 10px;
+ min-width: 350px;
+ text-align: center;
+}
+
.information{
border: 1px solid #0047FF;
padding: 3px 30px;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment