[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm /interface loncommon.pm

raeburn raeburn at source.lon-capa.org
Mon Apr 19 19:07:34 EDT 2021


raeburn		Mon Apr 19 23:07:34 2021 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
    /loncom/interface	loncommon.pm 
  Log:
  - Display progress indicator after selecting role in a course while course
    session is established.
  
  
-------------- next part --------------
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.346 loncom/auth/lonroles.pm:1.347
--- loncom/auth/lonroles.pm:1.346	Mon Apr 19 20:09:07 2021
+++ loncom/auth/lonroles.pm	Mon Apr 19 23:07:33 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.346 2021/04/19 20:09:07 raeburn Exp $
+# $Id: lonroles.pm,v 1.347 2021/04/19 23:07:33 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -148,6 +148,49 @@
 my $registered_cleanup;
 my $rosterupdates;
 
+sub start_loading_course {
+    my ($r,$title) = @_;
+    &Apache::loncommon::content_type($r,'text/html');
+    &Apache::loncommon::no_cache($r);
+    $r->send_http_header;
+    my $swinfo=&Apache::lonmenu::rawconfig();
+    # Breadcrumbs
+    my $brcrum = [{'href' => '',
+                   'text' => $title},];
+    my $start_page = &Apache::loncommon::start_page($title,undef,
+                                                    {'bread_crumbs' => $brcrum,});
+    $r->print(<<ENDREDIR);
+$start_page
+<script type="text/javascript">
+// <![CDATA[
+$swinfo
+// ]]>
+</script>
+ENDREDIR
+    return;
+}
+
+sub finish_loading_course {
+    my ($r,$msg,$url) = @_;
+#FIXME add continue link, and add jquery to enable menu links when page is loaded
+    my $link;
+    my $end_page = &Apache::loncommon::end_page();
+    my $js_url = &js_escape($url);
+    $r->print(<<END);
+$msg
+<script type="text/javascript">
+// <![CDATA[
+\$(document).ready(function() {
+    var url = "$js_url";
+    \$(location).attr('href',url);
+});
+</script>
+$link
+$end_page
+END
+    return;
+}
+
 sub redirect_user {
     my ($r,$title,$url,$msg) = @_;
     $msg = $title if (! defined($msg));
@@ -182,29 +225,22 @@
 
 sub error_page {
     my ($r,$error,$dest)=@_;
-    &Apache::loncommon::content_type($r,'text/html');
-    &Apache::loncommon::no_cache($r);
-    $r->send_http_header;
-    return OK if $r->header_only;
-    # Breadcrumbs
-    my $brcrum = [{'href' => $dest,
-                   'text' => 'Problems during Course Initialization'},];
-    $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
-                                             undef,
-                                             {'bread_crumbs' => $brcrum,})
-    );
-    $r->print(
-        '<script type="text/javascript">'.
-        '// <![CDATA['.
-        &Apache::lonmenu::rawconfig().
-        '// ]]>'.
-        '</script>'.
-	      '<p class="LC_error">'.&mt('The following problems occurred:').
-          '<br />'.
-	      $error.
-	      '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
+    my %lt = &Apache::lonlocal::texthash(
+        pdc => 'Problems during Course Initialization',
+        tfp => 'The following problems occurred:',
+        con => 'Continue',
     );
-    $r->print(&Apache::loncommon::end_page());
+    my $end_page = &Apache::loncommon::end_page();
+    $dest = &HTML::Entities::encode($dest,'"<>&');
+    $r->print(<<END);
+<h3>$lt{'pdc'}</h3>
+<p class="LC_error">$lt{'tfp'}
+<br />
+$error
+</p><br /><a href="$dest">$lt{'con'}</a>
+$end_page
+END
+    return;
 }
 
 sub handler {
@@ -234,7 +270,7 @@
     @{$rosterupdates}=();
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 
-# -------------------------------------------------- Check if setting hot list 
+# -------------------------------------------------- Check if setting hot list
     my $hotlist;
     if ($env{'form.action'} eq 'verify_and_change_rolespref') {
         $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
@@ -591,7 +627,26 @@
                                 }
                             }
                         }
-                        my ($msg,$blockcrit,$critmsg_check); 
+                        my $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+                        $crstype = lc($crstype);
+                        my $preamble = '<div id="LC_update_'.$cdom.'_'.$cnum.'" class="LC_info">'.
+                                       '<br />'.
+                                       &mt("Please be patient while your $crstype loads").
+                                       '<br /></div>'.
+                                       '<div style="padding:0;clear:both;margin:0;border:0"></div>';
+                        my $closure = <<ENDCLOSE;
+<script type="text/javascript">
+// <![CDATA[
+\$("#LC_update_${cdom}_${cnum}").hide('slow');
+// ]]>
+</script>
+ENDCLOSE
+                        my $title = &mt("Loading $crstype");
+                        &start_loading_course($r,$title);
+                        my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
+                        &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Loading ...'));
+                        $r->rflush();
+                        my ($msg,$blockcrit,$critmsg_check);
                         $critmsg_check = 1;
                         $blockcrit = &Apache::loncommon::blocking_status('alert',$cnum,$cdom,undef,1);
                         if ($blockcrit) {
@@ -604,9 +659,15 @@
                                 $critmsg_check = 0;
                             }
                         }
-			my ($furl,$ferr)=
-			    &Apache::lonuserstate::readmap($cdom.'/'.$cnum,$critmsg_check);
-                        unless ($ferr) {
+                        my ($furl,$ferr)=
+                            &Apache::lonuserstate::readmap($cdom.'/'.$cnum,$critmsg_check);
+                        &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
+                        &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+                        $r->print($closure);
+                        $r->rflush();
+                        if ($ferr) {
+                            $furl = '/adm/roles?tryagain=1';
+                        } else {
                             &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
                             unless (($env{'form.switchrole'}) || 
                                     ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
@@ -662,8 +723,16 @@
                             }
 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
+                            if ($ferr) {
+                                if ($env{'form.orgurl'}) {
+                                    $furl .= '&orgurl='.&HTML::Entities::encode($env{'form.orgurl'},'<>&"');
+                                }
+                                if ($env{'form.symb'}) {
+                                    $furl .= '&symb='.&HTML::Entities::encode($env{'form.symb'};
+                                }
+                            }
                             if (($ferr) && ($tadv)) {
-				&error_page($r,$ferr,$dest);
+				&error_page($r,$ferr,$furl);
 			    } else {
                                 if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
                                     if (($env{'form.orgurl'} ne '') && ($env{'form.symb'} ne '')) {
@@ -679,30 +748,49 @@
                                                                                        $cdom.'_'.$cnum);
                                     }
                                 }
-                                if (($env{'request.lti.login'}) &&
-                                    ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) {
-                                    &process_lti($r,$cdom,$cnum);
+                                if ($ferr) {
+                                    if (!$env{'request.course.id'}) {
+                                        &Apache::lonnet::appenv(
+                                           {"request.course.id"  => $cdom.'_'.$cnum});
+                                        $r->print('<p class="LC_error">'.
+                                                  &mt('Could not initialize [_1] at this time.',
+                                                      $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                                  '</p>'.
+                                                  '<p><a href="'.$furl.'">'.
+                                                  &mt('Please try again.').'</a></p>'.
+                                                  &Apache::loncommon::end_page());
+                                    }
+                                } else {
+                                    if (($env{'request.lti.login'}) &&
+                                        ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) {
+                                        &process_lti($r,$cdom,$cnum);
+                                    }
+                                    $msg = '<p>'.&mt('Entering [_1] ...',
+                                                     $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                           '</p>';
+                                    &finish_loading_course($r,$msg,$dest);
                                 }
-				$r->internal_redirect($dest);
 			    }
+                            $r->rflush();
 			    return OK;
 			} else {
 			    if (!$env{'request.course.id'}) {
 				&Apache::lonnet::appenv(
 				      {"request.course.id"  => $cdom.'_'.$cnum});
-				$furl='/adm/roles?tryagain=1';
-                $msg='<p><span class="LC_error">'
-                    .&mt('Could not initialize [_1] at this time.',
-                         $env{'course.'.$cdom.'_'.$cnum.'.description'})
-                    .'</span></p>'
-                    .'<p>'.&mt('Please try again.').'</p>'
-                    .'<p>'.$ferr.'</p>';
 			    }
 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
-
-			    if (($ferr) && ($tadv)) {
-				&error_page($r,$ferr,$furl);
+			    if ($ferr) {
+                                if ($tadv) {
+				    &error_page($r,$ferr,$furl);
+                                } else {
+                                    $r->print('<p class="LC_error">'.
+                                              &mt('Could not initialize [_1] at this time.',
+                                                  $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                              '</p>'.
+                                              '<p><a href="'.$furl.'">'.&mt('Please try again.').'</a></p>'.
+                                              &Apache::loncommon::end_page());
+                                }
 			    } else {
                                 if (($env{'request.lti.login'}) &&
                                     ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) {
@@ -720,9 +808,11 @@
                                         my ($score,$incomplete) = 
                                             &Apache::lonplacementtest::check_completion(undef,undef,1);
                                         if (($incomplete) && ($incomplete < 100)) {
-                                            &redirect_user($r, &mt('Entering [_1]',
-                                                          $env{'course.'.$cdom.'_'.$cnum.'.description'}),
-                                                          '/adm/placement', $msg);
+                                            $msg = '<p>'.&mt('Entering [_1] ...',
+                                                             $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                                   '</p>';
+                                            &finish_loading_course($r,$msg,'/adm/placement');
+                                            $r->rflush();
                                             return OK;
                                         }
                                     }
@@ -784,12 +874,13 @@
                                                 $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb;
                                             }
                                         }
-                                        my $title;
                                         unless ($env{'request.lti.login'}) {
-                                            $title = &mt('Entering [_1]',
-                                                         $env{'course.'.$cdom.'_'.$cnum.'.description'});
+                                            $msg = '<p>'.&mt('Entering [_1] ...',
+                                                             $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                                   '</p>';
                                         }
-                                        &redirect_user($r,$title,$dest,$msg);
+                                        &finish_loading_course($r,$msg,$dest);
+                                        $r->rflush();
                                         return OK;
                                     }
 				    if (&Apache::lonnet::allowed('whn',
@@ -800,10 +891,11 @@
 					) {
 					my $startpage = &courseloadpage($env{'request.course.id'});
 					unless ($startpage eq 'firstres') {         
-					    $msg = &mt('Entering [_1] ...',
-						       $env{'course.'.$env{'request.course.id'}.'.description'});
-					    &redirect_user($r, &mt('New in course'),
-                                       '/adm/whatsnew?refpage=start', $msg);
+					    $msg = '<p>'.&mt('Entering [_1] ...',
+						             $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                                   '</p>';
+                                            &finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start');
+                                            $r->rflush();
 					    return OK;
 					}
 				    }
@@ -827,17 +919,17 @@
                                 } elsif ($access eq 'B') {
                                     $furl = '/adm/navmaps?showOnlyHomework=1';
                                 }
-                                my $title;
                                 if ($env{'request.lti.login'}) {
                                     undef($msg);
+                                    &finish_loading_course($r,$msg,$furl);
                                 } else {
-                                    $title = &mt('Entering [_1]',
-                                                 $env{'course.'.$cdom.'_'.$cnum.'.description'});
-                                    $msg = &mt('Entering [_1] ...',
-					       $env{'course.'.$cdom.'_'.$cnum.'.description'});
+                                    $msg = '<p>'.&mt('Entering [_1] ...',
+					              $env{'course.'.$cdom.'_'.$cnum.'.description'}).
+                                           '</p>';
+                                    &finish_loading_course($r,$msg,$furl);
                                 }
-				&redirect_user($r,$title,$furl,$msg);
 			    }
+                            $r->rflush();
 			    return OK;
 			}
 		    }
@@ -901,7 +993,7 @@
         $crumbtext = 'Courses';
         $pagetitle = 'My Courses';
         $recent = &mt('Recent Courses');
-        $standby = &mt('Course selected. Please stand by.'); 
+        $standby = &mt('Course selected. Please stand by.');
     }
     my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
 
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1356 loncom/interface/loncommon.pm:1.1357
--- loncom/interface/loncommon.pm:1.1356	Sun Apr 11 18:05:43 2021
+++ loncom/interface/loncommon.pm	Mon Apr 19 23:07:34 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1356 2021/04/11 18:05:43 raeburn Exp $
+# $Id: loncommon.pm,v 1.1357 2021/04/19 23:07:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6144,12 +6144,24 @@
     if ($realm) {
         $realm = '/'.$realm;
     }
-    if ($role  eq 'ca') {
+    if ($role eq 'ca') {
         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
         $realm = &plainname($rname,$rdom);
     } 
 # realm
+    my ($cid,$sec);
     if ($env{'request.course.id'}) {
+        $cid = $env{'request.course.id'};
+        if ($env{'request.course.sec'}) {
+            $sec = $env{'request.course.sec'};
+        }
+    } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
+        if (&Apache::lonnet::is_course($1,$2)) {
+            $cid = $1.'_'.$2;
+            $sec = $3;
+        }
+    }
+    if ($cid) {
         if ($env{'request.role'} !~ /^cr/) {
             $role = &Apache::lonnet::plaintext($role,&course_type());
         } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
@@ -6161,10 +6173,10 @@
         } else {
             $role = (split(/\//,$role,4))[-1]; 
         }
-        if ($env{'request.course.sec'}) {
-            $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
+        if ($sec) {
+            $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
         }   
-	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
+	$realm = $env{'course.'.$cid.'.description'};
     } else {
         $role = &Apache::lonnet::plaintext($role);
     }
@@ -6187,7 +6199,7 @@
 	undef($role);
     }
 
-    if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
+    if (($cid) && ($env{'request.lti.login'})) {
         if (ref($ltimenu) eq 'HASH') {
             unless ($ltimenu->{'role'}) {
                 undef($role);
@@ -6202,17 +6214,15 @@
     #
     # Extra info if you are the DC
     my $dc_info = '';
-    if ($env{'user.adv'} && exists($env{'user.role.dc./'.
-                        $env{'course.'.$env{'request.course.id'}.
-                                 '.domain'}.'/'})) {
-        my $cid = $env{'request.course.id'};
+    if (($env{'user.adv'}) && ($env{'request.course.id'}) &&
+        (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
         $dc_info =~ s/\s+$//;
     }
 
     my $crstype;
-    if ($env{'request.course.id'}) {
-        $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+    if ($cid) {
+        $crstype = $env{'course.'.$cid.'.type'};
     } elsif ($args->{'crstype'}) {
         $crstype = $args->{'crstype'};
     }


More information about the LON-CAPA-cvs mailing list