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>
This commit is contained in:
parent
5e22e21769
commit
6b28da672e
@ -3605,19 +3605,13 @@ sub fill_project_list_info {
|
|||||||
return @projects;
|
return @projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
# print 'sort by' <th> element, either sorting by $key if $name eq $order
|
# print 'sort by' <th> element, generating 'sort by $name' replay link
|
||||||
# (changing $list), or generating 'sort by $name' replay link otherwise
|
# if that order is not selected
|
||||||
sub print_sort_th {
|
sub print_sort_th {
|
||||||
my ($str_sort, $name, $order, $key, $header, $list) = @_;
|
my ($name, $order, $header) = @_;
|
||||||
$key ||= $name;
|
|
||||||
$header ||= ucfirst($name);
|
$header ||= ucfirst($name);
|
||||||
|
|
||||||
if ($order eq $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";
|
print "<th>$header</th>\n";
|
||||||
} else {
|
} else {
|
||||||
print "<th>" .
|
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 {
|
sub git_project_list_body {
|
||||||
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
|
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
|
||||||
|
|
||||||
@ -3645,20 +3631,29 @@ sub git_project_list_body {
|
|||||||
$from = 0 unless defined $from;
|
$from = 0 unless defined $from;
|
||||||
$to = $#projects if (!defined $to || $#projects < $to);
|
$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";
|
print "<table class=\"project_list\">\n";
|
||||||
unless ($no_header) {
|
unless ($no_header) {
|
||||||
print "<tr>\n";
|
print "<tr>\n";
|
||||||
if ($check_forks) {
|
if ($check_forks) {
|
||||||
print "<th></th>\n";
|
print "<th></th>\n";
|
||||||
}
|
}
|
||||||
print_sort_th_str('project', $order, 'path',
|
print_sort_th('project', $order, 'Project');
|
||||||
'Project', \@projects);
|
print_sort_th('descr', $order, 'Description');
|
||||||
print_sort_th_str('descr', $order, 'descr_long',
|
print_sort_th('owner', $order, 'Owner');
|
||||||
'Description', \@projects);
|
print_sort_th('age', $order, 'Last Change');
|
||||||
print_sort_th_str('owner', $order, 'owner',
|
|
||||||
'Owner', \@projects);
|
|
||||||
print_sort_th_num('age', $order, 'age',
|
|
||||||
'Last Change', \@projects);
|
|
||||||
print "<th></th>\n" . # for links
|
print "<th></th>\n" . # for links
|
||||||
"</tr>\n";
|
"</tr>\n";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user