Skip to content

Commit

Permalink
Make the PG problem editor always regenerate dynamic images.
Browse files Browse the repository at this point in the history
Currently if a problem that uses dynamically generated images is edited
and the code for generated an image changes the image is not regenerated
unless you force it by adding `$refreshCachedImages = 1` to the problem
itself.  This is problematic as an author may forget to remove that
later which can cause unneeded image regeneration in production use.

The problem editor now forces image generation by setting
`refreshCachedImages` in the PG environment.  For this to work a minor
change is needed to PG.
  • Loading branch information
drgrice1 committed Dec 17, 2023
1 parent 2b193de commit f1a4586
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions htdocs/js/PGProblemEditor/pgproblemeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
requestData.set('send_pg_flags', 1);
requestData.set(button.name, button.value);
requestData.set('set_id', document.getElementsByName('hidden_set_id')[0]?.value ?? 'Unknown Set');
requestData.set('refreshCachedImages', 1);

renderProblem(requestData);

Expand Down Expand Up @@ -357,6 +358,7 @@
showFooter: 0,
displayMode: document.getElementById('action_view_displayMode_id')?.value ?? 'MathJax',
language: document.querySelector('input[name="hidden_language"]')?.value ?? 'en',
refreshCachedImages: 1,
send_pg_flags: 1,
view_problem_debugging_info: 1
})).then(() => resolve());
Expand Down Expand Up @@ -444,6 +446,7 @@
noprepostambles: 1,
processAnswers: 1,
displayMode: 'tex',
refreshCachedImages: 1,
view_problem_debugging_info: 1
})
});
Expand Down
17 changes: 9 additions & 8 deletions lib/WeBWorK/Utils/Rendering.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ sub constructPGOptions ($ce, $user, $set, $problem, $psvn, $formFields, $transla
$options{problemSeed} = $problem->problem_seed;

# Display information
$options{displayMode} = $translationOptions->{displayMode};
$options{showHints} = $translationOptions->{showHints};
$options{showSolutions} = $translationOptions->{showSolutions};
$options{forceScaffoldsOpen} = $translationOptions->{forceScaffoldsOpen};
$options{setOpen} = time > $set->open_date;
$options{pastDue} = time > $set->due_date;
$options{answersAvailable} = time > $set->answer_date;
$options{refreshMath2img} = $translationOptions->{refreshMath2img};
$options{displayMode} = $translationOptions->{displayMode};
$options{showHints} = $translationOptions->{showHints};
$options{showSolutions} = $translationOptions->{showSolutions};
$options{forceScaffoldsOpen} = $translationOptions->{forceScaffoldsOpen};
$options{setOpen} = time > $set->open_date;
$options{pastDue} = time > $set->due_date;
$options{answersAvailable} = time > $set->answer_date;
$options{refreshMath2img} = $translationOptions->{refreshMath2img};
$options{refreshCachedImages} = $translationOptions->{refreshCachedImages};

# Default values for evaluating answers
$options{ansEvalDefaults} = $ce->{pg}{ansEvalDefaults};
Expand Down
3 changes: 2 additions & 1 deletion lib/WebworkWebservice/RenderProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ async sub renderProblem {
showHints => $rh->{showHints},
showSolutions => $rh->{showSolutions},
refreshMath2img => $rh->{showHints} || $rh->{showSolutions},
processAnswers => $rh->{processAnswers} // 1,
refreshCachedImages => $rh->{refreshCachedImages} // 0,
processAnswers => $rh->{processAnswers} // 1,
catchWarnings => 1,
r_source => $r_problem_source,
problemUUID => $rh->{problemUUID} // 0,
Expand Down

0 comments on commit f1a4586

Please sign in to comment.