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

raeburn raeburn at source.lon-capa.org
Mon Dec 18 17:56:46 EST 2017


raeburn		Mon Dec 18 22:56:46 2017 EDT

  Modified files:              
    /loncom/interface	lonextresedit.pm londocs.pm 
  Log:
  - Bug 6754 LON-CAPA as LTI Consumer
   - Course Coordinator can set an instance of a Tool Provider to be gradable,
     e.g., when the provider will be passing grades back to LON-CAPA.
  
  
-------------- next part --------------
Index: loncom/interface/lonextresedit.pm
diff -u loncom/interface/lonextresedit.pm:1.22 loncom/interface/lonextresedit.pm:1.23
--- loncom/interface/lonextresedit.pm:1.22	Fri Dec 15 16:33:51 2017
+++ loncom/interface/lonextresedit.pm	Mon Dec 18 22:56:45 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: lonextresedit.pm,v 1.22 2017/12/15 16:33:51 raeburn Exp $
+# $Id: lonextresedit.pm,v 1.23 2017/12/18 22:56:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -161,6 +161,9 @@
             $newurl = $1;
             $marker = $2;
             $args = $3;
+            if ((!$symb) && (!$supplementalflag)) {
+                $symb = "uploaded/$cdom/$cnum/$folder.$container"."___$newidx"."___adm/$cdom/$cnum/$marker/ext.tool";
+            }
         }
     }
     if ($supplementalflag) {
@@ -170,7 +173,7 @@
     }
     if ($folder && $container) {
         if ($env{'form.importdetail'}) {
-            my ($errtext,$fatal,$mismatchedid, at imports);
+            my ($errtext,$fatal,$mismatchedid,$needreload,$newgradable, at imports);
             if (!$supplementalflag) {
                 if (($oldidx) && ($oldidx != $newidx)) {
                     $mismatchedid = 1;
@@ -181,9 +184,27 @@
             } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
                 if ($type eq 'tool') {
                     if ($args) {
-                        ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
-                        unless ($updated) {
-                            $output = &mt('No change');      
+                        ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
+                                                                            $supplementalflag,$args);
+                        if ($updated) {
+                            if ($newgradable) {
+                                my $map = "/uploaded/$cdom/$cnum/$folder.$container";
+                                my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
+                                if ($fatal) {
+                                    $errormsg = &mt('Update failed: [_1].',$errtext);
+                                } else {
+                                    &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',
+                                                                  $newgradable,'string_yesno');
+                                    my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
+                                    if ($errtext) {
+                                        $errormsg = &mt('Update failed: [_1].',$errtext);
+                                    } else {
+                                        $needreload = 1;
+                                    }
+                                }
+                            }
+                        } else {
+                            $output = &mt('No change');
                         }
                     } else {
                         $output = &mt('No change');
@@ -202,13 +223,25 @@
                     my $ext = 'true';
                     if ($type eq 'tool') {
                         if ($args) {
-                            ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
+                            ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
+                                                                                $supplementalflag,$args);
+                            if ($newgradable) {
+                                &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$newgradable,
+                                                              'string_yesno');
+                                $needreload = 1;
+                            }
                         }
                         $ext = 'false';
                     }
+                    my $dotimeupdate;
+                    unless ($supplementalflag) {
+                        if (($newgradable) || ($newurl ne $oldurl)) {
+                            $dotimeupdate = 1;
+                        }
+                    }
                     $LONCAPA::map::resources[$residx] =
                         join(':', ($savetitle,$saveurl,$ext,'normal','res'));
-                    my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
+                    my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,$dotimeupdate);
                     if ($errtext) {
                         $errormsg = &mt('Update failed: [_1].',$errtext);
                     } else {
@@ -230,19 +263,24 @@
                                     &Apache::lonnet::devalidate_title_cache($symb);
                                 }
                             }
-                        }
-                        my ($furl,$ferr) = 
-                            &Apache::lonuserstate::readmap("$cdom/$cnum");
-                        if ($ferr) {
-                            $errormsg = &mt('Reload failed: [_1].',$ferr);
-                        } else {
-                            unless ($supplementalflag) {
-                                &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
-                            }
+                            $needreload = 1;
                         }
                     }
                 }
             }
+            if ($needreload) {
+                my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
+                if ($ferr) {
+                    $errormsg = &mt('Reload failed: [_1].',$ferr);
+                } else {
+                    &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
+                                                                   $cdom.'_'.$cnum);
+                }
+            }
+            if (($type eq 'tool') && ($newgradable)) {
+                my $uri = &Apache::lonnet::declutter($url);
+                &Apache::lonnet::devalidate_cache_new('meta',$uri);
+            }
         } else {
             $output = &mt('No change');
         }
@@ -257,16 +295,16 @@
 }
 
 sub update_exttool {
-    my ($marker,$cdom,$cnum,$args) = @_;
+    my ($marker,$cdom,$cnum,$supplementalflag,$args) = @_;
     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
-    my (%newhash,$changed, at deleted,$errormsg);
+    my (%newhash,$changed,$newgradable, at deleted,$errormsg);
     ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
-     $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'}) = split(/:/,$args);
+     $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}) = split(/:/,$args);
     foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') {
         $newhash{$item} = &unescape($newhash{$item});
     }
     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
-    foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend') {
+    foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable') {
         $newhash{$item} =~ s/^\s+//;
         $newhash{$item} =~ s/\s+$//;
         if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
@@ -277,8 +315,19 @@
                     $newhash{$item} = '';
                 }
             }
+        } elsif ($item eq 'gradable') {
+            unless ($newhash{$item} == 1) {
+                $newhash{$item} = '';
+            }
         }
         if ($toolhash{$item} ne $newhash{$item}) {
+            if (($item eq 'gradable') && (!$supplementalflag)) {
+                if ($newhash{$item}) {
+                    $newgradable = 'yes';
+                } else {
+                    $newgradable = 'no';
+                }
+            }
             if ($newhash{$item} eq '') {
                 unless (($item eq 'target') ||
                         ((($item eq 'width') || ($item eq 'height')) &&
@@ -306,7 +355,7 @@
     if (@deleted) {
         &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
     }
-    return ($changed,$errormsg);
+    return ($changed,$newgradable,$errormsg);
 }
 
 sub extedit_form {
@@ -335,16 +384,16 @@
     }
     my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
         $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
-        $appendstyle,$legend,$urlelem,$toolelem,%toolattr);
+        $appendstyle,$gradablestyle,$legend,$urlelem,$toolelem,%toolattr);
     $formname = 'new'.$type;
     $toggle = $type;
     $fieldsetid = 'upload'.$type.'form';
     $urlid = $type.'url';
     map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
                                        'crstitlediv','crslabeldiv','crsappenddiv',
-                                       'crstitle','crslabel','crsappend','windiv',
-                                       'linktextdiv','explanationdiv','linktext',
-                                       'explanation','providerurl'); 
+                                       'gradablediv','crstitle','crslabel','crsappend',
+                                       'windiv','linktextdiv','explanationdiv',
+                                       'linktext','explanation','providerurl');
     $dispdivstyle = 'display:none';
     $dimendivstyle = 'display:none';
     $windivstyle = 'display:none';
@@ -353,6 +402,7 @@
     $labelstyle = 'display:none';
     $titlestyle = 'display:none';
     $appendstyle = 'display:none';
+    $gradablestyle = 'display:none';
     if ($supplementalflag) {
         $formname = 'newsupp'.$type;
         $toggle = 'supp'.$type;
@@ -362,7 +412,7 @@
     }
     my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
         $crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
-        $linktext,$explanation,$providerurl,%chkstate);
+        $linktext,$explanation,$providerurl,$chkgrd,$chknogrd,%chkstate);
     $fieldsetstyle = 'display: none;';
     $action = '/adm/coursedocs';
     my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
@@ -471,6 +521,11 @@
                                 $height = $toolhash{'height'};
                                 $linktext = $toolhash{'linktext'};
                                 $explanation = $toolhash{'explanation'};
+                                if ($toolhash{'gradable'}) {
+                                    $chkgrd = ' checked="checked"';
+                                } else {
+                                    $chknogrd = ' checked="checked"';
+                                }
                                 if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') {
                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) {
                                         $crstitle = $toolhash{'crstitle'};
@@ -495,6 +550,7 @@
                                     }
                                 }
                                 $toolelem = '<span class="LC_nobreak">'.$image.' '.$tooltitle.'</span><br />';
+                                $gradablestyle = 'display:inline';
                             }
                         }
                     }
@@ -527,6 +583,7 @@
             $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
             $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
             $crsappend = '';
+            $chknogrd = ' checked="checked"';
         }
         $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
                     '<span class="'.$class.'">'.&mt('Display target:').' '.
@@ -564,7 +621,13 @@
                     '<span class="'.$class.'">'.&mt('Append to URL[_1]',
                     '<span id="'.$toolattr{'providerurl'}.'"> ('.$providerurl.')<br /></span>').
                     '<input type="text" id="'.$toolattr{'crsappend'}.'" size="30" name="exttoolappend" value="'.$crsappend.'"'.$disabled.' /></span><br />'.
-                    '</div>';
+                    '</div>'.
+                    '<div id="'.$toolattr{'gradablediv'}.'" style="'.$gradablestyle.'">'.
+                    '<span class="'.$class.'">'.&mt('Gradable').' '.
+                    '<label><input type="radio" name="exttoolgradable" value="1"'.$chkgrd.$disabled.
+                    ' />'.&mt('Yes').'</label>'.(' 'x2).
+                    '<label><input type="radio" name="exttoolgradable" value="0"'.$chknogrd.$disabled.
+                    ' />'.&mt('No').'</label></span></div>';
     }
     my $chooser = $toolelem;
     if ($type eq 'ext') {
@@ -656,7 +719,7 @@
                    "        var ltitoolsLink = new Array($num);\n".
                    "        var ltitoolsExplain = new Array($num);\n".
                    "        var ltitoolsLabel = new Array($num);\n".
-                   "        var ltitoolsTitle = new Array($num);\n";
+                   "        var ltitoolsTitle = new Array($num);\n".
                    "        var ltitoolsAppend = new Array($num);\n";
         my $i = 0;
         foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) {
@@ -843,6 +906,32 @@
         } else {
             info += ':';
         }
+        var gradablediv = prefix+'toolgradablediv';
+        if (residx > 0) {
+            gradablediv += '_'+residx;
+        }
+        if (document.getElementById(gradablediv)) {
+            if (document.getElementById(gradablediv).style.display == 'inline') {
+                if (extform.exttoolgradable.length) {
+                    for (var i=0; i<extform.exttoolgradable.length; i++) {
+                        if (extform.exttoolgradable[i].checked) {
+                            if (extform.exttoolgradable[i].value == '1') {
+                                info += ':1';
+                            } else {
+                                info += ':';
+                            }
+                            break;
+                        }
+                    }
+                } else {
+                    info += ':';
+                }
+            } else {
+                info += ':';
+            }
+        } else {
+            info += ':';
+        }
         info=escape(info);
         if (residx > 0) {
             eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
@@ -894,6 +983,7 @@
     labeldiv = prefix+'toolcrslabeldiv';
     titlediv = prefix+'toolcrstitlediv';
     appenddiv = prefix+'toolcrsappenddiv';
+    gradablediv = prefix+'toolgradablediv';
     providerurl = prefix+'toolproviderurl';
     labelinput = prefix+'toolcrslabel';
     titleinput = prefix+'toolcrstitle';
@@ -931,6 +1021,9 @@
             if (document.getElementById(appenddiv)) {
                 document.getElementById(appenddiv).style.display = 'none';
             }
+            if (document.getElementById(gradablediv)) {
+                document.getElementById(gradablediv).style.display = 'none';
+            }
         } else {
             if (ltitools.length > 0) {
                 for (var j=0; j<ltitools.length; j++) {
@@ -1029,6 +1122,11 @@
                                 }
                             }
                         }
+                        if (document.getElementById(gradablediv)) {
+                            if (supplementalflag != 1) {
+                                document.getElementById(gradablediv).style.display = 'inline';
+                            }
+                        }
                         break;
                     }
                 }
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.644 loncom/interface/londocs.pm:1.645
--- loncom/interface/londocs.pm:1.644	Thu Nov 30 14:41:20 2017
+++ loncom/interface/londocs.pm	Mon Dec 18 22:56:45 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.644 2017/11/30 14:41:20 raeburn Exp $
+# $Id: londocs.pm,v 1.645 2017/12/18 22:56:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,6 +45,7 @@
 use Apache::lonsimplepage();
 use Apache::lonhomework();
 use Apache::lonpublisher();
+use Apache::lonparmset();
 use HTML::Entities;
 use HTML::TokeParser;
 use GDBM_File;
@@ -670,11 +671,14 @@
                 }
                 $toolid =~ s/\D//g;
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
-                 $toolhash{'linktext'},$toolhash{'explanation'},
-                 $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
+                 $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
+                 $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
                 foreach my $item (@extras) {
                     $toolhash{$item} = &unescape($toolhash{$item});
                 }
+                if ($folder =~ /^supplemental/) {
+                    delete($toolhash{'gradable'}); 
+                }
                 if (ref($ltitoolsref) eq 'HASH') {
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
                         my @deleted;
@@ -762,11 +766,35 @@
                             $toolhash{'rostersecret'} = $rostersecret;
                             $toolhash{'rostersecretdate'} = time;
                         }
+                        my $changegradable;
+                        if (($residx) && ($folder =~ /^default/)) {
+                            if (exists($toolsettings{'gradable'})) {
+                                if (!exists($toolhash{'gradable'})) {
+                                    push(@deleted,'gradable');
+                                    $changegradable = 1;
+                                }
+                            } elsif (exists($toolhash{'gradable'})) {
+                                $changegradable = 1;
+                            }
+                        }
                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                         if ($putres eq 'ok') {
                             if (@deleted) {
                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
-                            } 
+                            }
+                            if (($changegradable) && ($folder =~ /^default/)) {
+                                my $val;
+                                if ($toolhash{'gradable'}) {
+                                    $val = 'yes';
+                                } else {
+                                    $val = 'no';
+                                }
+                                &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
+                                                              'string_yesno');
+                                &remember_parms($residx,'gradable','set',$val);
+                            }
+                        } else {
+                            return (&mt('Failed to save update to external tool.'),1);
                         }
                     }
                 }
@@ -1004,6 +1032,7 @@
 	    'encrypturl'     => 'URL hidden',
 	    'randompick'     => 'Randomly pick',
 	    'randomorder'    => 'Randomly ordered',
+            'gradable'       => 'Grade can be assigned to External Tool',
 	    'set'            => 'set to',
 	    'del'            => 'deleted');
     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
@@ -1111,7 +1140,7 @@
 	$r->print('</ul>');
 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
 	    $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
-	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
+	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
 # FIXME: internationalization seems wrong here
 		    $r->print('<li>'.


More information about the LON-CAPA-cvs mailing list