[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 23 Jul 2004 22:38:11 -0000
albertel Fri Jul 23 18:38:11 2004 EDT
Modified files:
/loncom/interface lonnavmaps.pm
Log:
- okay you can now 'sort' the navmaps display by title or duedate
in the title case it doesn't show any maps
in the duedate case it only shows homeworks (right now, will do contentclose soonish)
- bugs,
- need to also do by 'type' then by title
- links for resource in pages are wrong
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.269 loncom/interface/lonnavmaps.pm:1.270
--- loncom/interface/lonnavmaps.pm:1.269 Wed Jul 21 16:19:01 2004
+++ loncom/interface/lonnavmaps.pm Fri Jul 23 18:38:10 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.269 2004/07/21 20:19:01 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.270 2004/07/23 22:38:10 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -100,7 +100,7 @@
}
if ($mode eq 'link') {
$result.='<a href="javascript:launch_navmapwin();void(0);">'
- .&mt("Launch Navmaps in seperate window")."</a>";
+ .&mt("Launch Navmaps in seperate window")."</a> ";
}
return $result;
}
@@ -119,6 +119,19 @@
ENDCLOSE
}
+sub update {
+ if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
+ if (!$ENV{'request.course.id'}) { return ''; }
+ if ($ENV{'REQUEST_URI'}=~m|^/adm/navmaps|) { return ''; }
+ return(<<ENDUPDATE);
+<form name="navform"></form>
+<script type="text/javascript">
+this.document.navform.action='/adm/navmaps#curloc';
+this.document.navform.target='loncapanav';
+this.document.navform.submit();
+</script>
+ENDUPDATE
+}
sub handler {
my $r = shift;
@@ -182,7 +195,7 @@
$r->print("<html><head>\n");
$r->print("<title>".&mt('Navigate Course Contents')."</title>");
# ------------------------------------------------------------ Get query string
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register']);
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort']);
# ----------------------------------------------------- Force menu registration
my $addentries='';
@@ -326,8 +339,20 @@
&mt("Show Only Uncompleted Homework")."</a> ");
}
+ $r->print("<form>
+ <nobr>
+ Sort by:
+ <select name=\"sort\">
+ <option value=\"\"></option>
+ <option value=\"title\">Title</option>
+ <option value=\"duedate\">Duedate</option>
+ </select>
+ <input type=\"submit\" name=\"Sort\" />
+ </nobr>
+ </form>");
# renderer call
- my $renderArgs = { 'cols' => [0,1,2,3],
+ my $renderArgs = { 'cols' => [0,2,3],
+ 'sort' => $ENV{'form.sort'},
'url' => '/adm/navmaps',
'navmap' => $navmap,
'suppressNavmap' => 1,
@@ -1347,7 +1372,10 @@
#$currenturl=~s/^[^\/]+//;
$here = $jump = &Apache::lonnet::symbread($currenturl);
- }
+ } else {
+ &Apache::lonnet::logthis("Hrrm,");
+
+ }
# Step three: Ensure the folders are open
my $mapIterator = $navmap->getIterator(undef, undef, undef, 1);
@@ -1574,7 +1602,33 @@
$args->{'here'} = $here;
$args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
- while ($curRes = $it->next($closeAllPages)) {
+ my @resources;
+ my $code='';# sub { !(shift->is_map();) };
+ if ($args->{'sort'} eq 'title') {
+ @resources=$navmap->retrieveResources(undef,
+ sub { !shift->is_map(); });
+ @resources= sort {lc($a->compTitle) cmp lc($b->compTitle)} @resources;
+ } elsif ($args->{'sort'} eq 'duedate') {
+ @resources=$navmap->retrieveResources(undef,
+ sub { shift->is_problem(); });
+ @resources= sort
+ {
+ if ($a->duedate ne $b->duedate) {
+ return $a->duedate cmp $b->duedate;
+ } else {
+ lc($a->compTitle) cmp lc($b->compTitle)
+ }
+ } @resources;
+ }
+
+ while (1) {
+ if ($args->{'sort'}) {
+ $curRes = shift(@resources);
+ } else {
+ $curRes = $it->next($closeAllPages);
+ }
+ if (!$curRes) { last; }
+
# Maintain indentation level.
if ($curRes == $it->BEGIN_MAP() ||
$curRes == $it->BEGIN_BRANCH() ) {
@@ -1688,10 +1742,15 @@
# Set up some data about the parts that the cols might want
my $filter = $it->{FILTER};
- my $stack = $it->getStack();
- my $src = getLinkForResource($stack);
+ my $src;
+ if ($args->{'sort'}) {
+ $src = $curRes->src(); # FIXME this is wrong for .pages
+ } else {
+ my $stack = $it->getStack();
+ $src=getLinkForResource($stack);
+ }
my $anchor='';
- if ($src=~s/(\#.*$)//) {
+ if ($src=~s/(\#.*)$//) {
$anchor=$1;
}
my $srcHasQuestion = $src =~ /\?/;
@@ -1699,7 +1758,7 @@
($srcHasQuestion?'&':'?') .
'symb=' . &Apache::lonnet::escape($curRes->symb()).
$anchor;
-
+
# Now, display each column.
foreach my $col (@$cols) {
my $colHTML = '';