From 0191669861e1dac327e352ba7f00a2986f9ffa35 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 30 May 2018 16:26:36 +0300 Subject: [PATCH] Support numeric fields in reports --- Bugzilla/Report.pm | 53 ++++++++++++++----- Bugzilla/Search.pm | 2 +- report.cgi | 5 +- .../en/default/reports/report-table.html.tmpl | 8 +-- template/en/default/reports/report.html.tmpl | 9 +--- 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/Bugzilla/Report.pm b/Bugzilla/Report.pm index 9bf34eed3..581cd60d3 100644 --- a/Bugzilla/Report.pm +++ b/Bugzilla/Report.pm @@ -131,6 +131,23 @@ sub _get_names } } +sub get_measures +{ + my $cols = Bugzilla::Search->REPORT_COLUMNS(); + my $descs = { + count => '', + times => '', + }; + for my $f (keys %$cols) + { + if ($cols->{$f}->{numeric}) + { + $descs->{$f} = $cols->{$f}->{title}; + } + } + return $descs; +} + sub execute { my $class = shift; @@ -206,24 +223,34 @@ sub execute } } - my $measures = { + my $measure_alias = { etime => 'estimated_time', rtime => 'remaining_time', wtime => 'interval_time', - count => '_count', }; + my $measures = { + count => 'count', + }; + my $old_columns = { %{Bugzilla::Search->COLUMNS($runner)} }; # Trick Bugzilla::Search: replace report columns SQL + add '_count' column # FIXME: Remove usage of global variable COLUMNS in search generation code - my %old_columns = %{Bugzilla::Search->COLUMNS($runner)}; - %{Bugzilla::Search->COLUMNS($runner)} = (%{Bugzilla::Search->COLUMNS($runner)}, %{Bugzilla::Search->REPORT_COLUMNS}); - Bugzilla::Search->COLUMNS($runner)->{_count}->{name} = '1'; - + %{Bugzilla::Search->COLUMNS($runner)} = (%{Bugzilla::Search->COLUMNS($runner)}, %{Bugzilla::Search->REPORT_COLUMNS($runner)}); + Bugzilla::Search->COLUMNS($runner)->{count}->{name} = '1'; + my $columns = Bugzilla::Search->COLUMNS($runner); + for my $column (keys %$columns) + { + if ($columns->{$column}->{numeric}) + { + $measures->{$column} = $column; + } + } my $measure = $ARGS->{measure} || ''; + $measure = $measure_alias->{$measure} || $measure; + # Check that $measure is available (+ etime/rtime/wtime is usable only in table mode) if ($measure eq 'times' ? !$is_table : !$measures->{$measure}) { $measure = 'count'; } - # If the user has no access to the measured column, reset it to 'count' if (!Bugzilla::Search->COLUMNS($runner)->{$measure eq 'times' ? 'remaining_time' : $measures->{$measure}}) { @@ -234,7 +261,7 @@ sub execute my %a; my @group_by = grep { !($a{$_}++) } values %$field; my @axis_fields = @group_by; - for ($measure eq 'times' ? qw(etime rtime wtime) : $measure) + for ($measure eq 'times' ? qw(estimated_time remaining_time interval_time) : $measure) { push @axis_fields, $measures->{$_} unless $a{$measures->{$_}}; } @@ -251,7 +278,7 @@ sub execute ($field->{x} || "''")." x, ". ($field->{y} || "''")." y, ". ($field->{z} || "''")." z, ". - join(', ', map { "SUM($measures->{$_}) $_" } $measure eq 'times' ? qw(etime rtime wtime) : $measure). + join(', ', map { "SUM($measures->{$_}) $_" } ($measure eq 'times' ? qw(etime rtime wtime) : $measure)). " FROM ($query) _report_table GROUP BY ".join(", ", @group_by); $::SIG{TERM} = 'DEFAULT'; @@ -264,11 +291,9 @@ sub execute my %data; my %names; - # Read the bug data and count the bugs for each possible value of row, column - # and table. + # Read the bug data and count the bugs for each possible value of row, column and table. # - # We detect a numerical field, and sort appropriately, if all the values are - # numeric. + # We detect a numerical field, and sort appropriately, if all the values are numeric. my %isnumeric; foreach my $group (@$results) @@ -369,7 +394,7 @@ sub execute $vars->{cumulate} = $ARGS->{cumulate} ? 1 : 0; $vars->{x_labels_vertical} = $ARGS->{x_labels_vertical} ? 1 : 0; - %{Bugzilla::Search->COLUMNS($runner)} = %old_columns; + %{Bugzilla::Search->COLUMNS($runner)} = %$old_columns; return $vars; } diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index c4e40b654..d1eec4bad 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -464,7 +464,7 @@ sub STATIC_COLUMNS qa_contact_short => { title => 'QA Contact Login' }, # FIXME save aggregated work_time in bugs table and search on it work_time => { name => $actual_time, numeric => 1 }, - interval_time => { name => $actual_time, title => 'Period Worktime', noreports => 1, numeric => 1 }, + interval_time => { name => $actual_time, title => 'Period Worktime', numeric => 1 }, percentage_complete => { name => "(CASE WHEN $actual_time + bugs.remaining_time = 0.0 THEN 0.0" . " ELSE 100 * ($actual_time / ($actual_time + bugs.remaining_time)) END)", diff --git a/report.cgi b/report.cgi index 1997c9def..377f567b4 100755 --- a/report.cgi +++ b/report.cgi @@ -51,7 +51,8 @@ my $dbh = Bugzilla->switch_to_shadow_db(); my $action = $ARGS->{action} || 'menu'; my $token = $ARGS->{token}; -if ($action eq "menu") +$vars->{measure_descs} = Bugzilla::Report->get_measures(); +if ($action eq 'menu') { # No need to do any searching in this case, so bail out early. $template->process("reports/menu.html.tmpl", $vars) @@ -111,7 +112,7 @@ $vars->{report_columns} = Bugzilla::Search->REPORT_COLUMNS(); my $formatparam = $ARGS->{format}; -if ($action eq "wrap") +if ($action eq 'wrap') { # So which template are we using? If action is "wrap", we will be using # no format (it gets passed through to be the format of the actual data), diff --git a/template/en/default/reports/report-table.html.tmpl b/template/en/default/reports/report-table.html.tmpl index 9e9d0c3e9..b048937fa 100644 --- a/template/en/default/reports/report-table.html.tmpl +++ b/template/en/default/reports/report-table.html.tmpl @@ -112,7 +112,7 @@ END; %] - [% data.$tbl.$col.$row.$m %] + [% data.$tbl.$col.$row.$m | format("%.01f") %] [% END %] [% END %] @@ -124,7 +124,7 @@ END; %] - [% row_total.$m %] + [% row_total.$m | format("%.01f") %] [% grand_total.$m = grand_total.$m + row_total.$m %] [% END %] @@ -142,7 +142,7 @@ END; %] - [% col_totals.$col_n.$m %] + [% col_totals.$col_n.$m | format("%.01f") %] [% END %] [% col_n = col_n + 1 %] @@ -153,7 +153,7 @@ END; %] [% grand_total.$m %] + [% "&$col_vals" IF col_vals %]">[% grand_total.$m | format("%.01f") %] [% END %] diff --git a/template/en/default/reports/report.html.tmpl b/template/en/default/reports/report.html.tmpl index cda42cd67..deab36b0e 100644 --- a/template/en/default/reports/report.html.tmpl +++ b/template/en/default/reports/report.html.tmpl @@ -139,13 +139,8 @@ Show: - [% measure_descs = { - rtime => 'Remaining time' - etime => 'Estimated time' - wtime => 'Actual time' - times => 'Estimated/Actual/Remaining' - count => "Number of $terms.bugs" - } %] + [% measure_descs.times = 'Estimated/Actual/Remaining' %] + [% measure_descs.count = "Number of $terms.bugs" %]