Skip to content

Commit

Permalink
Change the name of the action to "Format Code" and fix some errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
pstaabp committed Jan 12, 2024
1 parent 4eccdc4 commit ded41b3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 49 deletions.
8 changes: 4 additions & 4 deletions htdocs/js/PGProblemEditor/pgproblemeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';

Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'),
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions lib/WebworkWebservice/ProblemActions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) = @_;
Expand Down Expand Up @@ -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 },
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div>
<div class="form-check">
<%= 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 =%>
<a class="help-popup" data-bs-content="<%== maketext('Perltidy is a reformatting '
. 'function that attempts to format code in a standard way. It does not change '
. 'the functionality of the code and in general is desired to have a common problem layout.') =%>"
data-bs-placement="top" data-bs-toggle="popover" role="button">
<i aria-hidden="true" class="icon fas fa-question-circle" data-alt="Help Icon"></i>
<span class="sr-only-glyphicon">Help Icon</span>
</a>
</div>
<div class="form-check">
<%= 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 =%>
<a class="help-popup" data-bs-content="<%== maketext('This option converts the text blocks '
. 'in the problem code to PGML and updates the loadMacros to include PGML and drop others. '
. 'This can be used as a first pass of the conversion, however the author will still need '
. 'to ensure the problem functions. One area of attention should be the answer blanks, '
. 'which are not automatically converted with the proper variable.') =%>"
data-bs-placement="top" data-bs-toggle="popover" role="button">
<i aria-hidden="true" class="icon fas fa-question-circle" data-alt="Help Icon"></i>
<span class="sr-only-glyphicon">Help Icon</span>
</a>
</div>
</div>
8 changes: 4 additions & 4 deletions templates/HelpFiles/InstructorPGProblemEditor.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@
</p>
</dd>

<dt><%= maketext('Clean Code') %></dt>
<dt><%= maketext('Format Code') %></dt>
<dd>
<%= 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.') =%>
</dd>
Expand Down

0 comments on commit ded41b3

Please sign in to comment.