Skip to content

Commit c381c81

Browse files
committed
Merge branch '6.0/config-history-pagination' into 6.0-trunk
2 parents 0a69109 + 1e5cabf commit c381c81

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

share/html/Admin/Tools/ConfigHistory.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@
5454
my $Transactions = RT::Transactions->new($session{CurrentUser});
5555
$Transactions->Limit(FIELD => 'ObjectType', VALUE => 'RT::Configuration');
5656
$Transactions->OrderBy(FIELD => 'Created', ORDER => 'DESC');
57+
$Transactions->RowsPerPage($PerPage);
58+
59+
my $TotalFound = $Transactions->CountAll();
60+
my $Pages;
61+
if ( $TotalFound && $TotalFound > $PerPage ) {
62+
$Pages = int( $TotalFound / $PerPage ) + ( $TotalFound % $PerPage ? 1 : 0 );
63+
$Page = $Pages if $Page > $Pages;
64+
}
65+
else {
66+
$Page = 1;
67+
}
68+
$Transactions->GotoPage($Page - 1);
69+
5770
</%INIT>
5871
<& /Admin/Elements/Header, Title => $title &>
5972
<& /Elements/Tabs &>
@@ -73,7 +86,23 @@
7386
RowNum => $i
7487
&>
7588
% $i++;
89+
% }
90+
91+
% if ( $TotalFound > $PerPage ) {
92+
<& /Elements/CollectionListPaging,
93+
BaseURL => '?',
94+
Rows => $PerPage,
95+
TotalFound => $TotalFound,
96+
CurrentPage => $Page,
97+
Pages => $Pages,
98+
URLParams => { map { $_ => $ARGS{$_} } qw/PerPage Page/ },
99+
&>
76100
% }
77101
</div>
78102
</&>
79103
</div>
104+
105+
<%ARGS>
106+
$PerPage => 50
107+
$Page => 1
108+
</%ARGS>

t/web/admin_tools_editconfig.t

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,49 @@ foreach my $change (@{$tests}) {
8686
check_history_page_item($tx_items->[$i++], $change );
8787
}
8888

89+
# Test pagination with PerPage=2 (5 items total = 3 pages)
90+
diag "Test pagination";
91+
92+
$m->get_ok( $url . '/Admin/Tools/ConfigHistory.html?PerPage=2', 'Get history with PerPage=2' );
93+
my $dom = $m->dom;
94+
my $paging = $dom->at('div.paging');
95+
ok( $paging, 'Pagination div exists' );
96+
my $pagination_ul = $paging->at('ul.pagination');
97+
ok( $pagination_ul, 'Pagination list exists' );
98+
99+
# Page 1 should be active
100+
my $active_item = $pagination_ul->at('li.page-item.active');
101+
ok( $active_item, 'Active page item exists' );
102+
is( $active_item->at('a')->text, '1', 'Page 1 is active' );
103+
104+
# Should have links to pages 2 and 3
105+
ok( $m->find_link( url_regex => qr/Page=2/ ), 'Link to page 2 exists' );
106+
ok( $m->find_link( url_regex => qr/Page=3/ ), 'Link to page 3 exists' );
107+
108+
# Count history items on page 1 - should be 2
109+
my @history_items = $dom->find('div.history-container div.transaction')->each;
110+
is( scalar @history_items, 2, 'Page 1 shows 2 history items' );
111+
112+
# Go to page 2 by clicking the pagination link
113+
$m->follow_link_ok( { text => '2', url_regex => qr/Page=2/ }, 'Click page 2 link' );
114+
$dom = $m->dom;
115+
$active_item = $dom->at('div.paging ul.pagination li.page-item.active');
116+
ok( $active_item, 'Active page item exists on page 2' );
117+
is( $active_item->at('a')->text, '2', 'Page 2 is active' );
118+
119+
@history_items = $dom->find('div.history-container div.transaction')->each;
120+
is( scalar @history_items, 2, 'Page 2 shows 2 history items' );
121+
122+
# Go to page 3 by clicking the pagination link
123+
$m->follow_link_ok( { text => '3', url_regex => qr/Page=3/ }, 'Click page 3 link' );
124+
$dom = $m->dom;
125+
$active_item = $dom->at('div.paging ul.pagination li.page-item.active');
126+
ok( $active_item, 'Active page item exists on page 3' );
127+
is( $active_item->at('a')->text, '3', 'Page 3 is active' );
128+
129+
@history_items = $dom->find('div.history-container div.transaction')->each;
130+
is( scalar @history_items, 1, 'Page 3 shows 1 history item (last page)' );
131+
89132
sub run_test {
90133
my %args = @_;
91134

0 commit comments

Comments
 (0)