[LON-CAPA-cvs] cvs: loncom /cgi quotacheck.pl /interface loncommon.pm
musolffc
musolffc at source.lon-capa.org
Thu Jul 31 11:57:29 EDT 2014
musolffc Thu Jul 31 15:57:29 2014 EDT
Modified files:
/loncom/cgi quotacheck.pl
/loncom/interface loncommon.pm
Log:
Courses displayed in quota list are now sortable by clicking on column headers
-------------- next part --------------
Index: loncom/cgi/quotacheck.pl
diff -u loncom/cgi/quotacheck.pl:1.4 loncom/cgi/quotacheck.pl:1.5
--- loncom/cgi/quotacheck.pl:1.4 Thu Jul 31 15:45:31 2014
+++ loncom/cgi/quotacheck.pl Thu Jul 31 15:57:24 2014
@@ -6,7 +6,7 @@
# requested domain, or current server should belong to requested
# domain.
#
-# $Id: quotacheck.pl,v 1.4 2014/07/31 15:45:31 musolffc Exp $
+# $Id: quotacheck.pl,v 1.5 2014/07/31 15:57:24 musolffc Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -93,7 +93,6 @@
# (b) value of domain item in query string
# (c) default login domain for current server
#
-
if (($Apache::lonnet::env{'user.name'}) && ($Apache::lonnet::env{'user.domain'})) {
my $q = CGI->new;
%params = $q->Vars;
@@ -101,9 +100,7 @@
if ($params{'type'} eq 'Community') {
$crstype = $params{'type'};
}
- if ($params{'fixeddom'}) {
- $reqdom = $params{'fixeddom'};
- }
+ if ($params{'fixeddom'}) { $reqdom = $params{'fixeddom'} }
}
if (($reqdom eq '') && ($ENV{'QUERY_STRING'})) {
&LONCAPA::loncgi::cgi_getitems($ENV{'QUERY_STRING'},\%gets);
@@ -125,7 +122,7 @@
&Apache::lonhtmlcommon::add_breadcrumb
({href=>$script."?domain=$reqdom",
text=>"Content disk usage"});
- if ($params{'gosearch'}) {
+ if ( ($params{'gosearch'}) || ($params{'sortby'}) ) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>$script."?domain=$reqdom",
text=>"Result"});
@@ -138,6 +135,19 @@
&Apache::lonhtmlcommon::breadcrumbs('Course/Community status').
'<h2>'.&Apache::lonlocal::mt('Quotas for uploaded course content').'</h2>'.
'<h3>'.$domdesc.'</h3>');
+ my $changejs = <<"ENDSCRIPT";
+<script>
+function changeSort(sortby) {
+ document.filterpicker.sortby.value = sortby;
+ if (('$params{'sortby'}' == sortby) && ('$params{'sortorder'}' != 'rev')) {
+ document.filterpicker.sortorder.value = 'rev';
+ }
+ document.filterpicker.submit();
+}
+</script>
+ENDSCRIPT
+
+ print($changejs);
#
# If this is for an authenticated user (i.e., not IP-based access)
@@ -166,15 +176,24 @@
$script,\$numtitles,
'quotacheck',undef,undef,undef,
\@codetitles,$reqdom,'quotacheck',$reqdom));
- if ($params{'gosearch'}) {
+ if ( ($params{'gosearch'}) || ($params{'sortby'}) ) {
if ($params{'official'} eq 'on') {
$Apache::lonnet::env{'form.state'} = $params{'state'};
}
+ # Sort by course title (cdesc) as default, not reversed
+ my $sortby = $params{'sortby'};
+ unless ($sortby =~ m{^(quota|current_disk_usage|percent|quotatype|instcode)$}) {
+ $sortby = 'cdesc';
+ }
+ my $sortorder;
+ if ($params{'sortorder'} eq 'rev') { $sortorder = 'rev'; }
+
my %courses = &Apache::loncommon::search_courses($reqdom,$crstype,$filter,$numtitles,
undef,undef,undef,\@codetitles);
my @showcourses = keys(%courses);
- &print_usage($lonhost,$reqdom,\@showcourses);
+ &print_usage($lonhost,$reqdom,\@showcourses,$sortby,$sortorder);
}
+
print(&Apache::loncommon::end_page());
return;
}
@@ -184,7 +203,7 @@
}
sub print_usage {
- my ($lonhost,$dom,$courses) = @_;
+ my ($lonhost,$dom,$courses,$sortby,$sortorder) = @_;
my @domains = &Apache::lonnet::current_machine_domains();
my @ids=&Apache::lonnet::current_machine_ids();
my $domain = &Apache::lonnet::host_domain($lonhost);
@@ -225,16 +244,31 @@
@showcourses = keys(%courseshash);
}
}
+
if (@showcourses) {
print(&Apache::loncommon::start_data_table().
- &Apache::loncommon::start_data_table_header_row().
- '<th>'.&Apache::lonlocal::mt('Course Type').'</th>'.
- '<th>'.&Apache::lonlocal::mt('Course Title').'</th>'.
- '<th>'.&Apache::lonlocal::mt('Institutional Code').'</th>'.
- '<th>'.&Apache::lonlocal::mt('Quota (MB)').'</th>'.
- '<th>'.&Apache::lonlocal::mt('Usage (MB)').'</th>'.
- '<th>'.&Apache::lonlocal::mt('Percent usage').'</th>'.
- &Apache::loncommon::end_data_table_header_row());
+ &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>'
+ .&Apache::loncommon::end_data_table_header_row());
+
+ my $usagehash = {}; # Sortable hash of courses
foreach my $cid (@showcourses) {
my %courseinfo=&Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
my $cdesc = $courseinfo{'description'};
@@ -285,7 +319,6 @@
foreach my $subdir ('docs','supplemental') {
$current_disk_usage += &Apache::lonnet::diskusage($dom,$cnum,"userfiles/$subdir",1);
}
- $current_disk_usage=int($current_disk_usage/1024);
}
my $percent;
if (($quota == 0) || ($quota =~ /[^\d\.]/)) {
@@ -296,13 +329,61 @@
$current_disk_usage = sprintf("%.0f",$current_disk_usage);
$quota = sprintf("%.0f",$quota);
$percent = sprintf("%.0f",$percent);
+
+ # Enter sortable data into hash
+ $usagehash->{ $cid } = {
+ "quotatype" => $quotatype,
+ "cdesc" => $cdesc,
+ "instcode" => $instcode,
+ "quota" => $quota,
+ "current_disk_usage" => $current_disk_usage,
+ "percent" => $percent,
+ };
+ }
+
+ # Sort courses by $sortby. "cdesc" is the default.
+ my @sorted_courses;
+ if ($sortby =~ m{^(quota|current_disk_usage|percent)$}) {
+ # Numerical fields
+ if ($sortorder eq "rev") {
+ @sorted_courses = sort {
+ $usagehash->{$a}->{$sortby} <=> $usagehash->{$b}->{$sortby}
+ or
+ uc($usagehash->{$a}->{"cdesc"}) cmp uc($usagehash->{$b}->{"cdesc"})
+ } (keys(%{$usagehash}));
+ } else {
+ @sorted_courses = sort {
+ $usagehash->{$b}->{$sortby} <=> $usagehash->{$a}->{$sortby}
+ or
+ uc($usagehash->{$a}->{"cdesc"}) cmp uc($usagehash->{$b}->{"cdesc"})
+ } (keys(%{$usagehash}));
+ }
+ } elsif ($sortby =~ m{^(cdesc|quotatype|instcode)$}) {
+ # String fields
+ if ($sortorder eq "rev") {
+ @sorted_courses = sort {
+ uc($usagehash->{$b}->{$sortby}) cmp uc($usagehash->{$a}->{$sortby})
+ or
+ uc($usagehash->{$a}->{"cdesc"}) cmp uc($usagehash->{$b}->{"cdesc"})
+ } (keys(%{$usagehash}));
+ } else {
+ @sorted_courses = sort {
+ uc($usagehash->{$a}->{$sortby}) cmp uc($usagehash->{$b}->{$sortby})
+ or
+ uc($usagehash->{$a}->{"cdesc"}) cmp uc($usagehash->{$b}->{"cdesc"})
+ } (keys(%{$usagehash}));
+ }
+ }
+
+ # Print data for each course.
+ foreach my $course (@sorted_courses) {
print(&Apache::loncommon::start_data_table_row().
- '<td>'.$quotatype.'</td>'.
- '<td>'.$cdesc.'</td>'.
- '<td>'.$instcode.'</td>'.
- '<td>'.$quota.'</td>'.
- '<td>'.$current_disk_usage.'</td>'.
- '<td>'.$percent.'</td>'.
+ '<td>'.$usagehash->{$course}->{"quotatype"}.'</td>'.
+ '<td>'.$usagehash->{$course}->{"cdesc"}.'</td>'.
+ '<td>'.$usagehash->{$course}->{"instcode"}.'</td>'.
+ '<td>'.$usagehash->{$course}->{"quota"}.'</td>'.
+ '<td>'.$usagehash->{$course}->{"current_disk_usage"}.'</td>'.
+ '<td>'.$usagehash->{$course}->{"percent"}.'</td>'.
&Apache::loncommon::end_data_table_row()
);
}
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1197 loncom/interface/loncommon.pm:1.1198
--- loncom/interface/loncommon.pm:1.1197 Sun Jul 27 11:39:36 2014
+++ loncom/interface/loncommon.pm Thu Jul 31 15:57:28 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1197 2014/07/27 11:39:36 raeburn Exp $
+# $Id: loncommon.pm,v 1.1198 2014/07/31 15:57:28 musolffc Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -14968,7 +14968,12 @@
$output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
'<input type="hidden" name="prevphase" value="'.
$prevphase.'" />'."\n";
- } elsif ($formname ne 'quotacheck') {
+ } elsif ($formname eq 'quotacheck') {
+ $output .= qq|
+<input type="hidden" name="sortby" value="" />
+<input type="hidden" name="sortorder" value="" />
+|;
+ } else {
my $name_input;
if ($cnameelement ne '') {
$name_input = '<input type="hidden" name="cnameelement" value="'.
More information about the LON-CAPA-cvs
mailing list