Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/assets/javascripts/manage_submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,56 @@ $(document).ready(function() {
}
}

$(document).on("click", "#regrade-all-btn, #regrade-all-trigger", function (event) {
event.preventDefault();
if (!confirm(`Are you sure you want to regrade all selected submissions?`)) return;
const icon = $("#regrade-all-icon");
const button = $("#regrade-all-btn");
const link = $('#regrade-all-trigger');
let refreshInterval = setInterval(() => {
location.reload();
}, 5000);

$.ajax({
url: "regradeAll",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-Token": $('meta[name="csrf-token"]').attr("content")
},
beforeSend: function () {
if (icon && button) {
button.addClass("disabled");
link.addClass("disabled-link");
icon.text("autorenew");
icon.addClass("loading-icon");
}
},
success: function (response) {
clearInterval(refreshInterval);
if (response.redirect) {
console.log(response.redirect);
window.location.href = response.redirect;
return;
}
if (response.error) {
alert(response.error);
}
if (response.success) {
alert(response.success);
}
},
error: function () {
clearInterval(refreshInterval);
alert("An error occurred while regrading.");
}
});
});

function changeButtonStates(state) {
buttonIDs.forEach((id) => {
const button = $(id);
const icon = button.find("i");
if (state) {
if (id === "#download-selected") {
$(id).prop('href', baseURLs[id]);
Expand Down Expand Up @@ -374,6 +421,13 @@ $(document).ready(function() {
headers: {
"X-CSRF-Token": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
button.addClass('disabled');
if (icon) {
icon.text("autorenew");
icon.addClass("loading-icon");
}
},
success: function (response) {
clearInterval(refreshInterval);
if (response.redirect) {
Expand Down
18 changes: 18 additions & 0 deletions app/assets/stylesheets/manage_submissions.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,21 @@ table.prettyBorder tr:hover {
.i-no-margin {
margin-left: 0;
}

.loading-icon {
animation: spin 1.5s linear infinite;
display: inline-block;
}

.disabled-link {
pointer-events: none;
color: gray !important;
opacity: 0.6;
text-decoration: none;
cursor: default;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
14 changes: 8 additions & 6 deletions app/controllers/assessment/autograde.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def regradeBatch
# any handins that fail.
submissions = submission_ids.filter_map do |sid|
_is_i?(sid) ? @assessment.submissions.find_by_id(sid) : nil
end

end.compact
begin
failed_list = sendJob_batch(@course, @assessment, submissions, @cud)
rescue AssessmentAutogradeCore::AutogradeError => e
Expand All @@ -119,7 +118,7 @@ def regradeBatch

failure_jobs = failed_list.length
if failure_jobs > 0
flash[:error] =
flash[:error] =
"Warning: Could not regrade #{ActionController::Base.helpers.pluralize(failure_jobs,
"submission")}:<br>"
failed_list.each do |failure|
Expand Down Expand Up @@ -193,7 +192,10 @@ def regradeAll
# For both :success and :error
flash[:html_safe] = true

redirect_to([@course, @assessment, :submissions]) && return
respond_to do |format|
format.html { redirect_to [@course, @assessment, :submissions] }
format.json { render json: { redirect: url_for([@course, @assessment, :submissions]) } }
end
end

##
Expand Down Expand Up @@ -260,7 +262,7 @@ def sendJob_AddHTMLMessages(course, assessment, submissions)
job
end

def _is_i?(string)
!!(string =~ /\A[-+]?[0-9]+\z/)
def _is_i?(value)
value.is_a?(Integer) || (value.is_a?(String) && value =~ /\A[-+]?\d+\z/)
end
end
25 changes: 12 additions & 13 deletions app/views/submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,16 @@
class: "btn submissions-main" } %>
</div>

<div id="regrade-all-html">
<%= link_to "<i class='material-icons left submissions-icons'>cached</i>Regrade All".html_safe,
regradeAll_course_assessment_path(@course, @assessment),
{ method: :post,
title: "Regrade all submissions for this assignment",
class: "btn submissions-main",
data: { confirm: "Are you sure you want to regrade all #{@assessment.submissions.where(special_type: [Submission::NORMAL, nil]).latest.count} latest submissions?" } } %>
</div>
<a id="regrade-all-btn" class="btn submissions-main" title="Regrade all submissions for this assignment">
<i class='material-icons left submissions-icons' id="regrade-all-icon">cached</i>Regrade All
</a>
</div>

<%# Selected buttons, hidden so HTML can be accessed in DataTables %>
<div class="selected-buttons-placeholder">
<div id="regrade-batch-html">
<%= link_to "Regrade Selected", class: "btn submissions-selected", title: "Regrade selected submissions" do %>
<i class="material-icons">cached</i> Regrade Selected
<%= link_to "Regrade Selected", class: "btn submissions-selected", id: "regrade-selected-btn", title: "Regrade selected submissions" do %>
<i class="material-icons" id="regrade-selected-icon">cached</i>Regrade Selected
<% end %>
</div>

Expand All @@ -125,9 +120,13 @@

<div class="selected-count-placeholder" style="display: none;">
<span id="selected-count-html">0 submissions selected</span>
<span>Click <%= link_to "Regrade All", regradeAll_course_assessment_path(@course, @assessment),
{ method: :post, title: "Regrade all submissions", class: "selected-count-red",
data: { confirm: "Are you sure you want to regrade all #{@assessment.submissions.where(special_type: [Submission::NORMAL, nil]).latest.count} latest submissions?" } } %> to regrade all </span><%= @submissions.latest.length %><span> latest submissions.</span>
<span>
Click
<a href="#" id="regrade-all-trigger" class="selected-count-red" title="Regrade all submissions">
Regrade All
</a>
to regrade all <%= @submissions.latest.length %> latest submissions.
</span>
</div>

<table class="prettyBorder" id="submissions">
Expand Down