From ded41b37143ad83213f98323606fb393195c4a57 Mon Sep 17 00:00:00 2001
From: Peter Staab
Date: Tue, 26 Sep 2023 07:30:39 -0400
Subject: [PATCH] Change the name of the action to "Format Code" and fix some
errors.
---
htdocs/js/PGProblemEditor/pgproblemeditor.js | 8 ++---
.../Instructor/PGProblemEditor.pm | 12 +++----
lib/WebworkWebservice/ProblemActions.pm | 5 ++-
.../PGProblemEditor/clean_code_form.html.ep | 32 -------------------
.../PGProblemEditor/format_code_form.html.ep | 32 +++++++++++++++++++
.../InstructorPGProblemEditor.html.ep | 8 ++---
6 files changed, 48 insertions(+), 49 deletions(-)
delete mode 100644 templates/ContentGenerator/Instructor/PGProblemEditor/clean_code_form.html.ep
create mode 100644 templates/ContentGenerator/Instructor/PGProblemEditor/format_code_form.html.ep
diff --git a/htdocs/js/PGProblemEditor/pgproblemeditor.js b/htdocs/js/PGProblemEditor/pgproblemeditor.js
index 94043f47d0..d36bb38143 100644
--- a/htdocs/js/PGProblemEditor/pgproblemeditor.js
+++ b/htdocs/js/PGProblemEditor/pgproblemeditor.js
@@ -99,14 +99,14 @@
}
// Send a request to the server to either perltidy or convert_to_PGML the current PG code in the CodeMirror editor.
- const cleanPGCode = () => {
+ const formatPGCode = () => {
const request_object = {
user: document.getElementById('hidden_user')?.value,
courseID: document.getElementsByName('courseID')[0]?.value,
key: document.getElementById('hidden_key')?.value
};
- request_object.rpc_command = document.querySelector('input[name="action.clean_code"]:checked').value;
+ request_object.rpc_command = document.querySelector('input[name="action.format_code"]:checked').value;
request_object.pgCode = webworkConfig?.pgCodeMirror?.getValue()
?? document.getElementById('problemContents')?.value ?? '';
@@ -140,9 +140,9 @@
};
document.getElementById('take_action')?.addEventListener('click', async (e) => {
- if (document.getElementById('current_action')?.value === 'clean_code') {
+ if (document.getElementById('current_action')?.value === 'format_code') {
e.preventDefault();
- cleanPGCode();
+ formatPGCode();
return;
}
diff --git a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
index ea0242bce5..2a769ca9ec 100644
--- a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
+++ b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
@@ -100,7 +100,7 @@ the submit button pressed (the action).
Requested actions and aliases
View/Reload action = view
Generate Hardcopy: action = hardcopy
- Clean Code: action = clean_code
+ Format Code: action = format_code
Save: action = save
Save as: action = save_as
Append: action = add_problem
@@ -125,11 +125,11 @@ use WeBWorK::Utils::Instructor qw(assignProblemToAllSetUsers addProblemToSet);
use constant DEFAULT_SEED => 123456;
# Editor tabs
-use constant ACTION_FORMS => [qw(view hardcopy clean_code save save_as add_problem revert)];
+use constant ACTION_FORMS => [qw(view hardcopy format_code save save_as add_problem revert)];
use constant ACTION_FORM_TITLES => {
view => x('View/Reload'),
hardcopy => x('Generate Hardcopy'),
- clean_code => x('Clean Code'),
+ format_code => x('Format Code'),
save => x('Save'),
save_as => x('Save As'),
add_problem => x('Append'),
@@ -845,10 +845,10 @@ sub view_handler ($c) {
return;
}
-# The hardcopy and pgtidy actions are handled by javascript. These are provided just in case
+# The hardcopy and format_code actions are handled by javascript. These are provided just in case
# something goes wrong and the actions are called.
-sub hardcopy_action { }
-sub clean_code_action { }
+sub hardcopy_action { }
+sub format_code_action { }
sub hardcopy_handler ($c) {
# Redirect to problem editor page.
diff --git a/lib/WebworkWebservice/ProblemActions.pm b/lib/WebworkWebservice/ProblemActions.pm
index 3d7f67c539..653bbc5d86 100644
--- a/lib/WebworkWebservice/ProblemActions.pm
+++ b/lib/WebworkWebservice/ProblemActions.pm
@@ -22,7 +22,7 @@ use warnings;
use Data::Structure::Util qw(unbless);
use WeBWorK::PG::Tidy qw(pgtidy);
-use Webwork::PG::ConvertToPGML qw(convertToPGML);
+use WeBWorK::PG::ConvertToPGML qw(convertToPGML);
sub getUserProblem {
my ($invocant, $self, $params) = @_;
@@ -151,8 +151,7 @@ sub convertCodeToPGML {
my ($invocant, $self, $params) = @_;
my $code = $params->{pgCode};
- # calling convertToPGML($code) without the module path returns an error. Not sure why.
- my $converted_code = WeBWorK::PG::ConvertToPGML::convertToPGML($code);
+ my $converted_code = convertToPGML($code);
return {
ra_out => { tidiedPGCode => $converted_code },
diff --git a/templates/ContentGenerator/Instructor/PGProblemEditor/clean_code_form.html.ep b/templates/ContentGenerator/Instructor/PGProblemEditor/clean_code_form.html.ep
deleted file mode 100644
index 433845cfe7..0000000000
--- a/templates/ContentGenerator/Instructor/PGProblemEditor/clean_code_form.html.ep
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
- <%= radio_button 'action.clean_code' => 'tidyPGCode',
- id => 'action_clean_code_perltidy', class => 'form-check-input', checked => undef =%>
- <%= label_for 'action_clean_code_perltidy', class => 'form-check-label', begin =%>
- <%== maketext('Reformat the code using perltidy.') =%>
- <% end =%>
-
-
-
- <%= radio_button 'action.clean_code' => 'convertCodeToPGML',
- id => 'action_clean_code_convert_PGML', class => 'form-check-input'=%>
- <%= label_for 'action_clean_code_convert_PGML', class => 'form-check-label', begin =%>
- <%== maketext('Convert the code to PGML') =%>
- <% end =%>
-
-
-
diff --git a/templates/ContentGenerator/Instructor/PGProblemEditor/format_code_form.html.ep b/templates/ContentGenerator/Instructor/PGProblemEditor/format_code_form.html.ep
new file mode 100644
index 0000000000..cb65dfda10
--- /dev/null
+++ b/templates/ContentGenerator/Instructor/PGProblemEditor/format_code_form.html.ep
@@ -0,0 +1,32 @@
+
+
+ <%= radio_button 'action.format_code' => 'tidyPGCode',
+ id => 'action_format_code_perltidy', class => 'form-check-input', checked => undef =%>
+ <%= label_for 'action_format_code_perltidy', class => 'form-check-label', begin =%>
+ <%== maketext('Reformat the code using perltidy.') =%>
+ <% end =%>
+
+
+
+ <%= radio_button 'action.format_code' => 'convertCodeToPGML',
+ id => 'action_format_code_convert_PGML', class => 'form-check-input'=%>
+ <%= label_for 'action_format_code_convert_PGML', class => 'form-check-label', begin =%>
+ <%== maketext('Convert the code to PGML') =%>
+ <% end =%>
+
+
+
diff --git a/templates/HelpFiles/InstructorPGProblemEditor.html.ep b/templates/HelpFiles/InstructorPGProblemEditor.html.ep
index 903cd0ae07..050cc8cdaf 100644
--- a/templates/HelpFiles/InstructorPGProblemEditor.html.ep
+++ b/templates/HelpFiles/InstructorPGProblemEditor.html.ep
@@ -129,12 +129,12 @@
- <%= maketext('Clean Code') %>
+ <%= maketext('Format Code') %>
<%= maketext('Reformat the code using perltidy or a conversion to PGML>. Using perltidy will change the code '
- . ' in the editor window, and save changes to the temporary file. In some cases (if the code contains '
- . 'backslashes or double tildes) this can result in odd spacing in the code. The convert to PGML '
- . 'feature changes the code in text blocks in the code to use PGML features. Generally the conversion of '
+ . 'in the editor window, and save changes to the temporary file. In some cases (if the code contains '
+ . 'backslashes or double tildes) this can result in odd spacing in the code. The convert to PGML '
+ . 'feature changes the code in text blocks in the code to use PGML features. Generally the conversion of '
. 'many of the formatting and LaTeX is performed correctly, however answer blanks need attention. In '
. 'either case, make sure to inspect the formatted code, and edit further or revert if needed.') =%>