From: Gavin L. v. a. <we...@ma...> - 2005-02-15 21:39:35
|
Log Message: ----------- major look and feel modification of GatewayQuiz module, to include jump to scrolling links, preview links for each problem, rearranged preview and correct answer output. Tags: ---- rel-2-1-a1 Modified Files: -------------- webwork2/lib/WeBWorK/ContentGenerator: GatewayQuiz.pm ProblemSet.pm Revision Data ------------- Index: ProblemSet.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/ProblemSet.pm,v retrieving revision 1.54.2.3 retrieving revision 1.54.2.4 diff -Llib/WeBWorK/ContentGenerator/ProblemSet.pm -Llib/WeBWorK/ContentGenerator/ProblemSet.pm -u -r1.54.2.3 -r1.54.2.4 --- lib/WeBWorK/ContentGenerator/ProblemSet.pm +++ lib/WeBWorK/ContentGenerator/ProblemSet.pm @@ -102,7 +102,7 @@ my @setIDs = sortByName(undef, $db->listUserSets($eUserID)); # do not show unpublished siblings unless user is allowed to view unpublished sets unless ($authz->hasPermissions($user, "view_unpublished_sets") ) { - @setIDs = grep {my $visible = $db->getGlobalSet( $_)->published; (defined($visible))? $visible : 1} + @setIDs = grep {my $vset = $db->getGlobalSet($_); my $visible = defined($vset) ? $vset->published : 0; (defined($visible))? $visible : 1} @setIDs; } print CGI::start_ul({class=>"LinksMenu"}); Index: GatewayQuiz.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm,v retrieving revision 1.9.4.6 retrieving revision 1.9.4.7 diff -Llib/WeBWorK/ContentGenerator/GatewayQuiz.pm -Llib/WeBWorK/ContentGenerator/GatewayQuiz.pm -u -r1.9.4.6 -r1.9.4.7 --- lib/WeBWorK/ContentGenerator/GatewayQuiz.pm +++ lib/WeBWorK/ContentGenerator/GatewayQuiz.pm @@ -48,6 +48,12 @@ use WeBWorK::ContentGenerator::Instructor qw(assignSetVersionToUser); +# template method +sub templateName { + return "gateway"; +} + + ################################################################################ # "can" methods ################################################################################ @@ -190,14 +196,12 @@ sub after { return time >= $_[0] } sub between { my $t = time; return $t > $_[0] && $t < $_[1] } -# *BeginPPM* ################################################################### -# this code taken from Problem.pm; excerpted section ends at *EndPPM* -# modifications are flagged with comments *GW* - ################################################################################ # output utilities ################################################################################ +# subroutine is modified from that in Problem.pm to produce a different +# table format sub attemptResults { my $self = shift; my $pg = shift; @@ -215,7 +219,7 @@ my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames; my $basename = "equation-" . $self->{set}->psvn. "." . $self->{problem}->problem_id . "-preview"; - + # to make grabbing these options easier, we'll pull them out now... my %imagesModeOptions = %{$ce->{pg}->{displayModeOptions}->{images}}; @@ -230,16 +234,21 @@ dvipng_align => $imagesModeOptions{dvipng_align}, dvipng_depth_db => $imagesModeOptions{dvipng_depth_db}, ); - - my $header; - #$header .= CGI::th("Part"); - $header .= $showAttemptAnswers ? CGI::th("Entered") : ""; - $header .= $showAttemptPreview ? CGI::th("Answer Preview") : ""; - $header .= $showCorrectAnswers ? CGI::th("Correct") : ""; - $header .= $showAttemptResults ? CGI::th("Result") : ""; - $header .= $showMessages ? CGI::th("Messages") : ""; - my @tableRows = ( $header ); + + my %resultsData = (); + $resultsData{'Entered'} = CGI::td({-class=>"label"}, "Your answer parses as:"); + $resultsData{'Preview'} = CGI::td({-class=>"label"}, "Your answer previews as:"); + $resultsData{'Correct'} = CGI::td({-class=>"label"}, "The correct answer is:"); + $resultsData{'Results'} = CGI::td({-class=>"label"}, "Result:"); + $resultsData{'Messages'} = CGI::td({-class=>"label"}, "Messages:"); + + my %resultsRows = (); + foreach ( qw( Entered Preview Correct Results Messages ) ) { + $resultsRows{$_} = ""; + } + my $numCorrect = 0; + my $numAns = 0; foreach my $name (@answerNames) { my $answerResult = $pg->{answers}->{$name}; my $studentAnswer = $answerResult->{student_ans}; # original_student_ans @@ -257,14 +266,29 @@ # of the answer names is changeable. this only fixes it for "AnSwEr" #$name =~ s/^AnSwEr//; - my $row; - #$row .= CGI::td($name); - $row .= $showAttemptAnswers ? CGI::td($self->nbsp($studentAnswer)) : ""; - $row .= $showAttemptPreview ? CGI::td($self->nbsp($preview)) : ""; - $row .= $showCorrectAnswers ? CGI::td($self->nbsp($correctAnswer)) : ""; - $row .= $showAttemptResults ? CGI::td($self->nbsp($resultString)) : ""; - $row .= $showMessages ? CGI::td($self->nbsp($answerMessage)) : ""; - push @tableRows, $row; + my $pre = $numAns ? CGI::td(" ") : ""; + + $resultsRows{'Entered'} .= $showAttemptAnswers ? + CGI::Tr( $pre . $resultsData{'Entered'} . + CGI::td({-class=>"output"}, $self->nbsp($studentAnswer))) : ""; + $resultsData{'Entered'} = ''; + $resultsRows{'Preview'} .= $showAttemptPreview ? + CGI::Tr( $pre . $resultsData{'Preview'} . + CGI::td({-class=>"output"}, $self->nbsp($preview)) ) : ""; + $resultsData{'Preview'} = ''; + $resultsRows{'Correct'} .= $showCorrectAnswers ? + CGI::Tr( $pre . $resultsData{'Correct'} . + CGI::td({-class=>"output"}, $self->nbsp($correctAnswer)) ) : ""; + $resultsData{'Correct'} = ''; + $resultsRows{'Results'} .= $showAttemptResults ? + CGI::Tr( $pre . $resultsData{'Results'} . + CGI::td({-class=>"output"}, $self->nbsp($resultString)) ) : ""; + $resultsRows{'Results'} = ''; + $resultsRows{'Messages'} .= $showMessages ? + CGI::Tr( $pre . $resultsData{'Messages'} . + CGI::td({-class=>"output"}, $self->nbsp($answerMessage)) ) : ""; + + $numAns++; } # render equation images @@ -282,23 +306,32 @@ my $summary = ""; if (scalar @answerNames == 1) { if ($numCorrect == scalar @answerNames) { - $summary .= CGI::div({class=>"ResultsWithoutError"},"The above answer is correct."); + $summary .= CGI::div({class=>"gwCorrect"},"This answer is correct."); } else { - $summary .= CGI::div({class=>"ResultsWithError"},"The above answer is NOT correct."); + $summary .= CGI::div({class=>"gwIncorrect"},"This answer is NOT correct."); } } else { if ($numCorrect == scalar @answerNames) { - $summary .= CGI::div({class=>"ResultsWithoutError"},"All of the above answers are correct."); + $summary .= CGI::div({class=>"gwCorrect"},"All of these answers are correct."); } else { - $summary .= CGI::div({class=>"ResultsWithError"},"At least one of the above answers is NOT correct."); + $summary .= CGI::div({class=>"gwIncorrect"},"At least one of these answers is NOT correct."); } } return - CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) - . ($showSummary ? CGI::p({class=>'emphasis'},$summary) : ""); +# CGI::table({-class=>"attemptResults"}, $resultsRows{'Entered'}, + CGI::table({-class=>"gwAttemptResults"}, $resultsRows{'Entered'}, + $resultsRows{'Preview'}, $resultsRows{'Correct'}, + $resultsRows{'Results'}, $resultsRows{'Messages'}) . + ($showSummary ? CGI::p({class=>'emphasis'},$summary) : ""); +# CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) +# . ($showSummary ? CGI::p({class=>'emphasis'},$summary) : ""); } +# *BeginPPM* ################################################################### +# this code taken from Problem.pm; excerpted section ends at *EndPPM* +# modifications are flagged with comments *GW* + sub viewOptions { my ($self) = @_; my $ce = $self->r->ce; @@ -411,6 +444,12 @@ my $effectiveUserName = $r->param('effectiveUser'); my $key = $r->param('key'); +# this is a horrible hack to allow use of a javascript link to trigger +# the preview of the page: set previewAnswers to yes if either the +# "previewAnswers" or "previewhack" inputs are set + my $prevOr = $r->param('previewAnswers') || $r->param('previewHack'); + $r->param('previewAnswers', $prevOr) if ( defined( $prevOr ) ); + my $User = $db->getUser($userName); die "record for user $userName (real user) does not exist." unless defined $User; @@ -431,9 +470,6 @@ # with that version. we do this after we've validated that the user is # assigned the set, below - # set a gateway template? FIXME - # $self->{templateName} = "gateway"; - ################################### # gateway content generator tests ################################### @@ -1198,7 +1234,7 @@ } if ( ! $can{recordAnswersNextTime} ) { - print CGI::start_div({style=>"background-color:#dddddd;"}); + print CGI::start_div({class=>"gwMessage"}); my $mesg = ( $requestedVersion ) ? '' : ", because you have used all available attempts on it or " . "because its time limit has expired.\n" . @@ -1210,7 +1246,7 @@ " right or wrong."), "\n\n"; print CGI::end_div(); } else { - print CGI::start_div({style=>"background-color:#ddddff;"}); + print CGI::start_div({class=>"gwTiming"}); print CGI::p(CGI::strong("This version started ", scalar(localtime($set->open_date())), CGI::br(),"\nTime limit : ", @@ -1220,7 +1256,7 @@ "The current time is ", scalar(localtime()))), "\n\n"; print CGI::end_div(); if ( $set->due_date() - $set->version_time_limit() < 1 ) { - print CGI::start_div({style=>"background-color:#ffffdd;"}); + print CGI::start_div({class=>"gwWarning"}); print CGI::p(CGI::strong("You have less than 1 minute to ", "complete this version.\n")); print CGI::end_div(); @@ -1228,9 +1264,25 @@ } - print CGI::startform("POST", $r->uri), $self->hidden_authen_fields, + print CGI::startform({-name=>"gwquiz", -method=>"POST", -action=>$r->uri}), $self->hidden_authen_fields, $self->hidden_proctor_authen_fields; +# FIXME RETURNTO +# this is a horrible hack to try and let us use a javascript link to +# trigger previews + print CGI::hidden({-name=>'previewHack', -value=>''}), CGI::br(); +# and the text for the link + my $jsprevlink = 'javascript:document.gwquiz.previewHack.value="1";' . + 'document.gwquiz.submit();'; + +# some links to easily move between problems + my $jumpLinks = "Jump to problem: "; + for my $i ( 0 .. $#pg_results ) { + my $pn = $i+1; + $jumpLinks .= "/ " . CGI::a({-href=>".", -onclick=>"jumpTo($i);return false;"}, "$pn") . " /"; + } + print CGI::p($jumpLinks,"\n"); + # print out problems and attempt results, as appropriate # note: args to attemptResults are (self,) $pg, $showAttemptAnswers, # $showCorrectAnswers, $showAttemptResults (and-ed with @@ -1262,42 +1314,74 @@ $problemNumber++; # print "pCA = >", (defined($pg->{flags}->{showPartialCorrectAnswers}) ? $pg->{flags}->{showPartialCorrectAnswers} : "undef"), "<"; - print CGI::start_div({class=>"problemHeader"}); + + my $recordMessage = ''; + my $resultsTable = ''; + +# print CGI::start_div({class=>"problemHeader", -style=>"border: solid black 1px;"}); + +# FIXME: I've coded the "ResultsWithError" style into the recordMessage strings +# FIXME: manually; this should be pushed out to the template or stylesheet. + if ($pg->{flags}->{showPartialCorrectAnswers} >= 0 && $submitAnswers) { if ( $scoreRecordedMessage[$probOrder[$i]] ne "Your score on this problem was recorded." ) { - print CGI::div({class=>'ResultsWithError'}, - "ANSWERS NOT RECORDED --", CGI::br(), - $scoreRecordedMessage[$probOrder[$i]],CGI::br()); + $recordMessage = CGI::span({class=>"resultsWithError"}, + "ANSWERS NOT RECORDED --", + $scoreRecordedMessage[$probOrder[$i]]); +# print CGI::div({class=>'ResultsWithError'}, +# "ANSWERS NOT RECORDED --", +# $scoreRecordedMessage[$probOrder[$i]],CGI::br()); } - print + $resultsTable = $self->attemptResults($pg, 1, $will{showCorrectAnswers}, $pg->{flags}->{showPartialCorrectAnswers}, 1, 1); +# print $self->attemptResults($pg, 1, $will{showCorrectAnswers}, +# $pg->{flags}->{showPartialCorrectAnswers}, +# 1, 1); + } elsif ( $checkAnswers ) { - print CGI::div({class=>'ResultsWithError'}, - "ANSWERS ONLY CHECKED -- ", CGI::br(), - "ANSWERS NOT RECORDED", CGI::br() ); - print + $recordMessage = CGI::span({class=>"resultsWithError"}, + "ANSWERS ONLY CHECKED -- ", + "ANSWERS NOT RECORDED"); +# print CGI::div({class=>'ResultsWithError'}, +# "ANSWERS ONLY CHECKED -- ", +# "ANSWERS NOT RECORDED", CGI::br() ); + $resultsTable = $self->attemptResults($pg, 1, $will{showCorrectAnswers}, $pg->{flags}->{showPartialCorrectAnswers}, 1, 1); +# print +# $self->attemptResults($pg, 1, $will{showCorrectAnswers}, +# $pg->{flags}->{showPartialCorrectAnswers}, +# 1, 1); } elsif ( $previewAnswers ) { - print CGI::div({class=>'ResultsWithError'}, - "PREVIEW ONLY -- ", CGI::br(), - "ANSWERS NOT RECORDED", CGI::br() ); - print $self->attemptResults($pg, 1, 0, 0, 0, 1); + $recordMessage = CGI::span({class=>"resultsWithError"}, + "PREVIEW ONLY -- ANSWERS NOT RECORDED"); +# print CGI::div({class=>'ResultsWithError'}, +# "PREVIEW ONLY -- ANSWERS NOT RECORDED", CGI::br() ); + $resultsTable = $self->attemptResults($pg, 1, 0, 0, 0, 1); +# print $self->attemptResults($pg, 1, 0, 0, 0, 1); } - print CGI::end_div(); - print CGI::start_div({class=>"problem"}); - print CGI::strong("Problem $problemNumber."), "\n"; + print CGI::start_div({class=>"gwProblem"}); + print CGI::a({-name=>"#$i"},""); + print CGI::strong("Problem $problemNumber."), "\n", $recordMessage; print CGI::p($pg->{body_text}), CGI::p($pg->{result}->{msg} ? CGI::b("Note: ") : "", CGI::i($pg->{result}->{msg})); + print CGI::p({class=>"gwPreview"}, + CGI::a({-href=>"$jsprevlink"}, "preview problems")); +# print CGI::end_div(); + + print $resultsTable if $resultsTable; + print CGI::end_div(); + print "\n", CGI::hr(), "\n"; } + print CGI::p($jumpLinks, "\n"); if ($can{showCorrectAnswers}) { print CGI::checkbox(-name => "showCorrectAnswers", |