[Rt-commit] rt branch, 4.2/chart-ui-gc-settings, created. rt-4.2.3-84-g29d33f2

Wallace Reis wreis at bestpractical.com
Wed Apr 16 14:31:13 EDT 2014


The branch, 4.2/chart-ui-gc-settings has been created
        at  29d33f2cb9714c85520c6d976e812f4a214c79f9 (commit)

- Log -----------------------------------------------------------------
commit 29d33f2cb9714c85520c6d976e812f4a214c79f9
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Tue Feb 18 21:19:47 2014 -0300

    Issues#29015 - Saved chart should load settings
    
    Use the %ARGS which gets updated with data from $saved_search
    and still honor the request payload in case the user wants to
    update the chart.
    
    The _right_ order is something like:
      1. Saved search values
      2. or GET/POST parameters
      3. or parameters on last Search/Build.html page
      4. or some sane defaults

diff --git a/share/html/Search/Chart.html b/share/html/Search/Chart.html
index 32fb651..86bca97 100644
--- a/share/html/Search/Chart.html
+++ b/share/html/Search/Chart.html
@@ -45,24 +45,23 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<%args>
- at GroupBy => 'Status'
-$ChartStyle => 'bars'
- at ChartFunction => ('COUNT')
-$Description => undef
-$Width => undef
-$Height => undef
-</%args>
 <%init>
+my $default_value = {
+    Query => ['id > 0'],
+    GroupBy => ['Status'],
+    ChartStyle => 'bars',
+    ChartFunction => ['COUNT'],
+};
+    
 $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
 
-$ARGS{Query} ||= 'id > 0';
-
 my $title = loc( "Grouped search results");
 
+my @search_fields = qw(Query GroupBy ChartStyle ChartFunction Width Height);
 my $saved_search = $m->comp( '/Widgets/SavedSearch:new',
     SearchType   => 'Chart',
-    SearchFields => [qw(Query GroupBy ChartStyle ChartFunction Width Height)] );
+    SearchFields => [@search_fields],
+);
 
 my @actions = $m->comp( '/Widgets/SavedSearch:process', args => \%ARGS, self => $saved_search );
 
@@ -101,7 +100,14 @@ my %query;
 
 }
 
-$m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
+foreach (@search_fields) {
+    $query{$_} = ref $ARGS{$_} ? $ARGS{$_} : [ $ARGS{$_} ];
+    $query{$_} = $default_value->{$_}
+        unless defined $query{$_} && defined $query{$_}[0];
+}
+
+$m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%ARGS );
+
 </%init>
 <& /Elements/Header, Title => $title &>
 <& /Elements/Tabs, QueryArgs => \%query &>
@@ -117,30 +123,30 @@ $m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
 <div class="chart-type">
 
 <form method="get" action="<% RT->Config->Get('WebPath') %>/Search/Chart.html">
-<input type="hidden" class="hidden" name="Query" value="<% $ARGS{Query} %>" />
+<input type="hidden" class="hidden" name="Query" value="<% $query{Query}[0] %>" />
 <input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $saved_search->{SearchId} || 'new' %>" />
 
 <&| /Widgets/TitleBox, title => loc('Group by'), class => "chart-group-by" &>
 <fieldset><legend><% loc('Group tickets by') %></legend>
 <& Elements/SelectGroupBy,
     Name => 'GroupBy',
-    Query => $ARGS{Query},
-    Default => $GroupBy[0],
+    Query => $query{Query}[0],
+    Default => $query{'GroupBy'}[0],
     &>
 </fieldset>
 <fieldset><legend><% loc('and then') %></legend>
 <& Elements/SelectGroupBy,
     Name => 'GroupBy',
-    Query => $ARGS{Query},
-    Default => $GroupBy[1],
+    Query => $query{Query}[0],
+    Default => $query{'GroupBy'}[1] // q{},
     ShowEmpty => 1,
     &>
 </fieldset>
 <fieldset><legend><% loc('and then') %></legend>
 <& Elements/SelectGroupBy,
     Name => 'GroupBy',
-    Query => $ARGS{Query},
-    Default => $GroupBy[2],
+    Query => $query{Query}[0],
+    Default => $query{'GroupBy'}[2] // q{},
     ShowEmpty => 1,
     &>
 </fieldset>
@@ -149,23 +155,23 @@ $m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
 <&| /Widgets/TitleBox, title => loc("Calculate"), class => "chart-calculate" &>
 
 <fieldset><legend><% loc('Calculate values of') %></legend>
-<& Elements/SelectChartFunction, Default => $ChartFunction[0] &>
+<& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[0] &>
 </fieldset>
 <fieldset><legend><% loc('and then') %></legend>
-<& Elements/SelectChartFunction, Default => $ChartFunction[1], ShowEmpty => 1 &>
+<& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[1] // q{}, ShowEmpty => 1 &>
 </fieldset>
 <fieldset><legend><% loc('and then') %></legend>
-<& Elements/SelectChartFunction, Default => $ChartFunction[2], ShowEmpty => 1 &>
+<& Elements/SelectChartFunction, Default => $query{'ChartFunction'}[2] // q{}, ShowEmpty => 1 &>
 </fieldset>
 
 </&>
 
 <&| /Widgets/TitleBox, title => loc('Picture'), class => "chart-picture" &>
-<label><% loc('Style') %>: <& Elements/SelectChartType, Default => $ChartStyle, Name => 'ChartStyle' &></label>
-<label><% loc("Width") %>: <input type="text" name="Width" value="<% $Width || "" %>"> <% loc("px") %></label>
+<label><% loc('Style') %>: <& Elements/SelectChartType, Default => $query{ChartStyle}, Name => 'ChartStyle' &></label>
+<label><% loc("Width") %>: <input type="text" name="Width" value="<% $query{Width}[0] || "" %>"> <% loc("px") %></label>
 <span class="height">
   &#x00d7;
-  <label><% loc("Height") %>: <input type="text" name="Height" value="<% $Height || "" %>"> <% loc("px") %></label>
+  <label><% loc("Height") %>: <input type="text" name="Height" value="<% $query{Height}[0] || "" %>"> <% loc("px") %></label>
 </span>
 </&>
 <script type="text/javascript">

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


More information about the rt-commit mailing list