From 36905704ea8b713fe534eedb856d04851d5b7d15 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 13 Jul 2015 14:32:13 +0300 Subject: [PATCH] Allow to show estimated, actual and remaining times at once in reports --- report.cgi | 19 ++-- .../en/default/reports/report-table.csv.tmpl | 32 +++---- .../en/default/reports/report-table.html.tmpl | 89 ++++++++++--------- template/en/default/reports/report.csv.tmpl | 11 ++- template/en/default/reports/report.html.tmpl | 15 ++-- 5 files changed, 94 insertions(+), 72 deletions(-) diff --git a/report.cgi b/report.cgi index 2cc41167f..a517a5094 100755 --- a/report.cgi +++ b/report.cgi @@ -150,8 +150,10 @@ if (defined($height)) # These shenanigans are necessary to make sure that both vertical and # horizontal 1D tables convert to the correct dimension when you ask to # display them as some sort of chart. -if (defined $ARGS->{format} && $ARGS->{format} =~ /^(table|simple)$/) +my $is_table; +if ($ARGS->{format} eq 'table' || $ARGS->{format} eq 'simple') { + $is_table = 1; if ($field->{x} && !$field->{y}) { # 1D *tables* should be displayed vertically (with a row_field only) @@ -185,14 +187,20 @@ my $measures = { Bugzilla::Search->COLUMNS->{_count}->{name} = '1'; my $measure = $ARGS->{measure}; -$measure = 'count' unless $measures->{$measure}; +if ($measure eq 'times' ? !$is_table : !$measures->{$measure}) +{ + $measure = 'count'; +} $vars->{measure} = $measure; # Validate the values in the axis fields or throw an error. my %a; my @group_by = grep { !($a{$_}++) } values %$field; my @axis_fields = @group_by; -push @axis_fields, $measures->{$measure} unless $a{$measures->{$measure}}; +for ($measure eq 'times' ? qw(etime rtime wtime) : $measure) +{ + push @axis_fields, $measures->{$_} unless $a{$measures->{$_}}; +} # Clone the params, so that Bugzilla::Search can modify them my $search = new Bugzilla::Search( @@ -205,7 +213,8 @@ $query = ($field->{x} || "''")." x, ". ($field->{y} || "''")." y, ". ($field->{z} || "''")." z, ". - "SUM(".$measures->{$measure}.") r FROM ($query) _report_table GROUP BY ".join(", ", @group_by); + join(', ', map { "SUM($measures->{$_}) $_" } $measure eq 'times' ? qw(etime rtime wtime) : $measure). + " FROM ($query) _report_table GROUP BY ".join(", ", @group_by); $::SIG{TERM} = 'DEFAULT'; $::SIG{PIPE} = 'DEFAULT'; @@ -231,7 +240,7 @@ foreach my $group (@$results) $isnumeric{$_} &&= ($group->{$_} =~ /^-?\d+(\.\d+)?$/o); $names{$_}{$group->{$_}} = 1; } - $data{$group->{z}}{$group->{x}}{$group->{y}} = $group->{r}; + $data{$group->{z}}{$group->{x}}{$group->{y}} = $is_table ? $group : $group->{$measure}; } my @tbl_names = @{get_names($names{z}, $isnumeric{z}, $field->{z})}; diff --git a/template/en/default/reports/report-table.csv.tmpl b/template/en/default/reports/report-table.csv.tmpl index dfae8b459..07304a76f 100644 --- a/template/en/default/reports/report-table.csv.tmpl +++ b/template/en/default/reports/report-table.csv.tmpl @@ -16,21 +16,21 @@ # Rights Reserved. # # Contributor(s): Gervase Markham + # + # TODO: Refactor this ugly trash. Table should be generated by code, not by TT. #%] [%# INTERFACE: # See report-table.html.tmpl. #%] [% colsepchar = user.settings.csv_colsepchar.value %] -[% num_bugs = BLOCK %]Number of [% terms.bugs %][% END %] [% tbl_field_disp = field_descs.$tbl_field || Bugzilla.get_field(tbl_field).description || tbl_field %] [% col_field_disp = field_descs.$col_field || Bugzilla.get_field(col_field).description || col_field %] [% row_field_disp = field_descs.$row_field || Bugzilla.get_field(row_field).description || row_field %] +[% mlist = (measure == 'times' ? [ 'etime', 'wtime', 'rtime' ] : [ measure ]) %] [% IF tbl_field %] - [% IF tbl_field == 'assigned_to' OR tbl_field == 'reporter' - OR tbl_field == 'qa_contact' - %] + [% IF tbl_field == 'assigned_to' OR tbl_field == 'reporter' OR tbl_field == 'qa_contact' %] [% tbl_disp = tbl FILTER email %] [% ELSE %] [% tbl_disp = tbl %] @@ -45,20 +45,24 @@ [% IF col_field -%] [% FOREACH col = col_names -%] [% colsepchar %] - [% PROCESS value_display value = col field = col_field %] + [% PROCESS value_display value=col field=col_field %] [% END -%] [% ELSE -%] - [% colsepchar %][% num_bugs FILTER csv %] + [% FOR m = mlist %] + [% colsepchar %][% measure_descs.$m | csv %] + [% END %] [% END %] [% FOREACH row = row_names %] - [% PROCESS value_display value = row field = row_field %] + [% PROCESS value_display value=row field=row_field %] [% FOREACH col = col_names %] - [% colsepchar %] - [% IF data.$tbl AND data.$tbl.$col AND data.$tbl.$col.$row %] - [% data.$tbl.$col.$row -%] - [% ELSE %] - [% -%]0 + [% FOREACH m = mlist %] + [% colsepchar %] + [% IF data.$tbl AND data.$tbl.$col AND data.$tbl.$col.$row.$m %] + [% data.$tbl.$col.$row.$m -%] + [% ELSE %] + [% -%]0 + [% END %] [% END %] [% END %] @@ -66,9 +70,7 @@ [% BLOCK value_display %] [% SET disp_value = value %] - [% IF field == 'assigned_to' OR field == 'reporter' - OR field == 'qa_contact' - %] + [% IF field == 'assigned_to' OR field == 'reporter' OR field == 'qa_contact' %] [% disp_value = value FILTER email %] [% END %] [% disp_value FILTER csv %] diff --git a/template/en/default/reports/report-table.html.tmpl b/template/en/default/reports/report-table.html.tmpl index bf755a027..ea6b2356f 100644 --- a/template/en/default/reports/report-table.html.tmpl +++ b/template/en/default/reports/report-table.html.tmpl @@ -71,7 +71,7 @@ END; %] [% classes = [ [ "t1", "t2" ] , [ "t3", "t4" ] ] %] [% col_idx = 0 %] [% row_idx = 0 %] -[% grand_total = 0 %] +[% mlist = (measure == 'times' ? [ 'etime', 'wtime', 'rtime' ] : [ measure ]) %] [% IF col_field %] @@ -79,72 +79,77 @@ END; %] [% FOREACH col = col_names %] - [% col_totals.$col = 0 %] [% col_idx = 1 - col_idx %] - [% END %] - [% END %] [% FOREACH row = row_names %] - [% row_total = 0 %] - + [% row_total = {} %] [% row_idx = 1 - row_idx %] [% FOREACH col = col_names %] - [% row_total = row_total + data.$tbl.$col.$row %] - [% col_totals.$col = col_totals.$col + data.$tbl.$col.$row %] - [% col_idx = 1 - col_idx %] - + [% FOR m = mlist %] + [% col_totals.$col.$m = col_totals.$col.$m + data.$tbl.$col.$row.$m %] + [% row_total.$m = row_total.$m + data.$tbl.$col.$row.$m %] + + [% END %] + [% END %] + [% IF col_names.size > 1 %] + [% FOR m = mlist %] + + [% END %] [% END %] - [% END %] [% row_idx = 1 - row_idx %] - + [% FOREACH col = col_names %] - + [% FOR m = mlist %] + + [% END %] + [% END %] + [% IF col_names.size > 1 %] + [% FOR m = mlist %] + + [% END %] [% END %] -
+ [% PROCESS value_display value = col field = col_field %] + Total
[% PROCESS value_display value = row field = row_field %] - [% IF data.$tbl.$col.$row AND data.$tbl.$col.$row > 0 %] - - [% data.$tbl.$col.$row %] - [% ELSE %] - . - [% END %] - + [% IF data.$tbl.$col.$row.$m AND data.$tbl.$col.$row.$m > 0 %] + + [% data.$tbl.$col.$row.$m %] + [% END %] + + + [% row_total.$m %] + [% grand_total.$m = grand_total.$m + row_total.$m %] + - - [% row_total %] - [% grand_total = grand_total + row_total %] -
- Total - Total - - [% col_totals.$col %] - + + [% col_totals.$col.$m %] + + + [% grand_total.$m %] + + - - [% grand_total %] - -
diff --git a/template/en/default/reports/report.csv.tmpl b/template/en/default/reports/report.csv.tmpl index f5c230f38..105531fcb 100644 --- a/template/en/default/reports/report.csv.tmpl +++ b/template/en/default/reports/report.csv.tmpl @@ -18,6 +18,11 @@ # Contributor(s): Gervase Markham #%] [% FOREACH tbl = tbl_names %] - [% PROCESS "reports/report-table.csv.tmpl" %] - -[% END %] + [% measure_descs = { + rtime => 'Remaining time' + etime => 'Estimated time' + wtime => 'Actual time' + count => "Number of $terms.bugs" + } %] + [% PROCESS "reports/report-table.csv.tmpl" %] +[% END %] diff --git a/template/en/default/reports/report.html.tmpl b/template/en/default/reports/report.html.tmpl index 12af37437..bfa51d411 100644 --- a/template/en/default/reports/report.html.tmpl +++ b/template/en/default/reports/report.html.tmpl @@ -136,7 +136,7 @@ [% other_format.description FILTER html %] [% "" UNLESS other_format.name == format %] | [% END %] - CSV + CSV [% IF format != "table" %] @@ -165,14 +165,15 @@ rtime => 'Remaining time' etime => 'Estimated time' wtime => 'Actual time' - count => 'Bugs count' + times => 'Estimated/Actual/Remaining' + count => "Number of $terms.bugs" } %] [% FOR m = measure_descs.keys.sort %] - [%+ IF measure != m %][% END %] - [% measure_descs.$m %] - [% IF measure != m %][% END %] - [% IF NOT loop.last %] - | + [% IF m != 'times' || format == 'table' %] + [%+ IF measure != m %][% END %] + [% measure_descs.$m %] + [% IF measure != m %][% END %] + [% IF NOT loop.last %] | [% END %] [% END %] [% END %]