[Rt-commit] rt branch, 4.2/chart-ui-gc-settings, created. rt-4.2.3-87-g2fef6eb
Wallace Reis
wreis at bestpractical.com
Thu Apr 24 17:26:16 EDT 2014
The branch, 4.2/chart-ui-gc-settings has been created
at 2fef6eb5b59e74581646b7db59a95ad0f3870ab3 (commit)
- Log -----------------------------------------------------------------
commit 2fef6eb5b59e74581646b7db59a95ad0f3870ab3
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..e1591b8 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,21 @@ my %query;
}
-$m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
+foreach (@search_fields) {
+ if ( ref $default_value->{$_} ) {
+ $query{$_} = ref $ARGS{$_} ? $ARGS{$_} : [ $ARGS{$_} ];
+ $query{$_} = $default_value->{$_}
+ unless defined $query{$_} && defined $query{$_}[0];
+ }
+ else {
+ $query{$_} = ref $ARGS{$_} ? $ARGS{$_} : $ARGS{$_};
+ $query{$_} = $default_value->{$_}
+ unless defined $query{$_};
+ }
+}
+
+$m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%ARGS );
+
</%init>
<& /Elements/Header, Title => $title &>
<& /Elements/Tabs, QueryArgs => \%query &>
@@ -117,30 +130,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} %>" />
<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},
+ Default => $query{'GroupBy'}[0],
&>
</fieldset>
<fieldset><legend><% loc('and then') %></legend>
<& Elements/SelectGroupBy,
Name => 'GroupBy',
- Query => $ARGS{Query},
- Default => $GroupBy[1],
+ Query => $query{Query},
+ 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},
+ Default => $query{'GroupBy'}[2] // q{},
ShowEmpty => 1,
&>
</fieldset>
@@ -149,23 +162,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}[0], Name => 'ChartStyle' &></label>
+<label><% loc("Width") %>: <input type="text" name="Width" value="<% $query{'Width'} || q{} %>"> <% loc("px") %></label>
<span class="height">
×
- <label><% loc("Height") %>: <input type="text" name="Height" value="<% $Height || "" %>"> <% loc("px") %></label>
+ <label><% loc("Height") %>: <input type="text" name="Height" value="<% $query{'Height'} || q{} %>"> <% loc("px") %></label>
</span>
</&>
<script type="text/javascript">
-----------------------------------------------------------------------
More information about the rt-commit
mailing list