Skip to content

Commit 6796ccf

Browse files
committed
Add previous and next buttons to tests.
The buttons go to the next or previous page. If there is only one problem per page, then the buttons are "Previous Problem" and "Next Problem" buttons. Otherwise they are "Previous Page" and "Next Page" buttons. These buttons are shown below the page/problem navigation links and like those links are shown both at the top and bottom of the page. This means that these buttons are above the "Grade Test" button at the bottom of the page, making it much clearer to students that there are more problems than those shown on the page. Note these buttons are not shown if all problems are on one page. This was requested in issue #2814. Also fix a couple of HTML validation issues that I observed. First, the "preview answer" buttons had a `data_page_number` attribute. The underscores are not the valid format for data attributes. They should be hyphens. I.e., kebab case, not snake case. This was caused by using the incorrect format for the data attribute argument to the `link_to` method. This was my fault and was done when I initially converted to Mojolicious. The other issue only occurs when the number of problems in the test is not evenly divisible by the number of problems per page. This resulted in the wrong number of columns in the problem/page navigation links table for the `colgroup` definition of the last column.
1 parent df5b59c commit 6796ccf

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

templates/ContentGenerator/GatewayQuiz.html.ep

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,18 @@
448448
% end
449449
% if ($numProbPerPage && $numPages > 1) {
450450
% content_for 'gw-navigation-cols' => begin
451-
% for (1 .. $numPages) {
451+
% for my $pageNum (1 .. $numPages) {
452452
<colgroup class="page">
453453
% for (1 .. $numProbPerPage) {
454+
% last if $_ * $pageNum > @$problem_numbers;
454455
<col class="problem">
455456
% }
456457
</colgroup>
457458
% }
458459
% end
459460
% for my $i (1 .. $numPages) {
460461
% content_for 'gw-navigation-pages' => begin
461-
<td colspan="<%= $numProbPerPage %>"
462+
<td colspan="<%= $i == $numPages ? (@$problem_numbers % $numProbPerPage) : $numProbPerPage %>"
462463
class="<%= $i == $pageNumber ? 'page active' : 'page' %>">
463464
% if ($i == $pageNumber) {
464465
<%= $i =%>
@@ -485,6 +486,24 @@
485486
</tr>
486487
% }
487488
% end
489+
% content_for 'gw-previous-next-buttons' => begin
490+
<div class="submit-buttons-container mb-3">
491+
% my $prevText = $numProbPerPage == 1 ? maketext('Previous Problem') : maketext('Previous Page');
492+
% if ($pageNumber > 1) {
493+
<%= link_to $prevText => '#',
494+
class => 'btn btn-primary page-change-link', data => { page_number => $pageNumber - 1 } =%>
495+
% } else {
496+
<a class="btn btn-primary disabled" role="button" aria-disabled="true"><%= $prevText =%></a>
497+
% }
498+
% my $nextText = $numProbPerPage == 1 ? maketext('Next Problem') : maketext('Next Page');
499+
% if ($pageNumber < $numPages) {
500+
<%= link_to $nextText => '#',
501+
class => 'btn btn-primary page-change-link', data => { page_number => $pageNumber + 1 } =%>
502+
% } else {
503+
<a class="btn btn-primary disabled" role="button" aria-disabled="true"><%= $nextText =%></a>
504+
% }
505+
</div>
506+
% end
488507
% } else {
489508
% content_for 'gw-navigation-cols' => begin
490509
<colgroup class="page"><% for (0 .. $#$pg_results) { =%><col class="problem"><% } =%></colgroup>
@@ -508,6 +527,7 @@
508527
<%= content 'gw-navigation-table-rows' =%>
509528
</table>
510529
</div>
530+
<%= content 'gw-previous-next-buttons' =%>
511531
% end
512532
<%= $jumpLinks->() =%>
513533
%
@@ -621,7 +641,7 @@
621641
<div class="text-end mb-2">
622642
<%= link_to maketext('preview answers') => '#',
623643
class => 'gateway-preview-btn btn btn-secondary',
624-
($numProbPerPage && $numPages > 1) ? (data_page_number => $pageNumber) : () =%>
644+
($numProbPerPage && $numPages > 1) ? (data => { page_number => $pageNumber }) : () =%>
625645
</div>
626646
%
627647
% if ($resultsTable) {

0 commit comments

Comments
 (0)