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

raeburn raeburn at source.lon-capa.org
Tue Sep 23 11:19:05 EDT 2025


raeburn		Tue Sep 23 15:19:05 2025 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  - Starting with rev. 1.516 parameters for all parts and all responseIDs are
    shown in table mode for a single resource. Retain this as the default,
    but provide option(s) to only show part 0 (or selected part), and/or not
    show parameters for responseIDs (where applicable). with both set to "No"
    this reverts to the behavior seen in 2.11 and earlier.     
  
  
-------------- next part --------------
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.629 loncom/interface/lonparmset.pm:1.630
--- loncom/interface/lonparmset.pm:1.629	Sun Sep  7 14:05:36 2025
+++ loncom/interface/lonparmset.pm	Tue Sep 23 15:19:05 2025
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.629 2025/09/07 14:05:36 raeburn Exp $
+# $Id: lonparmset.pm,v 1.630 2025/09/23 15:19:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2367,6 +2367,8 @@
 # @param {hash reference} $keyorder - hash parameter key -> appearance rank for this parameter when looking through every resource and every parameter, starting at 100 (integer)
 # @param {hash reference} $defkeytype - hash parameter name -> parameter type
 # @param {string} $pssymb - resource symb (when a single resource is selected)
+# @param {hash reference} $respids - responseIDs for parts being shown 
+#                         (only populated when a single resource is selected)
 sub extractResourceInformation {
     my $ids = shift;
     my $typep = shift;
@@ -2381,8 +2383,10 @@
     my $keyorder=shift;
     my $defkeytype=shift;
     my $pssymb=shift;
+    my $respids=shift;
 
     my $keyordercnt=100;
+    my $get_respids;
 
     my $navmap = Apache::lonnavmaps::navmap->new();
     return unless(ref($navmap));
@@ -2392,6 +2396,9 @@
         if (ref($res)) {
             @allres = ($res);
         }
+        if (ref($respids) eq 'HASH') {
+            $get_respids = 1;
+        }
     }
     if (!@allres) { 
         @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
@@ -2438,6 +2445,25 @@
             }
 
 #
+# Try to extract responseIDs for parameters which are not filtered out.
+# This assumes the partID doesn't contain any underscore(s), which  
+# may not be the case if a library file containing part tag(s) has been 
+# imported as a standard library.
+#
+            if ($get_respids) {
+                if ($key =~ /^parameter_([^_]+)_([^_]+_?[^_]*)_\Q$name\E$/) {
+                    my $partid = $1;
+                    my $resp = $2;
+                    unless ((($env{'form.filter'} ne '') &&
+                             ($env{'form.filter'} !~ /\Q$name\E/)) ||
+                            (($env{'form.part'} ne '') &&
+                             ($partid ne $env{'form.part'}))) {
+                        $respids->{$resp} = 1;
+                    }
+                }
+            }
+
+#
 # allparts is a hash of all parts
 #
             my $part= &Apache::lonnet::metadata($srcf,$key.'.part',$toolsymb);
@@ -3460,6 +3486,10 @@
 
     my %allparms; # hash parameter name -> parameter title
     my %allparts; # hash parameter part -> part title
+
+    # Following hash is only populated if a single resource is selected,
+    # i.e., $pssymb is defined.
+    my %respids; # hash; keys are responseIDs (unless filtered out).
 # ------------------------------------------------------------------------------
 
 #
@@ -3693,7 +3723,7 @@
 # --------------------------------------------------------- Get all assessments
     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
                 \%mapp, \%symbp,\%maptitles,\%uris,
-                \%keyorder,undef,$pssymb);
+                \%keyorder,undef,$pssymb,\%respids);
 
     %allmaps_inverted = reverse(%allmaps);
 
@@ -3931,7 +3961,8 @@
 // ]]>
 </script>
 ENDPARMSELSCRIPT
-    
+
+    my %allpartids;
     if (!$pssymb) {
         # No single resource selected, print forms to select things (hidden after first selection)
         my $parmselhiddenstyle=' style="display:none"';
@@ -3993,12 +4024,59 @@
         # parameter screen for a single resource. 
         my ($map,$iid,$resource)=&Apache::lonnet::decode_symb($pssymb);
         my $title = &Apache::lonnet::gettitle($pssymb);
+        my ($allpartson,$allpartsoff,$allrespson,$allrespsoff);
+        if ($env{'form.psprt'} eq '0') {
+            $allpartson = '';
+            $allpartsoff = ' checked="checked"';
+        } else {
+            $allpartson = ' checked="checked"';
+            $allpartsoff = '';
+        }
+        if ($env{'form.psresp'} eq '0') {
+            $allrespson = '';
+            $allrespsoff = ' checked="checked"';
+        } else {
+            $allrespson = ' checked="checked"';
+            $allrespsoff = '';
+        }
         $r->print(&mt('Specific Resource: [_1] ([_2])',
                          $title,'<span class="LC_filename">'.$resource.'</span>').
                 '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
                   '<br />');
         $r->print(&Apache::lonhtmlcommon::topic_bar('',&mt('Additional Display Specification (optional)')));
         $r->print(&Apache::lonhtmlcommon::start_pick_box());
+        foreach my $item (keys(%allparts)) {
+            if ($item =~ /_/) {
+                my ($part) = split(/_/,$item);
+                $allpartids{$part} = 1;
+            } else {
+                $allpartids{$item} = 1;
+            }
+        }
+        if (keys(%allpartids) > 1) {
+            $r->print(&Apache::lonhtmlcommon::row_title(&mt('Show All Parts?')).
+                      '<label>'.
+                      '<input type="radio" name="psprt" value="all"'.$allpartson.' />'.
+                      &mt('Yes').
+                      '</label>    '.
+                      '<label>'.
+                      '<input type="radio" name="psprt" value="0"'.$allpartsoff.' />'.
+                      &mt('No').
+                      '</label>'.
+                      &Apache::lonhtmlcommon::row_closure());
+        }
+        if (keys(%respids) > 0) {
+            $r->print(&Apache::lonhtmlcommon::row_title(&mt('Show Parameters for Response(s)?')).
+                      '<label>'.
+                      '<input type="radio" name="psresp" value="all"'.$allrespson.' />'.
+                      &mt('Yes').
+                      '</label>    '.
+                      '<label>'.
+                      '<input type="radio" name="psresp" value="0"'.$allrespsoff.' />'.
+                      &mt('No').
+                      '</label>'.
+                      &Apache::lonhtmlcommon::row_closure());
+        }
         &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
         $r->print(&Apache::lonhtmlcommon::row_closure(1));
         $r->print(&Apache::lonhtmlcommon::end_pick_box());
@@ -4157,6 +4235,21 @@
                     }
 
                     my $filter=$env{'form.filter'};
+                    my ($part_reqd,$no_resp);
+                    if ($pssymb) {
+                        if ($env{'form.psprt'} eq '0') {
+                            if (scalar(keys(%allpartids)) == 0) {
+                                $part_reqd = '0';
+                            } elsif (scalar(keys(%allpartids)) == 1) {
+                                $part_reqd = (keys(%allpartids))[0];
+                            } elsif ($env{'form.part'} ne '0') {
+                                $part_reqd = $env{'form.part'};
+                            }
+                        }
+                        if ($env{'form.psresp'} eq '0') {
+                            $no_resp = 1;
+                        }
+                    }
                     foreach my $tempkeyp (&keysplit($keyp{$rid})) {
                         if (grep $_ eq $tempkeyp, @catmarker) {
                             my $parmname=&Apache::lonnet::metadata($uri,$tempkeyp.'.name',$toolsymb);
@@ -4164,6 +4257,12 @@
                             if ($filter) {
                                 unless ($filter=~/\Q$parmname\E/) { next; }
                             }
+                            if ($part_reqd ne '') {
+                                next unless ($tempkeyp =~ /^parameter_\Q$part_reqd\E_/);
+                            }
+                            if ($no_resp) {
+                                next if ($tempkeyp =~ /^parameter_[^_]+_[^_]+_/);
+                            }
                             $name{$tempkeyp}=$parmname;
                             $part{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.part',$toolsymb);
 


More information about the LON-CAPA-cvs mailing list