1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
51 GroupBy => ['Status'],
52 ChartStyle => ['bar+table+sql'],
53 ChartFunction => ['COUNT'],
56 $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
58 my $title = loc( "Grouped search results");
60 my @search_fields = qw(Query GroupBy ChartStyle ChartFunction Width Height);
61 my $saved_search = $m->comp( '/Widgets/SavedSearch:new',
62 SearchType => 'Chart',
63 SearchFields => [@search_fields],
66 my @actions = $m->comp( '/Widgets/SavedSearch:process', args => \%ARGS, self => $saved_search );
71 if ($saved_search->{'CurrentSearch'}->{'Object'}) {
72 foreach my $search_field (@{ $saved_search->{'SearchFields'} }) {
73 $query{$search_field} = $saved_search->{'CurrentSearch'}->{'Object'}->Content->{$search_field};
77 my $current = $session{'CurrentSearchHash'};
79 my @session_fields = qw(
82 SavedSearchDescription
88 for(@session_fields) {
89 $query{$_} = $DECODED_ARGS->{$_} unless defined $query{$_};
90 $query{$_} = $current->{$_} unless defined $query{$_};
93 if ($DECODED_ARGS->{'SavedSearchLoadSubmit'}) {
94 $query{'SavedChartSearchId'} = $DECODED_ARGS->{'SavedSearchLoad'};
97 if ($DECODED_ARGS->{'SavedSearchSave'}) {
98 $query{'SavedChartSearchId'} = $saved_search->{'SearchId'};
103 foreach (@search_fields) {
104 if ( ref $default_value->{$_} ) {
105 $query{$_} = ref $ARGS{$_} ? $ARGS{$_} : [ $ARGS{$_} ];
106 $query{$_} = $default_value->{$_}
107 unless defined $query{$_} && defined $query{$_}[0];
110 $query{$_} = ref $ARGS{$_} ? $ARGS{$_} : $ARGS{$_};
111 $query{$_} = $default_value->{$_}
112 unless defined $query{$_};
116 $m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
119 <& /Elements/Header, Title => $title &>
120 <& /Elements/Tabs, QueryArgs => \%query &>
121 <& /Elements/ListActions, actions => \@actions &>
123 % $m->callback( ARGSRef => \%ARGS, CallbackName => 'BeforeChart' );
125 <& /Search/Elements/Chart, %ARGS &>
127 % $m->callback( ARGSRef => \%ARGS, CallbackName => 'AfterChart' );
129 <div class="chart-meta">
130 <div class="chart-type">
132 <form method="get" action="<% RT->Config->Get('WebPath') %>/Search/Chart.html">
133 <input type="hidden" class="hidden" name="Query" value="<% $query{Query} %>" />
134 <input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $saved_search->{SearchId} || 'new' %>" />
136 <&| /Widgets/TitleBox, title => loc('Group by'), class => "chart-group-by" &>
137 <fieldset><legend><% loc('Group tickets by') %></legend>
138 <& Elements/SelectGroupBy,
140 Query => $query{Query},
141 Default => $query{'GroupBy'}[0],
144 <fieldset><legend><% loc('and then') %></legend>
145 <& Elements/SelectGroupBy,
147 Query => $query{Query},
148 Default => $query{'GroupBy'}[1] // q{},
152 <fieldset><legend><% loc('and then') %></legend>
153 <& Elements/SelectGroupBy,
155 Query => $query{Query},
156 Default => $query{'GroupBy'}[2] // q{},
162 <&| /Widgets/TitleBox, title => loc("Calculate"), class => "chart-calculate" &>
164 <fieldset><legend><% loc('Calculate values of') %></legend>
165 <& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[0] &>
167 <fieldset><legend><% loc('and then') %></legend>
168 <& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[1] // q{}, ShowEmpty => 1 &>
170 <fieldset><legend><% loc('and then') %></legend>
171 <& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[2] // q{}, ShowEmpty => 1 &>
176 <&| /Widgets/TitleBox, title => loc('Picture'), class => "chart-picture" &>
177 <input name="ChartStyle" type="hidden" value="<% $query{ChartStyle}[0] %>" />
178 <label><% loc('Style') %>: <& Elements/SelectChartType, Default => $query{ChartStyle}[0] =~ /^(pie|bar|table)\b/ ? $1 : undef &></label>
180 <label><% loc("Width") %>: <input type="text" name="Width" value="<% $query{'Width'} || q{} %>"> <% loc("px") %></label>
182 <span class="height">
184 <label><% loc("Height") %>: <input type="text" name="Height" value="<% $query{'Height'} || q{} %>"> <% loc("px") %></label>
186 <div class="include-table">
187 <input type="checkbox" name="ChartStyleIncludeTable" <% $query{ChartStyle}[0] =~ /\btable\b/ ? 'checked="checked"' : '' |n %>> <% loc('Include data table') %>
189 <div class="include-sql">
190 <input type="checkbox" name="ChartStyleIncludeSQL" <% $query{ChartStyle}[0] =~ /\bsql\b/ ? 'checked="checked"' : '' |n %>> <% loc('Include TicketSQL query') %>
193 <script type="text/javascript">
194 var updateChartStyle = function() {
195 var val = jQuery(".chart-picture [name=ChartType]").val();
196 if ( val != 'table' && jQuery(".chart-picture [name=ChartStyleIncludeTable]").is(':checked') ) {
199 if ( jQuery(".chart-picture [name=ChartStyleIncludeSQL]").is(':checked') ) {
202 jQuery(".chart-picture [name=ChartStyle]").val(val);
204 jQuery(".chart-picture [name=ChartType]").change(function(){
205 var t = jQuery(this);
206 t.closest("form").find("[name=Height]").closest(".height").toggle( t.val() == 'bar' );
207 t.closest("form").find("[name=Width]").closest(".width").toggle( t.val() !== 'table' );
208 t.closest("form .chart-picture").find("div.include-table").toggle( t.val() !== 'table' );
212 jQuery(".chart-picture [name=ChartStyleIncludeTable]").change( updateChartStyle );
213 jQuery(".chart-picture [name=ChartStyleIncludeSQL]").change( updateChartStyle );
216 <& /Elements/Submit, Label => loc('Update Chart'), Name => 'Update' &>
220 <div class="saved-search">
221 <& /Widgets/SavedSearch:show, %ARGS, Action => 'Chart.html', self => $saved_search, Title => loc('Saved charts') &>