Skip to content

Commit

Permalink
More improvements to the User Detail page.
Browse files Browse the repository at this point in the history
The header on the user override dates now read "User Overrides" unless
it is a test version in which case it is "User's Test Version Dates".

The header on the dates for the global set reads "Test Dates" for tests
and "Assignment Dates" for other assignments.

The placeholder in the user override date inputs now reads "Test
Default" for tests, and "Assignment Default" for other assignments.

The date override checkboxes have been removed.

Remove the "s" from the end of the "Close" date label.  That was
inconsistent with the other date labels.

The class dates for the set are now in readonly inputs instead of just
being text.  This is the same as on the set detail page.  One advantage
of this is that it makes it easier to cut and paste those dates.

There is also a small tweak to the datepicker.js (which is used on this
page as well as on the sets manager page and the set detail page).  When
flatpickr adds the date picker, it hides the input originally on the
page, and adds another input. This moves the id from the original input
onto the added flatpickr input so that labels still work.  The ids
aren't used for anything else after the date picker javascript has found
them.  Also remove the placeholder that flatpickr copies to the new
input since that isn't valid on a hidden input.
  • Loading branch information
drgrice1 committed Mar 1, 2024
1 parent 6c7aa6d commit 69c78c5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 68 deletions.
8 changes: 8 additions & 0 deletions htdocs/js/DatePicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@
// input to fix that.
this.altInput.after(this.input);

// Move the id of the now hidden input onto the added input so the labels still work.
this.altInput.id = this.input.id;

// Remove the placeholder from the hidden input. Flatpickr has copied that to the added input, and
// that isn't valid on a hidden input.
this.input.removeAttribute('id');
this.input.removeAttribute('placeholder');

// Make the alternate input left-to-right even for right-to-left languages.
this.altInput.dir = 'ltr';

Expand Down
16 changes: 0 additions & 16 deletions htdocs/js/UserDetail/userdetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@
}
});

// Make the date override checkboxes checked or unchecked appropriately
// as determined by the value of the date input when that value changes.
document
.querySelectorAll('input[type="text"][data-override],input[type="hidden"][data-override]')
.forEach((input) => {
const overrideCheck = document.getElementById(input.dataset.override);
if (!overrideCheck) return;
const changeHandler = () => (overrideCheck.checked = input.value != '');
input.addEventListener('change', changeHandler);
// Attach the keyup and blur handlers to the flatpickr alternate input.
input.previousElementSibling?.addEventListener('keyup', changeHandler);
input.previousElementSibling?.addEventListener('blur', () => {
if (input.previousElementSibling.value == '') overrideCheck.checked = false;
});
});

// If the "Assign All Sets to Current User" button is clicked, then check all assignments.
document.getElementsByName('assignAll').forEach((button) => {
button.addEventListener('click', () => {
Expand Down
17 changes: 7 additions & 10 deletions lib/WeBWorK/ContentGenerator/Instructor/UserDetail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use WeBWorK::Debug;
use constant DATE_FIELDS => {
open_date => x('Open:'),
reduced_scoring_date => x('Reduced:'),
due_date => x('Closes:'),
due_date => x('Close:'),
answer_date => x('Answer:')
};
use constant DATE_FIELDS_ORDER => [qw(open_date reduced_scoring_date due_date answer_date )];
Expand Down Expand Up @@ -90,14 +90,11 @@ sub initialize ($c) {
unless ($rh_dates->{error}) {
# If no error update database
for my $field (@{ DATE_FIELDS_ORDER() }) {
if (defined $c->param("set.$setID.$field.override") && $c->param("set.$setID.$field") ne '') {
if ($c->param("set.$setID.$field") && $c->param("set.$setID.$field") ne '') {
$userSetRecord->$field($rh_dates->{$field});
} else {
$userSetRecord->$field(undef); #stop override

# Update the parameters so the user interface reflects the changes made.
$c->param("set.$setID.$field.override", undef);
$c->param("set.$setID.$field", undef);
# Stop override
$userSetRecord->$field(undef);
}
}
$db->putUserSet($userSetRecord);
Expand All @@ -120,8 +117,8 @@ sub initialize ($c) {
unless ($rh_dates->{error}) {
for my $field (@{ DATE_FIELDS_ORDER() }) {
$setVersionRecord->$field($rh_dates->{$field})
if defined $c->param("set.$setID,v$ver.$field.override")
&& $c->param("set.$setID,v$ver.$field") ne '';
if ($c->param("set.$setID,v$ver.$field")
&& $c->param("set.$setID,v$ver.$field") ne '');
}
$db->putSetVersion($setVersionRecord);
}
Expand Down Expand Up @@ -182,7 +179,7 @@ sub checkDates ($c, $setRecord, $setID) {
my %dates;
for my $field (@{ DATE_FIELDS_ORDER() }) {
$dates{$field} =
(defined $c->param("set.$setID.$field.override") && $c->param("set.$setID.$field") ne '')
($c->param("set.$setID.$field") && $c->param("set.$setID.$field") ne '')
? $c->param("set.$setID.$field")
: ($setID =~ /,v\d+$/ ? 0 : $setRecord->$field);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
% my $setID = $globalRecord->set_id;
%
% # Modify set id to include the version if this is a versioned set.
% my $isVersioned = 0;
% if (defined $mergedRecord && $mergedRecord->assignment_type =~ /gateway/ && $mergedRecord->can('version_id')) {
% $setID .= ',v' . $mergedRecord->version_id;
% $isVersioned = 1;
% }
% my $isGateway = $globalRecord->assignment_type =~ /gateway/;
% my $isVersioned = $isGateway && defined $mergedRecord && $mergedRecord->can('version_id');
% $setID .= ',v' . $mergedRecord->version_id if $isVersioned;
%
<table>
<tr>
<th scope="col" colspan="3">
% if (defined $userRecord) {
<%= maketext("User overrides") =%>
% }
</th>
<th scope="col">
<%= maketext("Set values") =%>
</th>
% if (defined $userRecord) {
<th scope="col" colspan="2">
<%= $isVersioned ? maketext(q{User's Test Version Dates}) : maketext('User Overrides') =%>
</th>
% }
% unless ($isVersioned) {
<th scope="col" <%== defined $userRecord ? '' : 'colspan="2"' %>>
<%= $isGateway ? maketext('Test Dates') : maketext('Assignment Dates') =%>
</th>
% }
</tr>
% for my $field (@$fields) {
% # Skip reduced credit dates for sets which don't have them.
Expand All @@ -28,49 +28,45 @@
% my $globalValue = $globalRecord->$field;
%
<td class="px-1 text-nowrap">
% if (defined $userRecord) {
<%= label_for "set.$setID.$field.override_id" => maketext($fieldLabels->{$field}),
class => 'form-check-label' =%>
% } else {
<%= maketext($fieldLabels->{$field}) =%>
% }
</td>
<td class="px-1 text-nowrap">
% if (defined $userRecord) {
<%= check_box "set.$setID.$field.override" => $field,
id => "set.$setID.$field.override_id", class => 'form-check-input',
(defined $mergedRecord ? $mergedRecord->$field : $globalValue) ne $globalValue
|| ($isVersioned && $field ne 'reduced_scoring_date')
? (checked => undef)
: () =%>
% }
<%= label_for "set.$setID.$field" . (defined $userRecord ? '_id' : '.class_value') =>
maketext($fieldLabels->{$field}),
class => 'form-label mb-0' =%>
</td>
<td class="px-1 text-nowrap">
% if (defined $userRecord) {
% if (defined $userRecord) {
<td class="px-1 text-nowrap">
<div class="input-group input-group-sm flex-nowrap flatpickr">
<%= text_field "set.$setID.$field" =>
defined $userRecord ? $userRecord->$field : $globalValue,
id => "set.$setID.${field}_id",
placeholder => maketext('None Specified'),
class => 'form-control w-auto' . ($field eq 'open_date' ? ' datepicker-group' : ''),
placeholder => $isGateway
? ($isVersioned ? maketext('Required') : maketext('Test Default'))
: maketext('Assignment Default'),
$isVersioned ? (required => undef) : (),
data => {
override => "set.$setID.$field.override_id",
input => undef,
done_text => maketext('Done'),
today_text => maketext('Today'),
now_text => maketext('Now'),
locale => $ce->{language},
timezone => $ce->{siteDefaults}{timezone}
} =%>
<a class="btn btn-secondary btn-sm" data-toggle><i class="fas fa-calendar-alt"></i></a>
<a class="btn btn-secondary btn-sm" data-toggle tabindex="0" role="button"
aria-label="<%= $c->maketext('Pick date and time') %>">
<i class="fas fa-calendar-alt"></i>
</a>
</div>
% }
</td>
<td class="px-1 text-nowrap">
<span dir="ltr">
<%= $c->formatDateTime($globalValue, 'datetime_format_short') =%>
</span>
</td>
</td>
% }
% unless ($isVersioned) {
<td class="px-1 text-nowrap">
<%= text_field "set.$setID.$field.class_value" =>
$c->formatDateTime($globalValue, 'datetime_format_short'),
id => "set.$setID.$field.class_value", readonly => undef, dir => 'ltr',
class => 'form-control form-control-sm w-auto',
defined $userRecord ? ('aria-labelledby' => "set.$setID.${field}_id") : () =%>
</td>
% }
</tr>
% }
</table>
3 changes: 2 additions & 1 deletion templates/HelpFiles/InstructorUserDetail.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
. 'date in order to override the date. (You can copy the date format from the date in the right hand column '
. 'which indicates the date when the homework set is due for the whole class.) Note that you should ensure '
. 'that the close date is before the answer date. If the close date for a student is extended until after the '
. 'class answer date for the set, then the answer date for the student must also be set to a later date. ') =%>
. 'class answer date for the set, then the answer date for the student must also be set to a later date. '
. 'If a date is left empty, then the assignment default date will be used.') =%>
</p>
<p class="mb-0">
<%= maketext('Click on the homework set links to edit the grades for this individual student on the homework set. '
Expand Down

0 comments on commit 69c78c5

Please sign in to comment.