... | ... |
@@ -6,6 +6,46 @@ use Text::Markdown::Hoedown qw(HOEDOWN_EXT_FENCED_CODE HOEDOWN_EXT_TABLES HOEDOW |
6 | 6 |
|
7 | 7 |
has 'cntl'; |
8 | 8 |
|
9 |
+sub get_issue_count { |
|
10 |
+ my ($self, $user_id, $project_id, $opt) = @_; |
|
11 |
+ |
|
12 |
+ $opt ||= {}; |
|
13 |
+ |
|
14 |
+ my $project_row_id = $self->get_project_row_id($user_id, $project_id); |
|
15 |
+ |
|
16 |
+ my $where = $self->app->dbi->where; |
|
17 |
+ my $clause = ['and', 'pull_request = 0', ':project{=}']; |
|
18 |
+ my $param = {project => $project_row_id}; |
|
19 |
+ |
|
20 |
+ # Open |
|
21 |
+ if (exists $opt->{open}) { |
|
22 |
+ push @$clause, ':issue.open{=}'; |
|
23 |
+ $param->{'issue.open'} = $opt->{open}; |
|
24 |
+ } |
|
25 |
+ |
|
26 |
+ $where->clause($clause); |
|
27 |
+ $where->param($param); |
|
28 |
+ |
|
29 |
+ my $issue_count = $self->app->dbi->model('issue')->select( |
|
30 |
+ 'count(*)', |
|
31 |
+ where => $where |
|
32 |
+ )->value; |
|
33 |
+ |
|
34 |
+ return $issue_count; |
|
35 |
+} |
|
36 |
+ |
|
37 |
+sub get_open_issue_count { |
|
38 |
+ my ($self, $user_id, $project_id) = @_; |
|
39 |
+ |
|
40 |
+ return $self->get_issue_count($user_id, $project_id, {open => 1}); |
|
41 |
+} |
|
42 |
+ |
|
43 |
+sub get_close_issue_count { |
|
44 |
+ my ($self, $user_id, $project_id) = @_; |
|
45 |
+ |
|
46 |
+ return $self->get_issue_count($user_id, $project_id, {open => 0}); |
|
47 |
+} |
|
48 |
+ |
|
9 | 49 |
sub api_update_issue_message { |
10 | 50 |
my ($self, $issue_message_row_id, $message, $user_id) = @_; |
11 | 51 |
|
... | ... |
@@ -124,7 +124,7 @@ |
124 | 124 |
<li class="<%= $tab eq 'issues' ? 'active' : '' %>"> |
125 | 125 |
<a href="<%= url_for("/$user_id/$project_id/issues") %>"> |
126 | 126 |
<i class="icon-tasks"></i> |
127 |
- Issues |
|
127 |
+ Issues <div style="background:#eee;color:#555;display:inline-block;width:18px; height:18px;border-radius:9px;"><%= $api->get_open_issue_count($user_id, $project_id) %></div> |
|
128 | 128 |
</a> |
129 | 129 |
</li> |
130 | 130 |
<li class="<%= $tab eq 'pulls' ? 'active' : '' %>"> |
... | ... |
@@ -29,22 +29,10 @@ |
29 | 29 |
)->all; |
30 | 30 |
|
31 | 31 |
# Open count |
32 |
- my $open_count = app->dbi->model('issue')->select( |
|
33 |
- 'count(*)', |
|
34 |
- where => [ |
|
35 |
- ['and', 'issue.open = 1', 'pull_request = 0', ':project{=}'], |
|
36 |
- {project => $project_row_id} |
|
37 |
- ] |
|
38 |
- )->value; |
|
32 |
+ my $open_count = $api->get_open_issue_count($user_id, $project_id); |
|
39 | 33 |
|
40 | 34 |
# Close count |
41 |
- my $close_count = app->dbi->model('issue')->select( |
|
42 |
- 'count(*)', |
|
43 |
- where => [ |
|
44 |
- ['and', 'issue.open = 0', 'pull_request = 0', ':project{=}'], |
|
45 |
- {project => $project_row_id} |
|
46 |
- ] |
|
47 |
- )->value; |
|
35 |
+ my $close_count = $api->get_close_issue_count($user_id, $project_id); |
|
48 | 36 |
|
49 | 37 |
# Initialize labels if there are no labels |
50 | 38 |
my $labels_count = app->dbi->model('label')->select('count(*)')->value; |