@matheusbsbs / matheus-bagliano / commits / 6b28da672e
Fork 0

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>

Petr Baudis committed Sep 25, 2008 at 18:48 UTC 6b28da672e8828111a8cf3cda9ed760e03140e11
1 file changed +20 -25
gitweb/gitweb.perl
+20 -25
@@ -3605,19 +3605,13 @@ sub fill_project_list_info {
3605 return @projects;
3606 }
3607
3608 -# print 'sort by' <th> element, either sorting by $key if $name eq $order
3609 -# (changing $list), or generating 'sort by $name' replay link otherwise
3608 +# print 'sort by' <th> element, generating 'sort by $name' replay link
3609 +# if that order is not selected
3610 sub print_sort_th {
3611 - my ($str_sort, $name, $order, $key, $header, $list) = @_;
3612 - $key ||= $name;
3611 + my ($name, $order, $header) = @_;
3612 $header ||= ucfirst($name);
3613
3614 if ($order eq $name) {
3616 - if ($str_sort) {
3617 - @$list = sort {$a->{$key} cmp $b->{$key}} @$list;
3618 - } else {
3619 - @$list = sort {$a->{$key} <=> $b->{$key}} @$list;
3620 - }
3615 print "<th>$header</th>\n";
3616 } else {
3617 print "<th>" .
@@ -3627,14 +3621,6 @@ sub print_sort_th {
3621 }
3622 }
3623
3630 -sub print_sort_th_str {
3631 - print_sort_th(1, @_);
3632 -}
3633 -
3634 -sub print_sort_th_num {
3635 - print_sort_th(0, @_);
3636 -}
3637 -
3624 sub git_project_list_body {
3625 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3626
@@ -3645,20 +3631,29 @@ sub git_project_list_body {
3631 $from = 0 unless defined $from;
3632 $to = $#projects if (!defined $to || $#projects < $to);
3633
3634 + my %order_info = (
3635 + project => { key => 'path', type => 'str' },
3636 + descr => { key => 'descr_long', type => 'str' },
3637 + owner => { key => 'owner', type => 'str' },
3638 + age => { key => 'age', type => 'num' }
3639 + );
3640 + my $oi = $order_info{$order};
3641 + if ($oi->{'type'} eq 'str') {
3642 + @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3643 + } else {
3644 + @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3645 + }
3646 +
3647 print "<table class=\"project_list\">\n";
3648 unless ($no_header) {
3649 print "<tr>\n";
3650 if ($check_forks) {
3651 print "<th></th>\n";
3652 }
3654 - print_sort_th_str('project', $order, 'path',
3655 - 'Project', \@projects);
3656 - print_sort_th_str('descr', $order, 'descr_long',
3657 - 'Description', \@projects);
3658 - print_sort_th_str('owner', $order, 'owner',
3659 - 'Owner', \@projects);
3660 - print_sort_th_num('age', $order, 'age',
3661 - 'Last Change', \@projects);
3653 + print_sort_th('project', $order, 'Project');
3654 + print_sort_th('descr', $order, 'Description');
3655 + print_sort_th('owner', $order, 'Owner');
3656 + print_sort_th('age', $order, 'Last Change');
3657 print "<th></th>\n" . # for links
3658 "</tr>\n";
3659 }