115
# the width (in characters) of the projects list "Description" column
116
our $projects_list_description_width = 25;
117
118
+# group projects by category on the projects list
119
+# (enabled if this variable evaluates to true)
120
+our $projects_list_group_categories = 0;
121
+
122
+# default category if none specified
123
+# (leave the empty string for no category)
124
+our $project_list_default_category = "";
125
+
126
# default order of projects list
127
# valid values are none, project, descr, owner, and age
128
our $default_projects_order = "project";
2592
return git_get_file_or_project_config($path, 'description');
2593
}
2594
2595
+sub git_get_project_category {
2596
+ my $path = shift;
2597
+ return git_get_file_or_project_config($path, 'category');
2598
+}
2599
+
2600
+
2601
# supported formats:
2602
# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)
2603
# - if its contents is a number, use it as tag weight,
4891
4892
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4893
4880
-# fills project list info (age, description, owner, forks) for each
4881
-# project in the list, removing invalid projects from returned list
4894
+# fills project list info (age, description, owner, category, forks)
4895
+# for each project in the list, removing invalid projects from
4896
+# returned list
4897
# NOTE: modifies $projlist, but does not remove entries from it
4898
sub fill_project_list_info {
4899
my $projlist = shift;
4919
if ($show_ctags) {
4920
$pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
4921
}
4922
+ if ($projects_list_group_categories && !defined $pr->{'category'}) {
4923
+ my $cat = git_get_project_category($pr->{'path'}) ||
4924
+ $project_list_default_category;
4925
+ $pr->{'category'} = to_utf8($cat);
4926
+ }
4927
+
4928
push @projects, $pr;
4929
}
4930
4952
return @projects;
4953
}
4954
4955
+# returns a hash of categories, containing the list of project
4956
+# belonging to each category
4957
+sub build_projlist_by_category {
4958
+ my ($projlist, $from, $to) = @_;
4959
+ my %categories;
4960
+
4961
+ $from = 0 unless defined $from;
4962
+ $to = $#$projlist if (!defined $to || $#$projlist < $to);
4963
+
4964
+ for (my $i = $from; $i <= $to; $i++) {
4965
+ my $pr = $projlist->[$i];
4966
+ push @{$categories{ $pr->{'category'} }}, $pr;
4967
+ }
4968
+
4969
+ return wantarray ? %categories : \%categories;
4970
+}
4971
+
4972
# print 'sort by' <th> element, generating 'sort by $name' replay link
4973
# if that order is not selected
4974
sub print_sort_th {
5097
"</tr>\n";
5098
}
5099
5062
- git_project_list_rows(\@projects, $from, $to, $check_forks);
5100
+ if ($projects_list_group_categories) {
5101
+ # only display categories with projects in the $from-$to window
5102
+ @projects = sort {$a->{'category'} cmp $b->{'category'}} @projects[$from..$to];
5103
+ my %categories = build_projlist_by_category(\@projects, $from, $to);
5104
+ foreach my $cat (sort keys %categories) {
5105
+ unless ($cat eq "") {
5106
+ print "<tr>\n";
5107
+ if ($check_forks) {
5108
+ print "<td></td>\n";
5109
+ }
5110
+ print "<td class=\"category\" colspan=\"5\">".esc_html($cat)."</td>\n";
5111
+ print "</tr>\n";
5112
+ }
5113
+
5114
+ git_project_list_rows($categories{$cat}, undef, undef, $check_forks);
5115
+ }
5116
+ } else {
5117
+ git_project_list_rows(\@projects, $from, $to, $check_forks);
5118
+ }
5119
5120
if (defined $extra) {
5121
print "<tr>\n";