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

raeburn raeburn at source.lon-capa.org
Wed Feb 6 19:49:54 EST 2019


raeburn		Thu Feb  7 00:49:54 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	lonnavmaps.pm 
  Log:
  - For 2.11
    Backport 1.533, 1.534, 1.535
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.509.2.9 loncom/interface/lonnavmaps.pm:1.509.2.10
--- loncom/interface/lonnavmaps.pm:1.509.2.9	Sun Feb  3 22:25:47 2019
+++ loncom/interface/lonnavmaps.pm	Thu Feb  7 00:49:53 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.509.2.9 2019/02/03 22:25:47 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.509.2.10 2019/02/07 00:49:53 raeburn Exp $
 
 #
 # Copyright Michigan State University Board of Trustees
@@ -486,7 +486,7 @@
 use Apache::lonnet;
 use Apache::lonmap;
 
-use POSIX qw (floor strftime);
+use POSIX qw (ceil floor strftime);
 use Time::HiRes qw( gettimeofday tv_interval );
 use LONCAPA;
 use DateTime();
@@ -1016,9 +1016,12 @@
             # Don't allow users to manipulate folder
             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
             $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
-
-            $linkopen = "";
-            $linkclose = "";
+            if ($params->{'caller'} eq 'sequence') {
+                $linkopen = "<a href=\"$link\">";
+            } else {
+                $linkopen = "";
+                $linkclose = "";
+            }
         }
         if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
              (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) &&
@@ -1390,10 +1393,11 @@
             my $currenturl = $env{'form.postdata'};
             #$currenturl=~s/^http\:\/\///;
             #$currenturl=~s/^[^\/]+//;
-            
-            $here = $jump = &Apache::lonnet::symbread($currenturl);
+            unless ($args->{'caller'} eq 'sequence') { 
+                $here = $jump = &Apache::lonnet::symbread($currenturl);
+            }
 	}
-	if ($here eq '') {
+	if (($here eq '') && ($args->{'caller'} ne 'sequence')) { 
 	    my $last;
 	    if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
                     &GDBM_READER(),0640)) {
@@ -1860,11 +1864,15 @@
 		$stack=$it->getStack();
 	    }
 	    ($src,$symb,$anchor)=getLinkForResource($stack);
-	    if (defined($anchor)) { $anchor='#'.$anchor; }
 	    my $srcHasQuestion = $src =~ /\?/;
-	    $args->{"resourceLink"} = $src.
-		($srcHasQuestion?'&':'?') .
-		'symb=' . &escape($symb).$inhibitmenu.$anchor;
+	    if (defined($anchor)) { $anchor='#'.$anchor; }
+            if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) {
+                $args->{"resourceLink"} = $src.($srcHasQuestion?'&':'?') .'navmap=1';
+            } else {
+	        $args->{"resourceLink"} = $src.
+		    ($srcHasQuestion?'&':'?') .
+		    'symb=' . &escape($symb).$inhibitmenu.$anchor;
+            }
 	}
         # Now, we've decided what parts to show. Loop through them and
         # show them.
@@ -2792,6 +2800,91 @@
     return @recurseup;
 }
 
+sub recursed_crumbs {
+    my ($self,$mapurl,$restitle) = @_;
+    my (@revmapinfo, at revmapres);
+    my $mapres = $self->getResourceByUrl($mapurl);
+    if (ref($mapres)) {
+        @revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_breadcrumbs());
+        shift(@revmapres);
+    }
+    my $allowedlength = 60;
+    my $minlength = 5;
+    my $allowedtitle = 30;
+    if (($env{'environment.icons'} eq 'iconsonly') && (!$env{'browser.mobile'})) {
+        $allowedlength = 100;
+        $allowedtitle = 70;
+    }
+    if (length($restitle) > $allowedtitle) {
+        $restitle = &truncate_crumb_text($restitle,$allowedtitle);
+    }
+    my $totallength = length($restitle);
+    my @links;
+
+    foreach my $map (@revmapres) {
+        my $pc = $map->map_pc();
+        next if ((!$pc) || ($pc == 1));
+        push(@links,$map);
+        push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});
+        $totallength += length($map->title());
+    }
+    my $numlinks = scalar(@links);
+    if ($numlinks) {
+        if ($totallength - $allowedlength > 0) {
+            my $available = $allowedlength - length($restitle);
+            my $avg = POSIX::ceil($available/$numlinks);
+            if ($avg < $minlength) {
+                $avg = $minlength;
+            }
+            @revmapinfo = ();
+            foreach my $map (@links) {
+                my $showntitle = &truncate_crumb_text($map->title(),$avg);
+                if ($showntitle ne '') {
+                    push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});
+                }
+            }
+        }
+    }
+    if ($restitle ne '') {
+        push(@revmapinfo,{'text' => $restitle, 'no_mt' => 1});
+    }
+    return @revmapinfo;
+}
+
+sub truncate_crumb_text {
+    my ($title,$limit) = @_;
+    my $showntitle = '';
+    if (length($title) > $limit) {
+        my @words = split(/\b\s*/,$title);
+        if (@words == 1) {
+            $showntitle = substr($title,0,$limit).' ...';
+        } else {
+            my $linklength = 0;
+            my $num = 0;
+            foreach my $word (@words) {
+                $linklength += 1+length($word);
+                if ($word eq '-') {
+                    $showntitle =~ s/ $//;
+                    $showntitle .= $word;
+                } elsif ($linklength > $limit) {
+                    if ($num < @words) {
+                        $showntitle .= $word.' ...';
+                        last;
+                    } else {
+                        $showntitle .= $word;
+                    }
+                } else {
+                    $showntitle .= $word.' ';
+                }
+            }
+            $showntitle =~ s/ $//;
+        }
+        return $showntitle;
+    } else {
+        return $title;
+    }
+}
+
 #
 #  Determines the open/close dates for printing a map that
 #  encloses a resource.
@@ -4414,6 +4507,12 @@
 for the hierarchy of maps containing a map, with the top level
 map first, then descending to deeper levels, with the enclosing map last.
 
+=item * B<map_breadcrumbs>:
+
+Same as map_hierarchy, except maps containing only a single itemm if
+it's a map, or containing no items are omitted, unless it's the top
+level map (map_pc = 1), which is always included.
+
 =back
 
 =cut
@@ -4449,6 +4548,11 @@
     my $pc = $self->map_pc();
     return $self->navHash("map_hierarchy_$pc", 0);
 }
+sub map_breadcrumbs {
+    my $self = shift;
+    my $pc = $self->map_pc();
+    return $self->navHash("map_breadcrumbs_$pc", 0);
+}
 
 #####
 # Property queries




More information about the LON-CAPA-cvs mailing list