Skip to content

Commit

Permalink
Automatically load new ticket history after inline edit changes
Browse files Browse the repository at this point in the history
This is for cases where $OldestTransactionsFirst is false. As new changes
appear at the top of the history widget, it makes sense to load them
automatically.
  • Loading branch information
sunnavy committed Apr 1, 2024
1 parent 23ba52c commit 08bbe8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions share/html/Elements/ShowHistoryHeader
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ if ( $ShowDisplayModes or $ShowTitle or $ScrollShowHistory ) {
<& /Widgets/TitleBoxStart, title => $title, titleright_raw => $titleright, class => 'fullwidth' &>
% }

% my $url = '';
% if ( $Object->isa('RT::Ticket') ) {

<%perl>
my %params = map { $_ => $ARGS{$_} } grep { !ref $ARGS{$_} } keys %ARGS;
my $url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .
$url = RT->Config->Get('WebPath') . "/Helpers/TicketHistoryPage?" .
$m->comp('/Elements/QueryString', %params, id => $Object->id );

my $oldestTransactionsFirst;
Expand Down Expand Up @@ -305,4 +306,4 @@ jQuery(function(){
</script>
% }

<div class="history-container">
<div class="history-container" data-url="<% $url %>">
3 changes: 2 additions & 1 deletion share/html/Helpers/TicketHistoryPage
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $oldestTransactionsFirst => RT->Config->Get("OldestTransactionsFirst", $session{
$lastTransactionId => undef
$focusTransactionId => undef
$loadAll => 0
$mode => 'append'
</%ARGS>
<%INIT>
my $TicketObj = RT::Ticket->new($session{'CurrentUser'});
Expand All @@ -69,7 +70,7 @@ my $order = $oldestTransactionsFirst ? 'ASC' : 'DESC';
if ($lastTransactionId) {
$transactions->Limit(
FIELD => 'id',
OPERATOR => $oldestTransactionsFirst ? '>' : '<',
OPERATOR => $mode eq 'prepend' || $oldestTransactionsFirst ? '>' : '<',
VALUE => $lastTransactionId
);
}
Expand Down
23 changes: 23 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,29 @@ jQuery(function() {
if ( RT.Config.OldestTransactionsFirst ) {
history_container.removeAttribute('data-disable-scroll-loading');
}
else {
const url = history_container.getAttribute('data-url');
if ( url ) {
let queryString = '&mode=prepend&loadAll=1';
let lastTransaction = history_container.querySelector('.transaction');
if ( lastTransaction ) {
queryString += '&lastTransactionId=' + lastTransaction.dataset.transactionId;
}

jQuery.ajax({
url: url + queryString,
success: function(html) {
const transactions = jQuery(html).filter('div.transaction');
if( html && transactions.length ) {
jQuery(".history-container").prepend(html);
}
},
error: function(xhr, reason) {
jQuery.jGrowl(reason, { sticky: true, themeState: 'none' });
}
});
}
}
}
}
});
Expand Down

0 comments on commit 08bbe8a

Please sign in to comment.