[Rt-commit] rt branch, 4.4/copy-saved-charts, created. rt-4.4.4-129-gfeec798d3d
? sunnavy
sunnavy at bestpractical.com
Wed Aug 5 17:37:23 EDT 2020
The branch, 4.4/copy-saved-charts has been created
at feec798d3d18fa4151042675e3eef359ba883010 (commit)
- Log -----------------------------------------------------------------
commit 406252f3112fda7dfce4cf590f77cf11b2df5b30
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Aug 6 04:44:17 2020 +0800
Support to copy saved charts like searches
i.e. the "Save as New" button
diff --git a/share/html/Search/Chart.html b/share/html/Search/Chart.html
index efa0ca4551..44fb74a473 100644
--- a/share/html/Search/Chart.html
+++ b/share/html/Search/Chart.html
@@ -222,6 +222,6 @@ jQuery(".chart-picture [name=ChartStyleIncludeSQL]").change( updateChartStyle );
</div>
<div class="saved-search">
- <& /Widgets/SavedSearch:show, %ARGS, Action => 'Chart.html', self => $saved_search, Title => loc('Saved charts') &>
+ <& /Widgets/SavedSearch:show, %ARGS, Action => 'Chart.html', self => $saved_search, Title => loc('Saved charts'), AllowCopy => 1 &>
</div>
</div>
diff --git a/share/html/Widgets/SavedSearch b/share/html/Widgets/SavedSearch
index 3e2670b8f3..83e8370ba4 100644
--- a/share/html/Widgets/SavedSearch
+++ b/share/html/Widgets/SavedSearch
@@ -106,8 +106,8 @@ if ($self->{SearchId} eq 'new') {
}
}
-if ( $args->{SavedSearchSave} ) {
- if ( my $search = $self->{CurrentSearch}{Object} ) {
+if ( $args->{SavedSearchSave} || $args->{SavedSearchCopy} ) {
+ if ( ( my $search = $self->{CurrentSearch}{Object} ) && !$args->{SavedSearchCopy} ) {
# rename
$search->SetDescription( $args->{SavedSearchDescription} );
$search->SetSubValues(%$SearchParams);
@@ -115,6 +115,14 @@ if ( $args->{SavedSearchSave} ) {
}
else {
# new saved search
+ if ( $args->{SavedSearchCopy}
+ && $self->{CurrentSearch}{Object}
+ && ( !$args->{SavedSearchDescription}
+ || $args->{SavedSearchDescription} eq $self->{CurrentSearch}{Object}->Description )
+ )
+ {
+ $args->{SavedSearchDescription} = loc( "[_1] copy", $self->{CurrentSearch}{Object}->Description );
+ }
$SearchParams->{$_} //= $defaults->{$_} for @{$self->{SearchFields}};
@@ -166,7 +174,7 @@ $defaults => {}
Type => $self->{SearchType},
CurrentSearch => $self->{CurrentSearch},
Title => $Title,
- AllowCopy => 0,
+ AllowCopy => $AllowCopy,
$self->{CurrentSearch}{Object} ?
( Object => $self->{CurrentSearch}{Object},
Description => $self->{CurrentSearch}{Object}->Description, ) : (),
@@ -188,6 +196,7 @@ foreach my $field ( @{$self->{SearchFields}} ) {
$self => undef
$Action => ''
$Title => loc('Saved searches')
+$AllowCopy => 0
</%ARGS>
<%init>
</%init>
commit de3e4f500064e00bc84f54336dfc8638607a1b5c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Aug 6 05:17:51 2020 +0800
Refactor saved chart tests a bit to reduce code duplication by using a loop
We are going to add more tests there, so this will help more.
diff --git a/t/web/saved_search_chart.t b/t/web/saved_search_chart.t
index 27e64b69a7..b72faa17a9 100644
--- a/t/web/saved_search_chart.t
+++ b/t/web/saved_search_chart.t
@@ -128,29 +128,16 @@ sub page_chart_link_has {
);
}
-# load the first chart
-$m->field('SavedSearchLoad' => $saved_search_ids[0]);
-$m->click('SavedSearchLoadSubmit');
-
-page_chart_link_has($m, $saved_search_ids[0]);
-
-$m->form_name('SaveSearch');
-is($m->form_number(3)->value('SavedChartSearchId'), $saved_search_ids[0]);
-
-$m->form_name('SaveSearch');
-
-# now load the second chart
-$m->field('SavedSearchLoad' => $saved_search_ids[1]);
-$m->click('SavedSearchLoadSubmit');
-
-page_chart_link_has($m, $saved_search_ids[1]);
+for my $i ( 0 .. 1 ) {
+ $m->form_name('SaveSearch');
-is(
- $m->form_number(3)->value('SavedChartSearchId'), $saved_search_ids[1],
- 'Second form is seen as a hidden field'
-);
+ # load chart $saved_search_ids[$i]
+ $m->field( 'SavedSearchLoad' => $saved_search_ids[$i] );
+ $m->click('SavedSearchLoadSubmit');
+ page_chart_link_has( $m, $saved_search_ids[$i] );
+ is( $m->form_number(3)->value('SavedChartSearchId'), $saved_search_ids[$i] );
+}
-page_chart_link_has($m, $saved_search_ids[1]);
diag "saving a chart without changing its config shows up on dashboards (I#31557)";
{
commit feec798d3d18fa4151042675e3eef359ba883010
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Aug 6 05:21:19 2020 +0800
Test the copy feature of saved charts
diff --git a/t/web/saved_search_chart.t b/t/web/saved_search_chart.t
index b72faa17a9..24c492e558 100644
--- a/t/web/saved_search_chart.t
+++ b/t/web/saved_search_chart.t
@@ -106,12 +106,22 @@ for ([A => 'subject="'.$$.'A"'], [BorC => 'subject="'.$$.'B" OR subject="'.$$.'C
}
+$m->submit_form(
+ form_name => 'SaveSearch',
+ fields => {
+ SavedSearchDescription => 'a copy',
+ SavedSearchOwner => $owner,
+ },
+ button => 'SavedSearchCopy',
+);
+$m->text_contains('Chart a copy saved.');
+
$m->form_name('SaveSearch');
my @saved_search_ids =
$m->current_form->find_input('SavedSearchLoad')->possible_values;
shift @saved_search_ids; # first value is blank
-cmp_ok(@saved_search_ids, '==', 2, 'Two saved charts were made');
+cmp_ok(@saved_search_ids, '==', 3, '3 saved charts were made');
# TODO get find_link('page-chart')->URI->params to work...
sub page_chart_link_has {
@@ -128,7 +138,7 @@ sub page_chart_link_has {
);
}
-for my $i ( 0 .. 1 ) {
+for my $i ( 0 .. 2 ) {
$m->form_name('SaveSearch');
# load chart $saved_search_ids[$i]
@@ -138,6 +148,18 @@ for my $i ( 0 .. 1 ) {
is( $m->form_number(3)->value('SavedChartSearchId'), $saved_search_ids[$i] );
}
+diag "testing the content of chart copy content";
+{
+ my ($from) = $saved_search_ids[1] =~ /SavedSearch-(\d+)$/;
+ my ($to) = $saved_search_ids[2] =~ /SavedSearch-(\d+)$/;
+ my $from_attr = RT::Attribute->new( RT->SystemUser );
+ $from_attr->Load($from);
+ ok( $from_attr->Id, "Found attribute #$from" );
+ my $to_attr = RT::Attribute->new( RT->SystemUser );
+ $to_attr->Load($to);
+ ok( $to_attr->Id, "Found attribute #$to" );
+ is_deeply( $from_attr->Content, $to_attr->Content, 'Chart copy content is correct' );
+}
diag "saving a chart without changing its config shows up on dashboards (I#31557)";
{
@@ -155,7 +177,7 @@ diag "saving a chart without changing its config shows up on dashboards (I#31557
@saved_search_ids =
$m->current_form->find_input('SavedSearchLoad')->possible_values;
shift @saved_search_ids; # first value is blank
- my $chart_without_updates_id = $saved_search_ids[2];
+ my $chart_without_updates_id = $saved_search_ids[3];
ok($chart_without_updates_id, 'got a saved chart id');
my ($privacy, $user_id, $search_id) = $chart_without_updates_id =~ /^(RT::User-(\d+))-SavedSearch-(\d+)$/;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list