aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Baudis <pasky@suse.cz>2008-09-25 18:48:37 +0200
committerShawn O. Pearce <spearce@spearce.org>2008-10-01 08:56:57 -0700
commit6b28da672e8828111a8cf3cda9ed760e03140e11 (patch)
tree46c2c6fbfb6190494d0f8bde7b8a92ddafc064dc
parent5e22e21769454857e00bc55be1f2eef8d873ba72 (diff)
downloadgit-6b28da672e8828111a8cf3cda9ed760e03140e11.tar.gz
git-6b28da672e8828111a8cf3cda9ed760e03140e11.tar.xz
gitweb: Clean-up sorting of project list
This decouples the sorting of project list and printing the column headers, so that the project list can be easily sorted even when the headers are not shown. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rwxr-xr-xgitweb/gitweb.perl45
1 files changed, 20 insertions, 25 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 18e70a366..58ffff8be 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3605,19 +3605,13 @@ sub fill_project_list_info {
return @projects;
}
-# print 'sort by' <th> element, either sorting by $key if $name eq $order
-# (changing $list), or generating 'sort by $name' replay link otherwise
+# print 'sort by' <th> element, generating 'sort by $name' replay link
+# if that order is not selected
sub print_sort_th {
- my ($str_sort, $name, $order, $key, $header, $list) = @_;
- $key ||= $name;
+ my ($name, $order, $header) = @_;
$header ||= ucfirst($name);
if ($order eq $name) {
- if ($str_sort) {
- @$list = sort {$a->{$key} cmp $b->{$key}} @$list;
- } else {
- @$list = sort {$a->{$key} <=> $b->{$key}} @$list;
- }
print "<th>$header</th>\n";
} else {
print "<th>" .
@@ -3627,14 +3621,6 @@ sub print_sort_th {
}
}
-sub print_sort_th_str {
- print_sort_th(1, @_);
-}
-
-sub print_sort_th_num {
- print_sort_th(0, @_);
-}
-
sub git_project_list_body {
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
@@ -3645,20 +3631,29 @@ sub git_project_list_body {
$from = 0 unless defined $from;
$to = $#projects if (!defined $to || $#projects < $to);
+ my %order_info = (
+ project => { key => 'path', type => 'str' },
+ descr => { key => 'descr_long', type => 'str' },
+ owner => { key => 'owner', type => 'str' },
+ age => { key => 'age', type => 'num' }
+ );
+ my $oi = $order_info{$order};
+ if ($oi->{'type'} eq 'str') {
+ @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
+ } else {
+ @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
+ }
+
print "<table class=\"project_list\">\n";
unless ($no_header) {
print "<tr>\n";
if ($check_forks) {
print "<th></th>\n";
}
- print_sort_th_str('project', $order, 'path',
- 'Project', \@projects);
- print_sort_th_str('descr', $order, 'descr_long',
- 'Description', \@projects);
- print_sort_th_str('owner', $order, 'owner',
- 'Owner', \@projects);
- print_sort_th_num('age', $order, 'age',
- 'Last Change', \@projects);
+ print_sort_th('project', $order, 'Project');
+ print_sort_th('descr', $order, 'Description');
+ print_sort_th('owner', $order, 'Owner');
+ print_sort_th('age', $order, 'Last Change');
print "<th></th>\n" . # for links
"</tr>\n";
}