[LON-CAPA-cvs] cvs: loncom /interface default.assesscalc default.classcalc default.studentcalc /interface/spreadsheet Spreadsheet.pm lonspreadsheet.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 18 Jun 2003 15:32:37 -0000
This is a MIME encoded message
--matthew1055950357
Content-Type: text/plain
matthew Wed Jun 18 11:32:37 2003 EDT
Removed files:
/loncom/interface default.assesscalc default.classcalc
default.studentcalc
Modified files:
/loncom/interface/spreadsheet Spreadsheet.pm lonspreadsheet.pm
Log:
Reworked spreadsheet filename handling.
--matthew1055950357
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030618113237.txt"
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.12 loncom/interface/spreadsheet/Spreadsheet.pm:1.13
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.12 Thu May 29 14:31:27 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm Wed Jun 18 11:32:37 2003
@@ -1,5 +1,5 @@
#
-# $Id: Spreadsheet.pm,v 1.12 2003/05/29 18:31:27 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.13 2003/06/18 15:32:37 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -145,25 +145,21 @@
if (@_) {
my ($newfilename) = @_;
if (! defined($newfilename) || $newfilename eq 'Default' ||
- $newfilename !~ /\w/) {
- my %tmphash = &Apache::lonnet::get('environment',
- ['spreadsheet_default_'.
- $self->{'type'}],
- $self->{'cdom'},
- $self->{'cnum'});
- my ($tmp) = keys(%tmphash);
- if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- $newfilename=$tmphash{'spreadsheet_default_'.$self->{'type'}};
- }
- if (! defined($newfilename) ||
- $newfilename !~ /\w/ ||
- $newfilename =~ /^\W*$/) {
- $newfilename = 'default.'.$self->{'type'};
+ $newfilename !~ /\w/ || $newfilename eq '') {
+ my $key = 'course.'.$self->{'cid'}.'.spreadsheet_default_'.
+ $self->{'type'};
+ if (exists($ENV{$key}) && $ENV{$key} ne '') {
+ $newfilename = $ENV{$key};
+ } else {
+ $newfilename = 'default_'.$self->{'type'};
}
- } elsif ($newfilename !~ /^\/res\/.*\.spreadsheet/ &&
- $newfilename !~ /^default\.$self->{'type'}$/ ) {
- my $regexp = '_'.$self->{'type'}.'$';
- if ($newfilename !~ /$regexp/) {
+ }
+ if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {
+ $newfilename = 'default_'.$self->{'type'};
+ }
+ if ($newfilename !~ /^default\.$self->{'type'}$/ ) {
+ if ($newfilename !~ /_$self->{'type'}$/) {
+ $newfilename =~ s/[\s_]*$//;
$newfilename .= '_'.$self->{'type'};
}
}
@@ -188,7 +184,7 @@
sub make_default {
my $self = shift();
my $result = &Apache::lonnet::put('environment',
- {'spreadsheet_default_'.$self->{'type'} => $self->filename()},
+ {'spreadsheet_default_'.$self->{'type'} => $self->filename()},
$self->{'cdom'},$self->{'cnum'});
return $result if ($result ne 'ok');
my $symb = $self->{'symb'};
@@ -221,6 +217,9 @@
if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
$default_filename = $tmphash{'spreadsheet_default_'.$self->{'type'}};
}
+ if ($default_filename =~ /^\s*$/) {
+ $default_filename = 'default_'.$self->{'type'};
+ }
return 1 if ($self->filename() eq $default_filename);
return 0;
}
@@ -1476,16 +1475,33 @@
undef(%spreadsheets);
}
-sub load {
+sub load_system_default_sheet {
my $self = shift;
my $includedir = $Apache::lonnet::perlvar{'lonIncludes'};
+ # load in the default defined spreadsheet
+ my $sheetxml='';
+ my $fh;
+ if ($fh=Apache::File->new($includedir.'/default_'.$self->{'type'})) {
+ $sheetxml=join('',<$fh>);
+ $fh->close();
+ } else {
+ # $sheetxml='<field row="0" col="A">"Error"</field>';
+ $sheetxml='<field row="0" col="A"></field>';
+ }
+ $self->filename('default_');
+ my ($formulas,undef) = &parse_sheet(\$sheetxml);
+ return $formulas;
+}
+
+sub load {
+ my $self = shift;
#
my $stype = $self->{'type'};
my $cnum = $self->{'cnum'};
my $cdom = $self->{'cdom'};
my $chome = $self->{'chome'};
- my $filename = $self->{'filename'};
#
+ my $filename = $self->filename();
my $cachekey = join('_',($cnum,$cdom,$stype,$filename));
#
# see if sheet is cached
@@ -1494,18 +1510,8 @@
$formulas = $spreadsheets{$cachekey}->{'formulas'};
} else {
# Not cached, need to read
- if (! defined($self->filename())) {
- # load in the default defined spreadsheet
- my $sheetxml='';
- my $fh;
- if ($fh=Apache::File->new($includedir.'/default.'.$filename)) {
- $sheetxml=join('',<$fh>);
- $fh->close();
- } else {
- # $sheetxml='<field row="0" col="A">"Error"</field>';
- $sheetxml='<field row="0" col="A"></field>';
- }
- ($formulas,undef) = &parse_sheet(\$sheetxml);
+ if (! defined($filename)) {
+ $formulas = $self->load_system_default_sheet();
} elsif($self->filename() =~ /^\/res\/.*\.spreadsheet$/) {
# Load a spreadsheet definition file
my $sheetxml=&Apache::lonnet::getfile
@@ -1515,31 +1521,30 @@
.$self->filename().'"</field>';
}
($formulas,undef) = &parse_sheet(\$sheetxml);
+ # Get just the filename and set the sheets filename
+ my ($newfilename) = ($filename =~ /\/([^\/]*)\.spreadsheet$/);
+ if ($self->is_default()) {
+ $self->filename($newfilename);
+ $self->make_default();
+ } else {
+ $self->filename($newfilename);
+ }
+ } elsif ($filename =~ /^default\.$self->{'type'}/) {
+ # if there is an Original_$stype, load it instead
+ $formulas = $self->load_system_default_sheet();
} else {
# Load the spreadsheet definition file from the save file
- my %tmphash = &Apache::lonnet::dump($self->filename(),$cdom,$cnum);
+ my %tmphash = &Apache::lonnet::dump($filename,$cdom,$cnum);
my ($tmp) = keys(%tmphash);
if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
while (my ($cell,$formula) = each(%tmphash)) {
$formulas->{$cell}=$formula;
}
} else {
- # Unable to grab the specified spreadsheet,
- # so we get the default ones instead.
- $filename = 'default.'.$stype;
- $self->filename($filename);
- my $sheetxml;
- if (my $fh=Apache::File->new($includedir.'/'.$filename)) {
- $sheetxml = join('',<$fh>);
- $fh->close();
- } else {
- $sheetxml='<field row="0" col="A">'.
- '"Unable to load spreadsheet"</field>';
- }
- ($formulas,undef) = &parse_sheet(\$sheetxml);
- $self->formulas($formulas);
+ $formulas = $self->load_system_default_sheet();
}
}
+ $filename=$self->filename(); # filename may have changed
$cachekey = join('_',($cnum,$cdom,$stype,$filename));
%{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas};
}
@@ -1595,7 +1600,7 @@
my $filename = $self->{'filename'};
my $cachekey = join('_',($cnum,$cdom,$stype,$filename));
# Cache new sheet
- %{$spreadsheets{$cachekey}}=%f;
+ %{$spreadsheets{$cachekey}->{'formulas'}}=%f;
# Write sheet
foreach (keys(%f)) {
delete($f{$_}) if ($f{$_} eq 'import');
@@ -1705,7 +1710,7 @@
if ($tmp =~ /^(con_lost|error|no_such_host)/i ) {
@alternatives = ('Default');
} else {
- @alternatives = sort (keys(%results));
+ @alternatives = ('Default', sort (keys(%results)));
}
return @alternatives;
}
@@ -1758,6 +1763,8 @@
# may not be the key we need to save
$self->{'maxrow'}++;
$self->{'row_numbers'}->{$key} = $self->{'maxrow'};
+# $self->logthis('added row '.$self->{'row_numbers'}->{$key}.
+# ' for '.$key);
$self->{'new_rows'} = 1;
}
return $self->{'row_numbers'}->{$key};
Index: loncom/interface/spreadsheet/lonspreadsheet.pm
diff -u loncom/interface/spreadsheet/lonspreadsheet.pm:1.9 loncom/interface/spreadsheet/lonspreadsheet.pm:1.10
--- loncom/interface/spreadsheet/lonspreadsheet.pm:1.9 Mon Jun 16 09:51:46 2003
+++ loncom/interface/spreadsheet/lonspreadsheet.pm Wed Jun 18 11:32:37 2003
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.9 2003/06/16 13:51:46 www Exp $
+# $Id: lonspreadsheet.pm,v 1.10 2003/06/18 15:32:37 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -126,12 +126,14 @@
##
## Create the save and load dialogs
my $filename = $spreadsheet->filename();
- $filename = 'Default' if ($filename =~ /^default\.$sheettype/i);
- $filename =~ s/_$sheettype$//;
+ my $truefilename = $filename;
+ if ($spreadsheet->is_default()) {
+ $filename = 'Default';
+ }
my $save_dialog = '<nobr>'.
'<input type="submit" name="save" value="Save as" /> '.
'<input type="text" name="savefilename" size="30" value="'.
- $filename.'" />'.
+ $truefilename.'" />'.
'</nobr>';
my $makedefault_dialog = '<input type="submit" name="makedefault" '.
'value="Make This Sheet the Default"/>';
@@ -142,7 +144,7 @@
<table bgcolor="$bgcolor">
<tr><td><input type="submit" name="load" value="Load" /></td>
<td><nobr>
- <input type="text" name="loadfilename" size="25" value="$filename" />
+ <input type="text" name="loadfilename" size="20" value="$filename" />
$link</nobr>
</td></tr>
<tr><td> </td><td>
@@ -150,7 +152,6 @@
END
my $default_filename_set = 0;
foreach my $sheetfilename ($spreadsheet->othersheets()) {
- $sheetfilename =~ s/_$sheettype$//;
$load_dialog .= ' <option name="'.$sheetfilename.'"';
if ($filename eq $sheetfilename) {
$load_dialog .= ' selected';
@@ -158,12 +159,6 @@
}
$load_dialog .= '>'.$sheetfilename."</option>\n";
}
- if ($default_filename_set) {
- $load_dialog .= '<option name="Default">Default</option>'."\n";
- } else {
- $load_dialog .= '<option name="Default" selected >Default</option>'.
- "\n";
- }
$load_dialog .= "</td><td> </td></tr>\n</table>\n";
#
$result .=<<END;
@@ -354,10 +349,12 @@
$spreadsheet->initialize();
#
# Output selector
- $r->print('<input type="submit" value="Update Display" /><br />');
##
## Editing/loading/saving
if ($allowed_to_edit) {
+ if ($ENV{'form.makedefault'}) {
+ $spreadsheet->make_default();
+ }
$r->print('<table><tr><td>'.$spreadsheet->html_header().'</td>'.
'<td valign="bottom">'.
&file_dialogs($spreadsheet)."</td></tr></table>\n");
@@ -367,6 +364,10 @@
"</td></tr></table>\n");
}
#
+ if (! exists($ENV{'form.not_first_run'}) && $sheettype eq 'classcalc') {
+ $r->print('<input type="submit" value="Generate Spreadsheet" /><br />');
+ }
+ #
# Keep track of the filename
$r->print(&hiddenfield('filename',$filename));
#
@@ -379,8 +380,6 @@
$r->print($spreadsheet->parent_link());
}
$spreadsheet->display($r);
- } else {
- $r->print("<h2>Make your selections and bonk the 'update display' button</h2>");
}
$r->print('</form></body></html>');
return OK;
--matthew1055950357--