Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PG Problem Editor file selector #2677

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

drgrice1
Copy link
Member

This changes the PG Problem Editor to not assume a file type when opened without a file type specified. So when the problem editor is opened from the site navigation link it does not directly open to the blank file template. Instead it opens to a file chooser page. On that page, three options are presented. The user may choose a "New Problem Template", a "File" and give a path relative to the course templates directory, or a "Sample Problem" and pick a sample problem file from a dropdown.

In order to support sample problems a new file type needed to be implemented for the problem editor. The sample problem parsing module for PG is used to strip out the documentation when the problem is loaded into the editor.

However, I observed that the current code for that used by the sample problem viewer to offer a sample problem file for download is highly innefficient. It currently reads all of the sample problem files, then reads all of the PG macros, and then parses the desired problem stripping out documentation, and finally serves the file. So the PG pull request openwebwork/pg#1198 adds a getSampleProblemCode method that simply reads only the desired sample problem and efficiently strips out the documentation without needing the macros and sample problem metadata. So instead of needing to read 253 files (the number of macros plus the number of sample problems currently), it only reads 1.

To test this make sure to check out openwebwork/pg#1198.

@drgrice1
Copy link
Member Author

I forgot to mention that I made the editor NOT show the "Append form for a new blank problem as it was before. That is because that doesn't work. If you use it, it adds the path /opt/webwork/webwork2/assets/pg/newProblem.pg to the set, and that path doesn't work quite right in a set. It actually works when you view the problem (and really shouldn't -- that is a security vulnerability that needs to be investigated), but it shows "This source file does not exist!" when you view the set on the set detail page. Really, the new problem should be saved to a new file in the course templates directory before adding it to a set.

@pstaabp
Copy link
Member

pstaabp commented Feb 25, 2025

I'm getting the following error:

"getCleanSampleProblemCode" is not exported by the SampleProblemParser module Can't continue after import errors at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/SampleProblemViewer.pm line 23. BEGIN failed--compilation aborted at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/SampleProblemViewer.pm line 23. Compilation failed in require at (eval 744) line 1.

I think you mean to import "getSampleProblemCode".

@drgrice1 drgrice1 force-pushed the problem-editor-file-chooser branch from 1ca3725 to 9d832a6 Compare February 25, 2025 16:19
@drgrice1
Copy link
Member Author

Oops. I changed the method name on the PG side at some point and forgot to change it here also.

@pstaabp
Copy link
Member

pstaabp commented Feb 25, 2025

This works now. Seems like the workflow to use the sample problems in the editor is to

  1. go to the Problem Editor
  2. Select the sample problem by name.
  3. Save a copy of the problem
  4. In the problem editor, Append the problem to an existing set.

We were discussing the ability to have a link (or button) on the Sample Problem page to take you to the problem editor. Did this not work well?

@drgrice1
Copy link
Member Author

I mentioned last week that a link on the sample problem page to the editor is challenging because you don't even have a course name on that page. I thought about it a little more, and I don't think it is even possible to do. I don't think that having a course name is even enough, and getting that in is a messy hack to begin with.

@pstaabp
Copy link
Member

pstaabp commented Feb 25, 2025

I know we had talked about this. Maybe we can add some help to the sample problems to explain how to use the problem editor to get the problem.

Also, I'm thinking we might be able to add an option on the "Save As" in the Problem Editor to append to an existing set to simplify a bit more.

Neither of these should be part of this PR, just brainstorming.

This changes the PG Problem Editor to not assume a file type when opened
without a file type specified.  So when the problem editor is opened
from the site navigation link it does not directly open to the blank
file template.  Instead it opens to a file chooser page. On that page,
three options are presented.  The user may choose a "New Problem
Template", a "File" and give a path relative to the course templates
directory, or a "Sample Problem" and pick a sample problem file from a
dropdown.

In order to support sample problems a new file type needed to be
implemented for the problem editor.  The sample problem parsing module
for PG is used to strip out the documentation when the problem is loaded
into the editor.

However, I observed that the current code for that used by the sample
problem viewer to offer a sample problem file for download is highly
innefficient.  It currently reads all of the sample problem files, then
reads all of the PG macros, and then parses the desired problem
stripping out documentation, and finally serves the file. So a
corresponding PG pull request adds a `getSampleProblemCode` method that
simply reads only the desired sample problem and efficiently strips out
the documentation without needing the macros and sample problem
metadata. So instead of needing to read 253 files (the number of macros
plus the number of sample problems currently), it only reads 1.
@drgrice1 drgrice1 force-pushed the problem-editor-file-chooser branch from 9d832a6 to bb23dbc Compare February 25, 2025 20:48
@Alex-Jordan
Copy link
Contributor

This is great. I'm just going to mention a thought, and defer to @drgrice1 about if it would be worth pursuing. What if there were a fourth option when you go to the Editor, that is basically like the File Manager? So you could browse files, enter folders, and then select a file to edit? It would be redundant, since you can also just go to File Manager if that's what you want. It only occurs to be if I was of a mind to go edit a file in some folder in my course, and on autopilot, I might go to the Editor instead of the File Manager. And I might not be able to recall (or correctly type) the path.

Copy link
Contributor

@Alex-Jordan Alex-Jordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, even with the comment/question I just left.

@drgrice1
Copy link
Member Author

drgrice1 commented Mar 1, 2025

I think that would be nice, and I also thought of something like that. I think that will take a bit more effort to achieve though. So perhaps that could be done in a future pull request.

As I mentioned in the meeting last week, I think there are other possibilities for options on this page as well. Like opening a file on the user's local computer directly in the editor.

Copy link
Member

@pstaabp pstaabp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good start and we can update the Problem Editor in a later PR.

As I mentioned I think we can do some other streamlining on the "Save As" tab as well.

@pstaabp pstaabp merged commit 79dced1 into openwebwork:develop Mar 4, 2025
2 checks passed
@drgrice1 drgrice1 deleted the problem-editor-file-chooser branch March 4, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants