Mercurial > hg > rc1
changeset 23:5a851d965bc1
sorting, some better displays
author | Charlie Root |
---|---|
date | Wed, 17 Jan 2018 09:13:17 -0500 |
parents | 61316094e61d |
children | 4869fae20b88 |
files | plugins/thunderbird_labels/thunderbird_labels.php |
diffstat | 1 files changed, 64 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/thunderbird_labels/thunderbird_labels.php Tue Jan 16 17:48:15 2018 -0500 +++ b/plugins/thunderbird_labels/thunderbird_labels.php Wed Jan 17 09:13:17 2018 -0500 @@ -102,15 +102,25 @@ { // if no user specific labels, use localized strings by default $max_id = $this->rc->config->get('tb_max_label'); + $parmLabs = array(); $tb_flag_text = array(); for ($i = 0; $i <= $max_id; $i++) { - $tb_flag_text[$i] = $this->getText('label'.$i); + $lab=$this->getText('label'.$i); + $isParm=($lab[-1]=='1'); + $lab=substr($lab,0,strlen($lab)-1); + $tb_flag_text[$i] = $lab; + if ($isParm) { + $parmLabs[$i]=strtolower($lab); + } } $this->rc->config->set('tb_label_custom_labels', - tb_flag_text); + $tb_flag_text); + $this->rc->config->set('tb_label_parm_labels', + $parmLabs); } // pass label strings to JS $this->rc->output->set_env('tb_label_custom_labels', $this->rc->config->get('tb_label_custom_labels')); + $this->rc->output->set_env('tb_label_parm_labels', $this->rc->config->get('tb_label_parm_labels')); } // create a section for the tb-labels Settings @@ -187,18 +197,18 @@ && $this->rc->config->get('tb_label_modify_labels')) { $old = $this->rc->config->get($key); + $oldParms = $this->rc->config->get('tb_label_parm_labels'); $max_id = $this->rc->config->get('tb_max_label'); for($i=1; $i<=$max_id; $i++) { $oldVal = $old[$i]; - $oname=substr($oldVal,0,-1); - $oparm=substr($oldVal,-1); + $oparm=$oldParms[$i]?1:0; $input = new html_inputfield(array( 'name' => $key.$i, 'id' => $key.$i, 'type' => 'text', 'autocomplete' => 'off', - 'value' => $oname)); + 'value' => $oldVal)); $parmBox = new html_checkbox(array( 'name' => $key.$i.'parm', 'id' => $key.$i.'parm', @@ -238,12 +248,16 @@ { $max_id = $this->rc->config->get('tb_max_label'); $tb_lab_prefs = array(); + $tb_parm_prefs = array(); $tb_lab_prefs[0] = $this->gettext('label0'); for ($i = 1; $i <= $max_id; $i++) { - $parm=rcube_utils::get_input_value('tb_label_custom_labels'.$i.'parm', rcube_utils::INPUT_POST)?'1':'0'; - $tb_lab_prefs[$i] = rcube_utils::get_input_value('tb_label_custom_labels'.$i, rcube_utils::INPUT_POST).$parm; + $tb_lab_prefs[$i] = rcube_utils::get_input_value('tb_label_custom_labels'.$i, rcube_utils::INPUT_POST); + if (rcube_utils::get_input_value('tb_label_custom_labels'.$i.'parm', rcube_utils::INPUT_POST)) { + $tb_parm_prefs[$i] = strtolower($tb_lab_prefs[$i]); + } } $args['prefs']['tb_label_custom_labels'] = $tb_lab_prefs; + $args['prefs']['tb_label_parm_labels'] = $tb_parm_prefs; } return $args; @@ -318,19 +332,20 @@ public function read_flags($args) { - rcube::write_log($this->name, "read: ".print_r($args, true)); + rcube::write_log($this->name, "read: ".$_SESSION['sort_col']); // add color information for all messages // dont loop over all messages if we dont have any highlights or no msgs if (!isset($args['messages']) or !is_array($args['messages'])) { return $args; } - // loop over all messages and add $LabelX info to the extra_flags foreach($args['messages'] as $message) { #rcube::write_log($this->name, print_r($message->flags, true)); $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! $message->list_flags['extra_flags']['tb_parms'] = array(); + $keyPos = array_search($_SESSION['sort_col'],$this->rc->config->get('tb_label_parm_labels')); + rcube::write_log($this->name,"sort? $keyPos ".$_SESSION['sort_order']." ".print_r($this->rc->config->get('tb_label_parm_labels'),true)); if (is_array($message->flags)) foreach ($message->flags as $flagname => $flagvalue) { @@ -342,9 +357,14 @@ rcube::write_log($this->name, "Flag:".$flag." Flag_no:".$flag_no); if ($ppos = strpos($flag_no,'_') > -1) { // We have a flag parameter value... + $pn=(int)substr($flag_no,0,$ppos); + $pv=substr($flag_no,$ppos+1); $message->list_flags['extra_flags']['tb_lparms'][]=array( - 'number' => substr($flag_no,0,$ppos), - 'parm' => substr($flag_no,$ppos+1)); + 'number' => $pn, + 'parm' => $pv); + if ($keyPos) { + $message->sortKey=array_map('intval',preg_split('/[/-]/',$pv)); + } } else { $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; @@ -352,6 +372,39 @@ } } } + if ($keyPos) { + $rev = $_SESSION['sort_order']=='DESC'; + usort($args['messages'], + function($a, $b) use ($rev) { + if ($ak=$a->sortKey) { + if ($bk=$b->sortKey) { + // each key is sd sm ed em + if ($ak[1]<$bk[1]) return $rev?1:-1; + if ($ak[1]>$bk[1]) return $rev?-1:1; + // start month is the same + if ($ak[0]<$bk[0]) return $rev?1:-1; + if ($ak[0]>$bk[0]) return $rev?-1:1; + // start date is the same + if ($ak[3]<$bk[3]) return $rev?1:-1; + if ($ak[3]>$bk[3]) return $rev?-1:1; + // end month is the same + if ($ak[2]<$bk[2]) return $rev?1:-1; + if ($ak[2]>$bk[2]) return $rev?-1:1; + // both dates are the same + return 0; + } + else { + return $rev?1:-1; + } + } + else if ($b->sortKey) { + return $rev?-1:1; + } + else { + return 0; + } + }); + } return($args); }