[LON-CAPA-cvs] cvs: loncom /homework edit.pm /interface loncommon.pm loncourseauthor.pm londocs.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Mon Mar 27 14:41:07 EDT 2023


raeburn		Mon Mar 27 18:41:07 2023 EDT

  Modified files:              
    /loncom/interface	loncommon.pm loncourseauthor.pm londocs.pm 
    /loncom/homework	edit.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - "In course" authoring.
    Improved handling of case where no suitable resources authored in course
    exist when (a) using "Import from Course Resources" in Course Editor, and
    (b) using Choose File >  "Use a course file" to select published file as src
    in img tag in colorful editor.
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1401 loncom/interface/loncommon.pm:1.1402
--- loncom/interface/loncommon.pm:1.1401	Sat Mar 11 21:58:18 2023
+++ loncom/interface/loncommon.pm	Mon Mar 27 18:41:04 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1401 2023/03/11 21:58:18 raeburn Exp $
+# $Id: loncommon.pm,v 1.1402 2023/03/27 18:41:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1851,7 +1851,7 @@
                     if (document.getElementById('crsres_include_'+element)) {
                         include = document.getElementById('crsres_include_'+element).value;
                     }
-                    populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1);
+                    populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
                 }
             }
             if (document.getElementById('chooser_'+element+'_upload')) {
@@ -1859,7 +1859,7 @@
                 if (currcrsupload == 'none') {
                     dirsel = 'crsauthorpath_'+element;
                     filesel = '';
-                    populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0);
+                    populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
                 }
             }
         }
@@ -1874,6 +1874,16 @@
                     if (document.getElementById('coursepath_'+element).length) {
                         numdirs = document.getElementById('coursepath_'+element).length;
                     }
+                    if ((document.getElementById('hascrsres_'+element)) &&
+                        (document.getElementById('nocrsres_'+element))) {
+                        if (numdirs) {
+                            document.getElementById('hascrsres_'+element).style.display='inline-block';
+                            document.getElementById('nocrsres_'+element).style.display='none';
+                        } else {
+                            document.getElementById('hascrsres_'+element).style.display='none';
+                            document.getElementById('nocrsres_'+element).style.display='inline-block';
+                        }
+                    }
                     form.elements['coursepath_'+element].selectedIndex = 0;
                     if (numdirs > 1) {
                         var selelem = form.elements['coursefile_'+element];
@@ -2266,7 +2276,7 @@
     return (0) unless (($cnum ne '') && ($cdom ne ''));
     my @ids=&Apache::lonnet::current_machine_ids();
     my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
-    
+
     if (grep(/^\Q$crshome\E$/, at ids)) {
         $is_home = 1;
     }
@@ -2278,25 +2288,29 @@
         $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
     }
     $exclude = &Apache::lonnet::priv_exclude();
-    &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,$toppath,'',\%subdirs,\%files);
+    &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
     my $numdirs = scalar(keys(%files));
     my %lt = &Apache::lonlocal::texthash (
         fnam => 'Filename',
         dire => 'Directory',
         se   => 'Select',
     );
-    $output = $lt{'dire'}.
+    $output = $lt{'dire'}.': '.
               '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
-              'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0".');">'.
+              'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
               '<option value="" selected="selected">'.$lt{'se'}.'</option>';
+    if ($files{'/'}) {
+        $output .= '<option value="/">/</option>'."\n";
+    }
     foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
+        next if ($key eq '/');
         $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
     }
     $output .= '</select><br />'."\n".
-               $lt{'fnam'}.'<select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
+               $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
                '<option value="" selected="selected"></option>'."\n".
-               '</select>'."\n";
-    $output .= '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
+               '</select>'."\n".
+               '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
     return ($numdirs,$output);
 }
 
@@ -2310,7 +2324,7 @@
     my $js = <<"END";
 
 
-    function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir) {
+    function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
         var relpath = '';
         if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
             var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
@@ -2340,7 +2354,7 @@
         if (exc) {
             exclude = '$exclude';
         }
-        var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&path="+relpath;
+        var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
         http.open("POST", url, true);
         http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         http.onreadystatechange = function() {
@@ -2358,11 +2372,7 @@
                         }
                         var len = data.dirs.length;
                         if (len) {
-                            if (len > 1) {
-                                selelem.options[selelem.options.length] = new Option('$se','');
-                            }
-                        }
-                        if (len) {
+                            selelem.options[selelem.options.length] = new Option('$se','');
                             var j;
                             for (j = 0; j < len; j++) {
                                 selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
@@ -18600,7 +18610,7 @@
         $name = &HTML::Entities::encode($name,'"<>&\'');
         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
         $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
-        if ($foldertitle ne '') { 
+        if ($foldertitle ne '') {
             $title .= ': <br />'.$foldertitle;
         }
     }
Index: loncom/interface/loncourseauthor.pm
diff -u loncom/interface/loncourseauthor.pm:1.2 loncom/interface/loncourseauthor.pm:1.3
--- loncom/interface/loncourseauthor.pm:1.2	Thu Mar 23 22:53:46 2023
+++ loncom/interface/loncourseauthor.pm	Mon Mar 27 18:41:04 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: loncourseauthor.pm,v 1.2 2023/03/23 22:53:46 raeburn Exp $
+# $Id: loncourseauthor.pm,v 1.3 2023/03/27 18:41:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,7 +39,7 @@
     my $r = shift;
     &Apache::loncommon::content_type($r,'application/json');
     $r->send_http_header;
-    my ($nonemptydir,%dirhash,%filehash);
+    my ($nonemptydir,$addtopdir,%dirhash,%filehash);
     if ($env{'request.course.id'}) {
         if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
             my ($context,$recurse,$role,$is_home,$inc,$exc,$toppath,$relpath,
@@ -65,6 +65,11 @@
                 if ($env{'form.nonempty'}) {
                     $nonemptydir = 1; 
                 }
+                if ($env{'form.addtop'}) {
+                    $addtopdir = 1;
+                } else {
+                    $addtopdir = 0;
+                }
                 my $now = time;
                 my @ids=&Apache::lonnet::current_machine_ids();
                 if ($role eq 'author') {
@@ -120,7 +125,7 @@
                         $filehashref = \%filehash;
                     }
                     &Apache::lonnet::recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,
-                                                 $toppath,$relpath,$dirhashref,$filehashref);
+                                                 $addtopdir,$toppath,$relpath,$dirhashref,$filehashref);
                 }
             }
         }
@@ -139,8 +144,6 @@
         } else {
             push(@dirs,(sort { lc($a) cmp lc($b) } (keys(%dirhash))));
         }
-    } elsif (($env{'form.role'} eq 'course') && ($env{'form.path'} eq '') && (!$env{'form.nonempty'})) {
-        push(@dirs,'/');
     }
     my %files;
     if (%filehash) {
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.697 loncom/interface/londocs.pm:1.698
--- loncom/interface/londocs.pm:1.697	Thu Mar 23 22:54:38 2023
+++ loncom/interface/londocs.pm	Mon Mar 27 18:41:04 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.697 2023/03/23 22:54:38 raeburn Exp $
+# $Id: londocs.pm,v 1.698 2023/03/27 18:41:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6163,6 +6163,7 @@
                 'dire' => 'Directory:',
                 'cate' => 'Category:',
                 'tmpl' => 'Template:',
+                'empd' => 'No resources found',
                 'comment' => 'Comment',
                 'parse' => 'Upload embedded images/multimedia files if HTML file',
                 'bb5'      => 'Blackboard 5',
@@ -6311,6 +6312,7 @@
         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
         <fieldset id="importcrsresform" style="display: none;">
         <legend>$lt{'imcr'}</legend>
+        <div id="importcrsrescontent" style="display: none;">
         <input type="hidden" name="active" value="bb" />
         $pickfile
         <p>
@@ -6318,6 +6320,12 @@
         </p>
         <input type="hidden" name="importdetail" value="" />
         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
+        </div>
+        <div id="importcrsresempty" style="display: none;">
+        <p>
+        $lt{'empd'}
+        </p>
+        </div>
         </fieldset>
         </form>
 CRSFORM
@@ -7963,7 +7971,22 @@
             var curr = document.getElementById('importcrsresform').style.display;
             if (curr == 'none') {
                 disp='block';
-                populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1);
+                populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
+                if ((document.getElementById('importcrsrescontent')) &&
+                    (document.getElementById('importcrsresempty'))) {
+                    var selelem = document.crsresimportform.elements['coursepath'];
+                    var numdirs = 0;
+                    if (selelem.options.length) {
+                        numdirs = selelem.options.length - 1;
+                    }
+                    if (numdirs) {
+                        document.getElementById('importcrsrescontent').style.display='block';
+                        document.getElementById('importcrsresempty').style.display='none';
+                    } else {
+                        document.getElementById('importcrsrescontent').style.display='none';
+                        document.getElementById('importcrsresempty').style.display='block';
+                    }
+                }
             }
         }
         document.getElementById('importcrsresform').style.display=disp;
@@ -8027,7 +8050,7 @@
             }
             var http = new XMLHttpRequest();
             var url = "/adm/courseauthor";
-            var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir;
+            var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
             http.open("POST", url, true);
             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
             http.onreadystatechange = function() {
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.156 loncom/homework/edit.pm:1.157
--- loncom/homework/edit.pm:1.156	Sat Dec 31 14:08:59 2022
+++ loncom/homework/edit.pm	Mon Mar 27 18:41:06 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.156 2022/12/31 14:08:59 raeburn Exp $
+# $Id: edit.pm,v 1.157 2023/03/27 18:41:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1214,6 +1214,7 @@
             upfi => 'Upload File',
             dire => 'Directory',
             news => 'New sub-directory',
+            empd => 'No suitable resources found',
         );
         my ($importcrsres,$uploadfile,$allonly);
         if ($only) {
@@ -1229,14 +1230,24 @@
         $importcrsres=(<<CRSRES);
         <fieldset id="importcrsresform_$element" style="display:inline;">
         <legend>$lt{'uacf'}</legend>
+        <div id="hascrsres_$element" style="padding:0;clear:both;margin:0;border:0;display:none;">
+        <p>
         $pickfile
-        <input type="button" name="crsres" value="$lt{'sefi'}" onclick="updateCrsFile(this.form,'$element');" />
+        </p><p>
+        <input type="button" name="crsres_$element" value="$lt{'sefi'}" onclick="updateCrsFile(this.form,'$element');" />
+        </p>
+        </div>
+        <div id="nocrsres_$element" style="padding:0;clear:both;margin:0;border:0display:none;">
+        <p>
+        $lt{'empd'}
+        </p>
+        </div>
         </fieldset>
 CRSRES
         my %subdirs;
         my $toppath="/priv/$cdom/$cnum";
         my $exclude = &Apache::lonnet::priv_exclude();
-        &Apache::lonnet::recursedirs(1,1,'',$exclude,'',$toppath,'',\%subdirs);
+        &Apache::lonnet::recursedirs(1,1,'',$exclude,'',0,$toppath,'',\%subdirs);
         my $numcrsdirs = keys(%subdirs);
         my $pickdir = $lt{'dire'}.'<select name="crsauthorpath_'.$element.'">'."\n".
                                    '<option value="/">/</option>'."\n";
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1504 loncom/lonnet/perl/lonnet.pm:1.1505
--- loncom/lonnet/perl/lonnet.pm:1.1504	Sun Mar 19 16:05:48 2023
+++ loncom/lonnet/perl/lonnet.pm	Mon Mar 27 18:41:07 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1504 2023/03/19 16:05:48 raeburn Exp $
+# $Id: lonnet.pm,v 1.1505 2023/03/27 18:41:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -12105,6 +12105,7 @@
 #             files which have a matching extension will be ignored.
 # $nonemptydir - if true, will only populate $fileshashref hash entry for a particular
 #             directory with first file found (with acceptable extension).
+# $addtopdir - if true, set $dirhashref->{'/'} = 1 
 # $toppath - Top level directory (i.e., /res/$dom/$uname or /priv/$dom/$uname
 # $relpath - Current path (relative to top level).
 # $dirhashref - reference to hash to populate with URLs of directories (Required)
@@ -12121,7 +12122,7 @@
 #
 
 sub recursedirs {
-    my ($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$relpath,$dirhashref,$filehashref) = @_;
+    my ($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$relpath,$dirhashref,$filehashref) = @_;
     return unless (ref($dirhashref) eq 'HASH');
     my $docroot = $perlvar{'lonDocRoot'};
     my $currpath = $docroot.$toppath;
@@ -12139,7 +12140,7 @@
         $checkexc = 1;
     }
     if ($is_home) {
-        if (opendir(my $dirh,$currpath)) {
+        if ((-e $currpath) && (opendir(my $dirh,$currpath))) {
             my $filecount = 0;
             foreach my $item (sort { lc($a) cmp lc($b) } grep(!/^\.+$/,readdir($dirh))) {
                 next if ($item eq '');
@@ -12152,7 +12153,7 @@
                     }
                     $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;
                     if ($recurse) {
-                        &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$newpath,$dirhashref,$filehashref);
+                        &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$newpath,$dirhashref,$filehashref);
                     }
                 } elsif (($savefile) || ($relpath eq '')) {
                     next if ($nonemptydir && $filecount);
@@ -12165,7 +12166,7 @@
                             next if ($extension && $exclude->{$extension});
                         }
                     }
-                    if (($relpath eq '') && (!exists($dirhashref->{'/'})))  {
+                    if (($relpath eq '') && (!exists($dirhashref->{'/'}))) {
                         $dirhashref->{'/'} = 1;
                     }
                     if ($savefile) {
@@ -12206,7 +12207,7 @@
                     }
                     $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;
                     if ($recurse) {
-                        &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$newpath,$dirhashref,$filehashref);
+                        &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$newpath,$dirhashref,$filehashref);
                     }
                 } elsif (($savefile) || ($relpath eq '')) {
                     next if ($nonemptydir && $filecount);
@@ -12234,6 +12235,11 @@
             }
         }
     }
+    if ($addtopdir) {
+        if (($relpath eq '') && (!exists($dirhashref->{'/'}))) {
+            $dirhashref->{'/'} = 1;
+        }
+    }
     return;
 }
 


More information about the LON-CAPA-cvs mailing list