Parent Directory
|
Revision Log
The script now reads takes the form data in problemContents and displays it in a textarea form. If there is no problemContents it reads from the file in template directory. The script is called with .../instructor/pgProblemEditor/set10/prob1 I'm using the current convention for labeling files in the template directory. Using '10' for set10 will not work right at the moment. .pg and the course template directory are combined with the path components to determine the path to the file. It remains to add the rest of the editing buttons and provide a method for saving to the template file. -- Mike
1 package WeBWorK::ContentGenerator::Instructor::PGProblemEditor; 2 use base qw(WeBWorK::ContentGenerator::Instructor); 3 4 5 =head1 NAME 6 7 WeBWorK::ContentGenerator::Instructor::ProblemSetEditor - Edit a set definition list 8 9 =cut 10 11 use strict; 12 use warnings; 13 use CGI qw(); 14 use WeBWorK::Utils qw(readFile); 15 16 our $libraryName; 17 our $rowheight; 18 19 sub title { 20 my $self = shift; 21 #FIXME don't need the entire path ?? 22 return "Instructor Tools - PG Problem Editor for ". $self->{ce}->{problemPath}; 23 } 24 25 sub body { 26 my $self = shift; 27 28 # test area 29 my $r = $self->{r}; 30 my $db = $self->{db}; 31 my $ce = $self->{ce}; 32 my $user = $r->param('user'); 33 my $key = $db->getKey($user)->key(); 34 35 36 ################ 37 # Gathering info 38 # What is needed 39 # $problemPath -- 40 # $formURL -- given by $r->uri 41 # $tmpProblemPath 42 #my ($problemPath,$formURL,$tmpProblemPath) = $self->initialize(); 43 my $problemPath = $ce->{problemPath}; 44 45 my $tmpProblemPath = $ce->{tmpProblemPath}; 46 47 48 49 50 51 52 my $header = 'Problem Editor'; 53 54 ######################################################################### 55 # Find the text for the problem, either in the tmp file, if it exists 56 # or in the original file in the template directory 57 ######################################################################### 58 my $problemContents = ''; 59 my $editMode = (defined($r->param('problemContents')))? 60 'tmpMode':'stdMode'; 61 62 if ( $editMode eq 'tmpMode') { 63 $problemContents = $r->param('problemContents'); 64 65 } else { 66 eval { 67 $problemContents = WeBWorK::Utils::readFile($problemPath); 68 }; 69 $problemContents = $@ if $@; 70 71 # create tmp file version for later use 72 # So that you don't need duplicate information in forms 73 # FIXME 74 # open(FILE,">$tmpProblemPath") || die "Failed to open $tmpProblemPath"; 75 # print FILE "tmpfileVersion\n\n" . $problemContents; 76 # close(FILE); 77 } 78 79 # Define parameters for textarea 80 my $rows = 40; 81 my $columns = 80; 82 83 ######################################################################### 84 # Define a link to view the problem 85 #fix me: 86 # Currently this link used the webwork problem library, which might be out of 87 # sync with the local library 88 ######################################################################### 89 90 91 92 ######################################################################### 93 # Format the page 94 ######################################################################### 95 96 return CGI::p($header), 97 CGI::startform("POST",$r->uri), 98 $self->hidden_authen_fields, 99 CGI::textarea(-name => 'problemContents', -default => $problemContents, 100 -rows => $rows, -columns => $columns, -override => 1, 101 ), 102 "<p> the parameters passed are " #FIXME -- debugging code 103 . join("<BR>", %{$r->param()}) . 104 "</p> and the gatheredInfo is ", 105 "problemPath=$problemPath<br> formURL=".$r->uri . "<br> tmpProblemPath=$tmpProblemPath<br>" , 106 107 ; 108 109 } 110 111 sub initialize { 112 #fix me. This is very much hacked together. In particular can we pass the key inside the post? 113 my ($self, @path_components) = @_; 114 my $ce = $self->{ce}; 115 my $r = $self->{r}; 116 my $path_info = $r->path_info || ""; 117 118 ## Determine relative path to the file to be edited 119 120 my $templateDirectory = $self->{ce}->{courseDirs}->{templates}; 121 my $problemPath = join("/",$templateDirectory,@path_components) .'.pg'; 122 123 124 # find path to the temporary file 125 my $tmpDirectory = $ce->{courseDirs}->{html_temp}; 126 my $fileName = join("-", $r->param('user'),@path_components).'.pg'; 127 my $tmpProblemPath = "$tmpDirectory/$fileName"; 128 $ce->{problemPath} = $problemPath; 129 $ce->{tmpProblemPath} = $tmpProblemPath; 130 } 131 132 # sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function) 133 # my $self = shift; 134 # my $setName = shift; 135 # my $output = ""; 136 # if ( defined($setName) and $setName ne "" ) { 137 # my $templateDirectory = $self->{ce}->{courseDirs}->{templates}; 138 # my $fileName = "$templateDirectory/$setName.def"; 139 # my @output = split("\n",WeBWorK::Utils::readFile($fileName) ); 140 # @output = grep /\.pg/, @output; # only get the .pg files 141 # @output = grep !/Header/, @output; # eliminate header files 142 # $output = join("\n",@output); 143 # } else { 144 # $output = "No set name |$setName| is defined"; 145 # } 146 # 147 # 148 # return $output 149 # 150 # 151 # 152 # 153 # } 154 # sub fetchSetDirectories { 155 # 156 # my $self = shift; 157 # my $defaultChoice = shift; 158 # my $templateDirectory = $self->{ce}->{courseDirs}->{templates}; 159 # opendir SETDEFDIR, $templateDirectory 160 # or return "Can't open directory $templateDirectory"; 161 # 162 # my @allFiles = grep !/^\./, readdir SETDEFDIR; 163 # closedir SETDEFDIR; 164 # 165 # ## filter to find only the set directories 166 # ## -- it is assumed that these directories don't contain a period in their names 167 # ## and that all other files do. Directories names must also begin with "set". 168 # ## A better plan would be to read only the names of directories, not files. 169 # 170 # ## sort the directories 171 # my @setDefFiles = grep /^set[^\.]*$/, @allFiles; 172 # my @sortedNames = sort @setDefFiles; 173 # 174 # return "$libraryName/" . CGI::br(). CGI::popup_menu(-name=>'setDirectory', -size=>$rowheight, 175 # -values=>\@sortedNames, -default=>$defaultChoice ) .CGI::br() ; 176 # } 177 # 178 # sub fetchPGproblems { 179 # 180 # my $self = shift; 181 # my $setDirectory = shift; 182 # 183 # # Handle default for setDirectory 184 # # fix me -- this is not bullet proof 185 # $setDirectory = "set0" unless defined($setDirectory); 186 # my $templateDirectory = $self->{ce}->{courseDirs}->{templates}; 187 # 188 # ## 189 # opendir SETDEFDIR, "$templateDirectory/$setDirectory" 190 # or return "Can't open directory $templateDirectory/$setDirectory"; 191 # 192 # my @allFiles = grep !/^\./, readdir SETDEFDIR; 193 # closedir SETDEFDIR; 194 # 195 # ## filter to find only pg problems 196 # ## Some problems are themselves in directories (if they have auxiliary 197 # ## .png's for example. This eventuallity needs to be handled. 198 # 199 # ## sort the directories 200 # my @pgFiles = grep /\.pg$/, @allFiles; 201 # my @sortedNames = sort @pgFiles; 202 # 203 # return "$setDirectory ". CGI::br() . 204 # CGI::popup_menu(-name=>'pgProblem', -size=>$rowheight, -multiple=>undef, -values=>\@sortedNames, ) . 205 # CGI::br() ; 206 # } 207 208 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |