Skip to content

Commit 7849f21

Browse files
sunnavycbrandtbuffalo
authored andcommitted
Make "Jump to Unread" links work with paginated history
When a URL contains an anchor referencing a transaction like #txn-123, RT will now automatically locate the history page containing transaction #123 and navigate to the appropriate page.
1 parent 59729ff commit 7849f21

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

share/html/Elements/JavascriptConfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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};

share/html/Elements/RT__Ticket/ColumnMap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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>' ),

share/html/Helpers/TicketHistoryPage

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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";

share/html/Ticket/Elements/PagedShowHistory

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

5860
my $url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .

share/html/Ticket/Elements/ShowUpdateStatus

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
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>

share/static/js/util.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff 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(/#(txn-\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(/#txn-\d+$/)) {
1792-
revealHistoryWidget();
1805+
1806+
if (window.location.hash) {
1807+
const hash = window.location.hash;
1808+
if (hash.match(/#txn-\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);

0 commit comments

Comments
 (0)