diff --git a/lib/Ukigumo/Server/API/Dispatcher.pm b/lib/Ukigumo/Server/API/Dispatcher.pm index f22eabd..e3d9817 100644 --- a/lib/Ukigumo/Server/API/Dispatcher.pm +++ b/lib/Ukigumo/Server/API/Dispatcher.pm @@ -81,7 +81,8 @@ post '/api/v1/report/add' => [ body => { isa => 'Str', optional => 1 }, revision => { isa => 'Str' }, repo => { isa => 'Str' }, - compare_url => { isa => 'Str', optional => 1 } + compare_url => { isa => 'Str', optional => 1 }, + elapsed_time_sec => { isa => 'Int', optional => 1 }, ] => sub { my ($c, $args) = @_; diff --git a/lib/Ukigumo/Server/Command/Report.pm b/lib/Ukigumo/Server/Command/Report.pm index 78d89f6..8b9c2ca 100644 --- a/lib/Ukigumo/Server/Command/Report.pm +++ b/lib/Ukigumo/Server/Command/Report.pm @@ -129,6 +129,9 @@ sub list { 0; } }; + + map {$_->{elapsed_time} = $class->_convert_sec_to_formatted_time($_->{elapsed_time_sec})} @$reports; + my $pager = Data::Page::NoTotalEntries->new( has_next => $has_next, entries_per_page => $args->{limit}, @@ -172,6 +175,7 @@ sub insert { body => { isa => 'Str', optional => 1 }, vc_log => { isa => 'Str', optional => 1 }, compare_url => { isa => 'Str', optional => 1 }, + elapsed_time_sec => { isa => 'Int', optional => 1 }, ); my $args = $rule->validate(@_); @@ -241,10 +245,17 @@ sub find { my $args = $rule->validate(@_); local c->db->{suppress_row_objects} = 1; - return $class->_uncompress_text_data(c->db->single_by_sql( + my $report = $class->_uncompress_text_data(c->db->single_by_sql( q{SELECT branch.project, branch.branch, report.* FROM report INNER JOIN branch ON (report.branch_id=branch.branch_id) WHERE report_id=?}, [$args->{report_id}] )); + + if (my $elapsed_time = $class->_convert_sec_to_formatted_time($report->{elapsed_time_sec})) { + $report->{elapsed_time} = $elapsed_time; + } + + return unless %$report; + return $report; } sub _compress_text_data { @@ -292,4 +303,23 @@ sub __uncompress { $_[0]; } +sub _convert_sec_to_formatted_time { + my ($class, $sec) = @_; + + return unless defined $sec; + + my $hour = int($sec / 3600); + $sec -= $hour * 3600; + my $min = int($sec / 60); + $sec -= $min * 60; + + my $formatted_time = ''; + if ($hour) { + $formatted_time = "$hour hour "; + } + $formatted_time .= "$min min $sec sec"; + + return $formatted_time; +} + 1; diff --git a/lib/Ukigumo/Server/DB/Schema.pm b/lib/Ukigumo/Server/DB/Schema.pm index 028cd01..67d3177 100644 --- a/lib/Ukigumo/Server/DB/Schema.pm +++ b/lib/Ukigumo/Server/DB/Schema.pm @@ -30,6 +30,7 @@ table { { name => 'body', type => SQL_LONGVARCHAR }, # TEXT { name => 'ctime', type => SQL_INTEGER }, # INTEGER { name => 'compare_url', type => SQL_VARCHAR }, # VARCHAR + { name => 'elapsed_time_sec', type => SQL_INTEGER }, # INTEGER ; }; diff --git a/lib/Ukigumo/Server/Schema.pm b/lib/Ukigumo/Server/Schema.pm index 82134f9..fb63b4a 100644 --- a/lib/Ukigumo/Server/Schema.pm +++ b/lib/Ukigumo/Server/Schema.pm @@ -27,6 +27,7 @@ create_table report => columns { text 'body', null; integer 'ctime'; varchar 'compare_url', null; + integer 'elapsed_time_sec', null; add_index report_branch_idx => [qw/branch_id/]; }; diff --git a/lib/Ukigumo/Server/Web/Dispatcher.pm b/lib/Ukigumo/Server/Web/Dispatcher.pm index a978aad..c7f9cfb 100644 --- a/lib/Ukigumo/Server/Web/Dispatcher.pm +++ b/lib/Ukigumo/Server/Web/Dispatcher.pm @@ -165,6 +165,7 @@ get '/project/{project}/{branch:[A-Za-z0-9/_\-\.]+}' => sub { page => $page, limit => $limit, ); + return $c->render( 'report_list.tx' => { project => $project, diff --git a/share/sql/mysql.sql b/share/sql/mysql.sql index bb4e9ec..5a3bdcb 100644 --- a/share/sql/mysql.sql +++ b/share/sql/mysql.sql @@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS `report` ( `body` text NULL, `ctime` INTEGER NOT NULL, `compare_url` VARCHAR(255) NULL DEFAULT NULL, + `elapsed_time_sec` INTEGER NULL DEFAULT NULL, INDEX `report_branch_idx` (`branch_id`), PRIMARY KEY (`report_id`) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8; diff --git a/share/sql/sqlite.sql b/share/sql/sqlite.sql index 0c4b5a9..df518ae 100644 --- a/share/sql/sqlite.sql +++ b/share/sql/sqlite.sql @@ -21,7 +21,8 @@ CREATE TABLE IF NOT EXISTS report ( vc_log TEXT, body TEXT, ctime INTEGER NOT NULL, - compare_url VARCHAR(255) DEFAULT NULL + compare_url VARCHAR(255) DEFAULT NULL, + elapsed_time_sec INTEGER DEFAULT NULL ); CREATE INDEX IF NOT EXISTS report_branch_idx ON report (branch_id); diff --git a/share/tmpl/report_list.tx b/share/tmpl/report_list.tx index 3d6e4e0..8687d76 100644 --- a/share/tmpl/report_list.tx +++ b/share/tmpl/report_list.tx @@ -13,12 +13,14 @@ <: l('Revision') :> <: l('Status') :> <: l('Date') :> + <: l('Elapsed Time') :> : for $reports -> $v { <: $v.revision || '-' :> <: $v.status | status_str :> <: ago($now-$v.ctime, 1) :> + <: $v.elapsed_time || '-' :> : } diff --git a/share/tmpl/show_report.tx b/share/tmpl/show_report.tx index a110de9..dd25814 100644 --- a/share/tmpl/show_report.tx +++ b/share/tmpl/show_report.tx @@ -9,11 +9,14 @@

<: $report.project :> [<: $report.branch :>](<: $report.revision :>) <: $report.status | status_str | l :>

+

: if $report.compare_url { -

- Compare: <: $report.compare_url :> -

+ Compare: <: $report.compare_url :> : } + : if $report.elapsed_time { + Elapsed Time: <: $report.elapsed_time :> + : } +

: if $report.vc_log {