Skip to content

Commit

Permalink
ref(frontend/backend): remove the remnants of the legacy page links (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
mercihabam authored Dec 24, 2024
1 parent 33d7e11 commit f93c37b
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 98 deletions.
4 changes: 2 additions & 2 deletions modules/core/js_modules/actions/pagination.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function refreshNextButton(current) {
const totalPages = $(".pagination .total").text();
if (current >= totalPages) {
if (parseInt(current) >= parseInt(totalPages)) {
$(".pagination .next").prop('disabled', true);
} else {
$(".pagination .next").prop('disabled', false);
}
}

function refreshPreviousButton(current) {
if (current <= 1) {
if (parseInt(current) <= 1) {
$(".pagination .prev").prop('disabled', true);
} else {
$(".pagination .prev").prop('disabled', false);
Expand Down
76 changes: 0 additions & 76 deletions modules/core/message_list_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,79 +602,3 @@ function search_field_selection($current, $output_mod) {
$res .= '</select>';
return $res;
}}

/**
* Build pagination links for a list of messages
* @subpackage core/functions
* @param int $page_size number of messages per page
* @param int $current current page number
* @param int $total number of messages total
* @param string $path list path
* @param string $filter list filter
* @param string $sort list sort
* @return string
*/
if (!hm_exists('build_page_links')) {
function build_page_links($page_size, $current_page, $total, $path, $filter=false, $sort=false, $keyword=false) {
$links = '';
$first = '';
$last = '';
$display_links = 10;
if ($filter) {
$filter_str = '&amp;filter='.$filter;
}
else {
$filter_str = '';
}
if ($sort) {
$sort_str = '&amp;sort='.$sort;
}
else {
$sort_str = '';
}
if ($keyword) {
$keyword_str = '&amp;keyword='.$keyword;
}
else {
$keyword_str = '';
}

$max_pages = ceil($total/$page_size);
if ($max_pages == 1) {
return '';
}
$floor = ($current_page - 1) - intval($display_links/2);
if ($floor < 0) {
$floor = 1;
}
$ceil = $floor + $display_links;
if ($ceil > $max_pages) {
$floor -= ($ceil - $max_pages);
}
$prev = '<a class="disabled_link"><i class="bi bi-caret-left-fill"></i></a>';
$next = '<a class="disabled_link"><i class="bi bi-caret-right-fill"></i></a>';

if ($floor > 1 ) {
$first = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page=1'.$keyword_str.$filter_str.$sort_str.'">1</a> ... ';
}
if ($ceil < $max_pages) {
$last = ' ... <a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.$max_pages.$keyword_str.$filter_str.$sort_str.'">'.$max_pages.'</a>';
}
if ($current_page > 1) {
$prev = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.($current_page - 1).$keyword_str.$filter_str.$sort_str.'"><i class="bi bi-caret-left-fill"></i></a>';
}
if ($max_pages > 1 && $current_page < $max_pages) {
$next = '<a href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.($current_page + 1).$keyword_str.$filter_str.$sort_str.'"><i class="bi bi-caret-right-fill"></i></a>';
}
for ($i=1;$i<=$max_pages;$i++) {
if ($i < $floor || $i > $ceil) {
continue;
}
$links .= ' <a ';
if ($i == $current_page) {
$links .= 'class="current_page fw-bolder" ';
}
$links .= 'href="?page=message_list&amp;list_path='.urlencode($path).'&amp;list_page='.$i.$keyword_str.$filter_str.$sort_str.'">'.$i.'</a>';
}
return $prev.' '.$first.$links.$last.' '.$next;
}}
3 changes: 1 addition & 2 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ class Hm_Output_message_list_end extends Hm_Output_Module {
* Close the table opened in Hm_Output_message_list_start
*/
protected function output() {
$res = '</tbody></table></div><div class="mb-5 page_links d-flex justify-content-center gap-3 align-content-center"></div></div>';
$res = '</tbody></table></div></div>';
return $res;
}
}
Expand Down Expand Up @@ -2444,6 +2444,5 @@ protected function output() {
$messageList = array_merge($messageList, $this->get('feed_list_data'), Hm_Output_filter_feed_list_data::formatMessageList($this));
}
$this->out('formatted_message_list', $messageList);
$this->out('page_links', 'There is no pagination in this view, please visit the individual mail boxes.');
}
}
1 change: 0 additions & 1 deletion modules/core/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
'msg_text' => array(FILTER_UNSAFE_RAW, false),
'msg_source' => array(FILTER_UNSAFE_RAW, false),
'msg_parts' => array(FILTER_UNSAFE_RAW, false),
'page_links' => array(FILTER_UNSAFE_RAW, false),
'pages' => array(FILTER_VALIDATE_INT, false),
'folder_status' => array(FILTER_DEFAULT, FILTER_REQUIRE_ARRAY),
'imap_server_id' => array(FILTER_DEFAULT, false),
Expand Down
3 changes: 1 addition & 2 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ var Hm_Ajax_Request = function() { return {
messages.load().then(() => {
if (messages.count != res.folder_status[name].messages) {
messages.load(true).then(() => {
display_imap_mailbox(messages.rows, messages.links);
display_imap_mailbox(messages.rows, messages.list);
})
}
});
Expand Down Expand Up @@ -889,7 +889,6 @@ function Message_List() {
else {
$('.message_list').append('<div class="empty_list">'+hm_empty_folder()+'</div>');
}
$(".page_links").css("display", "none");// Hide page links as message list is empty
}
}
else {
Expand Down
3 changes: 0 additions & 3 deletions modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,6 @@ class Hm_Output_filter_combined_inbox extends Hm_Output_Module {
protected function output() {
if ($this->get('imap_combined_inbox_data')) {
prepare_imap_message_list($this->get('imap_combined_inbox_data'), $this, 'combined_inbox');
$this->out('page_links', 'There is no pagination in this view, please visit the individual mail boxes.');
}
else {
$this->out('formatted_message_list', array());
Expand Down Expand Up @@ -1006,8 +1005,6 @@ protected function output() {
}
$max_pages = ceil($details['detail']['exists']/$details['limit']);
$this->out('pages', $max_pages);
$this->out('page_links', build_page_links($details['limit'], $page_num, $details['detail']['exists'],
$this->get('imap_mailbox_page_path'), $this->html_safe($this->get('list_filter')), $this->html_safe($this->get('list_sort')), $this->html_safe($this->get('list_keyword'))));
}
elseif (!$this->get('formatted_message_list')) {
$this->out('formatted_message_list', array());
Expand Down
11 changes: 0 additions & 11 deletions tests/phpunit/modules/core/message_list_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,4 @@ public function test_search_field_selection() {
$this->assertEquals('<select class="form-select form-select-sm w-auto" id="search_fld" name="search_fld"><option selected="selected" value="TEXT">Entire message</option><option value="BODY">Message body</option><option value="SUBJECT">Subject</option><option value="FROM">From</option><option value="TO">To</option><option value="CC">Cc</option></select>', search_field_selection('TEXT', $mod));
$this->assertEquals('<select class="form-select form-select-sm w-auto" id="search_fld" name="search_fld"><option value="TEXT">Entire message</option><option value="BODY">Message body</option><option value="SUBJECT">Subject</option><option value="FROM">From</option><option value="TO">To</option><option value="CC">Cc</option></select>', search_field_selection('foo', $mod));
}
/**
* @preserveGlobalState disabled
* @runInSeparateProcess
*/
public function test_build_page_links() {
$this->assertEquals('<a href="?page=message_list&amp;list_path=%2F&amp;list_page=4"><i class="bi bi-caret-left-fill"></i></a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=1">1</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2">2</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=3">3</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=4">4</a> <a class="current_page fw-bolder" href="?page=message_list&amp;list_path=%2F&amp;list_page=5">5</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=6">6</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=7">7</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=8">8</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=9">9</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=10">10</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=11">11</a> ... <a href="?page=message_list&amp;list_path=%2F&amp;list_page=100">100</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=6"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 5, 1000, '/'));
$this->assertEquals('<a href="?page=message_list&amp;list_path=%2F&amp;list_page=9"><i class="bi bi-caret-left-fill"></i></a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=1">1</a> ... <a href="?page=message_list&amp;list_path=%2F&amp;list_page=4">4</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=5">5</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=6">6</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=7">7</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=8">8</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=9">9</a> <a class="current_page fw-bolder" href="?page=message_list&amp;list_path=%2F&amp;list_page=10">10</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=11">11</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=12">12</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=13">13</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=14">14</a> ... <a href="?page=message_list&amp;list_path=%2F&amp;list_page=100">100</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=11"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 10, 1000, '/'));
$this->assertEquals('', build_page_links(10, 1, 10, '/'));
$this->assertEquals('<a class="disabled_link"><i class="bi bi-caret-left-fill"></i></a> <a class="current_page fw-bolder" href="?page=message_list&amp;list_path=%2F&amp;list_page=1&amp;filter=1&amp;sort=1">1</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;filter=1&amp;sort=1">2</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=3&amp;filter=1&amp;sort=1">3</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=4&amp;filter=1&amp;sort=1">4</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=5&amp;filter=1&amp;sort=1">5</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=6&amp;filter=1&amp;sort=1">6</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=7&amp;filter=1&amp;sort=1">7</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=8&amp;filter=1&amp;sort=1">8</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=9&amp;filter=1&amp;sort=1">9</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=10&amp;filter=1&amp;sort=1">10</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;filter=1&amp;sort=1"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 1, 100, '/', true, true));
$this->assertEquals('<a class="disabled_link"><i class="bi bi-caret-left-fill"></i></a> <a class="current_page fw-bolder" href="?page=message_list&amp;list_path=%2F&amp;list_page=1&amp;keyword=cypht&amp;filter=1&amp;sort=1">1</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;keyword=cypht&amp;filter=1&amp;sort=1">2</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=3&amp;keyword=cypht&amp;filter=1&amp;sort=1">3</a> <a href="?page=message_list&amp;list_path=%2F&amp;list_page=2&amp;keyword=cypht&amp;filter=1&amp;sort=1"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 1, 30, '/', true, true, "cypht"));
}
}
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,6 @@ public function test_message_list_heading() {
public function test_message_list_end() {
$test = new Output_Test('message_list_end', 'core');
$res = $test->run();
$this->assertEquals(array('</tbody></table></div><div class="mb-5 page_links d-flex justify-content-center gap-3 align-content-center"></div></div>'), $res->output_response);
$this->assertEquals(array('</tbody></table></div></div>'), $res->output_response);
}
}

0 comments on commit f93c37b

Please sign in to comment.