[Rt-commit] [svn] r1166 - in rt/branches/rt-3.1/html/Search: .
Elements
alexmv at pallas.eruditorum.org
alexmv at pallas.eruditorum.org
Tue Jun 29 07:11:13 EDT 2004
Author: alexmv
Date: Tue Jun 29 07:11:12 2004
New Revision: 1166
Modified:
rt/branches/rt-3.1/html/Search/Build.html
rt/branches/rt-3.1/html/Search/Elements/EditSearches
Log:
RT-Ticket: 5720
RT-Status: resolved
RT-Update: correspond
* Saved searches now store "order by" and "rows per page" (#5720)
* Fixed bug where Format was not being correctly displayed after
loading from session or save (#5780)
* Consolidate code (one section for defaults)
* Use only one <form> per page instead of three
* Save a database hit on checking for dirty searches
Modified: rt/branches/rt-3.1/html/Search/Build.html
==============================================================================
--- rt/branches/rt-3.1/html/Search/Build.html (original)
+++ rt/branches/rt-3.1/html/Search/Build.html Tue Jun 29 07:11:12 2004
@@ -27,17 +27,17 @@
Title => $title,
Format => $Format,
Query => $Query,
- Rows => $ARGS{'Rows'},
- OrderBy => $ARGS{'OrderBy'}
+ OrderBy => $OrderBy,
+ Rows => $RowsPerPage
&>
-<table width=100%>
-<tr>
-<td valign=top class="boxcontainer">
<FORM METHOD="POST" ACTION="Build.html" NAME="BuildQuery">
<input type=hidden name=SearchId value="<%$SearchId%>">
<input type=hidden name=Query value="<%$Query%>">
<input type=hidden name=Format value="<%$Format%>">
+<table width=100%>
+<tr>
+<td valign=top class="boxcontainer">
<& Elements/PickCriteria, query => $Query, cfqueues => \%queues &>
<& /Elements/Submit, Caption => loc('Add additional criteria'), Label => loc('Add'), Name => 'AddClause'&>
@@ -60,28 +60,19 @@
%#<input type=submit name="EditQuery" value="Advanced">
</center>
<& /Elements/TitleBoxEnd &>
-</form>
<br>
-<FORM METHOD="POST" ACTION="Build.html" NAME="SavedSearch">
-<input type=hidden name=Query value="<%$Query%>">
-<input type=hidden name=Format value="<%$Format%>">
-<& Elements/EditSearches, CurrentSearch => $search_hash, Dirty => $dirty &>
-</FORM>
+<& Elements/EditSearches, CurrentSearch => $search_hash, Dirty => $dirty, SearchId => $SearchId &>
</td>
</tr>
<tr>
<td colspan=2 class="boxcontainer">
-<FORM METHOD="POST" ACTION="Build.html" NAME="EditFormat">
-<input type=hidden name=Query value="<%$Query%>">
-<input type=hidden name=Format value="<%$Format%>">
-<input type=hidden name=SearchId value="<%$SearchId%>">
<& Elements/DisplayOptions, %ARGS, Format=> $Format,
-AvailableColumns => $AvailableColumns, CurrentFormat => $CurrentFormat &>
-</FORM>
+AvailableColumns => $AvailableColumns, CurrentFormat => $CurrentFormat, RowsPerPage => $RowsPerPage, OrderBy => $OrderBy &>
</td>
</tr>
</table>
+</FORM>
<%INIT>
use Tree::Simple;
@@ -90,27 +81,41 @@
my $search;
my $title = loc("Query Builder");
-if ($NewQuery) {
- # Wipe everything clear if we want a new search
+# {{{ Clear out unwanted data
+if ($NewQuery or $ARGS{'Delete'}) {
+ # Wipe all seven data-carrying variables clear if we want a new
+ # search, or we're deleting an old one..
$Query = '';
$Format = '';
$Description = '';
- $SearchId = 'new';
+ $SearchId = '';
+ $OrderBy = '';
+ $RowsPerPage = '';
+ # ($search hasn't been set yet; no need to clear)
+
+ # ..then wipe the session out..
undef $session{'CurrentSearchHash'};
+
+ # ..and the search results.
$session{'tickets'}->CleanSlate() if defined $session{'tickets'};
-} else {
- # Otherwise, attempt to load what we can from the session
- # We don't read or write to the session again until the end
- $search_hash = $session{'CurrentSearchHash'};
-
- # These five variables are what define a search
- $Query ||= $search_hash->{'Query'};
- $Format ||= $search_hash->{'Format'};
- $Description ||= $search_hash->{'Description'};
- $SearchId ||= $search_hash->{'SearchId'} || 'new';
- $ARGS{'OrderBy'} ||= $search_hash->{'OrderBy'} || 'id';
- $search ||= $search_hash->{'Object'};
}
+# }}}
+
+# {{{ Attempt to load what we can from the session
+
+# We don't read or write to the session again until the end
+$search_hash = $session{'CurrentSearchHash'};
+
+# These seven variables are what define a search_hash; this is also
+# where we give sane defaults.
+$Query ||= $search_hash->{'Query'};
+$Format ||= $search_hash->{'Format'};
+$Description ||= $search_hash->{'Description'};
+$SearchId ||= $search_hash->{'SearchId'} || 'new';
+$OrderBy ||= $search_hash->{'OrderBy'} || 'id';
+$RowsPerPage ||= $search_hash->{'RowsPerPage'} || 50;
+$search ||= $search_hash->{'Object'};
+# }}}
my @actions = ();
my %queues;
@@ -120,7 +125,8 @@
# {{{ If we're asked to delete the current search, make it go away and reset the search parameters
if ( $ARGS{'Delete'} ) {
- if ( $SearchId =~ /^(.*?)-(\d+)-SavedSearch-(\d+)$/ ) {
+ # We set $SearchId to 'new' above already, so peek into the %ARGS
+ if ( $ARGS{'SearchId'} =~ /^(.*?)-(\d+)-SavedSearch-(\d+)$/ ) {
my $obj_type = $1;
my $obj_id = $2;
my $search_id = $3;
@@ -138,14 +144,6 @@
# We have the object the entry is an attribute on; delete
# the entry..
$container_object->Attributes->DeleteEntry( Name => 'SavedSearch', id => $search_id);
-
- # And wipe the slate clean
- $Format = '';
- $Query = '';
- $SearchId = 'new';
- undef $search;
- $Description = '';
- $session{'tickets'}->CleanSlate() if defined $session{'tickets'};
}
}
@@ -190,6 +188,8 @@
$Description = $search->Description;
$Format = $search->SubValue('Format');
$Query = $search->SubValue('Query');
+ $OrderBy = $search->SubValue('OrderBy');
+ $RowsPerPage = $search->SubValue('RowsPerPage');
}
# }}}
@@ -648,39 +648,20 @@
# {{{ Deal with format changes
my ($AvailableColumns, $CurrentFormat);
-($Format, $AvailableColumns, $CurrentFormat) = $m->comp('Elements/BuildFormatString', cfqueues => \%queues, %ARGS);
+($Format, $AvailableColumns, $CurrentFormat) = $m->comp('Elements/BuildFormatString', cfqueues => \%queues, %ARGS, Format => $Format);
# }}}
-# {{{ If we're modifying an old query, check if it has changed
-my $dirty = 0;
-if ($SearchId =~ /^(.*?)-(\d+)-SavedSearch-(\d+)$/) {
- my $obj_type = $1;
- my $obj_id = $2;
- my $search_id = $3;
-
- my $oldsearch;
- if ( ( $obj_type eq 'RT::User' ) && ( $obj_id == $session{'CurrentUser'}->id ) ) {
- $oldsearch = $session{'CurrentUser'}->UserObj->Attributes->WithId($search_id);
- }
- elsif ($obj_type eq 'RT::Group') {
- my $group = RT::Group->new($session{'CurrentUser'});
- $group->Load($obj_id);
- $oldsearch = $group->Attributes->WithId($search_id);
- }
- $dirty = 1 if $oldsearch->SubValue('Format') ne $Format
- or $oldsearch->SubValue('Query') ne $Query;
-}
-#}}}
-
# {{{ if we're asked to save the current search, save it
if ( $ARGS{'Save'} ) {
if ($search && $search->id) {
- # This search is based on a previously loades search -- so
+ # This search is based on a previously loaded search -- so
# just update the current search object with new values
$search->SetSubValues(
- Format => $Format,
- Query => $Query,
+ Format => $Format,
+ Query => $Query,
+ OrderBy => $OrderBy,
+ RowsPerPage => $RowsPerPage,
);
$search->SetDescription( $Description );
@@ -694,7 +675,7 @@
# Find out if we're saving on the user, or a group
my $container_object;
if ( $obj_type eq 'RT::User' && $obj_id == $session{'CurrentUser'}->Id) {
- $container_object = $session{'CurrentUser'}->UserObj;
+ $container_object = $session{'CurrentUser'}->UserObj;
}
elsif ($obj_type eq 'RT::Group') {
$container_object = RT::Group->new($session{'CurrentUser'});
@@ -707,8 +688,10 @@
Name => 'SavedSearch',
Description => $Description,
Content => {
- Format => $Format,
- Query => $Query
+ Format => $Format,
+ Query => $Query,
+ OrderBy => $OrderBy,
+ RowsPerPage => $RowsPerPage,
}
);
$search = $session{'CurrentUser'}->UserObj->Attributes->WithId($search_id);
@@ -726,7 +709,15 @@
}
}
+# }}}
+# {{{ If we're modifying an old query, check if it has changed
+my $dirty = 0;
+$dirty = 1 if defined $search and
+ ($search->SubValue('Format') ne $Format or
+ $search->SubValue('Query') ne $Query or
+ $search->SubValue('OrderBy') ne $OrderBy or
+ $search->SubValue('RowsPerPage') ne $RowsPerPage);
# }}}
# {{{ Push the updates into the session so we don't loose 'em
@@ -735,14 +726,15 @@
$search_hash->{'Query'} = $Query;
$search_hash->{'Description'} = $Description;
$search_hash->{'Object'} = $search;
-$search_hash->{'OrderBy'} = $ARGS{'OrderBy'};
+$search_hash->{'OrderBy'} = $OrderBy;
+$search_hash->{'RowsPerPage'} = $RowsPerPage;
$session{'CurrentSearchHash'} = $search_hash;
# }}}
# {{{ Show the results, if we were asked.
if ( $ARGS{"DoSearch"} ) {
- $m->comp("Results.html" , Query => $Query, Format => $Format, OrderBy => $ARGS{OrderBy}, Rows => $ARGS{RowsPerPage});
+ $m->comp("Results.html" , Query => $Query, Format => $Format, OrderBy => $OrderBy, Rows => $RowsPerPage);
$m->abort();
}
# }}}
@@ -755,8 +747,9 @@
} else {
$QueryString = '?' . $m->comp('/Elements/QueryString',
Query => $Query,
- Format => $Format,
- Rows =>$ARGS{'Rows'}) if ($Query);
+ Format => $Format,
+ OrderBy => $OrderBy,
+ Rows => $RowsPerPage) if ($Query);
}
# }}}
@@ -768,5 +761,7 @@
$Query => undef
$Format => undef
$Description => undef
+$OrderBy => undef
+$RowsPerPage => undef
$HideResults => 0
</%ARGS>
Modified: rt/branches/rt-3.1/html/Search/Elements/EditSearches
==============================================================================
--- rt/branches/rt-3.1/html/Search/Elements/EditSearches (original)
+++ rt/branches/rt-3.1/html/Search/Elements/EditSearches Tue Jun 29 07:11:12 2004
@@ -1,5 +1,4 @@
<& /Elements/TitleBoxStart, title => loc('Saved searches') &>
-<input type="hidden" name="SearchId" value="<%$SearchId%>">
<&|/l&>Privacy:</&>
% if ($CurrentSearch->{'Object'} && $CurrentSearch->{'Object'}->id) {
<& SearchPrivacy, Object => $CurrentSearch->{'Object'}->Object &><br>
@@ -39,15 +38,10 @@
Recursively => 1);
push (@Objects, @{$groups->ItemsArrayRef()});
-
-if ($CurrentSearch->{'SearchId'}) {
- $SearchId= $CurrentSearch->{'SearchId'};
-}
-
</%INIT>
<%ARGS>
-$SearchId => 'new'
+$SearchId => undef
$CurrentSearch => undef
$Description => undef
$HideResults => 0
More information about the Rt-commit
mailing list