Skip to content

Commit

Permalink
Merge pull request openwebwork#2299 from drgrice1/achievement-item-pr…
Browse files Browse the repository at this point in the history
…oblem-ids

Fix achievement issues openwebwork#2281 and openwebwork#2279
  • Loading branch information
pstaabp authored Feb 7, 2024
2 parents 9f25f96 + 833a81e commit e1c4a15
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 136 deletions.
32 changes: 24 additions & 8 deletions htdocs/js/AchievementItems/achievementitems.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
(() => {
for (const setSelect of document.querySelectorAll('select[data-problems]')) {
setSelect.addEventListener('change', () => {
const max = parseInt(Array.from(setSelect.querySelectorAll('option'))
.find((option) => option.value === setSelect.value)?.dataset.max ?? '0');
const problemIds = JSON.parse(
Array.from(setSelect.querySelectorAll('option')).find((option) => option.value === setSelect.value)
?.dataset.problemIds ?? '[]'
);

document.querySelectorAll(`#${setSelect.dataset.problems} option`).forEach((option, index) => {
option.style.display = index < max ? '' : 'none';
});
const problemSelect = document.getElementById(setSelect.dataset.problems);
if (problemSelect) {
for (const option of problemSelect.querySelectorAll('option')) option.remove();
for (const id of problemIds) {
const option = document.createElement('option');
option.value = id;
option.text = id;
problemSelect.add(option);
}
}

// This is only used by the "Box of Transmogrification".
document.querySelectorAll(`#${setSelect.dataset.problems2} option`).forEach((option, index) => {
option.style.display = index < max ? '' : 'none';
});
const problemSelect2 = document.getElementById(setSelect.dataset.problems2);
if (problemSelect2) {
for (const option of problemSelect2.querySelectorAll('option')) option.remove();
for (const id of problemIds) {
const option = document.createElement('option');
option.value = id;
option.text = id;
problemSelect2.add(option);
}
}
});
}
})();
8 changes: 4 additions & 4 deletions lib/WeBWorK/AchievementItems/AddNewTestGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
my $db = $c->db;

my $effectiveUserName = $c->param('effectiveUser') // $c->param('user');
my @unfilteredsets = $db->getMergedSets(map { [ $effectiveUserName, $_ ] } $db->listUserSets($effectiveUserName));
my @openGateways;

# Find the template sets of open gateway quizzes.
for my $set (@unfilteredsets) {
for my $set (@$sets) {
push(@openGateways, [ format_set_name_display($set->set_id) => $set->set_id ])
if $set->assignment_type =~ /gateway/
&& $set->set_id !~ /,v\d+$/
&& between($set->open_date, $set->due_date);
}

return unless @openGateways;

return $c->c(
$c->tag('p', $c->maketext('Add a new version for which test?')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
26 changes: 13 additions & 13 deletions lib/WeBWorK/AchievementItems/DoubleProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;

# Item to make a problem worth double.

use Mojo::JSON qw(encode_json);

use WeBWorK::Utils qw(between x nfreeze_base64 thaw_base64 format_set_name_display);

sub new ($class) {
Expand All @@ -28,31 +30,29 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
# Construct a dropdown with open sets and another with problems.
# Javascript ensures the appropriate number of problems are shown for the selected set.
# Javascript ensures the appropriate problems are shown for the selected set.

my @openSets;
my $maxProblems = 0;
my (@openSets, @initialProblemIDs);

for my $i (0 .. $#$sets) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default') {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date)
&& $sets->[$i]->assignment_type eq 'default'
&& @{ $setProblemIds->{ $sets->[$i]->set_id } })
{
push(
@openSets,
[
format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id,
data => { max => $setProblemCount->[$i] }
data => { problem_ids => encode_json($setProblemIds->{ $sets->[$i]->set_id }) }
]
);
$maxProblems = $setProblemCount->[$i] if $setProblemCount->[$i] > $maxProblems;
@initialProblemIDs = @{ $setProblemIds->{ $sets->[$i]->set_id } } unless @initialProblemIDs;
}
}

my @problemIDs;

for my $i (1 .. $maxProblems) {
push(@problemIDs, [ $i => $i, $i > $openSets[0][3]{max} ? (style => 'display:none') : () ]);
}
return unless @openSets;

return $c->c(
$c->tag(
Expand All @@ -71,7 +71,7 @@ sub print_form ($self, $sets, $setProblemCount, $c) {
$c,
id => 'dbp_problem_id',
label_text => $c->maketext('Problem Number'),
values => \@problemIDs,
values => \@initialProblemIDs,
menu_container_attr => { class => 'col-3' }
)
)->join('');
Expand Down
4 changes: 3 additions & 1 deletion lib/WeBWorK/AchievementItems/DoubleSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
my @openSets;

for my $i (0 .. $#$sets) {
push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ])
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set which you would like to be worth twice as much.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
27 changes: 14 additions & 13 deletions lib/WeBWorK/AchievementItems/DuplicateProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;

# Item to turn one problem into another problem

use Mojo::JSON qw(encode_json);

use WeBWorK::Utils qw(between x nfreeze_base64 thaw_base64 format_set_name_display);

sub new ($class) {
Expand All @@ -28,30 +30,29 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
# Show open sets and allow for a choice of two problems from the set.
# Javascript ensures the appropriate problems are shown for the selected set.

my @openSets;
my $maxProblems = 0;
my (@openSets, @initialProblemIDs);

for my $i (0 .. $#$sets) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default') {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date)
&& $sets->[$i]->assignment_type eq 'default'
&& @{ $setProblemIds->{ $sets->[$i]->set_id } })
{
push(
@openSets,
[
format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id,
data => { max => $setProblemCount->[$i] }
data => { problem_ids => encode_json($setProblemIds->{ $sets->[$i]->set_id }) }
]
);
$maxProblems = $setProblemCount->[$i] if $setProblemCount->[$i] > $maxProblems;
@initialProblemIDs = @{ $setProblemIds->{ $sets->[$i]->set_id } } unless @initialProblemIDs;
}
}

my @problemIDs;

for my $i (1 .. $maxProblems) {
push(@problemIDs, [ $i => $i, $i > $openSets[0][3]{max} ? (style => 'display:none') : () ]);
}
return unless @openSets;

return $c->c(
$c->tag(
Expand All @@ -78,15 +79,15 @@ sub print_form ($self, $sets, $setProblemCount, $c) {
WeBWorK::AchievementItems::form_popup_menu_row(
$c,
id => 'tran_problem_id',
values => \@problemIDs,
values => \@initialProblemIDs,
label_text => $c->maketext('Copy this Problem'),
menu_container_attr => { class => 'col-2 ps-0' },
add_container => 0
),
WeBWorK::AchievementItems::form_popup_menu_row(
$c,
id => 'tran_problem_id2',
values => \@problemIDs,
values => \@initialProblemIDs,
label_text => $c->maketext('To this Problem'),
menu_container_attr => { class => 'col-2 ps-0' },
add_container => 0
Expand Down
4 changes: 3 additions & 1 deletion lib/WeBWorK/AchievementItems/ExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
my @openSets;

for my $i (0 .. $#$sets) {
push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ])
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set whose close date you would like to extend.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
8 changes: 4 additions & 4 deletions lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
my $db = $c->db;

my $effectiveUserName = $c->param('effectiveUser') // $c->param('user');
my @unfilteredsets = $db->getMergedSets(map { [ $effectiveUserName, $_ ] } $db->listUserSets($effectiveUserName));
my @openGateways;

# Find the template sets for open tests.
for my $set (@unfilteredsets) {
for my $set (@$sets) {
push(@openGateways, [ format_set_name_display($set->set_id) => $set->set_id ])
if $set->assignment_type =~ /gateway/
&& $set->set_id !~ /,v\d+$/
&& between($set->open_date, $set->due_date);
}

return unless @openGateways;

return $c->c(
$c->tag('p', $c->maketext('Extend the close date for which test?')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
26 changes: 13 additions & 13 deletions lib/WeBWorK/AchievementItems/FullCreditProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;

# Item to give full credit on a single problem

use Mojo::JSON qw(encode_json);

use WeBWorK::Utils qw(between x nfreeze_base64 thaw_base64 format_set_name_display);

sub new ($class) {
Expand All @@ -28,31 +30,29 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
# Construct a dropdown with open sets and another with problems.
# Javascript ensures the appropriate number of problems are shown for the selected set.
# Javascript ensures the appropriate problems are shown for the selected set.

my @openSets;
my $maxProblems = 0;
my (@openSets, @initialProblemIDs);

for my $i (0 .. $#$sets) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default') {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date)
&& $sets->[$i]->assignment_type eq 'default'
&& @{ $setProblemIds->{ $sets->[$i]->set_id } })
{
push(
@openSets,
[
format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id,
data => { max => $setProblemCount->[$i] }
data => { problem_ids => encode_json($setProblemIds->{ $sets->[$i]->set_id }) }
]
);
$maxProblems = $setProblemCount->[$i] if $setProblemCount->[$i] > $maxProblems;
@initialProblemIDs = @{ $setProblemIds->{ $sets->[$i]->set_id } } unless @initialProblemIDs;
}
}

my @problemIDs;

for my $i (1 .. $maxProblems) {
push(@problemIDs, [ $i => $i, $i > $openSets[0][3]{max} ? (style => 'display:none') : () ]);
}
return unless @openSets;

return $c->c(
$c->tag(
Expand All @@ -71,7 +71,7 @@ sub print_form ($self, $sets, $setProblemCount, $c) {
$c,
id => 'fcp_problem_id',
label_text => $c->maketext('Problem Number'),
values => \@problemIDs,
values => \@initialProblemIDs,
menu_container_attr => { class => 'col-3' }
)
)->join('');
Expand Down
4 changes: 3 additions & 1 deletion lib/WeBWorK/AchievementItems/FullCreditSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
my @openSets;

for my $i (0 .. $#$sets) {
push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ])
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Please choose the set for which all problems should be given full credit.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
26 changes: 13 additions & 13 deletions lib/WeBWorK/AchievementItems/HalfCreditProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;

# Item to give half credit on a single problem.

use Mojo::JSON qw(encode_json);

use WeBWorK::Utils qw(between x nfreeze_base64 thaw_base64 format_set_name_display);

sub new ($class) {
Expand All @@ -28,31 +30,29 @@ sub new ($class) {
}, $class;
}

sub print_form ($self, $sets, $setProblemCount, $c) {
sub print_form ($self, $sets, $setProblemIds, $c) {
# Construct a dropdown with open sets and another with problems.
# Javascript ensures the appropriate number of problems are shown for the selected set.
# Javascript ensures the appropriate problems are shown for the selected set.

my @openSets;
my $maxProblems = 0;
my (@openSets, @initialProblemIDs);

for my $i (0 .. $#$sets) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default') {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date)
&& $sets->[$i]->assignment_type eq 'default'
&& @{ $setProblemIds->{ $sets->[$i]->set_id } })
{
push(
@openSets,
[
format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id,
data => { max => $setProblemCount->[$i] }
data => { problem_ids => encode_json($setProblemIds->{ $sets->[$i]->set_id }) }
]
);
$maxProblems = $setProblemCount->[$i] if $setProblemCount->[$i] > $maxProblems;
@initialProblemIDs = @{ $setProblemIds->{ $sets->[$i]->set_id } } unless @initialProblemIDs;
}
}

my @problemIDs;

for my $i (1 .. $maxProblems) {
push(@problemIDs, [ $i => $i, $i > $openSets[0][3]{max} ? (style => 'display:none') : () ]);
}
return unless @openSets;

return $c->c(
$c->tag(
Expand All @@ -70,7 +70,7 @@ sub print_form ($self, $sets, $setProblemCount, $c) {
WeBWorK::AchievementItems::form_popup_menu_row(
$c,
id => 'hcp_problem_id',
values => \@problemIDs,
values => \@initialProblemIDs,
label_text => $c->maketext('Problem Number'),
menu_container_attr => { class => 'col-3' }
)
Expand Down
Loading

0 comments on commit e1c4a15

Please sign in to comment.