[LON-CAPA-cvs] cvs: loncom /cgi quotacheck.pl /publisher lonpubdir.pm

musolffc musolffc at source.lon-capa.org
Tue Aug 5 15:32:23 EDT 2014


musolffc		Tue Aug  5 19:32:23 2014 EDT

  Modified files:              
    /loncom/cgi	quotacheck.pl 
    /loncom/publisher	lonpubdir.pm 
  Log:
  Columns are sortable in the course quota list as well as well as the resource list in authoring space.  An up or down arrow is displayed next to the sorted column header indicating whether it is in ascending or descending order.
  
  This resolves Bug #6704
  
  
-------------- next part --------------
Index: loncom/cgi/quotacheck.pl
diff -u loncom/cgi/quotacheck.pl:1.5 loncom/cgi/quotacheck.pl:1.6
--- loncom/cgi/quotacheck.pl:1.5	Thu Jul 31 15:57:24 2014
+++ loncom/cgi/quotacheck.pl	Tue Aug  5 19:32:19 2014
@@ -6,7 +6,7 @@
 # requested domain, or current server should belong to requested
 # domain.
 #
-# $Id: quotacheck.pl,v 1.5 2014/07/31 15:57:24 musolffc Exp $
+# $Id: quotacheck.pl,v 1.6 2014/08/05 19:32:19 musolffc Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -101,6 +101,7 @@
             $crstype = $params{'type'};
         }
         if ($params{'fixeddom'}) { $reqdom = $params{'fixeddom'} }
+        unless ($params{'sortby'}) { $params{'sortby'} = 'cdesc'; }
     }
     if (($reqdom eq '') && ($ENV{'QUERY_STRING'})) {
         &LONCAPA::loncgi::cgi_getitems($ENV{'QUERY_STRING'},\%gets);
@@ -246,26 +247,57 @@
     }
 
     if (@showcourses) {
-        print(&Apache::loncommon::start_data_table().
-            &Apache::loncommon::start_data_table_header_row()
-            .'<th><a href="javascript:changeSort('."'quotatype'".')">'
-                .&Apache::lonlocal::mt('Course Type')
-                .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-            .'<th><a href="javascript:changeSort('."'cdesc'".')">'
-                .&Apache::lonlocal::mt('Course Title')
-                .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-            .'<th><a href="javascript:changeSort('."'instcode'".')">'
-                .&Apache::lonlocal::mt('Institutional Code')
-                .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-            .'<th><a href="javascript:changeSort('."'quota'".')">'
-                .&Apache::lonlocal::mt('Quota (MB)')
-                .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-            .'<th><a href="javascript:changeSort('."'current_disk_usage'".')">'
-                .&Apache::lonlocal::mt('Usage (MB)')
-                .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-            .'<th><a href="javascript:changeSort('."'percent'".')">'
-                .&Apache::lonlocal::mt('Percent usage')
-                .'<span class="LC_fontsize_small"> ▼</span></a></th>'
+        # Order in which columns are displayed from left to right
+        my @order = ('quotatype','cdesc','instcode','quota',
+                        'current_disk_usage','percent');
+
+        # Up and down arrows to indicate sort order
+        my @arrows = (' ▲',' ▼','');
+
+        # Default sort order and column title
+        my %columns = (
+            quotatype => {
+                        order => 'ascending',
+                        text  => &Apache::lonlocal::mt('Course Type'),
+                         },
+            cdesc => {
+                        order => 'ascending',
+                        text  => &Apache::lonlocal::mt('Course Title'),
+                     },
+            instcode => {
+                        order => 'ascending',
+                        text  => &Apache::lonlocal::mt('Institutional Code'),
+                        },
+            quota => {
+                        order => 'descending',
+                        text  => &Apache::lonlocal::mt('Quota (MB)'),
+                     },
+            current_disk_usage => {
+                        order => 'descending',
+                        text  => &Apache::lonlocal::mt('Usage (MB)'),
+                                  },
+            percent => {
+                        order => 'descending',
+                        text  => &Apache::lonlocal::mt('Percent usage'),
+                       },
+        ); 
+        
+        # Print column headers
+        my $output = '';
+        foreach my $key (@order) {
+            my $idx;
+            # Append an up or down arrow to sorted column
+            if ($sortby eq $key) {
+                $idx = ($columns{$key}{order} eq 'ascending') ? 0:1;
+                if ($sortorder eq 'rev') { $idx ++; }
+                $idx = $idx%2;
+            } else { $idx = 2; } # No arrow if column not sorted
+            $output .= '<th><a href="javascript:changeSort('
+                        ."'$key'".');">'.$columns{$key}{text}
+                        .$arrows[$idx].'</a></th>';
+        }
+        print(&Apache::loncommon::start_data_table()
+            .&Apache::loncommon::start_data_table_header_row().$output
             .&Apache::loncommon::end_data_table_header_row());
              
         my $usagehash = {};  # Sortable hash of courses
Index: loncom/publisher/lonpubdir.pm
diff -u loncom/publisher/lonpubdir.pm:1.159 loncom/publisher/lonpubdir.pm:1.160
--- loncom/publisher/lonpubdir.pm:1.159	Thu Jul 31 19:25:39 2014
+++ loncom/publisher/lonpubdir.pm	Tue Aug  5 19:32:23 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Authoring Space Directory Lister
 #
-# $Id: lonpubdir.pm,v 1.159 2014/07/31 19:25:39 musolffc Exp $
+# $Id: lonpubdir.pm,v 1.160 2014/08/05 19:32:23 musolffc Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,6 +115,16 @@
     my $numdir = 0;
     my $numres = 0;
   
+    if ((@files == 0) && ($thisdisfn =~ m{^/$match_domain/$match_username})) {
+        if ($thisdisfn =~ m{^/$match_domain/$match_username$}) {
+            $r->print('<p class="LC_info">'.&mt('This Authoring Space is currently empty.').'</p>');
+        } else {
+            $r->print('<p class="LC_info">'.&mt('This subdirectory is currently empty.').'</p>');
+        }
+        $r->print(&Apache::loncommon::end_page());
+        return OK;
+    }
+
     # Retrieving value for "sortby" and "sortorder" from QUERY_STRING
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
         ['sortby','sortorder']);
@@ -122,48 +132,68 @@
     # Sort by name as default, not reversed
     if (! exists($env{'form.sortby'})) { $env{'form.sortby'} = 'filename' }
     if (! exists($env{'form.sortorder'})) { $env{'form.sortorder'} = '' }
-
     my $sortby = $env{'form.sortby'};
     my $sortorder = $env{'form.sortorder'};
 
-    if ((@files == 0) && ($thisdisfn =~ m{^/$match_domain/$match_username})) {
-        if ($thisdisfn =~ m{^/$match_domain/$match_username$}) {
-            $r->print('<p class="LC_info">'.&mt('This Authoring Space is currently empty.').'</p>');
-        } else {
-            $r->print('<p class="LC_info">'.&mt('This subdirectory is currently empty.').'</p>');
-        }
-        $r->print(&Apache::loncommon::end_page());
-        return OK;
+    # Order in which columns are displayed from left to right
+    my @order = ('filetype','actions','filename','title',
+                    'pubstatus','cmtime','size');
+
+    # Up and down arrows to indicate sort order
+    my @arrows = (' ▲',' ▼','');
+
+    # Default sort order and column title
+    my %columns = (
+        filetype =>     {
+                            order => 'ascending',
+                            text  => &mt('Type'),
+                        },
+        actions =>      {
+                            # Not sortable
+                            text  => &mt('Actions'),
+                        },
+        filename =>     {
+                            order => 'ascending',
+                            text  => &mt('Name'),
+                        },
+        title =>        {
+                            order => 'ascending',
+                            text  => &mt('Title'),
+                        },
+        pubstatus =>    {
+                            order => 'ascending',
+                            text  => &mt('Status'),
+                            colspan => '2',
+                        },
+        cmtime =>       {
+                            order => 'descending',
+                            text  => &mt('Last Modified'),
+                        },
+        size =>         {
+                            order => 'ascending',
+                            text  => &mt('Size').' (kB)',
+                        },
+    ); 
+
+    # Print column headers
+    my $output = '';
+    foreach my $key (@order) {
+        my $idx;
+        # Append an up or down arrow to sorted column
+        if ($sortby eq $key) {
+            $idx = ($columns{$key}{order} eq 'ascending') ? 0:1;
+            if ($sortorder eq 'rev') { $idx ++; }
+            $idx = $idx%2;
+        } else { $idx = 2; } # No arrow if column is not sorted
+        $output .= (($columns{$key}{order}) ?
+            '<th'.($columns{$key}{colspan} ? ' colspan="'.$columns{$key}{colspan}.'"' : '')
+            .'><a href="'.$linkdir.'/?sortby='.$key.'&sortorder='
+            .((($sortby eq $key) && ($sortorder ne 'rev')) ? 'rev' : '').'">'
+            .$columns{$key}{text}.$arrows[$idx].'</a></th>' :
+            '<th>'.$columns{$key}{text}.'</th>');
     }
-
-    # Start off the directory table.
     $r->print(&Apache::loncommon::start_data_table()
-        .&Apache::loncommon::start_data_table_header_row()
-        .'<th><a href="'.$linkdir.'/?sortby=filetype&sortorder='
-            .((($sortby eq "filetype") && ($sortorder ne 'rev')) ? 'rev' : '') 
-            .'">'.&mt('Type')
-            .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-        .'<th>'.&mt('Actions').'</th>'
-        .'<th><a href="'.$linkdir.'/?sortby=filename&sortorder='
-            .((($sortby eq "filename") && ($sortorder ne 'rev')) ? 'rev' : '') 
-            .'">'.&mt('Name')
-            .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-        .'<th><a href="'.$linkdir.'/?sortby=title&sortorder='
-            .((($sortby eq "title") && ($sortorder ne 'rev')) ? 'rev' : '') 
-            .'">'.&mt('Title')
-            .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-        .'<th colspan="2"><a href="'.$linkdir.'/?sortby=pubstatus&sortorder='
-            .((($sortby eq "pubstatus") && ($sortorder ne 'rev')) ? 'rev' : '') 
-            .'">'.&mt('Status')
-            .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-        .'<th><a href="'.$linkdir.'/?sortby=cmtime&sortorder='
-            .((($sortby eq "cmtime") && ($sortorder ne 'rev')) ? 'rev' : '') 
-            .'">'.&mt('Last Modified')
-            .'<span class="LC_fontsize_small"> ▼</span></a></th>'
-        .'<th><a href="'.$linkdir.'/?sortby=size&sortorder='
-            .((($sortby eq "size") && ($sortorder ne 'rev')) ? 'rev' : '') 
-            .'">'.&mt('Size').' (kB)'
-            .'<span class="LC_fontsize_small"> ▼</span></a></th>'
+        .&Apache::loncommon::start_data_table_header_row() . $output
         .&Apache::loncommon::end_data_table_header_row()
     );
 


More information about the LON-CAPA-cvs mailing list