Browse Source

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>
maint
Petr Baudis 17 years ago committed by Shawn O. Pearce
parent
commit
6b28da672e
  1. 45
      gitweb/gitweb.perl

45
gitweb/gitweb.perl

@ -3605,19 +3605,13 @@ sub fill_project_list_info { @@ -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 { @@ -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 { @@ -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";
}

Loading…
Cancel
Save