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

raeburn raeburn at source.lon-capa.org
Sat Sep 9 20:11:27 EDT 2017


raeburn		Sun Sep 10 00:11:27 2017 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm lonmenu.pm 
  Log:
  - Titles in breadcrumb trail of folder hierarchy shown when a resource 
    is viewed in course context are truncated at word boundaries if they
    are too long. 
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.534 loncom/interface/lonnavmaps.pm:1.535
--- loncom/interface/lonnavmaps.pm:1.534	Sun Sep  3 18:52:27 2017
+++ loncom/interface/lonnavmaps.pm	Sun Sep 10 00:11:27 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.534 2017/09/03 18:52:27 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.535 2017/09/10 00:11:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -501,7 +501,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();
@@ -2882,21 +2882,90 @@
 }
 
 sub recursed_crumbs {
-    my ($self,$mapurl) = @_;
+    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.
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.478 loncom/interface/lonmenu.pm:1.479
--- loncom/interface/lonmenu.pm:1.478	Sat Sep  9 21:30:12 2017
+++ loncom/interface/lonmenu.pm	Sun Sep 10 00:11:27 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.478 2017/09/09 21:30:12 raeburn Exp $
+# $Id: lonmenu.pm,v 1.479 2017/09/10 00:11:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -669,7 +669,7 @@
                 (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
                 $navmap = Apache::lonnavmaps::navmap->new();
                 if (ref($navmap)) {
-                    @mapcrumbs = $navmap->recursed_crumbs($mapurl);
+                    @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
                 }
             }
             unless (($forcereg) &&
@@ -693,8 +693,9 @@
                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
                 push @crumbs, {text => $maptitle, no_mt => 1, href => $mapurl};
             }
-
-            push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
+            if ($restitle && !@mapcrumbs) {
+                push(@crumbs,{text => $restitle, no_mt => 1});
+            }
             my @tools;
             if ($env{'request.filename'} =~ /\.page$/) {
                 my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();




More information about the LON-CAPA-cvs mailing list