indicator on the top bar for new activity on tickets, #41670
[freeside.git] / rt / share / html / Search / UnrepliedTickets.html
1 %# false laziness with Results.html; basically this is the same thing but with
2 %# a hardcoded RT::Tickets object instead of a Query param
3
4 <& /Elements/Header, Title => $title,
5     Refresh => $refresh,
6     LinkRel => \%link_rel &>
7
8 % $m->callback( ARGSRef => \%ARGS, Format => \$Format, CallbackName => 'BeforeResults' );
9
10 <& /Elements/CollectionList, 
11     Class => 'RT::Tickets',
12     Collection => $session{tickets},
13     TotalFound => $ticketcount,
14     AllowSorting => 1,
15     OrderBy => $OrderBy,
16     Order => $Order,
17     Rows => $Rows,
18     Page => $Page,
19     Format => $Format,
20     BaseURL => $BaseURL,
21     SavedSearchId => $ARGS{'SavedSearchId'},
22     SavedChartSearchId => $ARGS{'SavedChartSearchId'},
23     PassArguments => [qw(Format Rows Page Order OrderBy SavedSearchId SavedChartSearchId)],
24 &>
25 % $m->callback( ARGSRef => \%ARGS, CallbackName => 'AfterResults' );
26
27 % my %hiddens = (Format => $Format, Rows => $Rows, OrderBy => $OrderBy, Order => $Order, HideResults => $HideResults, Page => $Page, SavedChartSearchId => $SavedChartSearchId );
28 <div align="right" class="refresh">
29 <form method="get" action="<%RT->Config->Get('WebPath')%>/Search/UnrepliedTickets.html">
30 % foreach my $key (keys(%hiddens)) {
31 <input type="hidden" class="hidden" name="<%$key%>" value="<% defined($hiddens{$key})?$hiddens{$key}:'' %>" />
32 % }
33 <& /Elements/Refresh, Name => 'TicketsRefreshInterval', Default => $session{'tickets_refresh_interval'}||RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'}) &>
34 <input type="submit" class="button" value="<&|/l&>Change</&>" />
35 </form>
36 </div>
37 <%INIT>
38 $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
39
40 # Read from user preferences
41 my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
42
43 # These variables are what define a search_hash; this is also
44 # where we give sane defaults.
45 $Format      ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat');
46 $Order       ||= $prefs->{'Order'} || RT->Config->Get('DefaultSearchResultOrder');
47 $OrderBy     ||= $prefs->{'OrderBy'} || RT->Config->Get('DefaultSearchResultOrderBy');
48
49 # In this case the search UI isn't available, so trust the defaults.
50
51 # Some forms pass in "RowsPerPage" rather than "Rows"
52 # We call it RowsPerPage everywhere else.
53
54 if ( defined $prefs->{'RowsPerPage'} ) {
55     $Rows = $prefs->{'RowsPerPage'};
56 } else {
57     $Rows = 50;
58 }
59 $Page = 1 unless $Page && $Page > 0;
60
61 use RT::Search::UnrepliedTickets;
62
63 $session{'i'}++;
64 $session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ;
65 my $search = RT::Search::UnrepliedTickets->new( TicketsObj => $session{'tickets'} );
66 $search->Prepare;
67
68 if ($OrderBy =~ /\|/) {
69     # Multiple Sorts
70     my @OrderBy = split /\|/,$OrderBy;
71     my @Order = split /\|/,$Order;
72     $session{'tickets'}->OrderByCols(
73         map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
74         .. $#OrderBy ) );; 
75 } else {
76     $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order); 
77 }
78 $session{'tickets'}->RowsPerPage( $Rows ) if $Rows;
79 $session{'tickets'}->GotoPage( $Page - 1 );
80
81 # use this to set a CSRF token applying to the search, so that the user can come
82 # back to this page without triggering a referrer check
83 $session{'CurrentSearchHash'} = {
84     Format      => $Format,
85     Page        => $Page,
86     Order       => $Order,
87     OrderBy     => $OrderBy,
88     RowsPerPage => $Rows
89 };
90
91
92 my $ticketcount = $session{tickets}->CountAll();
93 my $title = loc('New activity on [quant,_1,ticket,tickets]', $ticketcount);
94
95 # pass this through on pagination links
96 my $QueryString = "?".$m->comp('/Elements/QueryString',
97                                Format => $Format,
98                                Rows => $Rows,
99                                OrderBy => $OrderBy,
100                                Order => $Order,
101                                Page => $Page);
102
103 if ($ARGS{'TicketsRefreshInterval'}) {
104     $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'};
105 }
106
107 my $refresh = $session{'tickets_refresh_interval'}
108     || RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'} );
109
110 # Check $m->request_args, not $DECODED_ARGS, to avoid creating a new CSRF token on each refresh
111 if (RT->Config->Get('RestrictReferrer') and $refresh and not $m->request_args->{CSRF_Token}) {
112     my $token = RT::Interface::Web::StoreRequestToken( $session{'CurrentSearchHash'} );
113     $m->notes->{RefreshURL} = RT->Config->Get('WebURL')
114         . "Search/UnrepliedTickets.html?CSRF_Token="
115             . $token;
116 }
117
118 my %link_rel;
119 my $genpage = sub {
120     return $m->comp(
121         '/Elements/QueryString',
122         Format  => $Format,
123         Rows    => $Rows,
124         OrderBy => $OrderBy,
125         Order   => $Order,
126         Page    => shift(@_),
127     );
128 };
129
130 if ( RT->Config->Get('SearchResultsAutoRedirect') && $ticketcount == 1 &&
131     $session{tickets}->First ) {
132 # $ticketcount is not always precise unless $UseSQLForACLChecks is set to true,
133 # check $session{tickets}->First here is to make sure the ticket is there.
134     RT::Interface::Web::Redirect( RT->Config->Get('WebURL')
135             ."Ticket/Display.html?id=". $session{tickets}->First->id );
136 }
137
138 my $BaseURL = RT->Config->Get('WebPath')."/Search/UnrepliedTickets.html?";
139 $link_rel{first} = $BaseURL . $genpage->(1)         if $Page > 1;
140 $link_rel{prev}  = $BaseURL . $genpage->($Page - 1) if $Page > 1;
141 $link_rel{next}  = $BaseURL . $genpage->($Page + 1) if ($Page * $Rows) < $ticketcount;
142 $link_rel{last}  = $BaseURL . $genpage->(POSIX::ceil($ticketcount/$Rows)) if $Rows and ($Page * $Rows) < $ticketcount;
143 </%INIT>
144 <%CLEANUP>
145 $session{'tickets'}->PrepForSerialization();
146 </%CLEANUP>
147 <%ARGS>
148 $HideResults => 0
149 $Rows => undef
150 $Page => 1
151 $OrderBy => undef
152 $Order => undef
153 $SavedSearchId => undef
154 $SavedChartSearchId => undef
155 $Format => undef
156 </%ARGS>