Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ render_app.conf
lib/WeBWorK/htdocs/tmp/renderer/gif/*
lib/WeBWorK/htdocs/tmp/renderer/images/*
lib/WeBWorK/htdocs/DATA/*.json
lib/WeBWorK/htdocs/js/apps/Problem/problem.css
lib/WeBWorK/bin/*
webwork-open-problem-library/
private/
tmp/
tmp/*
logs/*.log
node_modules
node_modules/*
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "lib/PG"]
path = lib/PG
url = https://github.com/drgrice1/pg.git
branch = ww3-rendering-work-new
url = https://github.com/openwebwork/pg.git
branch = main
2 changes: 1 addition & 1 deletion lib/PG
Submodule PG updated 239 files
25 changes: 13 additions & 12 deletions lib/RenderApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ BEGIN {
use Mojo::File;
$main::dirname = Mojo::File::curfile->dirname;

#RENDER_ROOT is required for initializing conf files
# RENDER_ROOT is required for initializing conf files.
$ENV{RENDER_ROOT} = $main::dirname->dirname
unless ( defined( $ENV{RENDER_ROOT} ) );

#WEBWORK_ROOT is required for PG/lib/WeBWorK/IO
$ENV{WEBWORK_ROOT} = $main::dirname . '/WeBWorK'
unless ( defined( $ENV{WEBWORK_ROOT} ) );
# WEBWORK_ROOT is required for PG/lib/WeBWorK/IO.
# PG_ROOT is required for PG/lib/PGEnvironment.pm.
# These are hardcoded to avoid conflict with environment variables for webwork2.
# There is no need for these to be configurable.
$ENV{WEBWORK_ROOT} = $main::dirname . '/WeBWorK';
$ENV{PG_ROOT} = $main::dirname . '/PG';

#used for reconstructing library paths from sym-links
# Used for reconstructing library paths from sym-links.
$ENV{OPL_DIRECTORY} = "webwork-open-problem-library";
$WeBWorK::Constants::WEBWORK_DIRECTORY = $main::dirname . "/WeBWorK";
$WeBWorK::Constants::PG_DIRECTORY = $main::dirname . "/PG";
Expand Down Expand Up @@ -60,7 +63,7 @@ sub startup {

# Handle optional CORS settings
if (my $CORS_ORIGIN = $self->config('CORS_ORIGIN')) {
die "CORS_ORIGIN ($CORS_ORIGIN) must be an absolute URL or '*'"
die "CORS_ORIGIN ($CORS_ORIGIN) must be an absolute URL or '*'"
unless ($CORS_ORIGIN eq '*' || $CORS_ORIGIN =~ /^https?:\/\//);

$self->hook(before_dispatch => sub {
Expand Down Expand Up @@ -108,12 +111,10 @@ sub startup {
$r->post('/render-api/tags')->to('IO#setTags');
}

# pass all requests via ww2_files through to lib/WeBWorK/htdocs
my $staticPath = $WeBWorK::Constants::WEBWORK_DIRECTORY."/htdocs/";
$r->any('/webwork2_files/*static' => sub {
my $c = shift;
$c->reply->file($staticPath.$c->stash('static'));
});
# Static file routes
$r->any('/webwork2_files/CAPA_Graphics/*static')->to('StaticFiles#CAPA_graphics_file');
$r->any('/webwork2_files/tmp/*static')->to('StaticFiles#temp_file');
$r->any('/pg_files/*static')->to('StaticFiles#pg_file');

# any other requests fall through
$r->any('/*fail' => sub {
Expand Down
63 changes: 34 additions & 29 deletions lib/RenderApp/Controller/FormatRenderedProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ FormatRenderedProblem.pm

package RenderApp::Controller::FormatRenderedProblem;

use warnings;
use strict;

use lib "$WeBWorK::Constants::WEBWORK_DIRECTORY/lib";
use lib "$WeBWorK::Constants::PG_DIRECTORY/lib";
use MIME::Base64 qw( encode_base64 decode_base64);
use WeBWorK::Utils::AttemptsTable; #import from ww2
use WeBWorK::PG::ImageGenerator; # import from ww2
use WeBWorK::Utils::LanguageAndDirection;
use WeBWorK::Utils qw( wwRound); # required for score summary
use WeBWorK::Utils qw(wwRound getAssetURL); # required for score summary
use WeBWorK::Localize ; # for maketext
our $UNIT_TESTS_ON = 0;

Expand All @@ -46,7 +49,7 @@ sub format_hash_ref {
sub new {
my $invocant = shift;
my $class = ref $invocant || $invocant;
$self = { # Is this function redundant given the declarations within sub formatRenderedProblem?
my $self = { # Is this function redundant given the declarations within sub formatRenderedProblem?
return_object => {},
encoded_source => {},
sourceFilePath => '',
Expand Down Expand Up @@ -199,7 +202,7 @@ sub formatRenderedProblem {
answersSubmitted => $self->{inputs_ref}{answersSubmitted}//0,
answerOrder => $answerOrder//[],
displayMode => $self->{inputs_ref}{displayMode},
imgGen => $imgGen,
imgGen => undef, # $imgGen,
ce => '', #used only to build the imgGen
showAnswerNumbers => 0,
showAttemptAnswers => 0,
Expand Down Expand Up @@ -242,45 +245,47 @@ sub formatRenderedProblem {

# Add JS files requested by problems via ADD_JS_FILE() in the PG file.
my $extra_js_files = '';
if (ref($rh_result->{flags}{extra_js_files}) eq "ARRAY") {
if (ref($rh_result->{flags}{extra_js_files}) eq 'ARRAY') {
$rh_result->{js} = [];
my %jsFiles;
for (@{$rh_result->{flags}{extra_js_files}}) {
# Avoid duplicates
next if $jsFiles{$_->{file}};
$jsFiles{$_->{file}} = 1;
my $attributes = ref($_->{attributes}) eq "HASH" ? $_->{attributes} : {};
for (@{ $rh_result->{flags}{extra_js_files} }) {
next if $jsFiles{ $_->{file} };
$jsFiles{ $_->{file} } = 1;
my %attributes = ref($_->{attributes}) eq 'HASH' ? %{ $_->{attributes} } : ();
if ($_->{external}) {
push @{$rh_result->{js}}, $_->{file};
$extra_js_files .= CGI::script({ src => $_->{file}, %$attributes}, '');
} elsif (!$_->{external} && -f "$ENV{WEBWORK_ROOT}/htdocs/$_->{file}") {
push @{$rh_result->{js}}, "$webwork_htdocs_url/$_->{file}";
$extra_js_files .= CGI::script({src => "$webwork_htdocs_url/$_->{file}", %$attributes}, '');
push @{ $rh_result->{js} }, $_->{file};
$extra_js_files .= CGI::script({ src => $_->{file}, %attributes }, '');
} else {
$extra_js_files .= "<!-- $_->{file} is not available in htdocs/ on this server -->";
my $url = getAssetURL($self->{inputs_ref}{language} // 'en', $_->{file});
push @{ $rh_result->{js} }, $SITE_URL.$url;
$extra_js_files .= CGI::script({ src => $url, %attributes }, '');
}
}
}

# Add CSS files requested by problems via ADD_CSS_FILE() in the PG file
# or via a setting of $self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}
# (the value should be an anonomous array).
my $extra_css_files = '';
my %cssFiles;
# Avoid duplicates
if (ref($self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_} = 0 for @{$self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}};
my @cssFiles;
if (ref($self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}) eq 'ARRAY') {
push(@cssFiles, { file => $_, external => 0 }) for @{ $self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files} };
}
if (ref($rh_result->{flags}{extra_css_files}) eq "ARRAY") {
$cssFiles{$_->{file}} = $_->{external} for @{$rh_result->{flags}{extra_css_files}};
if (ref($rh_result->{flags}{extra_css_files}) eq 'ARRAY') {
push @cssFiles, @{ $rh_result->{flags}{extra_css_files} };
}
my %cssFilesAdded; # Used to avoid duplicates
$rh_result->{css} = [];
for (keys(%cssFiles)) {
if ($cssFiles{$_}) {
push @{$rh_result->{css}}, $_;
$extra_css_files .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$_\" />\n";
} elsif (!$cssFiles{$_} && -f "$ENV{WEBWORK_ROOT}/htdocs/$_") {
push @{$rh_result->{css}}, "$webwork_htdocs_url/$_";
$extra_css_files .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$webwork_htdocs_url/$_\" />\n";
for (@cssFiles) {
next if $cssFilesAdded{ $_->{file} };
$cssFilesAdded{ $_->{file} } = 1;
if ($_->{external}) {
push @{ $rh_result->{css} }, $_->{file};
$extra_css_files .= CGI::Link({ rel => 'stylesheet', href => $_->{file} });
} else {
$extra_css_files .= "<!-- $_ is not available in htdocs/ on this server -->\n";
my $url = getAssetURL($self->{inputs_ref}{language} // 'en', $_->{file});
push @{ $rh_result->{css} }, $SITE_URL.$url;
$extra_css_files .= CGI::Link({ href => $url, rel => 'stylesheet' });
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/RenderApp/Controller/Render.pm
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ sub checkOutputs {
}
return
"Output from rendering "
. $outputs_ref->{sourceFilePath}
. ($outputs_ref->{sourceFilePath} // '')
. " contained errors: {"
. join "}, {", @errs . "}";
}
Expand Down Expand Up @@ -304,4 +304,4 @@ sub jwtFromRequest {
return $c->render( text => $req_jwt );
}

1;
1;
27 changes: 1 addition & 26 deletions lib/RenderApp/Controller/RenderProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ sub standaloneRenderer {
refreshMath2img => 1,
processAnswers => $processAnswers,
QUIZ_PREFIX => $inputs_ref->{answerPrefix} // '',
useMathQuill => !defined $inputs_ref->{entryAssist} || $inputs_ref->{entryAssist} eq 'MathQuill' ? 1 : 0,

#use_site_prefix => 'http://localhost:3000',
use_opaque_prefix => 0,
Expand Down Expand Up @@ -428,8 +429,6 @@ sub standaloneRenderer {
['Problem failed during render - no PGcore received.'];
}

insert_mathquill_responses( $inputs_ref, $pg );

my $out2 = {
text => $pg->{body_text},
header_text => $pg->{head_text},
Expand Down Expand Up @@ -523,30 +522,6 @@ sub generateJWTs {
return ($sessionJWT, $answerJWT);
}

# insert_mathquill_responses subroutine

# Add responses to each answer's response group that store the latex form of the students'
# answers and add corresponding hidden input boxes to the page.

sub insert_mathquill_responses {
my ( $form_data, $pg ) = @_;
for my $answerLabel ( keys %{ $pg->{pgcore}{PG_ANSWERS_HASH} } ) {
my $mq_opts = $pg->{pgcore}{PG_ANSWERS_HASH}{$answerLabel}{ans_eval}{rh_ans}{mathQuillOpts} // '';
next if ( $mq_opts =~ /\s*disabled\s*/ );
my $response_obj = $pg->{pgcore}{PG_ANSWERS_HASH}{$answerLabel}->response_obj;
for my $response ( $response_obj->response_labels ) {
next if ( ref( $response_obj->{responses}{$response} ) );
my $name = "MaThQuIlL_$response";
push( @{ $response_obj->{response_order} }, $name );
$response_obj->{responses}{$name} = '';
my $value = defined( $form_data->{$name} ) ? $form_data->{$name} : '';
$pg->{body_text} .= CGI::hidden({
-name => $name, -id => $name, -value => $value, data_mq_opts => "$mq_opts"
});
}
}
}

sub fake_user {
my $user = {
user_id => 'Motoko_Kusanagi',
Expand Down
31 changes: 31 additions & 0 deletions lib/RenderApp/Controller/StaticFiles.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package RenderApp::Controller::StaticFiles;
use Mojo::Base 'Mojolicious::Controller', -signatures;

use Mojo::File qw(path);

sub reply_with_file_if_readable ($c, $file) {
if (-r $file) {
return $c->reply->file($file);
} else {
return $c->render(data => 'File not found', status => 404);
}
}

# Route requests for webwork2_files/CAPA_Graphics to render root Contrib/CAPA/CAPA_Graphics
sub CAPA_graphics_file ($c) {
return $c->reply_with_file_if_readable($c->app->home->child('Contrib/CAPA/CAPA_Graphics', $c->stash('static')));
}

# Route requests for webwork2_files to the render root tmp. The
# only requests should be for files in the temporary directory.
# FIXME: Perhaps this directory should be configurable.
sub temp_file ($c) {
$c->reply_with_file_if_readable($c->app->home->child('tmp', $c->stash('static')));
}

# Route request to pg_files to lib/PG/htdocs.
sub pg_file ($c) {
$c->reply_with_file_if_readable(path($WeBWorK::Constants::PG_DIRECTORY, 'htdocs', $c->stash('static')));
}

1;
4 changes: 0 additions & 4 deletions lib/WeBWorK/VERSION

This file was deleted.

Loading