[Rt-commit] r5289 - in rtfm/branches/2.1-TESTING: .
html/RTFM/Article
ruz at bestpractical.com
ruz at bestpractical.com
Tue May 23 23:07:03 EDT 2006
Author: ruz
Date: Tue May 23 23:07:02 2006
New Revision: 5289
Modified:
rtfm/branches/2.1-TESTING/ (props changed)
rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults
rtfm/branches/2.1-TESTING/html/RTFM/Article/Search.html
Log:
r258 at cubic-pc: cubic | 2006-05-24 07:15:08 +0400
* add basic searches ordering
Modified: rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults
==============================================================================
--- rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults (original)
+++ rtfm/branches/2.1-TESTING/html/RTFM/Article/Elements/ShowSearchResults Tue May 23 23:07:02 2006
@@ -25,15 +25,15 @@
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr class="collection-as-table">
-<th style="text-align: left" class="collection-as-table"><&|/l&>id</&></th>
-<th style="text-align: left" class="collection-as-table"><&|/l&>Name</&></th>
+<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('id'), 'id') |n %></th>
+<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Name'), 'Name') |n %></th>
<th style="text-align: left" class="collection-as-table"><&|/l&>Class</&></th>
-<th style="text-align: left" class="collection-as-table"><&|/l&>Created</&></th>
-<th style="text-align: left" class="collection-as-table"><&|/l&>Modified</&></th>
+<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Created'), 'Created') |n %></th>
+<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Modified'), 'LastUpdated') |n %></th>
</tr>
<tr class="collection-as-table">
<th class="collection-as-table"></th>
-<th style="text-align: left" class="collection-as-table"><&|/l&>Summary</&></th>
+<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Summary'), 'Summary') |n %></th>
<th style="text-align: left" class="collection-as-table" colspan="3"><&|/l&>Topics</&></th>
</tr>
@@ -76,8 +76,26 @@
% }
<%init>
my $i;
+
+my @OrderBy = $query{'OrderBy'}? @{ $query{'OrderBy'} }: ();
+my @Order = $query{'Order'}? @{ $query{'Order'} }: ();
+
+my $sort_link = sub {
+ my ($title, $column) = @_;
+ my $res = qq{<a href="$RT::WebPath/RTFM/Article/Search.html?};
+ my $order;
+ for ( grep $OrderBy[$_] eq $column, 0..$#OrderBy ) {
+ $order = 'DESC' if !$Order[$_] || $Order[$_] =~ /^ASC/i;
+ }
+ $res .= $m->comp('/Elements/QueryString', %query, OrderBy => $column, Order => ($order || 'ASC'));
+
+ $res .= q{">} . $m->interp->apply_escapes($title, 'h')
+ . q{</a>};
+ return $res;
+};
</%init>
<%args>
$articles => undef
$did_search => 1
+%query => ()
</%args>
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 Tue May 23 23:07:02 2006
@@ -18,7 +18,7 @@
<& /RTFM/Article/Elements/Tabs, current_tab => "RTFM/Article/Search.html", Title => loc("Search for articles") &>
-% unless (%ARGS) {
+% unless ( keys %ARGS ) {
% my $Classes=new RT::FM::ClassCollection($session{'CurrentUser'});
% $Classes->LimitToEnabled();
<table width="100%" border="0">
@@ -47,7 +47,7 @@
<& /Elements/ListActions, actions => \@results &>
<div style="float: right"><a href="#criteria"><&|/l&>Modify this search...</&></a></div>
-<& Elements/ShowSearchResults, articles => $articles &>
+<& Elements/ShowSearchResults, query => \%filtered, articles => $articles &>
<br />
<br />
@@ -76,8 +76,7 @@
# If it is a number, load the article with that ID. Otherwise, search
# on name and summary.
if ($ARGS{'q'} =~ /^(\d+)$/) {
- $m->comp("/RTFM/Article/Display.html", id => $1);
- return;
+ return $m->comp("/RTFM/Article/Display.html", id => $1);
} elsif ($ARGS{'q'}) {
$articles->Limit( FIELD => 'Name',
SUBCLAUSE => 'NameOrSummary',
@@ -449,12 +448,24 @@
}
}
+if ( @OrderBy ) {
+ if ( $OrderBy[0] && $OrderBy[0] =~ /\|/ ) {
+ @OrderBy = split '|', @OrderBy;
+ @Order = split '|', @Order;
+ }
+ my @tmp = map
+ {{ FIELD => $OrderBy[$_], ORDER => $Order[$_] }}
+ 0..$#OrderBy;
+ $articles->OrderByCols( @tmp );
+}
+
$m->comp('/Elements/Callback', %ARGS, _Search => $articles);
my %filtered = %ARGS;
delete $filtered{$_} for (@metakeys, "EditTopics", "ExpandTopics");
delete $filtered{$_} for grep {$filtered{$_} !~ /\S/} keys %filtered;
+ at filtered{qw(OrderBy Order)} = (\@OrderBy, \@Order);
my $QueryString = "?".$m->comp('/Elements/QueryString', %filtered);
</%init>
@@ -466,4 +477,6 @@
$RefersTo => undef
$ReferredToBy => undef
$CurrentSearch => 'new'
+ at OrderBy => ()
+ at Order => ()
</%ARGS>
More information about the Rt-commit
mailing list