[LON-CAPA-cvs] cvs: rat / lonsequence.pm loncom/interface lonfeedback.pm lonmenu.pm lonnavmaps.pm loncom/lti ltiutils.pm

raeburn raeburn at source.lon-capa.org
Sat Apr 14 13:52:53 EDT 2018


raeburn		Sat Apr 14 17:52:53 2018 EDT

  Modified files:              
    /loncom/interface	lonmenu.pm lonnavmaps.pm lonfeedback.pm 
    /loncom/lti	ltiutils.pm 
    /rat	lonsequence.pm 
  Log:
  - Bug 6754 LON-CAPA as LTI Provider
    - No page flip arrows in inline menu if LTI launch was or a resource
    - No forward arrow if LTI launch was for map and this is last resource.
    - No reverse arrow if LTI launch was for map and this is first resource.
    - No Contents in inline breadcrumbs if LTI launch was for resource or map.
  
  
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.485 loncom/interface/lonmenu.pm:1.486
--- loncom/interface/lonmenu.pm:1.485	Fri Dec 22 02:00:46 2017
+++ loncom/interface/lonmenu.pm	Sat Apr 14 17:52:43 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.485 2017/12/22 02:00:46 raeburn Exp $
+# $Id: lonmenu.pm,v 1.486 2018/04/14 17:52:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -99,7 +99,7 @@
 
 =over
 
-=item prep_menuitems(\@menuitem)
+=item prep_menuitems(\@menuitem,$ltitarget)
 
 This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
 secondary_menu().
@@ -210,6 +210,7 @@
 use Apache::lonlocal;
 use Apache::lonmsg();
 use LONCAPA qw(:DEFAULT :match);
+use LONCAPA::ltiutils;
 use HTML::Entities();
 use Apache::lonwishlist();
 
@@ -219,7 +220,7 @@
 my @inlineremote;
 
 sub prep_menuitem {
-    my ($menuitem) = @_;
+    my ($menuitem,$ltitarget) = @_;
     return '' unless(ref($menuitem) eq 'ARRAY');
     my $link;
     if ($$menuitem[1]) { # graphical Link
@@ -229,10 +230,14 @@
     } else {             # textual Link
         $link = &mt($$menuitem[3]);
     }
+    my $target = ' target="_top"';
+    if ($ltitarget eq 'iframe') {
+        $target ='';
+    }
     return '<li><a' 
            # highlighting for new messages
            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
-           . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
+           . qq| href="$$menuitem[0]"$target>$link</a></li>|;
 }
 
 # primary_menu() evaluates @primary_menu and returns a two item array,
@@ -260,6 +265,10 @@
         my %roles_in_env;
         $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
     }
+    my $ltitarget;
+    if ($env{'request.lti.login'}) {
+        $ltitarget = $env{'request.lti.target'};
+    }
     foreach my $menuitem (@primary_menu) {
         # evaluate conditions 
         next if    ref($menuitem)       ne 'ARRAY';    #
@@ -293,7 +302,9 @@
             my ($link,$target);
             if ($menuitem->[0] ne '') {
                 $link = $menuitem->[0];
-                $target = '_top';
+                unless ($ltitarget eq 'iframe') {
+                    $target = '_top';
+                }
             } else {
                 $link = '#';
             }
@@ -328,13 +339,13 @@
                                                                   'helpdeskmail',
                                                                   $defdom,$origmail);
                 if ($to ne '') {
-                    $menu{$position} .= &prep_menuitem($menuitem); 
+                    $menu{$position} .= &prep_menuitem($menuitem,$ltitarget); 
                 }
             } else {
                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
             }
         } else {
-            $menu{$position} .= prep_menuitem($menuitem);
+            $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
         }
     }
     my @output = ('','');
@@ -441,7 +452,10 @@
             $canmodifycoauthor = 1;
         }
     }
-    my ($roleswitcher_js,$roleswitcher_form);
+    my ($roleswitcher_js,$roleswitcher_form,$ltitarget);
+    if ($env{'request.lti.login'}) {
+        $ltitarget = $env{'request.lti.target'};
+    }
 
     foreach my $menuitem (@secondary_menu) {
         # evaluate conditions 
@@ -484,7 +498,9 @@
             my ($link,$target);
             if ($menuitem->[0] ne '') {
                 $link = $menuitem->[0];
-                $target = '_top';
+                unless ($ltitarget eq 'iframe') {   
+                    $target = '_top';
+                }
             } else {
                 $link = '#';
             }
@@ -517,7 +533,7 @@
                 &roles_selector(
                         $env{'course.' . $env{'request.course.id'} . '.domain'},
                         $env{'course.' . $env{'request.course.id'} . '.num'},
-                        $httphost
+                        $httphost,$ltitarget
                 );
             $menu .= $switcher;
         } else {
@@ -543,7 +559,7 @@
                 }
                 $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
             }
-            $menu .= &prep_menuitem(\@$menuitem);
+            $menu .= &prep_menuitem(\@$menuitem,$ltitarget);
         }
     }
     if ($menu =~ /\[url\].*\[symb\]/) {
@@ -651,7 +667,9 @@
                     $href =~ s/\[user\]/$env{'user.name'}/g;
                 }
                 unless (($href eq '') || ($href =~ /^\#/)) {
-                    $target = ' target="_top"';
+                    if ($target eq '_top') {
+                        $target = ' target="_top"';
+                    }
                 }
 
                 $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
@@ -674,13 +692,18 @@
 
     undef(@inlineremote);
 
-    my ($mapurl,$resurl,$crstype,$navmap);
+    my ($mapurl,$resurl,$crstype,$navmap,$ltiscope,$ltiuri);
 
     if ($env{'request.course.id'}) {
 #
 #course_type:  Course, Community, or Placement
 #
         $crstype = &Apache::loncommon::course_type();
+        if (($env{'request.lti.login'}) && ($env{'request.lti.uri'})) {
+            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
+        }
         if ($env{'request.symb'}) {
             my $ignorenull;
             unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
@@ -695,22 +718,29 @@
             my (@crumbs, at mapcrumbs);
             if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
                 (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
-                $navmap = Apache::lonnavmaps::navmap->new();
-                if (ref($navmap)) {
-                    @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
+                unless ($ltiscope eq 'resource') {
+                    if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
+                        !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
+                        $navmap = Apache::lonnavmaps::navmap->new();
+                        if (ref($navmap)) {
+                            @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
+                        }
+                    }
                 }
             }
             unless (($forcereg) &&
                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
-                    (($crstype eq 'Placement') && (!$env{'request.role.adv'}))) {
+                    (($crstype eq 'Placement') && (!$env{'request.role.adv'})) ||
+                    ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
                 @crumbs = ({text  => $crstype.' Contents', 
                             href  => "Javascript:gopost('/adm/navmaps','')"});
             }
             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                 if (@mapcrumbs) {
                     push(@crumbs, at mapcrumbs);
-                } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'}))) {
+                } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'})) &&
+                         ($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
                     push(@crumbs, {text  => '...',
                                    no_mt => 1});
                 }
@@ -718,8 +748,10 @@
 
             unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) ||
                     (!$maptitle) || ($maptitle eq 'default.sequence') ||
-                    ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
-                push @crumbs, {text => $maptitle, no_mt => 1, href => $mapurl};
+                    ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
+                    ($ltiscope eq 'resource')) {
+                push @crumbs, {text => $maptitle, no_mt => 1, 
+                               href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
             }
             if ($restitle && !@mapcrumbs) {
                 push(@crumbs,{text => $restitle, no_mt => 1});
@@ -912,7 +944,35 @@
 # Should probably be in mydesk.tab
 #
             $menuitems = "c&3&1";
-            if (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
+            if ($ltiscope eq 'resource') {
+# Suppress display of backward arrow for LTI Provider if scope is resource.
+# Suppress display of forward arrow for LTI Provider if scope is resource.
+            } elsif ($ltiscope eq 'map') {
+# Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
+# Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
+                my $showforw = 1;
+                my $showback = 1;
+                my $navmap = Apache::lonnavmaps::navmap->new();
+                if (ref($navmap)) {
+                    my $mapres = $navmap->getResourceByUrl($ltiuri);
+                    if (ref($mapres)) {
+                        if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
+                            $showforw = 0;
+                        }
+                        if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
+                            $showback = 0;
+                        }
+                    }
+                }
+                if ($showback) {
+                    $menuitems.="
+s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
+                }
+                if ($showforw) {
+                    $menuitems.="
+s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
+                }
+            } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
                 $menuitems.="
 s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
 s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
@@ -2168,8 +2228,12 @@
 }
 
 sub serverform {
+    my $target;
+    unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
+        $target = ' target="_top"';
+    }
     return(<<ENDSERVERFORM);
-<form name="server" action="/adm/logout" method="post" target="_top">
+<form name="server" action="/adm/logout" method="post"$target>
 <input type="hidden" name="postdata" value="none" />
 <input type="hidden" name="command" value="none" />
 <input type="hidden" name="url" value="none" />
@@ -2207,7 +2271,7 @@
 }
 
 sub roles_selector {
-    my ($cdom,$cnum,$httphost) = @_;
+    my ($cdom,$cnum,$httphost,$ltitarget) = @_;
     my $crstype = &Apache::loncommon::course_type();
     my $now = time;
     my (%courseroles,%seccount,%courseprivs,%roledesc);
@@ -2369,7 +2433,7 @@
             }
         }
         if (@submenu > 0) {
-            $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
+            $switcher = &create_submenu('','',&mt('Switch role'),\@submenu,'','',$ltitarget);
         }
     }
     return ($js,$form,$switcher);
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.541 loncom/interface/lonnavmaps.pm:1.542
--- loncom/interface/lonnavmaps.pm:1.541	Wed Jan 31 14:05:12 2018
+++ loncom/interface/lonnavmaps.pm	Sat Apr 14 17:52:43 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.541 2018/01/31 14:05:12 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.542 2018/04/14 17:52:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3481,6 +3481,71 @@
     return $self->navhash("version_$linkurl");
 }
 
+sub isFirstResource {
+    my $self = shift;
+    my $map = shift;
+    my $symb = shift;
+    return unless (ref($map));
+    my $isfirst;
+    my $firstResource = $map->map_start();
+    if (ref($firstResource)) {
+        if ((!$firstResource->is_map()) && ($firstResource->src() ne ''))  {
+            if ($firstResource->symb() eq $symb) {
+                $isfirst = 1;
+            } else {
+                $isfirst = 0;
+            }
+        } else {
+            my $it = $self->getIterator($firstResource,undef,undef,1);
+            while ( my $res=$it->next()) {
+                if ((ref($res)) && ($res->src() ne '') && (!$res->is_map())) {
+                    if ($res->symb() eq $symb) {
+                        $isfirst = 1;
+                    } else {
+                        $isfirst = 0;
+                    }
+                    last;
+                }
+            }
+        }
+    }
+    return $isfirst;
+}
+
+sub isLastResource {
+    my $self = shift;
+    my $map = shift;
+    my $symb = shift;
+    return unless (ref($map));
+    my $islast;
+    my $lastResource = $map->map_finish();
+    if (ref($lastResource)) {
+        if ((!$lastResource->is_map()) && ($lastResource->src() ne ''))  {
+            if ($lastResource->symb() eq $symb) {
+                $islast = 1;
+            } else {
+                $islast = 0;
+            }
+        } else {
+            my $currRes = $self->getBySymb($symb);
+            if (ref($currRes)) {
+                my $it = $self->getIterator($currRes,undef,undef,1);
+                while ( my $res=$it->next()) {
+                    if ((ref($res)) && ($res->src() ne '') && (!$res->is_map())) {
+                        if ($res->symb() eq $symb) {
+                            $islast = 1;
+                        } else {
+                            $islast = 0;
+                        }
+                        last;
+                    }
+                }
+            }
+        }
+    }
+    return $islast;
+}
+
 1;
 
 package Apache::lonnavmaps::iterator;
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.378 loncom/interface/lonfeedback.pm:1.379
--- loncom/interface/lonfeedback.pm:1.378	Mon Dec 18 23:20:48 2017
+++ loncom/interface/lonfeedback.pm	Sat Apr 14 17:52:43 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.378 2017/12/18 23:20:48 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.379 2018/04/14 17:52:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2840,6 +2840,10 @@
   my $start_page=
       &Apache::loncommon::start_page('Feedback sent',undef,\%parms);
   my $end_page = &Apache::loncommon::end_page();
+  my $windowname = 'loncapaclient';
+  if ($env{'request.lti.login'}) {
+     $windowname .= 'lti';
+  }
   $r->print(<<ENDREDIR);
 $start_page
 <img align="right" src="$logo" />
@@ -2848,7 +2852,7 @@
 $blog
 $toolarge
 <font color="red">$status</font>
-<form name="reldt" action="$feedurl" target="loncapaclient">
+<form name="reldt" action="$feedurl" target="$windowname">
 $prevtag
 $sorttag
 $statustag
@@ -4047,11 +4051,15 @@
 					  'only_body'   => 1,
 					  'add_entries' => \%onload});
       my $end_page = &Apache::loncommon::end_page();
+      my $windowname = 'loncapaclient';
+      if ($env{'request.lti.login'}) {
+          $windowname .= 'lti';
+      }
       $r->print (<<ENDREDIR);
 $start_page
 <img align="right" src="$logo" />
 $textline
-<form name="reldt" action="$feedurl" target="loncapaclient">
+<form name="reldt" action="$feedurl" target="$windowname">
 </form>
 <br />
 $end_page
Index: loncom/lti/ltiutils.pm
diff -u loncom/lti/ltiutils.pm:1.6 loncom/lti/ltiutils.pm:1.7
--- loncom/lti/ltiutils.pm:1.6	Sat Apr 14 02:30:07 2018
+++ loncom/lti/ltiutils.pm	Sat Apr 14 17:52:48 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA LTI interactions 
 #
-# $Id: ltiutils.pm,v 1.6 2018/04/14 02:30:07 raeburn Exp $
+# $Id: ltiutils.pm,v 1.7 2018/04/14 17:52:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -481,13 +481,12 @@
             $scope = 'map';
             $realuri = $tail;
         } else {
-            $scope = 'resource';
             my ($map,$resid,$url) = &Apache::lonnet::decode_symb($tail);
             $realuri = &Apache::lonnet::clutter($url);
-            if (($url =~ /\.sequence$/) &&
-                ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
-                $realuri .= '?navmap=1';
+            if ($url =~ /\.sequence$/) {
+                $scope = 'map';
             } else {
+                $scope = 'resource';
                 $realuri .= '?symb='.$tail;
             }
         }
@@ -516,18 +515,12 @@
             if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) &&
                 (!$env{'request.role.adv'})) {
                 $realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url));
-                if (($url =~ /\.sequence$/) &&
-                    ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
-                    $realuri .= '?navmap=1';
-                } else {
+                if ($scope eq 'resource') {
                     $realuri .= '?symb='.&Apache::lonenc::encrypted($symb);
                 }
             } else {
                 $realuri = &Apache::lonnet::clutter($url);
-                if (($url =~ /\.sequence$/) &&
-                    ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) {
-                    $realuri .= '?navmap=1';
-                } else {
+                if ($scope eq 'resource') {
                     $realuri .= '?symb='.$symb;
                 }
             }
Index: rat/lonsequence.pm
diff -u rat/lonsequence.pm:1.49 rat/lonsequence.pm:1.50
--- rat/lonsequence.pm:1.49	Sat Apr 14 02:29:57 2018
+++ rat/lonsequence.pm	Sat Apr 14 17:52:53 2018
@@ -2,7 +2,7 @@
 #
 # Sequence Handler
 #
-# $Id: lonsequence.pm,v 1.49 2018/04/14 02:29:57 raeburn Exp $
+# $Id: lonsequence.pm,v 1.50 2018/04/14 17:52:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -252,23 +252,26 @@
            if (ref($navmap)) {
                # renderer call
                if (&Apache::lonnet::is_on_map($requrl)) {
-                   my $ltiscope;
+                   my ($ltiscope,$ltiuri);
                    if (($env{'request.lti.login'}) && ($env{'request.lti.uri'})) {
                        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-                       ($ltiscope) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
+                       ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
                    }
                    my $mapurl = &Apache::lonnet::declutter($requrl);
                    my @crumbs;
-                   unless (($ltiscope eq 'resource') || ($ltiscope eq 'map')) {
-                       @crumbs = ({text  => $crstype.' Contents',
-                                   href  => "javascript:gopost('/adm/navmaps','')"});
+                   unless ($ltiscope eq 'resource') {
+                       unless ($ltiscope eq 'map') {
+                           @crumbs = ({text  => $crstype.' Contents',
+                                       href  => "javascript:gopost('/adm/navmaps','')"});
+                       }
                        my $res = $navmap->getResourceByUrl($mapurl);
                        if (ref($res)) {
                            my $symb = $res->symb();
                            if ($symb) {
                                my ($parent) = &Apache::lonnet::decode_symb($res->symb());
-                               if ($parent ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
+                               if (($parent ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
+                                   !(($ltiscope eq 'map') && ($requrl eq $ltiuri))) {
                                    my @mapcrumbs = $navmap->recursed_crumbs($parent);
                                    if (@mapcrumbs) {
                                        push(@crumbs, at mapcrumbs);


More information about the LON-CAPA-cvs mailing list