File tree Expand file tree Collapse file tree 6 files changed +49
-7
lines changed
Expand file tree Collapse file tree 6 files changed +49
-7
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ my $Config = {};
5454$Config->{$_} = RT->Config->Get( $_, $session{CurrentUser} )
5555 for qw(rtname WebURL WebPath MessageBoxRichText MessageBoxRichTextHeight
5656 MaxAttachmentSize WebDefaultStylesheet QuoteSelectedText OldestTransactionsFirst
57- MessageBoxRichTextInitArguments EnableKeyboardShortcuts);
57+ MessageBoxRichTextInitArguments EnableKeyboardShortcuts ShowHistory );
5858
5959# In case the value is string '0', which is true in js if condition.
6060$Config->{EnableKeyboardShortcuts} = 0 unless $Config->{EnableKeyboardShortcuts};
Original file line number Diff line number Diff line change @@ -419,7 +419,8 @@ $COLUMN_MAP = {
419419
420420 my $link = RT->Config->Get('WebPath');
421421 $link .= $session{'CurrentUser'}->Privileged ? '/Ticket/Display.html?id=' : '/SelfService/Display.html?id=';
422- $link .= $self->id . '&MarkAsSeen=1&ShowHistory=1&Anchor=txn-' . $first_unread->id;
422+ $link .= $self->id . '&MarkAsSeen=1&Anchor=txn-' . $first_unread->id;
423+ $link .= '&ShowHistory=1' if RT->Config->Get( 'ShowHistory', $session{'CurrentUser'} ) eq 'click';
423424
424425 my $title = loc("Jump to Unread & Mark as Seen");
425426 return \( '<a data-bs-toggle="tooltip" data-bs-title="' . $title . '" href="' . $link . '"><b>' ),
Original file line number Diff line number Diff line change @@ -147,6 +147,21 @@ if ($ShowPagination && defined $Page) {
147147 # Apply pagination to collection (RT uses 0-based page indexing internally)
148148 $transactions->RowsPerPage($PerPage);
149149 $transactions->GotoPage($Page - 1);
150+
151+ # Auto jump to the page that contains specified txn
152+ if ($focusTransactionId) {
153+ my $auto_page = $Page;
154+ while ( !grep { $focusTransactionId == $_->Id } @{ $transactions->ItemsArrayRef || [] } ) {
155+ $auto_page++;
156+ $transactions->GotoPage( $auto_page - 1 );
157+ if ( $auto_page > $total_pages ) {
158+ RT->Logger->debug("Couldn't find transaction #$focusTransactionId");
159+ undef $auto_page;
160+ last;
161+ }
162+ }
163+ $Page = $auto_page if $auto_page;
164+ }
150165} elsif ($focusTransactionId) { # make sure we load enough if we need to focus a transaction
151166 $transactions->Limit(
152167 FIELD => 'id',
@@ -172,7 +187,8 @@ if ($ShowPagination && defined $Page) {
172187
173188 # Add pagination controls if there are multiple pages
174189 if ($total_pages > 1) {
175- my %url_params = map { $_ => $ARGS{$_} } grep { defined $ARGS{$_} && !blessed $ARGS{$_} } keys %ARGS;
190+ my %url_params = map { $_ => $ARGS{$_} }
191+ grep { defined $ARGS{$_} && !blessed $ARGS{$_} && $_ ne 'focusTransactionId' } keys %ARGS;
176192 $url_params{ShowPagination} = 1;
177193
178194 my $base_url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage";
Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ my %params = (
5353 PerPage => $ARGS{PerPage} || 10,
5454 Page => $ARGS{Page} || 1,
5555 id => $Ticket->id,
56+ ( RT::Interface::Web::RequestENV('HTTP_HX_CURRENT_URL') // '' ) =~ m{#txn-(\d+)$}
57+ && !$ARGS{Page} ? ( focusTransactionId => $1 ) : (),
5658);
5759
5860my $url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .
Original file line number Diff line number Diff line change 6767 <div class="d-sm-none mt-1"></div>
6868 <a class="btn btn-primary btn-sm" href="<% RT->Config->Get('WebPath') ."/$DisplayPath/Display.html?id=". $Ticket->id. "&MarkAsSeen=1" |n %>"><&|/l&>Mark as Seen</&></a>
6969 <div class="d-sm-none mt-1"></div>
70- <a class="btn btn-primary btn-sm" href="<% RT->Config->Get('WebPath') ."/$DisplayPath/Display.html?id=". $Ticket->id ." &MarkAsSeen=1&ShowHistory=1& Anchor=txn-" . $txn->id |n %>"><&|/l&>Jump & Mark as Seen</&></a>
70+ <a class="btn btn-primary btn-sm" href="<% $url . ' &MarkAsSeen=1&Anchor=txn-' . $txn->id |n %>"><&|/l&>Jump & Mark as Seen</&></a>
7171 </span>
7272 </div>
7373 </div>
Original file line number Diff line number Diff line change @@ -1785,11 +1785,34 @@ htmx.onLoad(function(elt) {
17851785
17861786 // Automatically reveal history widget so anchor links like #txn-586 can work
17871787 elt . querySelector ( 'a.jump-to-unread' ) ?. addEventListener ( 'click' , ( evt ) => {
1788- revealHistoryWidget ( ) ;
1788+ const widget = document . querySelector ( '.htmx-load-widget[hx-get$="/Widgets/Display/History"]' ) ;
1789+ if ( widget ) {
1790+ // For paginated history, we need to reload widget if the specified txn is not on current page
1791+ if ( RT . Config . ShowHistory === 'page' && widget . getAttribute ( 'data-hx-revealed' ) === 'true' ) {
1792+ const matched = evt . target . getAttribute ( 'href' ) . match ( / # ( t x n - \d + ) $ / ) ;
1793+ if ( matched && ! document . querySelector ( '[name="' + matched [ 1 ] + '"]' ) ) {
1794+ // Update location first so widget can retrieve the txn id from hash in URL
1795+ location . href = evt . target . getAttribute ( 'href' ) ;
1796+ reloadElement ( widget , { "hx-vals" : JSON . stringify ( { id : ( new URLSearchParams ( location . search ) ) . get ( 'id' ) } ) } ) ;
1797+ }
1798+ }
1799+ else {
1800+ revealHistoryWidget ( ) ;
1801+ }
1802+ }
17891803 } ) ;
17901804
1791- if ( window . location . hash . match ( / # t x n - \d + $ / ) ) {
1792- revealHistoryWidget ( ) ;
1805+
1806+ if ( window . location . hash ) {
1807+ const hash = window . location . hash ;
1808+ if ( hash . match ( / # t x n - \d + $ / ) ) {
1809+ revealHistoryWidget ( ) ;
1810+ }
1811+
1812+ // Automatically scroll to the specified element
1813+ if ( elt . querySelector ( hash ) || elt . querySelector ( '[name="' + hash . substring ( 1 ) + '"]' ) ) {
1814+ location . href = location . href ;
1815+ }
17931816 }
17941817
17951818 expandCalendar ( elt ) ;
You can’t perform that action at this time.
0 commit comments