Skip to content

Commit 245b48c

Browse files
committed
Remove the update-ww script, return the download-OPL script ...
to it's previous state and now run the parse-search-json.pl script upon startup of webwork2. Restore the minisearch package.
1 parent 2f15fa7 commit 245b48c

File tree

7 files changed

+54
-98
lines changed

7 files changed

+54
-98
lines changed

bin/build-search-json.pl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,18 @@ =head1 SYNOPSIS
99
build-search-db.pl [options]
1010
1111
Options:
12-
-p|--pg-root Directory containing a git clone of pg.
13-
If this option is not set, then the environment
14-
variable $PG_ROOT will be used if it is set.
1512
-f|--json-file Location (relative to WW_ROOT) to store the resulting JSON file.
1613
Default value is htdocs/DATA/search.json
17-
-s|--sample-prob-dir Location (relative to $PG_ROOT) where the sample problems are located.
14+
-s|--sample-prob-dir Location (relative to $pg_root) where the sample problems are located.
1815
Default value is tutorial/samples-problems
1916
-b|--build One of (all, macros, samples) to determine if the macros, sample
2017
problems or both should be scraped for data.
2118
-v|--verbose Setting this flag provides details as the script runs.
22-
23-
Note that --pg-root must be provided or the PG_ROOT environment variable set
24-
if the POD for pg is desired.
19+
-h|--help Show this help message.
2520
2621
=head1 DESCRIPTION
2722
28-
This script parses all of the files in $PG_ROOT/tutorial/samples-problems and the POD in the macro files.
23+
This script parses all of the files in $pg_root/tutorial/samples-problems and the POD in the macro files.
2924
The result is a JSON file containing information about every file to be searched for in the sample-problems
3025
space. The purpose of creating this file is to be used on the Sample Problems page (linked from
3126
the PG Editor) to search through macros and samples problems.
@@ -42,34 +37,37 @@ =head1 DESCRIPTION
4237
use Mojo::JSON qw(encode_json);
4338
use Mojo::File qw(curfile);
4439
use Pod::Simple::SimpleTree;
40+
use Pod::Usage;
41+
use YAML::XS qw(LoadFile);
42+
43+
my $ww_root = Mojo::File->curfile->dirname->dirname;
44+
45+
# Load the configuration file to obtain the PG root directory.
46+
my $config_file = "$ww_root/conf/webwork2.mojolicious.yml";
47+
$config_file = "$ww_root/conf/webwork2.mojolicious.dist.yml" unless -e $config_file;
48+
my $config = LoadFile($config_file);
4549

50+
my $pg_root = $config->{pg_dir};
4651
my $build = "all";
47-
my $pg_root = $ENV{PG_ROOT};
4852

4953
# These are the default sample problem directory and JSON file.
5054
my $sample_prob_dir = "tutorial/sample-problems";
5155
my $json_file = "htdocs/DATA/search.json";
52-
my ($verbose, $show_warnings) = (1, 0);
56+
my ($verbose, $show_warnings, $show_help) = (0, 0, 0);
5357

5458
GetOptions(
55-
'p|pg-root=s' => \$pg_root,
5659
'f|json-file=s' => \$json_file,
5760
's|sample-prob-dir=s' => \$sample_prob_dir,
5861
'b|build=s' => \$build,
5962
'w|show-warnings' => \$show_warnings,
60-
'v|verbose+' => \$verbose
63+
'v|verbose+' => \$verbose,
64+
'h|help' => \$show_help
6165
);
66+
pod2usage(2) if $show_help;
6267

6368
die "The build options must be one of (all, macros, samples). The value $build is not valid."
6469
if ((grep { $_ eq $build } qw/all macros samples/) != 1);
6570

66-
my $ww_root = $ENV{WW_ROOT};
67-
$ww_root = Mojo::File->curfile->dirname->dirname->realpath unless defined($ww_root);
68-
69-
say $ww_root;
70-
71-
die "ww_root: $ww_root is not a directory" unless -d $ww_root;
72-
7371
$sample_prob_dir = "$pg_root/$sample_prob_dir";
7472
$json_file = Mojo::File->new("$ww_root/$json_file");
7573

bin/download-OPL-metadata-release.pl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,8 @@ BEGIN
8080
die "The directory $libraryDirectory does not exist or is not writable."
8181
if (!-d $libraryDirectory || !-w $libraryDirectory);
8282

83-
warn $ENV{OPL_GIT_REPOSITORY};
84-
85-
my $git_repo = $ENV{OPL_GIT_REPOSITORY} // 'origin';
86-
8783
# Checkout the release tag in the library clone if it hasn't already been done.
88-
`$ce->{externalPrograms}{git} -C $libraryDirectory fetch --tags $git_repo`;
84+
`$ce->{externalPrograms}{git} -C $libraryDirectory fetch --tags origin`;
8985
`$ce->{externalPrograms}{git} -C $libraryDirectory show-ref refs/heads/$releaseTag -q`;
9086
if ($?) {
9187
say "Switching OPL clone in $libraryDirectory to new branch of release tag $releaseTag.";

bin/update-ww.pl

Lines changed: 0 additions & 72 deletions
This file was deleted.

bin/webwork2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use strict;
44
use warnings;
5+
use feature 'say';
56

67
BEGIN {
78
use Mojo::File qw(curfile);
@@ -26,5 +27,16 @@ use Mojolicious::Commands;
2627
use lib "$WEBWORK_ROOT/lib";
2728
use lib "$PG_ROOT/lib";
2829

30+
# Build the search database if it doesn't exist (or is XXX days old)
31+
32+
unless (-f "$WEBWORK_ROOT/htdocs/DATA/search.json") {
33+
say "Building the search json file.";
34+
`$WEBWORK_ROOT/bin/build-search-json.pl`;
35+
say "There was an error running the build-search-json.pl script. Try running it manually with "
36+
. "the verbose flag." if $?;
37+
say "Successfully built the search json file at $WEBWORK_ROOT/htdocs/DATA/search.json"
38+
if -f "$WEBWORK_ROOT/htdocs/DATA/search.json";
39+
}
40+
2941
# Start command line interface for application
3042
Mojolicious::Commands->start_app('Mojolicious::WeBWorK');

htdocs/js/SampleProblemViewer/search.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@
55
(() => {
66
const miniSearch = new MiniSearch({ fields: ['terms', 'filename', 'name', 'description', 'methods'] });
77
let pages;
8+
const resultList = document.getElementById('searchResults');
89
// This is the data from sample-problems/macros POD.
910
fetch('../../DATA/search.json')
1011
.then((res) => res.json())
1112
.then((p) => {
1213
pages = p;
1314
miniSearch.addAll(pages);
1415
})
15-
.catch((e) => console.error(e));
16+
.catch((e) => {
17+
if (e) {
18+
console.error(e);
19+
const error_box = document.createElement('div');
20+
error_box.classList.add('alert', 'alert-danger');
21+
error_box.innerText =
22+
'There was a error loading the search box. Please contact the webwork administrator';
23+
resultList.append(error_box);
24+
}
25+
});
1626

17-
const resultList = document.getElementById('searchResults');
1827
const searchBox = document.getElementById('searchDocs');
1928
document.getElementById('clearSearchButton').addEventListener('click', () => {
2029
searchBox.value = '';

htdocs/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htdocs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"jquery-ui-dist": "^1.13.2",
2323
"luxon": "^3.4.4",
2424
"mathjax": "^3.2.2",
25+
"minisearch": "^7.1.2",
2526
"shortcut-buttons-flatpickr": "^0.4.0",
2627
"sortablejs": "^1.15.2"
2728
},

0 commit comments

Comments
 (0)