[Rt-commit] r6571 - in rt/branches/3.6-RELEASE: . html/Search
html/Search/Elements
jesse at bestpractical.com
jesse at bestpractical.com
Fri Dec 1 13:57:55 EST 2006
Author: jesse
Date: Fri Dec 1 13:57:54 2006
New Revision: 6571
Added:
rt/branches/3.6-RELEASE/html/Widgets/SavedSearch
Modified:
rt/branches/3.6-RELEASE/ (props changed)
rt/branches/3.6-RELEASE/html/Search/Chart.html
rt/branches/3.6-RELEASE/html/Search/Elements/EditSearches
Log:
r45311 at pinglin (orig r6508): clkao | 2006-11-23 05:24:36 -0500
Support load and save for charts, in a separate widget SavedSearch.
Modified: rt/branches/3.6-RELEASE/html/Search/Chart.html
==============================================================================
--- rt/branches/3.6-RELEASE/html/Search/Chart.html (original)
+++ rt/branches/3.6-RELEASE/html/Search/Chart.html Fri Dec 1 13:57:54 2006
@@ -46,60 +46,20 @@
<%args>
$Query => "id > 0"
$PrimaryGroupBy => 'Queue'
-$SecondaryGroupBy => undef
+$SecondaryGroupBy => ''
$ChartStyle => 'bars'
$Description => undef
-
</%args>
<%init>
-my $title = loc( "Search results grouped by [_1]", $PrimaryGroupBy );
+$ARGS{SecondaryGroupBy} ||= '';
-my @Objects = RT::SavedSearches->new( $session{CurrentUser} )->_PrivacyObjects;
-push @Objects, RT::System->new($session{'CurrentUser'})
- if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
- Right => 'SuperUser');
-# look for the current one in the available saved searches
-my $SearchParams = {
- Query => $Query,
- PrimaryGroupBy => $PrimaryGroupBy,
- SecondaryGroupBy => $SecondaryGroupBy || '',
- ChartStyle => $ChartStyle
-};
+my $title = loc( "Search results grouped by [_1]", $PrimaryGroupBy );
-my $CurrentSearch;
-my $SearchId = 'new';
-for my $obj (@Objects) {
- for ( $m->comp( "/Search/Elements/SearchesForObject", Object => $obj ) ) {
- my ( $desc, $search ) = @$_;
- use Data::Dumper;
- # FFS
- $Data::Dumper::Sortkeys = 1;
- if ( Dumper( $search->Content ) eq
- Dumper( { %$SearchParams, SearchType => 'Chart' } ) )
- {
- $CurrentSearch->{Object} = $search;
- $CurrentSearch->{Description} = $search->Description;
- $SearchId = $search->Id;
- warn "got... $SearchId";
- }
- }
-}
+my $saved_search = $m->comp( '/Widgets/SavedSearch:new',
+ SearchType => 'Chart',
+ SearchFields => [qw(Query PrimaryGroupBy SecondaryGroupBy ChartStyle)] );
-my @actions;
-if ( $ARGS{Save} ) {
- my $saved_search = RT::SavedSearch->new( $session{'CurrentUser'} );
- my ( $ok, $search_msg ) = $saved_search->Save(
- Privacy => $ARGS{'Owner'},
- Name => $Description,
- Type => 'Chart',
- SearchParams => $SearchParams );
- if ($ok) {
- push @actions, loc( 'Chart [_1] saved.', $Description );
- }
- else {
- push @actions, [ loc("Can't save chart").': '.loc($search_msg), 0 ];
- }
-}
+my @actions = $m->comp( '/Widgets/SavedSearch:process', args => \%ARGS, self => $saved_search );
</%init>
<& /Elements/Header, Title => $title &>
@@ -107,14 +67,4 @@
<& /Elements/ListActions, actions => \@actions &>
<& /Search/Elements/Chart, %ARGS &>
-<form method="post" action="Chart.html" name="SaveChart">
-
-<& Elements/EditSearches, Name => 'Owner', SearchType => 'Chart',
- CurrentSearch => $CurrentSearch, SearchId => $SearchId &><br />
-<input type="hidden" class="hidden" name="Query" value="<%$Query%>" />
-<input type="hidden" class="hidden" name="PrimaryGroupBy" value="<%$PrimaryGroupBy%>" />
-<input type="hidden" class="hidden" name="SecondaryGroupBy" value="<%$SecondaryGroupBy%>" />
-<input type="hidden" class="hidden" name="ChartStyle" value="<%$ChartStyle%>" />
-
-<input type="submit" name="Save" value="<%loc('Save')%>" class="button" />
-</form>
+<& /Widgets/SavedSearch:show, %ARGS, Action => 'Chart.html', self => $saved_search &>
Modified: rt/branches/3.6-RELEASE/html/Search/Elements/EditSearches
==============================================================================
--- rt/branches/3.6-RELEASE/html/Search/Elements/EditSearches (original)
+++ rt/branches/3.6-RELEASE/html/Search/Elements/EditSearches Fri Dec 1 13:57:54 2006
@@ -61,7 +61,9 @@
<input type="submit" class="button" name="Revert" value="<%loc('Revert')%>" />
% }
<input type="submit" class="button" name="Delete" value="<%loc('Delete')%>" />
+% if ($AllowCopy) {
<input type="submit" class="button" name="CopySearch" value="<%loc('Copy')%>" />
+% }
</nobr>
% }
@@ -93,4 +95,5 @@
$Description => undef
$HideResults => 0
$Dirty => 0
+$AllowCopy => 1
</%ARGS>
Added: rt/branches/3.6-RELEASE/html/Widgets/SavedSearch
==============================================================================
--- (empty file)
+++ rt/branches/3.6-RELEASE/html/Widgets/SavedSearch Fri Dec 1 13:57:54 2006
@@ -0,0 +1,103 @@
+<%method new>
+<%init>
+return \%ARGS;
+</%init>
+</%method>
+
+<%method process>
+
+<%init>
+my @actions;
+my @Objects = RT::SavedSearches->new( $session{CurrentUser} )->_PrivacyObjects;
+push @Objects, RT::System->new($session{'CurrentUser'})
+ if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
+ Right => 'SuperUser');
+$self->{SearchId} ||= 'new';
+my $SearchParams = { map { $_ => $args->{$_} } @{$self->{SearchFields}} };
+
+if ( my ( $container_object, $search_id ) = _parse_saved_search( $args->{'LoadSavedSearch'} ) ) {
+ my $search = $container_object->Attributes->WithId($search_id);
+ # We have a $search and now; import the others
+ $self->{SearchId} = $args->{'LoadSavedSearch'};
+ $self->{CurrentSearch}{Object} = $search;
+ $args->{$_} = $search->SubValue($_) for @{ $self->{SearchFields} };
+}
+
+# look for the current one in the available saved searches
+if ($self->{SearchId} eq 'new') {
+ for my $obj (@Objects) {
+ for ( $m->comp( "/Search/Elements/SearchesForObject", Object => $obj ) ) {
+ my ( $desc, $search ) = @$_;
+ use Data::Dumper;
+ # FFS
+ local $Data::Dumper::Sortkeys = 1;
+ if ( Dumper( $search->Content ) eq
+ Dumper( { %$SearchParams, SearchType => $self->{SearchType} } ) ) {
+ $self->{CurrentSearch}{Object} = $search;
+ $self->{SearchId} = $search->Id;
+ }
+ }
+ }
+}
+
+if ( $args->{Save} ) {
+ if ( my $search = $self->{CurrentSearch}{Object} ) {
+ # rename
+ $search->SetDescription( $args->{Description} );
+ push @actions, loc($self->{SearchType}).loc( ' [_1] renamed to [_2].', $self->{CurrentSearch}{Description}, $args->{Description} );
+ }
+ else {
+ # new saved search
+ my $saved_search = RT::SavedSearch->new( $session{'CurrentUser'} );
+ my ( $ok, $search_msg ) = $saved_search->Save(
+ Privacy => $args->{'Owner'},
+ Name => $args->{'Description'},
+ Type => $self->{'SearchType'},
+ SearchParams => $SearchParams
+ );
+ if ($ok) {
+ $self->{CurrentSearch}{Object} = $saved_search->{Attribute};
+ push @actions, loc($self->{SearchType}).loc( ' [_1] saved.', $args->{Description} );
+ } else {
+ push @actions,
+ [ loc("Can't save [_1]", loc($self->{SearchType})) . ': ' . loc($search_msg), 0 ];
+ }
+ }
+}
+
+if ( $args->{Delete} && $self->{CurrentSearch}{Object} ) {
+ my ($ok, $msg) = $self->{CurrentSearch}{Object}->Delete;
+ push @actions, $ok ? loc($self->{SearchType}).loc( ' [_1] deleted.', $self->{CurrentSearch}{Object}->Description ) : $msg;
+ delete $self->{CurrentSearch}{Object};
+ delete $self->{SearchId};
+
+}
+
+$self->{CurrentSearch}{Description} = $self->{CurrentSearch}{Object}->Description
+ if $self->{CurrentSearch}{Object};
+
+return @actions;
+</%init>
+<%ARGS>
+$self
+$args
+</%ARGS>
+
+</%method>
+
+<%method show>
+<form method="post" action="<% $Action %>" name="SaveSearch">
+<& /Search/Elements/EditSearches, Name => 'Owner', SearchType => $self->{SearchType}, AllowCopy => 0,
+ CurrentSearch => $self->{CurrentSearch}, SearchId => $self->{SearchId} &><br />
+% for my $field (@{$self->{SearchFields}}) {
+<input type="hidden" class="hidden" name="<%$field%>" value="<%$ARGS{$field} || ''%>" />
+% }
+<input type="submit" name="Save" value="<%loc('Save')%>" class="button" />
+</form>
+<%ARGS>
+$self => undef
+$Action => ''
+</%ARGS>
+<%init>
+</%init>
+</%method>
More information about the Rt-commit
mailing list