Skip to content
Draft
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gem 'bootstrap3-datetimepicker-rails' # for the datetime widget
gem 'bootstrap-toggle-rails' # for toggle buttons instead of checkboxes

gem 'momentjs-rails', '>= 2.9.0' # needed for human-friendly textual dates
gem 'moment_timezone-rails'
gem 'font-awesome-rails'

gem 'addressable'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ GEM
builder
minitest (>= 5.0)
ruby-progressbar
moment_timezone-rails (0.5.0)
momentjs-rails (2.20.1)
railties (>= 3.1)
net-ldap (0.16.2)
Expand Down Expand Up @@ -330,6 +331,7 @@ DEPENDENCIES
launchy
listen
minitest-reporters
moment_timezone-rails
momentjs-rails (>= 2.9.0)
passenger (>= 5.0.25)
pg
Expand Down
19 changes: 19 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//= require jquery.keyDecoder
//= require cocoon
//= require moment
//= require moment-timezone-with-data
//= require bootstrap-sprockets
//= require bootstrap-datetimepicker
//= require bootstrap.treeview
Expand Down Expand Up @@ -172,6 +173,24 @@ function makeFriendlyDate(str, showTime) {
}
}

// convert human-readable datetimes to ISO8601 times, including timezone
function makeDatesIso8601($dates) {
var savedDates = [];
$dates.each(function(index, dtp) {
var $dtp = $(dtp);
savedDates[index] = $dtp.val();
$dtp.val($dtp.data("DateTimePicker").date().format());
});
return savedDates;
}

function restoreDatesFromIso8601($dates, savedDates) {
$dates.each(function(index, dtp) {
$(dtp).val(savedDates[index]);
});
}


function activate_file_picker($e) {
$e.find(".custom-file").change(function() {
var label = $(this).val().replace(/\\/g, '/').replace(/.*\//, '');
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
function init_datetime() {
$('.datetime-picker').datetimepicker({
sideBySide: true,
format: "YYYY/MM/DD h:mm A",
format: "YYYY/MM/DD h:mm A z",
timeZone: moment.tz.guess(),
defaultDate: undefined
});
}
Expand Down Expand Up @@ -240,6 +241,7 @@
return false;
}
}
makeDatesIso8601($(".datetime-picker"));
return true;
});

Expand Down
5 changes: 3 additions & 2 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def score_summary(for_students = nil)
if sub.score.nil?
if assns[sub.assignment_id].extra_credit
extra_adjust += assns[sub.assignment_id].points_available
extra_avail -= assns[sub.assignment_id].points_available # Don't double-count
else
adjust += assns[sub.assignment_id].points_available
end
Expand All @@ -223,10 +224,10 @@ def score_summary(for_students = nil)
unsubs += o.points_available
end
end
max = min + remaining + extra_adjust + adjust + unsubs
max = min + remaining + extra_adjust + adjust + unsubs + extra_avail
{s: s, dropped: dropped,
min: min * (100.0 / total_points), cur: cur * (100.0 / total_points), max: max * (100.0 / total_points),
pending: adjust + extra_adjust, pending_names: pending_names,
pending: adjust + extra_adjust + extra_avail, pending_names: pending_names,
unsub: unsubs, unsub_names: unsub_names,
remaining: remaining, used: used}
end
Expand Down
15 changes: 12 additions & 3 deletions app/views/individual_extensions/_edit.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ $(function() {
$initialFilled.closest("tr").find("button.revoke").removeClass("hidden");
$('.datetime-picker').datetimepicker({
sideBySide: true,
format: "YYYY/MM/DD h:mm A",
format: "YYYY/MM/DD h:mm A z",
timeZone: moment.tz.guess(),
defaultDate: undefined
});
$("form").map(function() {
Expand All @@ -24,11 +25,15 @@ $(function() {
var $valuesToSubmit = $row.find("form");
var $check = $row.find("#success_" + $valuesToSubmit[0].id);
var $fail = $row.find("#failure_" + $valuesToSubmit[0].id);
var $dates = $row.find(".datetime-picker");
var savedDates = makeDatesIso8601($dates);
var data = $valuesToSubmit.serialize();
restoreDatesFromIso8601($dates, savedDates);
debugger
$.ajax({
type: "PATCH",
url: "<%= patch_course_assignment_extensions_path(@course, @assignment) %>",
data: $valuesToSubmit.serialize(),
data: data,
dataType: "JSON",
timeout: 500
}).done(function(json) {
Expand All @@ -55,10 +60,14 @@ $(function() {
var $valuesToSubmit = $row.find("form");
var $check = $row.find("#success_" + $valuesToSubmit[0].id);
var $fail = $row.find("#failure_" + $valuesToSubmit[0].id);
var $dates = $row.find(".datetime-picker");
var savedDates = makeDatesIso8601($dates);
var data = $valuesToSubmit.serialize();
restoreDatesFromIso8601($dates, savedDates);
$.ajax({
type: "DELETE",
url: "<%= delete_course_assignment_extensions_path(@course, @assignment) %>",
data: $valuesToSubmit.serialize(),
data: data,
dataType: "JSON",
timeout: 500
}).done(function(json) {
Expand Down
5 changes: 3 additions & 2 deletions app/views/submissions/_new_common.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<div class="col-sm-6">
<p>If lateness is not ignored, this <%= type[:noun] %> should claim to
have been submitted at:</p>
<%= f.text_field :created_at, class: 'form-control', disabled: "disabled" %>
<%= f.text_field :created_at, class: 'form-control datetime-picker', disabled: "disabled" %>
</div>
<% end %>
<div class="col-sm-6" style="padding-top: 1em;">
Expand All @@ -70,7 +70,8 @@
$(function () {
$('#submission_created_at').datetimepicker({
sideBySide: true,
format: "YYYY/MM/DD h:mm A",
format: "YYYY/MM/DD h:mm A z",
timeZone: moment.tz.guess(),
minDate: "<%= @course.created_at.beginning_of_day.iso8601 %>",
<% if @course.created_at < DateTime.current %>
defaultDate: "<%= DateTime.current.iso8601 %>"
Expand Down
6 changes: 5 additions & 1 deletion app/views/submissions/new_codereview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@
warning.find("h3").removeClass("hidden");
}, Math.max(deadline - now, 0));
$("form").submit(function(e) {
return ensureValidNumericInputOnSubmit(e, "input.numeric:not([disabled])");
var num = ensureValidNumericInputOnSubmit(e, "input.numeric:not([disabled])");
if (num) {
makeDatesIso8601($(".datetime-picker"));
}
return num;
});
</script>
<% end %><%# content-for %>
3 changes: 3 additions & 0 deletions app/views/submissions/new_files.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
$("form").submit(function(e) {
var num = ensureValidNumericInputOnSubmit(e, "span.spinner > input");
var files = ensureFilesPresentOnSubmit(e);
if (num && files) {
makeDatesIso8601($(".datetime-picker"));
}
return num && files;
});
</script>
Expand Down
6 changes: 5 additions & 1 deletion app/views/submissions/new_questions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@
warning.find("h3").removeClass("hidden");
}, Math.max(deadline - now, 0));
$("form").submit(function(e) {
return ensureValidNumericInputOnSubmit(e, "input.numeric:not([disabled])");
var num = ensureValidNumericInputOnSubmit(e, "input.numeric:not([disabled])");
if (num) {
makeDatesIso8601($(".datetime-picker"));
}
return num;
});
</script>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions test/integration/submissions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ def clean(summary)
@as3.reload # needed for the lateness config
@summary = clean(@cs101.score_summary(@john))
assert_equal(@summary[@john.id],
{dropped: nil, min: 7.5, cur: 75.0, max: 97.5,
{dropped: nil, min: 7.5, cur: 75.0, max: 102.5,
pending: 0.0, pending_names: [], unsub: 0.0, unsub_names: [],
remaining: 90.0},
"After creating an extra credit assignment, but not submitting, nothing should change in the grades")
"After creating an extra credit assignment, but not submitting, max goes up by the available e.c.")

@sub3 = create(:submission, user: @john, assignment: @as3, created_at: Time.now - 2.days)
@sub3.set_used_sub!
Expand Down