Skip to content

Commit

Permalink
keep the sorting client-side for the search page
Browse files Browse the repository at this point in the history
  • Loading branch information
mercihabam committed Jan 30, 2025
1 parent c7e66c9 commit 34534c0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
3 changes: 1 addition & 2 deletions modules/core/js_modules/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function performSearch(routeParams) {
Object.values(response.formatted_message_list).forEach((message) => {
Hm_Utils.tbody().append(message['0']);
});
// sort by arrival date
Hm_Message_List.sort(4);
Hm_Message_List.sort(getParam('sort') || 'arrival');
}
Hm_Message_List.check_empty_list();
}
Expand Down
6 changes: 6 additions & 0 deletions modules/core/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function applySearchPageHandlers(routeParams) {
Hm_Message_List.select_combined_view();
sortHandlerForMessageListAndSearchPage();
$('.search_reset').on("click", Hm_Utils.reset_search_form);
$('.combined_sort').on("change", function() { Hm_Message_List.sort($(this).val()); });

performSearch(routeParams);

Expand Down Expand Up @@ -86,6 +87,11 @@ function applyMessaleListPageHandlers(routeParams) {
if (routeParams.list_path === 'github_all') {
return applyGithubMessageListPageHandler(routeParams);
}


$('.combined_sort').on("change", function() {
sortCombinedLists($(this).val());
});

// TODO: Refactor this handler to be more modular(applicable only for the imap list type)
return applyImapMessageListPageHandlers(routeParams);
Expand Down
8 changes: 8 additions & 0 deletions modules/core/message_list_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ function date_callback($vals, $style, $output_mod) {
return sprintf('<td class="msg_date%s" title="%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></td>', $snooze_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
}}

function dates_holders_callback($vals) {
$res = '<td class="dates d-none">';
$res .= '<input type="hidden" name="arrival" class="arrival" value="'. $vals[0] .'" arial-label="Arrival date" />';
$res .= '<input type="hidden" name="date" class="date" value="'. $vals[1] .'" arial-label="Sent date" />';
$res .= '</td>';
return $res;
}

/**
* Callback for an icon in a message list row
* @subpackage core/functions
Expand Down
34 changes: 11 additions & 23 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,31 +528,22 @@ function Message_List() {
var aval;
var bval;
var sort_result = listitems.sort(function(a, b) {
switch (Math.abs(fld)) {
case 1:
case 2:
case 3:
aval = $($('td', a)[Math.abs(fld)]).text().replace(/^\s+/g, '');
bval = $($('td', b)[Math.abs(fld)]).text().replace(/^\s+/g, '');
break;
case 4:
default:
aval = $('input', $($('td', a)[Math.abs(fld)])).val();
bval = $('input', $($('td', b)[Math.abs(fld)])).val();
break;
}
if (fld == 4 || fld == -4 || !fld) {
if (fld == -4) {
const sortField = fld.replace('-', '');
if (['arrival', 'date'].includes(sortField)) {
aval = new Date($(`input.${sortField}`, $('td.dates', a)).val());
bval = new Date($(`input.${sortField}`, $('td.dates', b)).val());
if (fld.startsWith('-')) {
return aval - bval;
}
return bval - aval;
}
else {
if (fld && fld < 0) {
return bval.toUpperCase().localeCompare(aval.toUpperCase());
}
return aval.toUpperCase().localeCompare(bval.toUpperCase());

aval = $(`td.${sortField}`, a).text().replace(/^\s+/g, '');
bval = $(`td.${sortField}`, b).text().replace(/^\s+/g, '');
if (fld.startsWith('-')) {
return bval.toUpperCase().localeCompare(aval.toUpperCase());
}
return aval.toUpperCase().localeCompare(bval.toUpperCase());
});
this.sort_fld = fld;
Hm_Utils.tbody().html('');
Expand Down Expand Up @@ -1810,9 +1801,6 @@ var hasLeadingOrTrailingSpaces = function(str) {
var Hm_Message_List = new Message_List();

function sortHandlerForMessageListAndSearchPage() {
$('.combined_sort').on("change", function() {
sortCombinedLists($(this).val());
});
$('.source_link').on("click", function() { $('.list_sources').toggle(); $('#list_controls_menu').hide(); return false; });
if (getListPathParam() == 'unread' && $('.menu_unread > a').css('font-weight') == 'bold') {
$('.menu_unread > a').css('font-weight', 'normal');
Expand Down
4 changes: 3 additions & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function format_imap_message_list($msg_list, $output_module, $parent_list=false,
array('safe_output_callback', 'source', $source),
array('safe_output_callback', 'from'.$nofrom, $from, null, str_replace(array($from, '<', '>'), '', $msg['from'])),
array('date_callback', $date, $timestamp),
array('dates_holders_callback', $msg['internal_date'], $msg['date']),
),
$id,
$style,
Expand All @@ -330,7 +331,8 @@ function format_imap_message_list($msg_list, $output_module, $parent_list=false,
array('safe_output_callback', 'from'.$nofrom, $from, null, str_replace(array($from, '<', '>'), '', $msg['from'])),
array('subject_callback', $subject, $url, $flags, null, $preview_msg),
array('date_callback', $date, $timestamp, $is_snoozed),
array('icon_callback', $flags)
array('icon_callback', $flags),
array('dates_holders_callback', $msg['internal_date'], $msg['date']),
),
$id,
$style,
Expand Down

0 comments on commit 34534c0

Please sign in to comment.