From a8e11f918e548c928e28d0185b5d5277805e3d70 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 2 Aug 2016 18:27:07 +0300 Subject: [PATCH] Move report generation logic to Bugzilla::Report, support reports in whines --- Bugzilla/DB/Schema.pm | 1 + Bugzilla/Install/DB.pm | 2 + Bugzilla/Report.pm | 257 ++++++++++++++++++ Bugzilla/Whine/Query.pm | 3 +- editwhines.cgi | 13 +- report.cgi | 251 +---------------- skins/contrib/Mozilla/global.css | 7 +- skins/standard/admin.css | 6 +- .../en/default/reports/report-bar.png.tmpl | 6 +- .../en/default/reports/report-line.png.tmpl | 6 +- .../en/default/reports/report-pie.png.tmpl | 6 +- template/en/default/reports/report.html.tmpl | 8 - template/en/default/whine/mail.html.tmpl | 31 ++- template/en/default/whine/schedule.html.tmpl | 17 +- whine.pl | 22 +- 15 files changed, 349 insertions(+), 287 deletions(-) diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index e71cdd3e8..05bcd99f8 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -1132,6 +1132,7 @@ use constant ABSTRACT_SCHEMA => { sortkey => {TYPE => 'INT4', NOTNULL => 1, DEFAULT => '0'}, onemailperbug => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'}, title => {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"}, + isreport => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'FALSE'}, ], INDEXES => [ whine_queries_eventid_idx => ['eventid'], diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 9aa09ab5b..62e14a1b0 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -866,6 +866,8 @@ WHERE description LIKE \'%[CC:%]%\''); $dbh->bz_add_column('checkers', 'bypass_group_id'); + $dbh->bz_add_column('whine_queries', 'isreport'); + _move_old_defaults($old_params); ################################################################ diff --git a/Bugzilla/Report.pm b/Bugzilla/Report.pm index 3477232bc..f12346f14 100644 --- a/Bugzilla/Report.pm +++ b/Bugzilla/Report.pm @@ -104,6 +104,263 @@ sub check return $report; } +sub _get_names +{ + my ($names, $isnumeric, $field) = @_; + + # These are all the fields we want to preserve the order of in reports. + my $f = $field && Bugzilla->get_field($field); + if ($f && $f->is_select) + { + my $values = [ '', map { $_->name } @{ $f->legal_values(1) } ]; + my %dup; + @$values = grep { exists($names->{$_}) && !($dup{$_}++) } @$values; + return $values; + } + elsif ($isnumeric) + { + # It's not a field we are preserving the order of, so sort it + # numerically... + sub numerically { $a <=> $b } + return [ sort numerically keys %$names ]; + } + else + { + # ...or alphabetically, as appropriate. + return [ sort keys %$names ]; + } +} + +sub execute +{ + my $class = shift; + my ($ARGS, $runner) = @_; + + my $valid_columns = Bugzilla::Search->REPORT_COLUMNS(); + + my $field = {}; + for (qw(x y z)) + { + my $f = $ARGS->{$_.'_axis_field'} || ''; + trick_taint($f); + if ($f) + { + if ($valid_columns->{$f}) + { + $field->{$_} = $f; + } + else + { + ThrowCodeError("report_axis_invalid", {fld => $_, val => $f}); + } + } + } + + if (!keys %$field) + { + ThrowUserError("no_axes_defined"); + } + + my $width = $ARGS->{width} || 600; + my $height = $ARGS->{height} || 350; + + if (defined($width)) + { + (detaint_natural($width) && $width > 0) + || ThrowCodeError("invalid_dimensions"); + $width <= 2000 || ThrowUserError("chart_too_large"); + } + + if (defined($height)) + { + (detaint_natural($height) && $height > 0) + || ThrowCodeError("invalid_dimensions"); + $height <= 2000 || ThrowUserError("chart_too_large"); + } + + # 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. + 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) + $field->{y} = $field->{x}; + delete $field->{x}; + } + } + else + { + if (!Bugzilla->feature('graphical_reports')) + { + ThrowCodeError('feature_disabled', { feature => 'graphical_reports' }); + } + if ($field->{y} && !$field->{x}) + { + # 1D *charts* should be displayed horizontally (with an col_field only) + $field->{x} = $field->{y}; + delete $field->{y}; + } + } + + my $measures = { + etime => 'estimated_time', + rtime => 'remaining_time', + wtime => 'interval_time', + count => '_count', + }; + # 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'; + + my $measure = $ARGS->{measure} || ''; + if ($measure eq 'times' ? !$is_table : !$measures->{$measure}) + { + $measure = 'count'; + } + + # 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; + 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( + fields => \@axis_fields, + params => { %$ARGS }, + user => $runner, + ); + my $query = $search->getSQL(); + $query = + "SELECT ". + ($field->{x} || "''")." x, ". + ($field->{y} || "''")." y, ". + ($field->{z} || "''")." z, ". + 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'; + + my $results = Bugzilla->dbh->selectall_arrayref($query, {Slice=>{}}); + + # We have a hash of hashes for the data itself, and a hash to hold the + # row/col/table names. + my %data; + my %names; + + # 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. + my %isnumeric; + + foreach my $group (@$results) + { + for (qw(x y z)) + { + $isnumeric{$_} &&= ($group->{$_} =~ /^-?\d+(\.\d+)?$/o); + $names{$_}{$group->{$_}} = 1; + } + $data{$group->{z}}{$group->{x}}{$group->{y}} = $is_table ? $group : $group->{$measure}; + } + + my @tbl_names = @{_get_names($names{z}, $isnumeric{z}, $field->{z})}; + my @col_names = @{_get_names($names{x}, $isnumeric{x}, $field->{x})}; + my @row_names = @{_get_names($names{y}, $isnumeric{y}, $field->{y})}; + + # The GD::Graph package requires a particular format of data, so once we've + # gathered everything into the hashes and made sure we know the size of the + # data, we reformat it into an array of arrays of arrays of data. + push @tbl_names, "-total-" if scalar(@tbl_names) > 1; + + my @image_data; + foreach my $tbl (@tbl_names) + { + my @tbl_data; + push @tbl_data, \@col_names; + foreach my $row (@row_names) + { + my @col_data; + foreach my $col (@col_names) + { + $data{$tbl}{$col}{$row} ||= {}; + push @col_data, $data{$tbl}{$col}{$row}; + if ($tbl ne "-total-") + { + # This is a bit sneaky. We spend every loop except the last + # building up the -total- data, and then last time round, + # we process it as another tbl, and push() the total values + # into the image_data array. + for my $m (keys %{$data{$tbl}{$col}{$row}}) + { + next if $m eq 'x' || $m eq 'y' || $m eq 'z'; + $data{"-total-"}{$col}{$row}{$m} += $data{$tbl}{$col}{$row}{$m}; + } + } + } + push @tbl_data, \@col_data; + } + unshift @image_data, \@tbl_data; + } + + # Below a certain width, we don't see any bars, so there needs to be a minimum. + if ($width && $ARGS->{format} eq "bar") + { + my $min_width = (scalar(@col_names) || 1) * 20; + if (!$ARGS->{cumulate}) + { + $min_width *= (scalar(@row_names) || 1); + } + $width = $min_width; + } + + my $vars = {}; + + $vars->{fields} = $field; + + # for debugging + $vars->{query} = $query; + + # We need to keep track of the defined restrictions on each of the + # axes, because buglistbase, below, throws them away. Without this, we + # get buglistlinks wrong if there is a restriction on an axis field. + $vars->{col_vals} = $field->{x} ? http_build_query({ $field->{x} => $ARGS->{$field->{x}} }) : ''; + $vars->{row_vals} = $field->{y} ? http_build_query({ $field->{y} => $ARGS->{$field->{y}} }) : ''; + $vars->{tbl_vals} = $field->{z} ? http_build_query({ $field->{z} => $ARGS->{$field->{z}} }) : ''; + my $a = { %$ARGS }; + delete $a->{$_} for qw(x_axis_field y_axis_field z_axis_field ctype format query_format measure), @axis_fields; + $vars->{buglistbase} = http_build_query($a); + + $vars->{image_data} = \@image_data; + $vars->{data} = \%data; + $vars->{measure} = $measure; + $vars->{tbl_field} = $field->{z}; + $vars->{col_field} = $field->{x}; + $vars->{row_field} = $field->{y}; + $vars->{col_names} = \@col_names; + $vars->{row_names} = \@row_names; + $vars->{tbl_names} = \@tbl_names; + $vars->{width} = $width; + $vars->{height} = $height; + $vars->{cumulate} = $ARGS->{cumulate} ? 1 : 0; + $vars->{x_labels_vertical} = $ARGS->{x_labels_vertical} ? 1 : 0; + + %{Bugzilla::Search->COLUMNS($runner)} = %old_columns; + + return $vars; +} + 1; __END__ diff --git a/Bugzilla/Whine/Query.pm b/Bugzilla/Whine/Query.pm index 11215759b..6247a6ce8 100644 --- a/Bugzilla/Whine/Query.pm +++ b/Bugzilla/Whine/Query.pm @@ -40,6 +40,7 @@ use constant DB_COLUMNS => qw( sortkey onemailperbug title + isreport ); use constant NAME_FIELD => 'id'; @@ -53,7 +54,7 @@ sub sortkey { return $_[0]->{'sortkey'}; } sub one_email_per_bug { return $_[0]->{'onemailperbug'}; } sub title { return $_[0]->{'title'}; } sub name { return $_[0]->{'query_name'}; } - +sub isreport { return $_[0]->{'isreport'}; } 1; diff --git a/editwhines.cgi b/editwhines.cgi index 51f4a0013..e6683c23e 100755 --- a/editwhines.cgi +++ b/editwhines.cgi @@ -247,6 +247,7 @@ if ($ARGS->{update}) my $title = $ARGS->{"query_title_$qid"} || ''; my $o_onemailperbug = $ARGS->{"orig_query_onemailperbug_$qid"} || 0; my $onemailperbug = $ARGS->{"query_onemailperbug_$qid"} ? 1 : 0; + my $isreport = 0; if ($o_sort != $sort || $o_queryname ne $queryname || $o_onemailperbug != $onemailperbug || $o_title ne $title) @@ -254,9 +255,13 @@ if ($ARGS->{update}) detaint_natural($sort); trick_taint($queryname); trick_taint($title); + if ($queryname =~ /^([01])-(.*)$/s) + { + ($isreport, $queryname) = ($1, $2); + } $dbh->do( - "UPDATE whine_queries SET sortkey=?, query_name=?, title=?, onemailperbug=? WHERE id=?", - undef, $sort, $queryname, $title, $onemailperbug, $qid + "UPDATE whine_queries SET sortkey=?, query_name=?, title=?, onemailperbug=?, isreport=? WHERE id=?", + undef, $sort, $queryname, $title, $onemailperbug, $isreport, $qid ); } } @@ -323,6 +328,7 @@ for my $event_id (keys %{$events}) sort => $query->sortkey, id => $query->id, onemailperbug => $query->one_email_per_bug, + isreport => $query->isreport, }; } } @@ -330,7 +336,8 @@ for my $event_id (keys %{$events}) $vars->{events} = $events; # get the available queries -$vars->{available_queries} = $dbh->selectcol_arrayref("SELECT name FROM namedqueries WHERE userid=?", undef, $userid) || []; +$vars->{available_queries} = $dbh->selectcol_arrayref("SELECT name FROM namedqueries WHERE userid=? ORDER BY name", undef, $userid) || []; +$vars->{available_reports} = $dbh->selectcol_arrayref("SELECT name FROM reports WHERE user_id=? ORDER BY name", undef, $userid) || []; $vars->{token} = issue_session_token('edit_whine'); $vars->{local_timezone} = Bugzilla->local_timezone->short_name_for_datetime(DateTime->now()); diff --git a/report.cgi b/report.cgi index c0c2e0d8b..dabf06290 100755 --- a/report.cgi +++ b/report.cgi @@ -34,7 +34,6 @@ use Bugzilla::Token; my $ARGS = Bugzilla->input_params; my $template = Bugzilla->template; my $vars = {}; -my $buffer = http_build_query($ARGS); # Go straight back to query.cgi if we are adding a boolean chart. if (grep /^cmd-/, keys %$ARGS) @@ -104,209 +103,11 @@ elsif ($action eq 'del') exit; } -my $valid_columns = Bugzilla::Search->REPORT_COLUMNS(); -$vars->{report_columns} = $valid_columns; - -my $field = {}; -for (qw(x y z)) -{ - my $f = $ARGS->{$_.'_axis_field'} || ''; - trick_taint($f); - if ($f) - { - if ($valid_columns->{$f}) - { - $field->{$_} = $f; - } - else - { - ThrowCodeError("report_axis_invalid", {fld => $_, val => $f}); - } - } -} - -if (!keys %$field) -{ - ThrowUserError("no_axes_defined"); -} - -my $width = $ARGS->{width}; -my $height = $ARGS->{height}; - -if (defined($width)) -{ - (detaint_natural($width) && $width > 0) - || ThrowCodeError("invalid_dimensions"); - $width <= 2000 || ThrowUserError("chart_too_large"); -} - -if (defined($height)) -{ - (detaint_natural($height) && $height > 0) - || ThrowCodeError("invalid_dimensions"); - $height <= 2000 || ThrowUserError("chart_too_large"); -} - -# 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. -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) - $field->{y} = $field->{x}; - delete $field->{x}; - } -} -else -{ - if (!Bugzilla->feature('graphical_reports')) - { - ThrowCodeError('feature_disabled', { feature => 'graphical_reports' }); - } - if ($field->{y} && !$field->{x}) - { - # 1D *charts* should be displayed horizontally (with an col_field only) - $field->{x} = $field->{y}; - delete $field->{y}; - } -} - -my $measures = { - etime => 'estimated_time', - rtime => 'remaining_time', - wtime => 'interval_time', - count => '_count', -}; -# Trick Bugzilla::Search: replace report columns SQL + add '_count' column -# FIXME: Remove usage of global variable COLUMNS in search generation code -%{Bugzilla::Search->COLUMNS} = (%{Bugzilla::Search->COLUMNS}, %{Bugzilla::Search->REPORT_COLUMNS}); -Bugzilla::Search->COLUMNS->{_count}->{name} = '1'; - -my $measure = $ARGS->{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; -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( - 'fields' => \@axis_fields, - 'params' => { %{ Bugzilla->input_params } }, -); -my $query = $search->getSQL(); -$query = - "SELECT ". - ($field->{x} || "''")." x, ". - ($field->{y} || "''")." y, ". - ($field->{z} || "''")." z, ". - 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'; - -my $results = $dbh->selectall_arrayref($query, {Slice=>{}}); - -# We have a hash of hashes for the data itself, and a hash to hold the -# row/col/table names. -my %data; -my %names; - -# 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. -my %isnumeric; - -foreach my $group (@$results) -{ - for (qw(x y z)) - { - $isnumeric{$_} &&= ($group->{$_} =~ /^-?\d+(\.\d+)?$/o); - $names{$_}{$group->{$_}} = 1; - } - $data{$group->{z}}{$group->{x}}{$group->{y}} = $is_table ? $group : $group->{$measure}; -} - -my @tbl_names = @{get_names($names{z}, $isnumeric{z}, $field->{z})}; -my @col_names = @{get_names($names{x}, $isnumeric{x}, $field->{x})}; -my @row_names = @{get_names($names{y}, $isnumeric{y}, $field->{y})}; - -# The GD::Graph package requires a particular format of data, so once we've -# gathered everything into the hashes and made sure we know the size of the -# data, we reformat it into an array of arrays of arrays of data. -push @tbl_names, "-total-" if scalar(@tbl_names) > 1; - -my @image_data; -foreach my $tbl (@tbl_names) -{ - my @tbl_data; - push @tbl_data, \@col_names; - foreach my $row (@row_names) - { - my @col_data; - foreach my $col (@col_names) - { - $data{$tbl}{$col}{$row} ||= {}; - push @col_data, $data{$tbl}{$col}{$row}; - if ($tbl ne "-total-") - { - # This is a bit sneaky. We spend every loop except the last - # building up the -total- data, and then last time round, - # we process it as another tbl, and push() the total values - # into the image_data array. - for my $m (keys %{$data{$tbl}{$col}{$row}}) - { - $data{"-total-"}{$col}{$row}{$m} += $data{$tbl}{$col}{$row}{$m}; - } - } - } - push @tbl_data, \@col_data; - } - unshift @image_data, \@tbl_data; -} - -$vars->{tbl_field} = $field->{z}; -$vars->{col_field} = $field->{x}; -$vars->{row_field} = $field->{y}; $vars->{time} = localtime(time()); - -$vars->{col_names} = \@col_names; -$vars->{row_names} = \@row_names; -$vars->{tbl_names} = \@tbl_names; - -# Below a certain width, we don't see any bars, so there needs to be a minimum. -if ($width && $ARGS->{format} eq "bar") -{ - my $min_width = (scalar(@col_names) || 1) * 20; - if (!$ARGS->{cumulate}) - { - $min_width *= (scalar(@row_names) || 1); - } - $vars->{min_width} = $min_width; -} - -$vars->{width} = $width if $width; -$vars->{height} = $height if $height; - -$vars->{query} = $query; +$vars = { %$vars, %{Bugzilla::Report->execute($ARGS)} }; $vars->{saved_report_id} = $ARGS->{saved_report_id}; $vars->{debug} = $ARGS->{debug}; +$vars->{report_columns} = Bugzilla::Search->REPORT_COLUMNS(); my $formatparam = $ARGS->{format}; @@ -323,32 +124,17 @@ if ($action eq "wrap") $vars->{format} = $formatparam; $formatparam = '' if $formatparam ne 'simple'; - # We need to keep track of the defined restrictions on each of the - # axes, because buglistbase, below, throws them away. Without this, we - # get buglistlinks wrong if there is a restriction on an axis field. - $vars->{col_vals} = join("&", $buffer =~ /[&?]($field->{x}=[^&]+)/g); - $vars->{row_vals} = join("&", $buffer =~ /[&?]($field->{y}=[^&]+)/g); - $vars->{tbl_vals} = join("&", $buffer =~ /[&?]($field->{z}=[^&]+)/g); - - # We need a number of different variants of the base URL for different URLs in the HTML. my $a = { %$ARGS }; - delete $a->{$_} for qw(x_axis_field y_axis_field z_axis_field ctype format query_format measure), @axis_fields; - $vars->{buglistbase} = http_build_query($a); - $a = { %$ARGS }; - delete $a->{$_} for $field->{z}, qw(action ctype format width height); + delete $a->{$_} for $vars->{fields}->{z}, qw(action ctype format width height); $vars->{imagebase} = http_build_query($a); $a = { %$ARGS }; delete $a->{$_} for qw(query_format action ctype format width height measure); $vars->{switchbase} = http_build_query($a); - $vars->{data} = \%data; } elsif ($action eq "plot") { # If action is "plot", we will be using a format as normal (pie, bar etc.) # and a ctype as normal (currently only png.) - $vars->{cumulate} = $ARGS->{cumulate} ? 1 : 0; - $vars->{x_labels_vertical} = $ARGS->{x_labels_vertical} ? 1 : 0; - $vars->{data} = \@image_data; } else { @@ -376,9 +162,9 @@ if ($ARGS->{debug}) { require Data::Dumper; print "
data hash:\n";
-    print html_quote(Data::Dumper::Dumper(%data)) . "\n\n";
+    print html_quote(Data::Dumper::Dumper($vars->{data})) . "\n\n";
     print "data array:\n";
-    print html_quote(Data::Dumper::Dumper(@image_data)) . "\n\n
"; + print html_quote(Data::Dumper::Dumper($vars->{image_data})) . "\n\n"; } # All formats point to the same section of the documentation. @@ -390,30 +176,3 @@ $template->process($format->{template}, $vars) || ThrowTemplateError($template->error()); exit; - -sub get_names -{ - my ($names, $isnumeric, $field) = @_; - - # These are all the fields we want to preserve the order of in reports. - my $f = Bugzilla->get_field($field); - if ($f && $f->is_select) - { - my $values = [ '', map { $_->name } @{ $f->legal_values(1) } ]; - my %dup; - @$values = grep { exists($names->{$_}) && !($dup{$_}++) } @$values; - return $values; - } - elsif ($isnumeric) - { - # It's not a field we are preserving the order of, so sort it - # numerically... - sub numerically { $a <=> $b } - return [ sort numerically keys %$names ]; - } - else - { - # ...or alphabetically, as appropriate. - return [ sort keys %$names ]; - } -} diff --git a/skins/contrib/Mozilla/global.css b/skins/contrib/Mozilla/global.css index 769e7d563..1299f0b43 100644 --- a/skins/contrib/Mozilla/global.css +++ b/skins/contrib/Mozilla/global.css @@ -946,13 +946,16 @@ table.tabs { } table.eventbox { - border-color: gray; - padding: 5px; + border-color: white; background: white; border-radius: 5px; box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.2); } +table.eventbox td.set { + background: #e0e0e0; +} + /* search */ #summary_field.search_field_row input { diff --git a/skins/standard/admin.css b/skins/standard/admin.css index 89aaee81a..8d797057f 100644 --- a/skins/standard/admin.css +++ b/skins/standard/admin.css @@ -95,16 +95,16 @@ td.forbidden { } table.eventbox { - border: 1px solid black; + border: 10px solid white; margin: 8px 0; } -td.set { +table.eventbox td.set { background: #ddd; padding: 5px; } -td.unset { +table.eventbox td.unset { color: red; } diff --git a/template/en/default/reports/report-bar.png.tmpl b/template/en/default/reports/report-bar.png.tmpl index 8edad97cf..b97346326 100644 --- a/template/en/default/reports/report-bar.png.tmpl +++ b/template/en/default/reports/report-bar.png.tmpl @@ -22,8 +22,8 @@ [% col_field_disp = field_descs.$col_field || Bugzilla.get_field(col_field).description || col_field %] -[% FOR i IN [ 0 .. data.0.0.max ] %] - [% data.0.0.$i = data.0.0.$i %] +[% FOR i IN [ 0 .. image_data.0.0.max ] %] + [% image_data.0.0.$i = image_data.0.0.$i %] [% END %] [% FOR i IN [ 0 .. row_names.max ] %] @@ -63,6 +63,6 @@ row_names.8, row_names.9, row_names.10, row_names.11, row_names.12, row_names.13, row_names.14, row_names.15); - graph.plot(data.0).png | stdout(1); + graph.plot(image_data.0).png | stdout(1); END; -%] diff --git a/template/en/default/reports/report-line.png.tmpl b/template/en/default/reports/report-line.png.tmpl index 72d8a707a..cd9a99bf7 100644 --- a/template/en/default/reports/report-line.png.tmpl +++ b/template/en/default/reports/report-line.png.tmpl @@ -22,8 +22,8 @@ [% col_field_disp = field_descs.$col_field || Bugzilla.get_field(col_field).description || col_field %] -[% FOR i IN [ 0 .. data.0.0.max ] %] - [% data.0.0.$i = data.0.0.$i %] +[% FOR i IN [ 0 .. image_data.0.0.max ] %] + [% image_data.0.0.$i = image_data.0.0.$i %] [% END %] [% IF cumulate %] @@ -61,7 +61,7 @@ row_names.8, row_names.9, row_names.10, row_names.11, row_names.12, row_names.13, row_names.14, row_names.15); - graph.plot(data.0).png | stdout(1); + graph.plot(image_data.0).png | stdout(1); END; -%] diff --git a/template/en/default/reports/report-pie.png.tmpl b/template/en/default/reports/report-pie.png.tmpl index ba626926c..2330c2d49 100644 --- a/template/en/default/reports/report-pie.png.tmpl +++ b/template/en/default/reports/report-pie.png.tmpl @@ -20,8 +20,8 @@ [% col_field_disp = field_descs.$col_field || Bugzilla.get_field(col_field).description || col_field %] -[% FOR i IN [ 0 .. data.0.0.max ] %] - [% data.0.0.$i = data.0.0.$i %] +[% FOR i IN [ 0 .. image_data.0.0.max ] %] + [% image_data.0.0.$i = image_data.0.0.$i %] [% END %] [% FILTER null; @@ -37,6 +37,6 @@ graph.set_label_font(Param('graph_font'), Param('graph_font_size')); graph.set_value_font(Param('graph_font'), Param('graph_font_size')); - graph.plot(data.0).png | stdout(1); + graph.plot(image_data.0).png | stdout(1); END; -%] diff --git a/template/en/default/reports/report.html.tmpl b/template/en/default/reports/report.html.tmpl index bfa51d411..f5b5b451d 100644 --- a/template/en/default/reports/report.html.tmpl +++ b/template/en/default/reports/report.html.tmpl @@ -33,14 +33,6 @@ # cumulate: boolean. For bar/line charts, whether to cumulate data sets. #%] -[% DEFAULT width = 600 - height = 350 -%] - -[% IF min_width AND width < min_width %] - [% width = min_width %] -[% END %] - [%# We ignore row_field for pie charts %] [% IF format == "pie" %] [% row_field = "" %] diff --git a/template/en/default/whine/mail.html.tmpl b/template/en/default/whine/mail.html.tmpl index f12e20833..e1625a373 100644 --- a/template/en/default/whine/mail.html.tmpl +++ b/template/en/default/whine/mail.html.tmpl @@ -58,13 +58,17 @@

[%+ query.title FILTER html %]

[% code = BLOCK %] - [% PROCESS "list/table.html.tmpl" - bugs = query.bugs - order_columns = query.order_columns - order = query.order_columns.join(',') - displaycolumns = query.displaycolumns - template_format = 'simple' - %] + [% IF query.isreport %] + [% "whinereport" | process(query.data) %] + [% ELSE %] + [% PROCESS "list/table.html.tmpl" + bugs = query.bugs + order_columns = query.order_columns + order = query.order_columns.join(',') + displaycolumns = query.displaycolumns + template_format = 'simple' + %] + [% END %] [% END %] [% code.replace(']*)href="([a-z_]+)\.cgi', ' + +[% BLOCK whinereport %] +
+ [% FOREACH tbl = tbl_names %] + [% IF tbl == "-total-" %] + [% tbl_disp = "Total" %] + [% ELSE %] + [% tbl_disp = tbl %] + [% END %] + [% PROCESS "reports/report-table.html.tmpl" %] + [% END %] +
+[% END %] diff --git a/template/en/default/whine/schedule.html.tmpl b/template/en/default/whine/schedule.html.tmpl index 9cc195020..5b8b14384 100644 --- a/template/en/default/whine/schedule.html.tmpl +++ b/template/en/default/whine/schedule.html.tmpl @@ -244,7 +244,7 @@ - + @@ -260,9 +260,9 @@ name="orig_query_sort_[% query.id %]" />
SortSearchSearch/Report Title - - [% PROCESS query_field thisquery=query.name %] + [% PROCESS query_field thisquery=query.name isreport=query.isreport %] 0 %] + [% IF available_queries.size > 0 || available_reports.size > 0 %] diff --git a/whine.pl b/whine.pl index 6cedad02d..05857ab8f 100755 --- a/whine.pl +++ b/whine.pl @@ -29,6 +29,9 @@ use Bugzilla::User; use Bugzilla::Mailer; use Bugzilla::Util; use Bugzilla::Group; +use Bugzilla::Report; + +Bugzilla->set_user(Bugzilla::User->super_user); # %seen_schedules is a list of all of the schedules that have already been # touched by reset_timer. If reset_timer sees a schedule more than once, it @@ -176,7 +179,7 @@ while (my $event = get_next_event()) my $there_are_bugs = 0; for my $query (@{$queries}) { - $there_are_bugs = 1 if scalar @{$query->{bugs}}; + $there_are_bugs = 1 if $query->{isreport} || scalar @{$query->{bugs}}; } next unless $there_are_bugs; } @@ -320,6 +323,8 @@ sub mail # Don't send mail to someone whose bugmail notification is disabled. return if $addressee->email_disabled; + $args->{report_columns} = Bugzilla::Search->REPORT_COLUMNS(); + my $template = Bugzilla->template_inner($addressee->settings->{lang}->{value}); my $msg = ''; # it's a temporary variable to hold the template output $args->{alternatives} ||= []; @@ -373,13 +378,26 @@ sub run_queries my $dbh = Bugzilla->dbh; my $queries = $dbh->selectall_arrayref( - "SELECT query_name, title, onemailperbug FROM whine_queries". + "SELECT query_name, title, onemailperbug, isreport FROM whine_queries". " WHERE eventid=? ORDER BY sortkey", {Slice=>{}}, $args->{eventid} ); foreach my $thisquery (@$queries) { next unless $thisquery->{query_name}; # named query is blank + if ($thisquery->{isreport}) + { + my ($savedreport) = @{ Bugzilla::Report->match({ name => $thisquery->{query_name}, user_id => $args->{author}->id }) }; + next unless $savedreport; # silently ignore missing reports + my $params = http_decode_query($savedreport->query); + $thisquery->{data} = Bugzilla::Report->execute($params, $args->{author}); + if (@{$thisquery->{data}->{image_data}}) + { + push @$return_queries, $thisquery; + } + next; + } + my $savedquery = Bugzilla::Search::Saved->new({ name => $thisquery->{query_name}, user => $args->{author} }); next unless $savedquery; # silently ignore missing queries