Skip to content

Commit

Permalink
Update the renderer for the restructuring of PG.
Browse files Browse the repository at this point in the history
The WeBWorK::PG module is now part of PG, and PG has its own environment
so the webwork2 WeBWorK::PG module (and its derivatives) have been
removed.

The WeBWorK::Constants, WeBWorK::Debug, and WeBWork::CourseEnvironment
modulesa and the webwork2 conf files are no longer needed and so are
removed.  The renderer uses the WeBWorK::PG::Environment module which is
part of PG.  Note that this adds one minor installation step for the
renderer.  The file conf/pg_config.yml must be copied to lib/PG/conf.
Usually that file will work as is, but in some cases administrators may
want to make changes to it.  For example, the externalPrograms are the
standard linux executables and in the standard locations.  On some
systems those may need to be changed.

Most of the WeBWorK::Utils module has been removed.  All that is left is
the two methods that the renderer uses.

In addition the renderer lib directory has been flattened.
lib/WeBWorK/lib/WeBWorK is now just lib/WeBWorK.  With this (among other
things) the WEBWORK_ROOT environment variable is not needed.  Note that
$WeBWorK::Constants::PG_DIRECTORY is not available.  $ENV{PG_ROOT} is
used instead in the renderer code.

Note that the unnecessary encoding and decoding of perl warnings has
been removed.

Also note that the references to drdrew42 have been changed to
openwebwork.
  • Loading branch information
drgrice1 committed Oct 27, 2022
1 parent ec3a7b8 commit dbedb41
Showing 48 changed files with 542 additions and 5,144 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lib/WeBWorK/htdocs/** linguist-vendored
public/** linguist-vendored
*.pl linguist-language=Perl
2 changes: 0 additions & 2 deletions .github/CODEOWNERS

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/createContainer.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ name: Github Packages Release
on:
push:
branches:
- master
- main
- development
tags:
- v*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ lib/WeBWorK/bin/*
webwork-open-problem-library/
private/
tmp/*
!tmp/.gitkeep
logs/*.log
node_modules
node_modules/*
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM ubuntu:20.04
LABEL org.opencontainers.image.source=https://github.com/drdrew42/renderer
MAINTAINER drdrew42
LABEL org.opencontainers.image.source=https://github.com/openwebwork/renderer

WORKDIR /usr/app
ARG DEBIAN_FRONTEND=noninteractive
@@ -11,10 +10,8 @@ RUN apt-get update \
apt-utils \
git \
gcc \
npm \
make \
curl \
nodejs \
dvipng \
openssl \
libc-dev \
@@ -43,6 +40,9 @@ RUN apt-get update \
libmath-random-secure-perl \
libdata-structure-util-perl \
liblocale-maketext-lexicon-perl \
libyaml-libyaml-perl \
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y --no-install-recommends --no-install-suggests nodejs \
&& apt-get clean \
&& rm -fr /var/lib/apt/lists/* /tmp/*

@@ -51,7 +51,13 @@ RUN cpanm install Mojo::Base Statistics::R::IO::Rserve Date::Format Future::Asyn

COPY . .

RUN cd lib/WeBWorK/htdocs && npm install && cd ../../..
RUN cp render_app.conf.dist render_app.conf

RUN cp conf/pg_config.yml lib/PG/conf/pg_config.yml

RUN npm install

RUN cd lib/PG/htdocs && npm install && cd ../../..

EXPOSE 3000

14 changes: 9 additions & 5 deletions Dockerfile_with_OPL
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM ubuntu:20.04
LABEL org.opencontainers.image.source=https://github.com/drdrew42/renderer
MAINTAINER drdrew42
LABEL org.opencontainers.image.source=https://github.com/openwebwork/renderer

WORKDIR /usr/app
ARG DEBIAN_FRONTEND=noninteractive
@@ -11,10 +10,8 @@ RUN apt-get update \
apt-utils \
git \
gcc \
npm \
make \
curl \
nodejs \
dvipng \
openssl \
libc-dev \
@@ -43,6 +40,9 @@ RUN apt-get update \
libmath-random-secure-perl \
libdata-structure-util-perl \
liblocale-maketext-lexicon-perl \
libyaml-libyaml-perl \
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y --no-install-recommends --no-install-suggests nodejs \
&& apt-get clean \
&& rm -fr /var/lib/apt/lists/* /tmp/*

@@ -64,7 +64,11 @@ COPY . .

RUN cp render_app.conf.dist render_app.conf

RUN cd lib/WeBWorK/htdocs && npm install && cd ../../..
RUN cp conf/pg_config.yml lib/PG/conf/pg_config.yml

RUN npm install

RUN cd lib/PG/htdocs && npm install && cd ../../..

EXPOSE 3000

74 changes: 42 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# WeBWorK Standalone Problem Renderer & Editor

![Commit Activity](https://img.shields.io/github/commit-activity/m/drdrew42/renderer?style=plastic)
![License](https://img.shields.io/github/license/drdrew42/renderer?style=plastic)

![Commit Activity](https://img.shields.io/github/commit-activity/m/openwebwork/renderer?style=plastic)
![License](https://img.shields.io/github/license/openwebwork/renderer?style=plastic)

This is a PG Renderer derived from the WeBWorK2 codebase
* https://github.com/openwebwork/WeBWorK2

## DOCKER CONTAINER INSTALL ###
* [https://github.com/openwebwork/webwork2](https://github.com/openwebwork/webwork2)

```
## DOCKER CONTAINER INSTALL

```bash
mkdir volumes
mkdir container
git clone https://github.com/openwebwork/webwork-open-problem-library volumes/webwork-open-problem-library
git clone --recursive https://github.com/drdrew42/renderer container/
git clone --recursive https://github.com/openwebwork/renderer container/
docker build --tag renderer:1.0 ./container

docker run -d \
@@ -25,35 +25,41 @@ docker run -d \
renderer:1.0
```

If you have non-OPL content, it can be mounted as a volume at `/usr/app/private` by adding the following line to the `docker run` command:
If you have non-OPL content, it can be mounted as a volume at `/usr/app/private` by adding the following line to the
`docker run` command:

```
```bash
--mount type=bind,source=/pathToYourLocalContentRoot,target=/usr/app/private \
```

A default configuration file is included in the container, but it can be overridden by mounting a replacement at the application root. This is necessary if, for example, you want to run the container in `production` mode.
A default configuration file is included in the container, but it can be overridden by mounting a replacement at the
application root. This is necessary if, for example, you want to run the container in `production` mode.

```
```bash
--mount type=bind,source=/pathToYour/render_app.conf,target=/usr/app/render_app.conf \
```

## LOCAL INSTALL ###
## LOCAL INSTALL

If using a local install instead of docker:

* Clone the renderer and its submodules: `git clone --recursive https://github.com/drdrew42/renderer`
* Clone the renderer and its submodules: `git clone --recursive https://github.com/openwebwork/renderer`
* Enter the project directory: `cd renderer`
* Install perl dependencies listed in Dockerfile (CPANMinus recommended)
* Install Perl dependencies listed in Dockerfile (CPANMinus recommended)
* clone webwork-open-problem-library into the provided stub ./webwork-open-problem-library
- `git clone https://github.com/openwebwork/webwork-open-problem-library ./webwork-open-problem-library`
* `git clone https://github.com/openwebwork/webwork-open-problem-library ./webwork-open-problem-library`
* copy `render_app.conf.dist` to `render_app.conf` and make any desired modifications
* install other dependencies
- `cd lib/WeBWorK/htdocs`
- `npm install`
* start the app with `morbo ./script/render_app` or `morbo -l http://localhost:3000 ./script/render_app` if changing root url
* copy `conf/pg_config.yml` to `lib/PG/pg_config.yml` and make any desired modifications
* install third party JavaScript dependencies
* `npm install`
* install PG JavaScript dependencies
* `cd lib/PG/htdocs`
* `npm install`
* start the app with `morbo ./script/render_app` or `morbo -l http://localhost:3000 ./script/render_app` if changing
root url
* access on `localhost:3000` by default or otherwise specified root url

# Editor Interface
## Editor Interface

* point your browser at [`localhost:3000`](http://localhost:3000/)
* select an output format (see below)
@@ -64,10 +70,12 @@ If using a local install instead of docker:

![image](https://user-images.githubusercontent.com/3385756/129100124-72270558-376d-4265-afe2-73b5c9a829af.png)

# Renderer API
## Renderer API

Can be interfaced through `/render-api`

## Parameters

| Key | Type | Default Value | Required | Description | Notes |
| --- | ---- | ------------- | -------- | ----------- | ----- |
| problemSourceURL | string | null | true if `sourceFilePath` and `problemSource` are null | The URL from which to fetch the problem source code | Takes precedence over `problemSource` and `sourceFilePath`. A request to this URL is expected to return valid pg source code in base64 encoding. |
@@ -80,19 +88,21 @@ Can be interfaced through `/render-api`
| format | string | '' | false | Determine how the response is formatted ('html' or 'json') ||
| outputFormat | string (enum) | static | false | Determines how the problem should render, see below descriptions below | |
| language | string | en | false | Language to render the problem in (if supported) | |
| showHints | number (boolean) | 1 | false | Whether or not to show hints (restrictions apply) | Irrelevant if `permissionLevel >= 10`, in which case `showHints` is regarded as automatically 'true' |
| showSolutions | number (boolean) | 0 | false | Whether or not to show the solutions (restrictions apply) | Irrelevant if `permissionLevel >= 10`, in which case `showSolutions` is regarded as automatically 'true' |
| permissionLevel | number | 0 | false | Affects the rendering of hints and solutions. Also controls display of scaffold problems (possibly more) | See the levels we use below |
| showHints | number (boolean) | 1 | false | Whether or not to show hints | |
| showSolutions | number (boolean) | 0 | false | Whether or not to show the solutions | |
| permissionLevel | number | 0 | false | Deprecated. See below. |
| isInstructor | number (boolean) | 0 | false | Is the user viewing the problem an instructor or not. | Used by PG to determine if scaffolds can be allowed to be open among other things |
| problemNumber | number | 1 | false | We don't use this | |
| numCorrect | number | 0 | false | The number of correct attempts on a problem | |
| numIncorrect | number | 1000 | false | the number of incorrect attempts on this problem | Relevant for triggering hints that are not immediately available |
| numIncorrect | number | 1000 | false | The number of incorrect attempts on this problem | |
| processAnswers | number (boolean) | 1 | false | Determines whether or not answer json is populated, and whether or not problem_result and problem_state are non-empty | |
| answersSubmitted | number (boolean) | ? | false? | Determines whether to process form-data associated to the available input fields | |
| showSummary | number (boolean) | ? | false? | Determines whether or not to show the summary result of processing the form-data associated with `answersSubmitted` above ||
| showComments | number (boolean) | 0 | false | Renders author comment field at the end of the problem ||
| includeTags | number (boolean) | 0 | false | Includes problem tags in the returned JSON | Only relevant when requesting `format: 'json'` |

## Output Format

| Key | Description |
| ----- | ----- |
| static | zero buttons, locked form fields (read-only) |
@@ -103,16 +113,16 @@ Can be interfaced through `/render-api`
| practice | check answers + show answers buttons |

## Permission level

| Key | Value |
| --- | ----- |
| student | 0 |
| prof | 10 |
| admin | 20 |

## Permission logic summary for hints and solutions
* If `permissionLevel >= 10`, then hints and solutions will be rendered - no exceptions.
* If `permissionLevel < 10`, then:
- solutions (if they are provided in the pg source code) will be rendered if and only if `showSolutions` is true.
- hints (if they are provided in the pg source code) will be rendered if and only if:
+ `showHints` is true, and
+ `numCorrect + numIncorrect > n` where `n` is set by the pg sourcce code being rendered
## Permission logic summary

* `permissionLevel` is ignored if `isInstructor` is directly set.
* If `permissionLevel >= 10`, then `isInstructor` will be set to true.
* If `permissionLevel < 10`, then `isInstructor` will be set to false.
* `permissionLevel` is not used to determine if hints or solutions are shown.
Loading

0 comments on commit dbedb41

Please sign in to comment.