[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 21 Sep 2004 20:33:50 -0000


albertel		Tue Sep 21 16:33:50 2004 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  - something like a 'What's New' button, sort by 'Has Discussion', sorts by title but only shows those that have discussion / error / feedback
  - fix bug is switching back to everything
  - break 'Mark As Read' for modes other than 'Sort By Discussion'
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.295 loncom/interface/lonnavmaps.pm:1.296
--- loncom/interface/lonnavmaps.pm:1.295	Tue Sep 21 15:12:59 2004
+++ loncom/interface/lonnavmaps.pm	Tue Sep 21 16:33:49 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.295 2004/09/21 19:12:59 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.296 2004/09/21 20:33:49 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -370,7 +370,7 @@
                             return $res->completable() || $res->is_map();
                         };
 	&add_linkitem(\%toplinkitems,'everything',
-		     'location.href="locatnavmaps?sort='.$ENV{'form.sort'}.'"',
+		     'location.href="navmaps?sort='.$ENV{'form.sort'}.'"',
 		      "Show Everything");
         $r->print("<p><font size='+2'>".&mt("Uncompleted Homework")."</font></p>");
         $ENV{'form.filter'} = '';
@@ -392,6 +392,7 @@
                        <option value=\"default\" $selected{'default'}>".&mt('Default')."</option>
                        <option value=\"title\"   $selected{'title'}  >".&mt('Title')."</option>
                        <option value=\"duedate\" $selected{'duedate'}>".&mt('Duedate')."</option>
+                       <option value=\"discussion\" $selected{'discussion'}>".&mt('Has Discussion')."</option>
                     </select>
                  </nobr>
                </form>");
@@ -1343,6 +1344,13 @@
     return $val;
 }
 
+sub cmp_title {
+    my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle));
+    $atitle=~s/^\s*//;
+    $btitle=~s/^\s*//;
+    return $atitle cmp $btitle;
+}
+
 sub render {
     my $args = shift;
     &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
@@ -1549,34 +1557,44 @@
 
     # Check for any unread discussions in all resources.
     if ($args->{'caller'} eq 'navmapsdisplay') {
-	my $totdisc = 0;
-	my $haveDisc = '';
-	my @allres=$navmap->retrieveResources();
-	foreach my $resource (@allres) {
-	    if ($resource->hasDiscussion()) {
-		my $ressymb;
-		if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
-		    $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
-		} else {
-		    $ressymb = $resource->symb();
+	&add_linkitem($args->{'linkitems'},'clearbubbles',
+		      'document.clearbubbles.submit()',
+		      'Mark all posts read');
+	$result .= (<<END);
+    <form name="clearbubbles" method="post" action="/adm/feedback">
+	<input type="hidden" name="navurl" value="$ENV{'QUERY_STRING'}" />
+END
+        if ($args->{'sort'} eq 'discussion') { 
+	    my $totdisc = 0;
+	    my $haveDisc = '';
+	    my @allres=$navmap->retrieveResources();
+	    foreach my $resource (@allres) {
+		if ($resource->hasDiscussion()) {
+		    my $ressymb;
+		    if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
+			$ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
+		    } else {
+			$ressymb = $resource->symb();
+		    }
+		    $haveDisc .= $ressymb.':';
+		    $totdisc ++;
 		}
-		$haveDisc .= $ressymb.':';
-		$totdisc ++;
 	    }
-	}
-	if ($totdisc > 0) {
-	    $haveDisc =~ s/:$//;
-            my $navurl = $ENV{'QUERY_STRING'};
-	    &add_linkitem($args->{'linkitems'},'clearbubbles',
-			  'document.clearbubbles.submit()',
-			  'Mark all posts read');
-            $result .= (<<END);
-		<form name="clearbubbles" method="post" action="/adm/feedback">
-		<input type="hidden" name="navurl" value="$ENV{'QUERY_STRING'}" />
-		<input type="hidden" name="navmaps" value="$haveDisc" />
-		</form>
+	    if ($totdisc > 0) {
+		$haveDisc =~ s/:$//;
+		my $navurl = $ENV{'QUERY_STRING'};
+		$result .= (<<END);
+	<input type="hidden" name="navmaps" value="$haveDisc" />
+    </form>
 END
-	}
+            }
+	} else {
+	    my $time=time;
+	    $result .= (<<END);
+	<input type="hidden" name="navtime" value="$time" />
+    </form>
+END
+        }
     }
 
     if ($args->{'caller'} eq 'navmapsdisplay') {
@@ -1685,23 +1703,35 @@
 		return &$oldFilterFunc($res);
 	    };
 	@resources=$navmap->retrieveResources(undef,$filterFunc);
-	@resources= sort {
-	    my ($atitle,$btitle) = (lc($a->compTitle),lc($b->compTitle));
-	    $atitle=~s/^\s*//;
-	    $btitle=~s/^\s*//;
-	    return $atitle cmp $btitle
-	    } @resources;
+	@resources= sort { &cmp_title($a,$b) } @resources;
     } elsif ($args->{'sort'} eq 'duedate') {
-	@resources=$navmap->retrieveResources(undef,
-					       sub { shift->is_problem(); });
-	@resources= sort
-	{
+	my $oldFilterFunc = $filterFunc;
+	my $filterFunc= 
+	    sub {
+		my ($res)=@_;
+		if (!$res->is_problem()) { return 0;}
+		return &$oldFilterFunc($res);
+	    };
+	@resources=$navmap->retrieveResources(undef,$filterFunc);
+	@resources= sort {
 	    if ($a->duedate ne $b->duedate) {
 	        return $a->duedate cmp $b->duedate;
-	    } else {
-		lc($a->compTitle) cmp lc($b->compTitle)
 	    }
+	    my $value=&cmp_title($a,$b);
+	    return $value;
 	} @resources;
+    } elsif ($args->{'sort'} eq 'discussion') {
+	my $oldFilterFunc = $filterFunc;
+	my $filterFunc= 
+	    sub {
+		my ($res)=@_;
+		if (!$res->hasDiscussion() &&
+		    !$res->getFeedback() &&
+		    !$res->getErrors()) { return 0;}
+		return &$oldFilterFunc($res);
+	    };
+	@resources=$navmap->retrieveResources(undef,$filterFunc);
+	@resources= sort { &cmp_title($a,$b) } @resources;
     } else {
 	#unknow sort mechanism or default
 	undef($args->{'sort'});