diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js index d485947..d64c96a 100644 --- a/js/app/views/CatalogUI.js +++ b/js/app/views/CatalogUI.js @@ -358,13 +358,7 @@ Ext.define('amdaUI.CatalogUI', { text: obj.name, sortable : true, dataIndex: obj.id, - menuDisabled: false, - listeners: { - 'sortchange' : function(ct, column, direction, eOpts) { - //console.log(column); - }, - scope: this - } + menuDisabled: false }; switch (obj.type) { case 1: //dateTime @@ -446,7 +440,7 @@ Ext.define('amdaUI.CatalogUI', { // // clear sort me.TTGrid.getStore().sorters.clear(); - me.TTGrid.getStore().sorters = new Ext.util.MixedCollection(); + //me.TTGrid.getStore().sorters = new Ext.util.MixedCollection(); //set cache token to the Catalog object me.object.set('cacheToken', result.token); @@ -764,11 +758,6 @@ Ext.define('amdaUI.CatalogUI', { }] }); - this.TTGrid.down('.headercontainer').on('sortchange', function(ct, column, direction, eOpts) { - console.log(column); -console.log(direction); -}); - this.formPanel = Ext.create('Ext.form.Panel', { region : 'center', layout: 'hbox', diff --git a/php/classes/CatalogCacheObject.php b/php/classes/CatalogCacheObject.php index 725e3a4..4b63de4 100644 --- a/php/classes/CatalogCacheObject.php +++ b/php/classes/CatalogCacheObject.php @@ -9,9 +9,9 @@ class CatalogCacheObject extends TimeTableCacheObject $this->parameters = array(); //ToDo - Init sort and filters for Catalog /*unset($this->filter); - $this->filter = new TimeTableCacheFilterObject();; + $this->filter = new TimeTableCacheFilterObject();;*/ unset($this->sort); - $this->sort = new TimeTableCacheSortObject();*/ + $this->sort = new CatalogCacheSortObject($this); } protected function createNewIntervalObject($id, $index = -1) { diff --git a/php/classes/CatalogCacheSortObject.php b/php/classes/CatalogCacheSortObject.php new file mode 100644 index 0000000..b784282 --- /dev/null +++ b/php/classes/CatalogCacheSortObject.php @@ -0,0 +1,147 @@ +<?php + +class CatalogCacheSortPartObject extends TimeTableCacheSortPartObject +{ + public static $TYPE_PARAMETER = 6; + + private $paramId = ""; + + public function compare($interval_a, $interval_b) { + if ($this->type != self::$TYPE_PARAMETER) { + return parent::compare($interval_a, $interval_b) ; + } + + $params_a = $interval_a->getParams(); + $params_b = $interval_b->getParams(); + + // Retrieve data type + $data_type = -1; + foreach ($this->cacheObject->getParametersInfo() as $parameter) { + if ($parameter['id'] == $this->paramId) { + $data_type = $parameter['type']; + break; + } + } + + //If something is not defined + if ($data_type < 0) { + return 0; + } + else if (!isset($params_a[$this->paramId]) && !isset($params_b[$this->paramId])) { + return 0; + } + else if(!isset($params_a[$this->paramId])) { + switch ($this->dir) { + case self::$DIRECTION_ASC : + return 1; + default : + return -1; + } + } + else if (!isset($params_b[$this->paramId])) { + switch ($this->dir) { + case self::$DIRECTION_ASC : + return -1; + default : + return 1; + } + } + + // Apply comparison on intervals parameter data + switch ($parameter['type']) { + case 0: //double + $val_a_minus_b = floatval($params_a[$this->paramId]) - floatval($params_b[$this->paramId]); + break; + case 1: //date (timestamp) + $val_a_minus_b = intval($params_a[$this->paramId]) - intval($params_b[$this->paramId]); + break; + case 2: //string + $val_a_minus_b = strcmp($params_a[$this->paramId], $params_b[$this->paramId]); + break; + case 3: //int + $val_a_minus_b = intval($params_a[$this->paramId]) - intval($params_b[$this->paramId]); + break; + default: // not defined => string + $val_a_minus_b = strcmp($params_a[$this->paramId], $params_b[$this->paramId]); + } + + if ($this->dir == self::$DIRECTION_ASC) { + return -$val_a_minus_b; + } + return $val_a_minus_b; + } + + public function loadFromObject($part_obj) { + parent::loadFromObject($part_obj); + if ($this->type == self::$TYPE_UNKNOWN) { + //Check if it's a catalog parameter + foreach ($this->cacheObject->getParametersInfo() as $parameter) { + if ($parameter['id'] == $part_obj->property) { + $this->type = self::$TYPE_PARAMETER; + $this->paramId = $parameter['id']; + } + } + } + } + + public function writeBin($handle) { + parent::writeBin($handle); + if ($this->type == self::$TYPE_PARAMETER) { + //Param Id length + fwrite($handle,pack('L',strlen($this->paramId))); + + //Param Id + for ($i = 0; $i < strlen($this->paramId); ++$i) + fwrite($handle,pack('C',ord($this->paramId[$i]))); + } + } + + public function loadBin($handle) { + parent::loadBin($handle); + if ($this->type == self::$TYPE_PARAMETER) { + //Param Id length + if (!$res = unpack('Lidlength',fread($handle,4))) + return false; + $idlength = $res['idlength']; + + //Param Id + $this->paramId = ""; + for ($j = 0; $j < $idlength; ++$j) + { + if (!$res = unpack('Cid',fread($handle,1))) + return false; + $this->paramId .= chr($res['id']); + } + } + } + + public function dump() { + if ($this->type == self::$TYPE_PARAMETER) { + echo " => ".get_class($this)." : type = parameter, id = ".$this->paramId; + echo ", direction = "; + switch ($this->dir) + { + case self::$DIRECTION_ASC : + echo "ASC"; + break; + case self::$DIRECTION_DES : + echo "DESC"; + break; + default: + echo "unknown"; + } + echo PHP_EOL; + return; + } + parent::dump(); + } +} + +class CatalogCacheSortObject extends TimeTableCacheSortObject +{ + protected function createNewPart() { + return new CatalogCacheSortPartObject($this->cacheObject); + } +} + + ?> diff --git a/php/classes/TimeTableCacheObject.php b/php/classes/TimeTableCacheObject.php index 3cbe5ae..21766a8 100644 --- a/php/classes/TimeTableCacheObject.php +++ b/php/classes/TimeTableCacheObject.php @@ -31,7 +31,7 @@ class TimeTableCacheObject unset($this->filter); $this->filter = new TimeTableCacheFilterObject();; unset($this->sort); - $this->sort = new TimeTableCacheSortObject(); + $this->sort = new TimeTableCacheSortObject($this); } public function setIsModified($isModified) { @@ -497,7 +497,7 @@ class TimeTableCacheObject } public function dump() { - echo " => TimeTableCacheObject : token = ".$this->token.", nb intervals = ".count($this->intervals).", last id = ".$this->lastId.", nb indexes = ".count($this->indexes).PHP_EOL; + echo " => ".get_class($this)." : token = ".$this->token.", nb intervals = ".count($this->intervals).", last id = ".$this->lastId.", nb indexes = ".count($this->indexes).PHP_EOL; echo PHP_EOL; $this->filter->dump(); diff --git a/php/classes/TimeTableCacheSortObject.php b/php/classes/TimeTableCacheSortObject.php index 60de5c3..03e34a2 100644 --- a/php/classes/TimeTableCacheSortObject.php +++ b/php/classes/TimeTableCacheSortObject.php @@ -13,12 +13,14 @@ class TimeTableCacheSortPartObject public static $DIRECTION_ASC = 1; public static $DIRECTION_DES = 2; + protected $cacheObject = NULL; protected $type; protected $dir; - function __construct() { + function __construct($cacheObject) { $this->type = self::$TYPE_UNKNOWN; $this->dir = self::$DIRECTION_UNKNOWN; + $this->cacheObject = $cacheObject; } public function getType() { @@ -119,7 +121,7 @@ class TimeTableCacheSortPartObject } public function dump() { - echo " => TimeTableCacheSortPartObject : type = "; + echo " => ".get_class($this)." : type = "; switch ($this->type) { case self::$TYPE_START : @@ -159,8 +161,14 @@ class TimeTableCacheSortPartObject class TimeTableCacheSortObject { protected $parts = array(); + protected $cacheObject = NULL; - function __construct() { + protected function createNewPart() { + return new TimeTableCacheSortPartObject($this->cacheObject); + } + + function __construct($cacheObject) { + $this->cacheObject = $cacheObject; } public function getParts() { @@ -179,14 +187,15 @@ class TimeTableCacheSortObject $this->reset(); foreach ($sort_obj as $sort_part) { - $part = new TimeTableCacheSortPartObject(); + $part = $this->createNewPart(); $part->loadFromObject($sort_part); array_push($this->parts, $part); } } public function isSameFromObject($sort_obj) { - $sort = new TimeTableCacheSortObject(); + $this_class = get_class(); + $sort = new $this_class($this->cacheObject); $sort->loadFromObject($sort_obj); return $this->isSame($sort); } @@ -245,14 +254,14 @@ class TimeTableCacheSortObject $res = unpack('Lcount',fread($handle,4)); for ($i = 0; $i < $res['count']; ++$i) { - $part = new TimeTableCacheSortPartObject(); + $part = $this->createNewPart(); $part->loadBin($handle); array_push($this->parts, $part); } } public function dump() { - echo " => TimeTableCacheSortObject : number of parts = ".count($this->parts).PHP_EOL; + echo " => ".get_class($this)." : number of parts = ".count($this->parts).PHP_EOL; foreach ($this->parts as $part) $part->dump(); } -- libgit2 0.21.2