rt 4.2.15
[freeside.git] / rt / share / html / Search / Chart.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
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
16 %# from www.gnu.org.
17 %#
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.
22 %#
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.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
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.)
37 %#
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.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <%init>
49 my $default_value = {
50     Query => 'id > 0',
51     GroupBy => ['Status'],
52     ChartStyle => ['bar+table+sql'],
53     ChartFunction => ['COUNT'],
54 };
55     
56 $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
57
58 my $title = loc( "Grouped search results");
59
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],
64 );
65
66 my @actions = $m->comp( '/Widgets/SavedSearch:process', args => \%ARGS, self => $saved_search );
67
68 my %query;
69
70 {
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};
74         }
75     }
76
77     my $current = $session{'CurrentSearchHash'};
78
79     my @session_fields = qw(
80         Query
81         SavedChartSearchId
82         SavedSearchDescription
83         SavedSearchLoad
84         SavedSearchLoadButton
85         SavedSearchOwner
86     );
87
88     for(@session_fields) {
89         $query{$_} = $DECODED_ARGS->{$_} unless defined $query{$_};
90         $query{$_} = $current->{$_} unless defined $query{$_};
91     }
92
93     if ($DECODED_ARGS->{'SavedSearchLoadSubmit'}) {
94         $query{'SavedChartSearchId'} = $DECODED_ARGS->{'SavedSearchLoad'};
95     }
96
97     if ($DECODED_ARGS->{'SavedSearchSave'}) {
98         $query{'SavedChartSearchId'} = $saved_search->{'SearchId'};
99     }
100
101 }
102
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];
108     }
109     else {
110         $query{$_} = ref $ARGS{$_} ? $ARGS{$_} : $ARGS{$_};
111         $query{$_} = $default_value->{$_}
112             unless defined $query{$_};
113     }
114 }
115
116 $m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
117
118 </%init>
119 <& /Elements/Header, Title => $title &>
120 <& /Elements/Tabs, QueryArgs => \%query &>
121 <& /Elements/ListActions, actions => \@actions &>
122
123 % $m->callback( ARGSRef => \%ARGS, CallbackName => 'BeforeChart' );
124
125 <& /Search/Elements/Chart, %ARGS &>
126
127 % $m->callback( ARGSRef => \%ARGS, CallbackName => 'AfterChart' );
128
129 <div class="chart-meta">
130 <div class="chart-type">
131
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' %>" />
135
136 <&| /Widgets/TitleBox, title => loc('Group by'), class => "chart-group-by" &>
137 <fieldset><legend><% loc('Group tickets by') %></legend>
138 <& Elements/SelectGroupBy,
139     Name => 'GroupBy',
140     Query => $query{Query},
141     Default => $query{'GroupBy'}[0],
142     &>
143 </fieldset>
144 <fieldset><legend><% loc('and then') %></legend>
145 <& Elements/SelectGroupBy,
146     Name => 'GroupBy',
147     Query => $query{Query},
148     Default => $query{'GroupBy'}[1] // q{},
149     ShowEmpty => 1,
150     &>
151 </fieldset>
152 <fieldset><legend><% loc('and then') %></legend>
153 <& Elements/SelectGroupBy,
154     Name => 'GroupBy',
155     Query => $query{Query},
156     Default => $query{'GroupBy'}[2] // q{},
157     ShowEmpty => 1,
158     &>
159 </fieldset>
160 </&>
161
162 <&| /Widgets/TitleBox, title => loc("Calculate"), class => "chart-calculate" &>
163
164 <fieldset><legend><% loc('Calculate values of') %></legend>
165 <& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[0] &>
166 </fieldset>
167 <fieldset><legend><% loc('and then') %></legend>
168 <& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[1] // q{}, ShowEmpty => 1 &>
169 </fieldset>
170 <fieldset><legend><% loc('and then') %></legend>
171 <& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[2] // q{}, ShowEmpty => 1 &>
172 </fieldset>
173
174 </&>
175
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>
179 <span class="width">
180 <label><% loc("Width") %>: <input type="text" name="Width" value="<% $query{'Width'} || q{} %>"> <% loc("px") %></label>
181 </span>
182 <span class="height">
183   &#x00d7;
184   <label><% loc("Height") %>: <input type="text" name="Height" value="<% $query{'Height'} || q{} %>"> <% loc("px") %></label>
185 </span>
186 <div class="include-table">
187     <input type="checkbox" name="ChartStyleIncludeTable" <% $query{ChartStyle}[0] =~ /\btable\b/ ? 'checked="checked"' : '' |n %>> <% loc('Include data table') %>
188 </div>
189 <div class="include-sql">
190     <input type="checkbox" name="ChartStyleIncludeSQL" <% $query{ChartStyle}[0] =~ /\bsql\b/ ? 'checked="checked"' : '' |n %>> <% loc('Include TicketSQL query') %>
191 </div>
192 </&>
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') ) {
197         val += '+table';
198     }
199     if ( jQuery(".chart-picture [name=ChartStyleIncludeSQL]").is(':checked') ) {
200         val += '+sql';
201     }
202     jQuery(".chart-picture [name=ChartStyle]").val(val);
203 };
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' );
209     updateChartStyle();
210 }).change();
211
212 jQuery(".chart-picture [name=ChartStyleIncludeTable]").change( updateChartStyle );
213 jQuery(".chart-picture [name=ChartStyleIncludeSQL]").change( updateChartStyle );
214 </script>
215
216 <& /Elements/Submit, Label => loc('Update Chart'), Name => 'Update' &>
217 </form>
218
219 </div>
220 <div class="saved-search">
221     <& /Widgets/SavedSearch:show, %ARGS, Action => 'Chart.html', self => $saved_search, Title => loc('Saved charts') &>
222 </div>
223 </div>