-
Notifications
You must be signed in to change notification settings - Fork 0
/
ukigumo_failurepage.patch
88 lines (85 loc) · 2.71 KB
/
ukigumo_failurepage.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
diff --git a/lib/Ukigumo/Server/Command/Report.pm b/lib/Ukigumo/Server/Command/Report.pm
index 831110c..415770a 100644
--- a/lib/Ukigumo/Server/Command/Report.pm
+++ b/lib/Ukigumo/Server/Command/Report.pm
@@ -63,6 +63,39 @@ sub recent_list {
return wantarray ? ($reports, $pager) : $reports;
}
+sub failure_list {
+ my $class = shift;
+ state $rule = Data::Validator->new(
+ limit => { isa => 'Int', default => 50 },
+ page => { isa => 'Int', default => 1 },
+ );
+ my $args = $rule->validate(@_);
+
+ my $reports = c->dbh->selectall_arrayref(
+ q{SELECT branch.project, branch.branch, report.report_id, report.revision, report.status, report.ctime
+ FROM report INNER JOIN branch ON (branch.branch_id=report.branch_id)
+ WHERE NOT report.status = 1
+ ORDER BY report_id DESC
+ LIMIT } . ($args->{limit} + 1) . " OFFSET " . $args->{limit}*($args->{page}-1),
+ { Slice => +{} },
+ );
+ my $has_next = do {
+ if (@$reports == $args->{limit}+1) {
+ pop @$reports;
+ 1;
+ } else {
+ 0;
+ }
+ };
+ my $pager = Data::Page::NoTotalEntries->new(
+ has_next => $has_next,
+ entries_per_page => $args->{limit},
+ current_page => $args->{page},
+ entries_on_this_page => @$reports,
+ );
+ return wantarray ? ($reports, $pager) : $reports;
+}
+
sub list {
my $class = shift;
state $rule = Data::Validator->new(
diff --git a/lib/Ukigumo/Server/Web/Dispatcher.pm b/lib/Ukigumo/Server/Web/Dispatcher.pm
index dbea5f7..7c0796b 100644
--- a/lib/Ukigumo/Server/Web/Dispatcher.pm
+++ b/lib/Ukigumo/Server/Web/Dispatcher.pm
@@ -70,6 +70,25 @@ get '/recent' => sub {
);
};
+get '/failure' => sub {
+ my ($c, $args) = @_;
+
+ my $page = $c->req->param('page') || 1;
+ my $limit = 50;
+
+ my ($reports, $pager) = Ukigumo::Server::Command::Report->failure_list(
+ page => $page,
+ limit => $limit,
+ );
+ return $c->render(
+ 'recent.tt' => {
+ reports => $reports,
+ pager => $pager,
+ now => time(),
+ }
+ );
+};
+
get '/project/{project}' => sub {
my ($c, $args) = @_;
diff --git a/tmpl/include/layout.tt b/tmpl/include/layout.tt
index be22ba0..78c1246 100644
--- a/tmpl/include/layout.tt
+++ b/tmpl/include/layout.tt
@@ -27,6 +27,9 @@
<li>
<a href="[% uri_for('/recent') %]">Recent</a>
</li>
+ <li>
+ <a href="[% uri_for('/failure') %]">Failure</a>
+ </li>
</ul>
</div>
</div>