[Rt-commit] r2606 - in rtfm/branches/2.1-TESTING/html/RTFM/Article:
. Elements
tla at bestpractical.com
tla at bestpractical.com
Mon Apr 11 14:46:26 EDT 2005
Author: tla
Date: Mon Apr 11 14:46:26 2005
New Revision: 2606
Modified:
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria
rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
Log:
Checkpoint. Still working on making it work.
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSavedSearches Mon Apr 11 14:46:26 2005
@@ -44,25 +44,27 @@
%#
%# END BPS TAGGED BLOCK }}}
<select name="<%$Name%>">
-% foreach my $object (@objects) {
-% my @searches = $object->Attributes->Named('ArticleSavedSearch');
-% next unless @searches;
-% if ($object->Id == $session{'CurrentUser'}->UserObj->Id) {
+% foreach my $privacy (keys %privacies) {
+% my $searches = RT::SavedSearches->new($session{'CurrentUser'});
+% $searches->Limit($privacy, 'Article');
+% next unless $searches->Count;
+% if ($privacy =~ /^RT::User/) {
<option value=""><&|/l&>My saved searches</&></option>
% } else {
-<option value=""><&|/l, $object->Name&>[_1]'s saved searches</&></option>
+<option value=""><&|/l, $privacies{$privacy}->Name&>[_1]'s saved searches</&></option>
% }
-% foreach my $search (@searches) {
-<option value="<%ref($object)%>-<%$object->id%>-ArticleSavedSearch-<%$search->Id%>"> -<%$search->Description||loc('Unnamed search')%></option>
+% while (my $search = $searches->Next) {
+<option value="<%$privacy%>-SavedSearch-<%$search->Id%>"> -<%$search->Name||loc('Unnamed search')%></option>
% }
% }
</select>
<%init>
+use RT::SavedSearches;
my $groups = $session{'CurrentUser'}->UserObj->OwnGroups;
-my @objects;
-push(@objects, $session{'CurrentUser'}->UserObj);
-push(@objects, @{$groups->ItemsArrayRef});
+my %privacies;
+$privacies{'RT::User-' . $session{'CurrentUser'}->UserObj->Id} = 1;
+map { $privacies{'RT::Group-'.$_->Id} = $_ } @{$groups->ItemsArrayRef};
</%init>
<%args>
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/SelectSearchPrivacy Mon Apr 11 14:46:26 2005
@@ -44,9 +44,9 @@
%#
%# END BPS TAGGED BLOCK }}}
<select name="<%$Name%>">
-<option value="User-<% $user->Id %>">My searches</option>
+<option value="RT::User-<% $user->Id %>">My searches</option>
% while (my $group = $groups->Next) {
-<option value="Group-<% $group->Id %>"><% $group->Name %>'s searches</option>
+<option value="RT::Group-<% $group->Id %>"><% $group->Name %>'s searches</option>
% }
</select>
<%INIT>
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSavedSearches Mon Apr 11 14:46:26 2005
@@ -44,12 +44,14 @@
%#
%# END BPS TAGGED BLOCK }}}
<& /Elements/TitleBoxStart, title => loc('Saved searches') &>
+%# Keep track of what our current search ID is.
+<input type="hidden" name="CurrentSearch" value="<% $CurrentSearch ? $CurrentSearch : 'new' %>">
%# Hide all the save functionality if the user shouldn't see it.
% if ($session{'CurrentUser'}->HasRight( Right => 'CreateSavedSearch',
% Object=> $RT::System )) {
<&|/l&>Save the current search:</&><br>
-<&|/l&>Name:</&> <input name="NewSearchName">
-<&|/l&>Privacy:</&> <& SelectSearchPrivacy &><br>
+<&|/l&>Name:</&> <input name="NewSearchName" value="<%$Description%>">
+<&|/l&>Privacy:</&> <& SelectSearchPrivacy, Name => 'SearchPrivacy' &><br>
<input value="<%loc('Save')%>" name="Save" type="submit">
<hr>
% } # if HasRight 'CreateSavedSearch'
@@ -68,9 +70,6 @@
</%INIT>
<%ARGS>
-$SearchId => undef
$CurrentSearch => undef
$Description => undef
-$HideResults => 0
-$Dirty => 0
</%ARGS>
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchCriteria Mon Apr 11 14:46:26 2005
@@ -22,7 +22,6 @@
<a href="Search.html?<%$qs%>"><&|/l&>Show advanced search options...</&></a>
% } else {
<& /Elements/TitleBoxStart, title => loc('Advanced Search Criteria')&>
-<form action="Search.html" method="GET">
<br>
<table>
<tr valign="middle">
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html Mon Apr 11 14:46:26 2005
@@ -17,17 +17,94 @@
%# END LICENSE BLOCK
<& /RTFM/Article/Elements/Tabs, current_tab => "RTFM/Article/Search.html", Title => loc("Search for articles") &>
+<& /Elements/ListActions, actions => \@results &>
<& Elements/ShowSearchResults, articles => $articles &>
-<& Elements/ShowSavedSearches &>
-
+<form action="Search.html" method="GET">
+<& Elements/ShowSavedSearches, CurrentSearch => $CurrentSearch,
+ Description => ($search ? $search->Name : undef) &>
<& Elements/ShowSearchCriteria, dates => \%dates, RefersTo => $RefersTo, customfields => $customfields, ReferredToBy => $ReferredToBy, %ARGS &>
<%init>
+use RT::SavedSearch;
my @results;
-
my $articles = RT::FM::ArticleCollection->new( $session{'CurrentUser'} );
+# {{{ Saved search logic
+
+my $search;
+
+# The keys that are not saved and loaded with named searches. These
+# need to be treated specially.
+my @metakeys = qw/NewSearchName CurrentSearch SearchPrivacy Save Load/;
+
+if ($CurrentSearch =~ /^(.*-\d+)-SavedSearch-(\d+)$/) {
+ $search = RT::SavedSearch->new($session{'CurrentUser'});
+ $search->Load($1, $2);
+}
+
+# Have we been asked to load a search?
+
+if ( $ARGS{'LoadSavedSearch'} =~ /^(.*-\d+)-SavedSearch-(\d+)$/ ) {
+ my $privacy = $1;
+ my $search_id = $3;
+
+ $search = RT::SavedSearch->new($session{'CurrentUser'});
+ $search->Load($privacy, $search_id);
+ if ($search->Id) {
+ my $searchargs = $search->GetParameter('args');
+ # Clean out ARGS and fill it in with the saved args from the
+ # loaded search.
+ foreach my $key (@metakeys) {
+ $searchargs->{$key} = $ARGS{$key};
+ }
+ %ARGS = %{$searchargs};
+ $CurrentSearch = "$privacy-SavedSearch-$search_id";
+ } else {
+ push(@results, "Error: could not load saved search "
+ . $ARGS{'LoadSavedSearch'});
+ }
+}
+
+# ...or have we been asked to save a search?
+
+if ( $ARGS{'Save'} ) {
+ my %searchargs = %ARGS;
+ foreach my $key (@metakeys) {
+ delete $searchargs{$key};
+ }
+
+ # Is it a new search, or have we asked for a different name than the
+ # current search has? If not, just update the current search.
+ if ($CurrentSearch ne 'new'
+ && $search->Name eq $ARGS{'NewSearchName'}
+ && $search->Privacy eq $ARGS{'SearchPrivacy'}) {
+ # There is a search loaded; we just want to update it.
+ $search->Save(undef, 'Article', undef, ('args' => \%searchargs));
+ } else {
+ # This is a new search.
+ $search = RT::SavedSearch->new($session{'CurrentUser'});
+ if ($ARGS{'SearchPrivacy'} =~ /^(.*)-(\d+)$/) {
+ $search->Save($ARGS{'SearchPrivacy'}, 'Article',
+ $ARGS{'NewSearchName'}, ('args' => \%searchargs));
+ $CurrentSearch = $ARGS{'SearchPrivacy'} . "-SavedSearch-" .
+ $search->Id;
+ push(@results, "Updated search " . $search->Name);
+ } else {
+ # No search privacy chosen? Warn and default to current user.
+ # Really this should never happen.
+ push(@results, "WARNING: Saving search to user-level privacy");
+ $search->Save('RT::User-'.$session{'CurrentUser'}->Id, 'Article',
+ $ARGS{'NewSearchName'}, ('args' => \%searchargs));
+ $CurrentSearch = "RT::User-" . $session{'CurrentUser'}->Id .
+ "-SavedSearch-" . $search->Id;
+ push(@results, "Created search" . $search->Name);
+ }
+ }
+}
+
+# }}}
+
# Don't want to search for a null class when there is no class specced
my $customfields = RT::CustomFields->new( $session{'CurrentUser'} );
$customfields->LimitToLookupType(RT::FM::Article->new($session{'CurrentUser'})->CustomFieldLookupType);
@@ -239,5 +316,5 @@
$LastUpdatedAfter => ''
$RefersTo => undef
$ReferredToBy => undef
-
+$CurrentSearch => 'new'
</%ARGS>
More information about the Rt-commit
mailing list