[Rt-commit] rt branch, 4.6/jschart, updated. rt-4.4.4-62-gaa5951852

? sunnavy sunnavy at bestpractical.com
Tue May 7 17:52:43 EDT 2019


The branch, 4.6/jschart has been updated
       via  aa59518521086d4aea59aed82a1116552b27840e (commit)
       via  67c894dcf5e36eadd9001a04817f9b25907acb94 (commit)
      from  10bf39d8230babb104389a7e3700e35188920d48 (commit)

Summary of changes:
 share/html/Search/JSChart | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

- Log -----------------------------------------------------------------
commit 67c894dcf5e36eadd9001a04817f9b25907acb94
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 7 23:44:32 2019 +0800

    Set y-axis label only for bar charts
    
    Pie charts don't have y-axis, thus $labels[$index-1] is undef, which
    could cause js syntax error.

diff --git a/share/html/Search/JSChart b/share/html/Search/JSChart
index bc0b1827c..1b05bc3bc 100644
--- a/share/html/Search/JSChart
+++ b/share/html/Search/JSChart
@@ -77,7 +77,10 @@ var searchChart = new Chart(ctx, {
 %   if ( $#data == 1 )  {
             backgroundColor: backgroundColor || [],
 %   }
+
+%   if ( $ChartStyle =~ /\bbar\b/ ) {
             label: <% $labels[$index-1] |n,j %>,
+%   }
             data: <% JSON($data[$index]) |n %>
           }
 %   if ( $index != $#data ) {

commit aa59518521086d4aea59aed82a1116552b27840e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed May 8 05:40:05 2019 +0800

    Redirect to ticket search result page via click on each bar/pie
    
    Thus people could easily get the list of tickets belonging to that group
    the bar/pie represents

diff --git a/share/html/Search/JSChart b/share/html/Search/JSChart
index 1b05bc3bc..c3a1c38cb 100644
--- a/share/html/Search/JSChart
+++ b/share/html/Search/JSChart
@@ -131,6 +131,29 @@ var searchChart = new Chart(ctx, {
 % }
     }
 });
+
+var group_by = <% JSON( \@GroupBy ) |n %>;
+var group_by_values = <% JSON( \@group_by_values ) |n %>;
+
+jQuery('#search-chart').click(function(e) {
+    var slice = searchChart.getElementAtEvent(e);
+    if ( !slice[0] ) return;
+
+    var query = <% $Query =~ /^\s*\(.*\)$/ ? $Query : "( $Query )" |n,j %>;
+    for ( var i=0; i < group_by.length; i++ ) {
+        var value = group_by_values[slice[0]._index][i];
+        if ( value == null ) {
+            query += ' AND ' + group_by[i] + ' IS NULL';
+        }
+        else {
+            value = value.replace("'", "\\'");
+            query += ' AND ' + group_by[i] + ' = ' + "'" + value + "'";
+        }
+    }
+    window.open(RT.Config.WebPath + '/Search/Results.html?Query=' + encodeURIComponent(query)
+        + '&' + <% $m->comp('/Elements/QueryString', map { $_ => $DECODED_ARGS->{$_} } grep { $_ ne 'Query' } keys %$DECODED_ARGS) |n,j%>);
+});
+
 </script>
 
 <%init>
@@ -142,6 +165,10 @@ $Height = $Width if $ChartStyle =~ /\bpie\b/;
 use RT::Report::Tickets;
 my $report = RT::Report::Tickets->new( $session{'CurrentUser'} );
 
+# Default GroupBy we use in RT::Report::Tickets, we also need it here to
+# generate sub queries.
+ at GroupBy = 'Status' unless @GroupBy;
+
 my %columns;
 if ( $Cache and my $data = delete $session{'charts_cache'}{ $Cache } ) {
     %columns = %{ $data->{'columns'} };
@@ -158,8 +185,10 @@ if ( $Cache and my $data = delete $session{'charts_cache'}{ $Cache } ) {
 }
 
 my @data = ([],[]);
+my @group_by_values;
 while ( my $entry = $report->Next ) {
     push @{ $data[0] }, [ map $entry->LabelValue( $_ ), @{ $columns{'Groups'} } ];
+    push @group_by_values, [ map $entry->RawValue( $_ ), @{ $columns{'Groups'} } ];
 
     my @values;
     foreach my $column ( @{ $columns{'Functions'} } ) {

-----------------------------------------------------------------------


More information about the rt-commit mailing list