Commit ab7c3c63db7662f8d54b5b65e51cae6cb065c4d0

Authored by Benjamin Renard
1 parent 42e2e019

Sort parameter columns of a catalog (#6897)

js/app/views/CatalogUI.js
... ... @@ -358,13 +358,7 @@ Ext.define('amdaUI.CatalogUI', {
358 358 text: obj.name,
359 359 sortable : true,
360 360 dataIndex: obj.id,
361   - menuDisabled: false,
362   - listeners: {
363   - 'sortchange' : function(ct, column, direction, eOpts) {
364   - //console.log(column);
365   - },
366   - scope: this
367   - }
  361 + menuDisabled: false
368 362 };
369 363 switch (obj.type) {
370 364 case 1: //dateTime
... ... @@ -446,7 +440,7 @@ Ext.define('amdaUI.CatalogUI', {
446 440 //
447 441 // clear sort
448 442 me.TTGrid.getStore().sorters.clear();
449   - me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
  443 + //me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
450 444  
451 445 //set cache token to the Catalog object
452 446 me.object.set('cacheToken', result.token);
... ... @@ -764,11 +758,6 @@ Ext.define('amdaUI.CatalogUI', {
764 758 }]
765 759 });
766 760  
767   - this.TTGrid.down('.headercontainer').on('sortchange', function(ct, column, direction, eOpts) {
768   - console.log(column);
769   -console.log(direction);
770   -});
771   -
772 761 this.formPanel = Ext.create('Ext.form.Panel', {
773 762 region : 'center',
774 763 layout: 'hbox',
... ...
php/classes/CatalogCacheObject.php
... ... @@ -9,9 +9,9 @@ class CatalogCacheObject extends TimeTableCacheObject
9 9 $this->parameters = array();
10 10 //ToDo - Init sort and filters for Catalog
11 11 /*unset($this->filter);
12   - $this->filter = new TimeTableCacheFilterObject();;
  12 + $this->filter = new TimeTableCacheFilterObject();;*/
13 13 unset($this->sort);
14   - $this->sort = new TimeTableCacheSortObject();*/
  14 + $this->sort = new CatalogCacheSortObject($this);
15 15 }
16 16  
17 17 protected function createNewIntervalObject($id, $index = -1) {
... ...
php/classes/CatalogCacheSortObject.php 0 โ†’ 100644
... ... @@ -0,0 +1,147 @@
  1 +<?php
  2 +
  3 +class CatalogCacheSortPartObject extends TimeTableCacheSortPartObject
  4 +{
  5 + public static $TYPE_PARAMETER = 6;
  6 +
  7 + private $paramId = "";
  8 +
  9 + public function compare($interval_a, $interval_b) {
  10 + if ($this->type != self::$TYPE_PARAMETER) {
  11 + return parent::compare($interval_a, $interval_b) ;
  12 + }
  13 +
  14 + $params_a = $interval_a->getParams();
  15 + $params_b = $interval_b->getParams();
  16 +
  17 + // Retrieve data type
  18 + $data_type = -1;
  19 + foreach ($this->cacheObject->getParametersInfo() as $parameter) {
  20 + if ($parameter['id'] == $this->paramId) {
  21 + $data_type = $parameter['type'];
  22 + break;
  23 + }
  24 + }
  25 +
  26 + //If something is not defined
  27 + if ($data_type < 0) {
  28 + return 0;
  29 + }
  30 + else if (!isset($params_a[$this->paramId]) && !isset($params_b[$this->paramId])) {
  31 + return 0;
  32 + }
  33 + else if(!isset($params_a[$this->paramId])) {
  34 + switch ($this->dir) {
  35 + case self::$DIRECTION_ASC :
  36 + return 1;
  37 + default :
  38 + return -1;
  39 + }
  40 + }
  41 + else if (!isset($params_b[$this->paramId])) {
  42 + switch ($this->dir) {
  43 + case self::$DIRECTION_ASC :
  44 + return -1;
  45 + default :
  46 + return 1;
  47 + }
  48 + }
  49 +
  50 + // Apply comparison on intervals parameter data
  51 + switch ($parameter['type']) {
  52 + case 0: //double
  53 + $val_a_minus_b = floatval($params_a[$this->paramId]) - floatval($params_b[$this->paramId]);
  54 + break;
  55 + case 1: //date (timestamp)
  56 + $val_a_minus_b = intval($params_a[$this->paramId]) - intval($params_b[$this->paramId]);
  57 + break;
  58 + case 2: //string
  59 + $val_a_minus_b = strcmp($params_a[$this->paramId], $params_b[$this->paramId]);
  60 + break;
  61 + case 3: //int
  62 + $val_a_minus_b = intval($params_a[$this->paramId]) - intval($params_b[$this->paramId]);
  63 + break;
  64 + default: // not defined => string
  65 + $val_a_minus_b = strcmp($params_a[$this->paramId], $params_b[$this->paramId]);
  66 + }
  67 +
  68 + if ($this->dir == self::$DIRECTION_ASC) {
  69 + return -$val_a_minus_b;
  70 + }
  71 + return $val_a_minus_b;
  72 + }
  73 +
  74 + public function loadFromObject($part_obj) {
  75 + parent::loadFromObject($part_obj);
  76 + if ($this->type == self::$TYPE_UNKNOWN) {
  77 + //Check if it's a catalog parameter
  78 + foreach ($this->cacheObject->getParametersInfo() as $parameter) {
  79 + if ($parameter['id'] == $part_obj->property) {
  80 + $this->type = self::$TYPE_PARAMETER;
  81 + $this->paramId = $parameter['id'];
  82 + }
  83 + }
  84 + }
  85 + }
  86 +
  87 + public function writeBin($handle) {
  88 + parent::writeBin($handle);
  89 + if ($this->type == self::$TYPE_PARAMETER) {
  90 + //Param Id length
  91 + fwrite($handle,pack('L',strlen($this->paramId)));
  92 +
  93 + //Param Id
  94 + for ($i = 0; $i < strlen($this->paramId); ++$i)
  95 + fwrite($handle,pack('C',ord($this->paramId[$i])));
  96 + }
  97 + }
  98 +
  99 + public function loadBin($handle) {
  100 + parent::loadBin($handle);
  101 + if ($this->type == self::$TYPE_PARAMETER) {
  102 + //Param Id length
  103 + if (!$res = unpack('Lidlength',fread($handle,4)))
  104 + return false;
  105 + $idlength = $res['idlength'];
  106 +
  107 + //Param Id
  108 + $this->paramId = "";
  109 + for ($j = 0; $j < $idlength; ++$j)
  110 + {
  111 + if (!$res = unpack('Cid',fread($handle,1)))
  112 + return false;
  113 + $this->paramId .= chr($res['id']);
  114 + }
  115 + }
  116 + }
  117 +
  118 + public function dump() {
  119 + if ($this->type == self::$TYPE_PARAMETER) {
  120 + echo " => ".get_class($this)." : type = parameter, id = ".$this->paramId;
  121 + echo ", direction = ";
  122 + switch ($this->dir)
  123 + {
  124 + case self::$DIRECTION_ASC :
  125 + echo "ASC";
  126 + break;
  127 + case self::$DIRECTION_DES :
  128 + echo "DESC";
  129 + break;
  130 + default:
  131 + echo "unknown";
  132 + }
  133 + echo PHP_EOL;
  134 + return;
  135 + }
  136 + parent::dump();
  137 + }
  138 +}
  139 +
  140 +class CatalogCacheSortObject extends TimeTableCacheSortObject
  141 +{
  142 + protected function createNewPart() {
  143 + return new CatalogCacheSortPartObject($this->cacheObject);
  144 + }
  145 +}
  146 +
  147 + ?>
... ...
php/classes/TimeTableCacheObject.php
... ... @@ -31,7 +31,7 @@ class TimeTableCacheObject
31 31 unset($this->filter);
32 32 $this->filter = new TimeTableCacheFilterObject();;
33 33 unset($this->sort);
34   - $this->sort = new TimeTableCacheSortObject();
  34 + $this->sort = new TimeTableCacheSortObject($this);
35 35 }
36 36  
37 37 public function setIsModified($isModified) {
... ... @@ -497,7 +497,7 @@ class TimeTableCacheObject
497 497 }
498 498  
499 499 public function dump() {
500   - echo " => TimeTableCacheObject : token = ".$this->token.", nb intervals = ".count($this->intervals).", last id = ".$this->lastId.", nb indexes = ".count($this->indexes).PHP_EOL;
  500 + echo " => ".get_class($this)." : token = ".$this->token.", nb intervals = ".count($this->intervals).", last id = ".$this->lastId.", nb indexes = ".count($this->indexes).PHP_EOL;
501 501 echo PHP_EOL;
502 502  
503 503 $this->filter->dump();
... ...
php/classes/TimeTableCacheSortObject.php
... ... @@ -13,12 +13,14 @@ class TimeTableCacheSortPartObject
13 13 public static $DIRECTION_ASC = 1;
14 14 public static $DIRECTION_DES = 2;
15 15  
  16 + protected $cacheObject = NULL;
16 17 protected $type;
17 18 protected $dir;
18 19  
19   - function __construct() {
  20 + function __construct($cacheObject) {
20 21 $this->type = self::$TYPE_UNKNOWN;
21 22 $this->dir = self::$DIRECTION_UNKNOWN;
  23 + $this->cacheObject = $cacheObject;
22 24 }
23 25  
24 26 public function getType() {
... ... @@ -119,7 +121,7 @@ class TimeTableCacheSortPartObject
119 121 }
120 122  
121 123 public function dump() {
122   - echo " => TimeTableCacheSortPartObject : type = ";
  124 + echo " => ".get_class($this)." : type = ";
123 125 switch ($this->type)
124 126 {
125 127 case self::$TYPE_START :
... ... @@ -159,8 +161,14 @@ class TimeTableCacheSortPartObject
159 161 class TimeTableCacheSortObject
160 162 {
161 163 protected $parts = array();
  164 + protected $cacheObject = NULL;
162 165  
163   - function __construct() {
  166 + protected function createNewPart() {
  167 + return new TimeTableCacheSortPartObject($this->cacheObject);
  168 + }
  169 +
  170 + function __construct($cacheObject) {
  171 + $this->cacheObject = $cacheObject;
164 172 }
165 173  
166 174 public function getParts() {
... ... @@ -179,14 +187,15 @@ class TimeTableCacheSortObject
179 187 $this->reset();
180 188 foreach ($sort_obj as $sort_part)
181 189 {
182   - $part = new TimeTableCacheSortPartObject();
  190 + $part = $this->createNewPart();
183 191 $part->loadFromObject($sort_part);
184 192 array_push($this->parts, $part);
185 193 }
186 194 }
187 195  
188 196 public function isSameFromObject($sort_obj) {
189   - $sort = new TimeTableCacheSortObject();
  197 + $this_class = get_class();
  198 + $sort = new $this_class($this->cacheObject);
190 199 $sort->loadFromObject($sort_obj);
191 200 return $this->isSame($sort);
192 201 }
... ... @@ -245,14 +254,14 @@ class TimeTableCacheSortObject
245 254 $res = unpack('Lcount',fread($handle,4));
246 255 for ($i = 0; $i < $res['count']; ++$i)
247 256 {
248   - $part = new TimeTableCacheSortPartObject();
  257 + $part = $this->createNewPart();
249 258 $part->loadBin($handle);
250 259 array_push($this->parts, $part);
251 260 }
252 261 }
253 262  
254 263 public function dump() {
255   - echo " => TimeTableCacheSortObject : number of parts = ".count($this->parts).PHP_EOL;
  264 + echo " => ".get_class($this)." : number of parts = ".count($this->parts).PHP_EOL;
256 265 foreach ($this->parts as $part)
257 266 $part->dump();
258 267 }
... ...