* Gitweb; ordering of fork list on summary page (was Vanilla gitweb vs repo.or.cz)
@ 2008-07-23 17:10 Mike Ralphson
2008-09-25 16:48 ` [PATCH] gitweb: Clean-up sorting of project list Petr Baudis
0 siblings, 1 reply; 3+ messages in thread
From: Mike Ralphson @ 2008-07-23 17:10 UTC (permalink / raw)
To: Petr Baudis; +Cc: git
2008/7/13 Petr Baudis <pasky@suse.cz>:
> Then, there is the http://repo.or.cz/w/git/gitweb.git repository,
> which was my old attempt at maintaining gitweb actively. Unfortunately,
> this didn't quite work out because of my general lack of time and
> dedication.
Notwithstanding the above, I've pushed a little 'fix' to the mob branch:
http://repo.or.cz/w/git/gitweb.git?a=commitdiff;h=3e8f6e9125071a7e17c88efb69c1780d775025bc
The list of forks on the summary page was unsorted, this just makes
them sorted by age, which seems a fair way to decide which forks are
shown before the list size cut-off (15) kicks in.
s/noheader/no_header was just to make it obvious what the parameter
affects, so all the code can be found with one grep, and s/undef/'age'
just shows the intent, although that parameter isn't what actually
controls the sort order. Or, I guess, the sorting could be refactored
out of the header generation code.
Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] gitweb: Clean-up sorting of project list 2008-07-23 17:10 Gitweb; ordering of fork list on summary page (was Vanilla gitweb vs repo.or.cz) Mike Ralphson @ 2008-09-25 16:48 ` Petr Baudis 2008-09-25 16:48 ` [PATCH] gitweb: Sort the list of forks on the summary page by age Petr Baudis 0 siblings, 1 reply; 3+ messages in thread From: Petr Baudis @ 2008-09-25 16:48 UTC (permalink / raw) To: git, git; +Cc: Mike Ralphson 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> --- gitweb/gitweb.perl | 45 ++++++++++++++++++++------------------------- 1 files changed, 20 insertions(+), 25 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index da474d0..bd81e14 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"; } -- tg: (c427559..) t/forks/sort-refactor (depends on: vanilla/master) ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] gitweb: Sort the list of forks on the summary page by age 2008-09-25 16:48 ` [PATCH] gitweb: Clean-up sorting of project list Petr Baudis @ 2008-09-25 16:48 ` Petr Baudis 0 siblings, 0 replies; 3+ messages in thread From: Petr Baudis @ 2008-09-25 16:48 UTC (permalink / raw) To: git, git; +Cc: Petr Baudis, Mike Ralphson From: Petr Baudis <pasky@suse.cz> From: Mike Ralphson <mike@abacus.co.uk> The list of forks on the summary page was unsorted, this just makes them sorted by age, which seems a fair way to decide which forks are shown before the list size cut-off (15) kicks in. s/noheader/no_header was just to make it obvious what the parameter affects, so all the code can be found with one grep. pb: As suggested by Mike, I have augmented this by an additional patch that refactors the sorting logic so that it is not tied to printing the headers. Signed-off-by: Mike Ralphson <mike@abacus.co.uk> Signed-off-by: Petr Baudis <pasky@suse.cz> --- gitweb/gitweb.perl | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index bd81e14..0f8a564 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4119,10 +4119,10 @@ sub git_summary { if (@forklist) { git_print_header_div('forks'); - git_project_list_body(\@forklist, undef, 0, 15, + git_project_list_body(\@forklist, 'age', 0, 15, $#forklist <= 15 ? undef : $cgi->a({-href => href(action=>"forks")}, "..."), - 'noheader'); + 'no_header'); } git_footer_html(); -- tg: (513dad1..) t/forks/sort-by-age (depends on: t/forks/sort-refactor) ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-25 16:56 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-07-23 17:10 Gitweb; ordering of fork list on summary page (was Vanilla gitweb vs repo.or.cz) Mike Ralphson 2008-09-25 16:48 ` [PATCH] gitweb: Clean-up sorting of project list Petr Baudis 2008-09-25 16:48 ` [PATCH] gitweb: Sort the list of forks on the summary page by age Petr Baudis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).