HomePageSavedSearches

From Request Tracker Wiki
Jump to navigation Jump to search

Saved Searches on RT Home Page

Posted by Stephen Turner, MIT on Wednesday, January 19, 2005.

This mod replaces the two ticket lists that traditionally appear on the RT home page with lists of saved searches (and a list of "standard" or globally defined searches). The idea is to give users direct access to "their" stuff from the home page.

The mod appears to work happily with RT 3.1.16, 3.2.x and 3.3.x/3.4. See below for comments on 3.8.

There are two sections:

  • Saved Searches (both user- and group- level saved searches)
  • Standard Searches (appear for all users)

In summary, the changes are:

  • A new Mason component to display saved searches (/Elements/SavedSearchList)
  • A new Mason component to display standard searches (/Elements/StandardSearchList)
  • Modification of /index.html to remove the ticket lists and add the search lists

Saved searches are in a new Mason component, /Elements/SavedSearchList :

/Elements/SavedSearchList

<& /Elements/TitleBoxStart, title => loc('Saved Searches') &>
 <table border="0" cellspacing="0" cellpadding="1" width="100%">
 
 % my $i=0;
 % foreach my $srch (@user_attrs) {
 % $m->out( '<TR class="' . ( $i % 2 ? 'oddline' : 'evenline' ) . '" >' );
 <td>
 % if ($srch->Id == $user_attrs[0]->Id) {
 My saved searches:
 % } else {
 
 % }
 </td>
 <td>
 
 % $format = $srch->SubValue('Format');
 % $format =~ s/%23/#/g;
 % $format =~ s/%26/&/g;
 
 <A HREF="Search/Results.html<% "?".$m->comp('/Elements/QueryString',
                         Query => $srch->SubValue('Query'),
                         Format => $format,
                         Rows => $srch->SubValue('RowsPerPage'),
                         Order => $srch->SubValue('Order'),
                         OrderBy => $srch->SubValue('OrderBy'),
                         Page => 1) %>"><% $srch->Description  %></A><br>
 </td>
 </tr>
 % $i++
 % }
 % for my $grp (@grouparr) {
 %    my @gattrs = $grp->Attributes->Named('SavedSearch');
 %    foreach my $srch (@gattrs) {
 % $m->out( '<TR class="' . ( $i % 2 ? 'oddline' : 'evenline' ) . '" >' );
 <td>
 % if ($srch->Id == $gattrs[0]->Id) {
 Group <% $grp->Name %> saved searches:
 % } else {
 
 % }
 </td>
 <td>
 % $format = $srch->SubValue('Format');
 % $format =~ s/%23/#/g;
 % $format =~ s/%26/&/g;
 <A HREF="Search/Results.html<% "?".$m->comp('/Elements/QueryString',
                        Query => $srch->SubValue('Query'),
                        Format => $format,
                        Rows => $srch->SubValue('RowsPerPage'),
                        Order => $srch->SubValue('Order'),
                        OrderBy => $srch->SubValue('OrderBy'),
                        Page => 1) %>"><% $srch->Description  %></A><br>
 </td>
 </tr>
 % $i++
 %    }
 % }
 
 </table>
 <& /Elements/TitleBoxEnd &>
 <%init>
 
 my $format;
 
 my @user_attrs = $session{'CurrentUser'}->UserObj->Attributes->Named('SavedSearch');
 
 # Get any group saved searches:
 my @attrs;
 my $groups = RT::Groups->new($session{'CurrentUser'});
 $groups->LimitToUserDefinedGroups;
 $groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
                     Recursively => 1);
 my $ref = $groups->ItemsArrayRef();
 my @grouparr = @$ref;
 
 </%init>
 <%ARGS>
 $user_attrs => undef
 </%ARGS>
 
 

"Standard" searches are in a new Mason component, /Elements/StandardSearchList :

/Elements/StandardSearchList

<& /Elements/TitleBoxStart, title => loc('Standard Searches') &>
<table border="0" cellspacing="0" cellpadding="1" width="100%">

<TR class="evenline">
<td>
<A HREF="Search/Results.html<% "?".$m->comp('/Elements/QueryString',
               Query => " Owner = '".$session{'CurrentUser'}->Id."' AND ( Status = 'new' OR Status = 'open')",
               Rows => 50,
               Page => 1) %>">New and Open Tickets I Own</A><br>
</td>
</tr>
<TR class="oddline">
<td>
<A HREF="Search/Results.html<% "?".$m->comp('/Elements/QueryString',
        Query => "Owner = 'Nobody' AND ( Status = 'new' OR Status = 'open')",
        Rows => 50,
        Page => 1) %>">New and Open Unowned Tickets</A><br>
</td>
</tr>
</table>
<& /Elements/TitleBoxEnd &>

/index.html

Finally, we removed the ticket lists from the stock RT home page (index.html) by removing these lines:

<& /Elements/MyTickets &>
<BR>
<& /Elements/MyRequests &>
<BR>

and we replaced them with these lines:

<& /Elements/SavedSearchList &>
<BR>
<& /Elements/StandardSearchList &>
<BR>

User Comments

posted on Aug 5, 2005.

I created the SavedSearchList file as described above and added the following to /index.html:

<& /Elements/SavedSearchList &>
<BR>

That way, the default ticket displays (highest priority, newest unowned) are still shown on the home page, and the Saved Searches display is just added below them. It seems to work great (thanks, Stephen), except that every once in awhile, when I load the home page, the following error shows up in place of the Saved Searches display:

error:   	RT::Attribute::Name Unimplemented in RT::Attributes. (/usr/local/rt3/lib/RT/Attributes_Overlay.pm line 99)

context:
...
481:  	else {
482:  	my ($package, $filename, $line);
483:  	($package, $filename, $line) = caller;
484:
485:  	die "$AUTOLOAD Unimplemented in $package. ($filename line $line) \n";
486:  	}
487:
488:  	}
489:
...

code stack:
/usr/local/lib/perl5/site_perl/5.8.6/DBIx/SearchBuilder/Record.pm:485
/usr/local/rt3/lib/RT/Attributes_Overlay.pm:99
/usr/local/rt3/lib/RT/Attributes_Overlay.pm:91
/usr/local/rt3/lib/RT/Attributes_Overlay.pm:106
/usr/local/rt3/lib/RT/Attributes_Overlay.pm:137
/usr/local/rt3/share/html/Elements/SavedSearchList:32
/usr/local/rt3/share/html/index.html:84
/usr/local/rt3/share/html/autohandler:221

raw error

RT::Attribute::Name Unimplemented in RT::Attributes. (/usr/local/rt3/lib/RT/Attributes_Overlay.pm line 99)


Trace begun at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Exceptions.pm line 131
HTML::Mason::Exceptions::rethrow_exception('RT::Attribute::Name Unimplemented in RT::Attributes. (/usr/local/rt3/lib/RT/Attributes_Overlay.pm line 99) ^J') called at /usr/local/lib/perl5/site_perl/5.8.6/DBIx/SearchBuilder/Record.pm line 485
DBIx::SearchBuilder::Record::AUTOLOAD('RT::Attribute=HASH(0x9878a00)') called at /usr/local/rt3/lib/RT/Attributes_Overlay.pm line 99
RT::Attributes::_BuildAccessTable('RT::Attributes=HASH(0x9a5e940)') called at /usr/local/rt3/lib/RT/Attributes_Overlay.pm line 91
RT::Attributes::_DoSearch('RT::Attributes=HASH(0x9a5e940)') called at /usr/local/rt3/lib/RT/Attributes_Overlay.pm line 106
RT::Attributes::_AttrHash('RT::Attributes=HASH(0x9a5e940)') called at /usr/local/rt3/lib/RT/Attributes_Overlay.pm line 137
RT::Attributes::Named('RT::Attributes=HASH(0x9a5e940)', 'SavedSearch') called at /usr/local/rt3/share/html/Elements/SavedSearchList line 32
HTML::Mason::Commands::__ANON__ at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Component.pm line 136
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x9aae4c4)') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 1074
eval {...} at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 1068
HTML::Mason::Request::comp(undef, undef) called at /usr/local/rt3/share/html/index.html line 84
HTML::Mason::Commands::__ANON__('pass', '********', 'user', 'marcus', 'user', 'marcus', 'pass', '*******') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Component.pm line 136
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x9ab7518)', 'pass', '********', 'user', 'marcus', 'user', 'marcus', 'pass', '*******') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 1074
eval {...} at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 1068
HTML::Mason::Request::comp(undef, undef, 'pass', '********', 'user', 'marcus', 'user', 'marcus', 'pass', '********') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 760
HTML::Mason::Request::call_next('HTML::Mason::Request::ApacheHandler=HASH(0x985c898)', 'user', 'marcus', 'pass', '********') called at /usr/local/rt3/share/html/autohandler line 221
HTML::Mason::Commands::__ANON__('pass', '********', 'user', 'marcus') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Component.pm line 136
HTML::Mason::Component::run('HTML::Mason::Component::FileBased=HASH(0x96b86bc)', 'pass', '********', 'user', 'marcus') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 1069
eval {...} at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 1068
HTML::Mason::Request::comp(undef, undef, undef, 'pass', '********', 'user', 'marcus') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 338
eval {...} at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 338
eval {...} at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm line 297
HTML::Mason::Request::exec('HTML::Mason::Request::ApacheHandler=HASH(0x985c898)') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/ApacheHandler.pm line 134
eval {...} at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/ApacheHandler.pm line 134
HTML::Mason::Request::ApacheHandler::exec('HTML::Mason::Request::ApacheHandler=HASH(0x985c898)') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Mason/ApacheHandler.pm line 827
HTML::Mason::ApacheHandler::handle_request('HTML::Mason::ApacheHandler=HASH(0x953e764)', 'Apache=SCALAR(0x96ec0d4)') called at /usr/local/rt3/bin/webmux.pl line 126
eval {...} at /usr/local/rt3/bin/webmux.pl line 126
RT::Mason::handler('Apache=SCALAR(0x96ec0d4)') called at /dev/null line 0
eval {...} at /dev/null line 0


The error seems to work itself out if I just reload the home page, or go to another page and come back to the home page. Of course, if anyone out there knows what's going on and how to fix it, the help would be appreciated. I'm running RT 3.2.2 on a FreeBSD machine, with apache (mod_perl) and mysql.

Posted 12/28/2005

I am having the same problem all of the sudden. It seems to happen when ever i load a search, and sometimes when i go to home page (with savedsearchmod). I first noticed it after I installed the Text Based priorites, but have since reversed that and i still get the same above error:

error:   	RT::Attribute::Name Unimplemented in RT::Attributes. (/opt/rt3/lib/RT/Attributes_Overlay.pm line 81)
context:
...
492:  	else {
493:  	my ( $package, $filename, $line );
494:  	( $package, $filename, $line ) = caller;
495:
496:  	die "$AUTOLOAD Unimplemented in $package. ($filename line $line) \n";
497:  	}
498:
499:  	}
500:
...
code stack:  	/usr/pkg/lib/perl5/site_perl/5.8.0/DBIx/SearchBuilder/Record.pm:496
/opt/rt3/lib/RT/Attributes_Overlay.pm:81
/opt/rt3/lib/RT/Attributes_Overlay.pm:73
/opt/rt3/lib/RT/Attributes_Overlay.pm:88
/opt/rt3/lib/RT/Attributes_Overlay.pm:119
/opt/rt3/share/html/Elements/SavedSearchList:65
/opt/rt3/share/html/index.html:80
/opt/rt3/share/html/autohandler:215



Similar mod caused error

posted on Oct. 4, 1005

I just wanted to add that I, too, am experiencing this error in version 3.4.4 on a Solaris 9 machine (apache modperl)

Similar mod caused error

December 9, 2005, S. Turner

I think a recent recent version of DBIx::SearchBuilder fixes this problem. [Thanks to J. Bachtel for correcting this part - Steve]

Worked like a charm

Worked like a charm for me as of Dec 12th, 2005 with RT 3.4.4, Apache2, Mod_perl2.0.2 on Netbsd 2.x. I did have to figure out that I needed to restart apache to clear the Mason Cache. Duncan Shannon.

RT 3.8

It's been said that 'With the Dashboards tool, this mod is not really needed. You can add saved searches to your Home or a custom dashboard.'. B.S. Try this for 3.8 (tested with 3.8.7)

--- local/html/Elements/PageLayout      2010-04-13 13:56:59.000000000 -0600
+++ share/html/Elements/PageLayout      2010-04-12 15:10:27.000000000 -0600
@@ -57,8 +57,6 @@
 % if ( $show_menu ) {
 <div id="nav">
 <& /Elements/Menu, toptabs => $toptabs, current_toptab => $current_toptab &>
-<div style='margin-top: 10px;'>&nbsp;</div>
-<& /Elements/SearchList &>
 </div>
 % }

And local/html/Elements/SearchList

% my $i=0;
 % foreach my $srch (@user_attrs) {
 % if ($srch->Id == $user_attrs[0]->Id) {
 <& /Elements/TitleBoxStart, title => 'My Searches' &>
 <ul id='system-menu'><div><div class='wrapper'>
 % }
 % $format = $srch->SubValue('Format');
 % $format =~ s/%23/#/g;
 % $format =~ s/%26/&/g;
 
 <li style='margin-left: -10px;'>
 <span class="bullet">&#183; </span>
 <A HREF="<% RT->Config->Get('WebPath') %>/Search/Results.html<% "?".$m->comp('/Elements/QueryString',
                         Query => $srch->SubValue('Query'),
                         Format => $format,
                         Rows => $srch->SubValue('RowsPerPage'),
                         Order => $srch->SubValue('Order'),
                         OrderBy => $srch->SubValue('OrderBy'),
                         Page => 1) %>"><% $srch->Description  %></A></li>
 % $i++
 % }
 </div></div></ul>
 <!-- End My Searches -->
 <& /Elements/TitleBoxEnd &>
 
 % for my $grp (@grouparr) {
 %    my @gattrs = $grp->Attributes->Named('SavedSearch');
 
 %    foreach my $srch (@gattrs) {
 % if ($srch->Id == $gattrs[0]->Id) {
 <& /Elements/TitleBoxStart, title => $grp->Name &>
 <ul><div><div class='wrapper'>
 % }
 % $format = $srch->SubValue('Format');
 % $format =~ s/%23/#/g;
 % $format =~ s/%26/&/g;
 <li style='margin-left: -10px;'><A HREF="<% RT->Config->Get('WebPath') %>/Search/Results.html<% "?".$m->comp('/Elements/QueryString',
                        Query => $srch->SubValue('Query'),
                        Format => $format,
                        Rows => $srch->SubValue('RowsPerPage'),
                        Order => $srch->SubValue('Order'),
                        OrderBy => $srch->SubValue('OrderBy'),
                        Page => 1) %>"><% $srch->Description  %></A></li>
 % $i++;
 %    }
 % if ($#gattrs > 0) {
 </div></div></ul>
 <!-- End <% $grp->Name %> Searches -->
 <& /Elements/TitleBoxEnd &>
 % }
 
 % }
 
 <%init>
 
 my $format;
 
 my @user_attrs = $session{'CurrentUser'}->UserObj->Attributes->Named('SavedSearch');
 
 # Get any group saved searches:
 my @attrs;
 my $groups = RT::Groups->new($session{'CurrentUser'});
 $groups->LimitToUserDefinedGroups;
 $groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
                     Recursively => 1);
 my $ref = $groups->ItemsArrayRef();
 my @grouparr = @$ref;
 
 </%init>
 <%ARGS>
 $user_attrs => undef
 </%ARGS>
 
 
 
 

RT 3.6.0

Create the element files as described above. Copy the $HomepageComponents line from RT_Config.pm and add the line to RT_SiteConfig.pm. Now edit the line to include SavedSearchList and StandardSearchList.

Restart your web server and hey presto! They should now be listed to add to your RT at a glance view.

Patch for RT 3.4.4

October 2, 2007

The following patch was submitted to the rt-users mailing list by Vitali Ostrovskyi on Jun 5, 2007. This appears to have fixed the problem I was continuing to have with the RT::Attributes.

-# {{{ sub _Init
 -
 -sub _Init {
 -    my $self = shift;
 -    $self->_BuildTableAttributes unless ($_TABLE_ATTR->{ref($self)}) and (scalar %{$_TABLE_ATTR->{ref($self)}});
 -    $self->CurrentUser(@_);
 -}
 -
 -# }}}
 +# {{{ sub _Init
 +
 +sub _Init {
 +    my $self = shift;
 +    $self->_BuildTableAttributes unless ($_TABLE_ATTR->{ref($self)}) and (scalar %{$_TABLE_ATTR->{ref($self)}});
 +    $self->CurrentUser(@_);
 +}
 +
 +# }}}