зеркало из https://github.com/microsoft/git.git
Merge branch 'jn/web'
* jn/web: gitweb: Separate generating 'sort by' table header gitweb: Separate filling list of projects info
This commit is contained in:
Коммит
5389db544d
|
@ -3520,21 +3520,24 @@ sub git_patchset_body {
|
|||
|
||||
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
sub git_project_list_body {
|
||||
my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
|
||||
|
||||
my ($check_forks) = gitweb_check_feature('forks');
|
||||
|
||||
# fills project list info (age, description, owner, forks) for each
|
||||
# project in the list, removing invalid projects from returned list
|
||||
# NOTE: modifies $projlist, but does not remove entries from it
|
||||
sub fill_project_list_info {
|
||||
my ($projlist, $check_forks) = @_;
|
||||
my @projects;
|
||||
|
||||
PROJECT:
|
||||
foreach my $pr (@$projlist) {
|
||||
my (@aa) = git_get_last_activity($pr->{'path'});
|
||||
unless (@aa) {
|
||||
next;
|
||||
my (@activity) = git_get_last_activity($pr->{'path'});
|
||||
unless (@activity) {
|
||||
next PROJECT;
|
||||
}
|
||||
($pr->{'age'}, $pr->{'age_string'}) = @aa;
|
||||
($pr->{'age'}, $pr->{'age_string'}) = @activity;
|
||||
if (!defined $pr->{'descr'}) {
|
||||
my $descr = git_get_project_description($pr->{'path'}) || "";
|
||||
$pr->{'descr_long'} = to_utf8($descr);
|
||||
$descr = to_utf8($descr);
|
||||
$pr->{'descr_long'} = $descr;
|
||||
$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
|
||||
}
|
||||
if (!defined $pr->{'owner'}) {
|
||||
|
@ -3546,14 +3549,52 @@ sub git_project_list_body {
|
|||
($pname !~ /\/$/) &&
|
||||
(-d "$projectroot/$pname")) {
|
||||
$pr->{'forks'} = "-d $projectroot/$pname";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$pr->{'forks'} = 0;
|
||||
}
|
||||
}
|
||||
push @projects, $pr;
|
||||
}
|
||||
|
||||
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
|
||||
sub print_sort_th {
|
||||
my ($str_sort, $name, $order, $key, $header, $list) = @_;
|
||||
$key ||= $name;
|
||||
$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>" .
|
||||
$cgi->a({-href => href(-replay=>1, order=>$name),
|
||||
-class => "header"}, $header) .
|
||||
"</th>\n";
|
||||
}
|
||||
}
|
||||
|
||||
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) = @_;
|
||||
|
||||
my ($check_forks) = gitweb_check_feature('forks');
|
||||
my @projects = fill_project_list_info($projlist, $check_forks);
|
||||
|
||||
$order ||= $default_projects_order;
|
||||
$from = 0 unless defined $from;
|
||||
$to = $#projects if (!defined $to || $#projects < $to);
|
||||
|
@ -3564,43 +3605,15 @@ sub git_project_list_body {
|
|||
if ($check_forks) {
|
||||
print "<th></th>\n";
|
||||
}
|
||||
if ($order eq "project") {
|
||||
@projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
|
||||
print "<th>Project</th>\n";
|
||||
} else {
|
||||
print "<th>" .
|
||||
$cgi->a({-href => href(project=>undef, order=>'project'),
|
||||
-class => "header"}, "Project") .
|
||||
"</th>\n";
|
||||
}
|
||||
if ($order eq "descr") {
|
||||
@projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
|
||||
print "<th>Description</th>\n";
|
||||
} else {
|
||||
print "<th>" .
|
||||
$cgi->a({-href => href(project=>undef, order=>'descr'),
|
||||
-class => "header"}, "Description") .
|
||||
"</th>\n";
|
||||
}
|
||||
if ($order eq "owner") {
|
||||
@projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
|
||||
print "<th>Owner</th>\n";
|
||||
} else {
|
||||
print "<th>" .
|
||||
$cgi->a({-href => href(project=>undef, order=>'owner'),
|
||||
-class => "header"}, "Owner") .
|
||||
"</th>\n";
|
||||
}
|
||||
if ($order eq "age") {
|
||||
@projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
|
||||
print "<th>Last Change</th>\n";
|
||||
} else {
|
||||
print "<th>" .
|
||||
$cgi->a({-href => href(project=>undef, order=>'age'),
|
||||
-class => "header"}, "Last Change") .
|
||||
"</th>\n";
|
||||
}
|
||||
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 "<th></th>\n" . # for links
|
||||
"</tr>\n";
|
||||
}
|
||||
my $alternate = 1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче