diff --git a/js/app/views/CatalogStatusGrid.js b/js/app/views/CatalogStatusGrid.js new file mode 100644 index 0000000..2e26dd5 --- /dev/null +++ b/js/app/views/CatalogStatusGrid.js @@ -0,0 +1,190 @@ +Ext.define('StatusColorPicker', { + extend: 'Ext.form.field.Picker', + alias: 'widget.statuscolorpicker', + + toUpper : function(x){ + return x.toUpperCase(); + }, + replaceColor : function(x){ + return x.replace("#","") + }, + createPicker: function() { + var me = this; + return Ext.create('Ext.picker.Color', { + pickerField: me, + renderTo: Ext.getBody(), + floating: true, + minWidth: 133, + maxWidth: 200, + minHeight: 225, + autoScroll:true, + focusOnShow: true, + colors: amdaPlotObj.PlotObjectConfig.availableColorsNew.map(this.replaceColor).map(this.toUpper), + listeners: { + select: function(picker, color) { + me.setValue(color); + me.picker.hide(); + }, + scope: me + } + }); + } +}); + +Ext.define('StatusColorEditor', { + extend: 'Ext.grid.CellEditor', + alias: 'widget.statuscoloreditor', + + requires: [ + 'StatusColorPicker' + ], + + field: { + xtype: 'statuscolorpicker' + }, +}); + + +Ext.define('amdaUI.CatalogStatusGrid', { + extend: 'Ext.grid.Panel', + alias: 'widget.catstatusgrid', + + statusStore: Ext.create('Ext.data.Store', { + fields:['value', 'label', 'color'], + data:{'items':[]}, + proxy: { + type: 'memory', + reader: { + type: 'json', + root: 'items' + } + } + }), + cellEditing: Ext.create('Ext.grid.plugin.CellEditing', {clicksToEdit: 1 }), + + xtype:'grid', + + constructor: function(config) { + if(config.status != null){ + this.parseStatus(config.status); + } + this.init(config); + this.callParent(); + }, + onAddClick: function(grid){ + // Create a model instance + var rec = {'value':0, 'label':'', 'color':'000000'}; + + this.statusStore.insert(0, rec); + this.cellEditing.startEditByPosition({ + row: 0, + column: 0 + }); + }, + clearStore: function(){ + this.statusStore.removeAll(); + }, + onRemoveClick: function(grid, rowIndex){ + this.statusStore.removeAt(rowIndex); + }, + + rgbToHex: function(rgbArray) { + var hex = ""; + for (var i = 0; i < rgbArray.length; i++) { + var hexValue = Number(rgbArray[i]).toString(16); + if (hexValue.length < 2) { + hexValue = "0" + hexValue; + } + hex += hexValue; + } + return hex.toUpperCase(); + }, + hexToRgb: function(hex) { + var r = parseInt(hex.substring(0,2), 16); + var g = parseInt(hex.substring(2,4), 16); + var b = parseInt(hex.substring(4,6), 16); + return [r, g, b]; + }, + + getStatusString: function() { + var me = this; + var data = this.statusStore.data.items.map(function(item) { + var label = item.get('label'); + var value = item.get('value'); + var color = item.get('color'); + return value + ' : ' + label + ' [' + me.hexToRgb(color).toString().replaceAll(",",", ") + ']'; + }); + + var outputString = data.join(' - '); + return outputString; + }, + + parseStatus: function(inputStr) { + var me = this; + var items = inputStr.split(" - "); + var data = []; + for (var i = 0; i < items.length; i++) { + var parts = items[i].split(" : "); + if(parts.length > 1){ + var labelParts = parts[1].split(" ["); + + me.statusStore.insert(i,{ + 'value': parseInt(parts[0]), + 'label': labelParts[0], + 'color': this.rgbToHex(labelParts[1].slice(0, -1).split(", ")) + }); + } + } + }, + + init: function(config) { + Ext.apply(this, { + + store:this.statusStore, + columns: [ + { text: 'Value', dataIndex: 'value',width: 55,editor: 'textfield',menuDisabled: true}, + { text: 'Label', dataIndex: 'label', width: 55,editor: 'textfield',menuDisabled: true,}, + { + text: 'Color', + dataIndex: 'color', + width: 40, + menuDisabled: true, + renderer: function(value) { + return '<div style="background-color:#' + value + '; margin-left: auto; \ + margin-right: auto;width:15px;height:15px;"></div>'; + }, + editor: { + xtype: 'statuscoloreditor' + } + }, + { + xtype: 'actioncolumn', + width: 25, + sortable: false, + menuDisabled: true, + items: [{ + iconCls: 'icon-delete', + scope: this, + handler: this.onRemoveClick + }] + } + ], + selType: 'cellmodel', + plugins: [this.cellEditing], + height: 130, + renderTo: Ext.getBody(), + tbar: [ + { + xtype:'text', + text : 'Status', + },'->', + { + iconCls: 'icon-add', + text: 'New line', + scope: this, + handler: this.onAddClick + }] + }); + } + +}); \ No newline at end of file diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js index d08c8da..30fcd68 100644 --- a/js/app/views/CatalogUI.js +++ b/js/app/views/CatalogUI.js @@ -19,6 +19,8 @@ Ext.define('amdaUI.CatalogUI', { 'Ext.ux.grid.filter.StringFilter', 'amdaUI.OperationsTT', 'Ext.grid.plugin.BufferedRenderer', + 'amdaPlotObj.PlotObjectConfig', + 'amdaUI.CatalogStatusGrid', 'amdaUI.StatisticalPlug', 'amdaDesktop.AmdaStateProvider', 'Ext.grid.plugin.CellEditing' @@ -26,6 +28,7 @@ Ext.define('amdaUI.CatalogUI', { isCatalog: true, activeField : null, + statusGrid:null, statics: { COL_TO_HIDE_DURATION: 'colToHideDuration' }, @@ -850,8 +853,9 @@ Ext.define('amdaUI.CatalogUI', { }, columnForm: function(isNew, self, me , columnInfo = null){ - - + + this.statusGrid = Ext.create('amdaUI.CatalogStatusGrid',{status : (columnInfo != null) ? columnInfo.status : null }); + var me = this; // Different avaible types var types = Ext.create('Ext.data.Store', { fields: ['type', 'name'], @@ -863,28 +867,10 @@ Ext.define('amdaUI.CatalogUI', { ] }); - Ext.create('Ext.data.Store', { - storeId:'simpsonsStore', - fields:['name', 'email', 'phone'], - data:{'items':[ - { 'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224" }, - { 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234" }, - { 'name': 'Homer', "email":"home@simpsons.com", "phone":"555-222-1244" }, - { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254" } - ]}, - proxy: { - type: 'memory', - reader: { - type: 'json', - root: 'items' - } - } - }); - // Window for the creation of the new Column var window = Ext.create('Ext.window.Window', { title: (isNew) ? 'New Column' : 'Edit Column', - width: 575, + width: 480, height: 210, closable:false, modal:true, @@ -901,15 +887,14 @@ Ext.define('amdaUI.CatalogUI', { defaults: { xtype: 'panel', bodyStyle: {background: '#dfe8f6'}, - flex: 1, border:false, layout: 'anchor' }, layout:'hbox', id: 'simpleForm', frame: true, - bodyPadding: '5 5 0', items: [{ + flex:6, items:[{ // Name xtype:'textfield', @@ -954,34 +939,19 @@ Ext.define('amdaUI.CatalogUI', { }] }, { - items:[ - { - xtype:'grid', - title: 'Status Color', - store: Ext.data.StoreManager.lookup('simpsonsStore'), - columns: [ - { text: 'Value', dataIndex: 'name',flex: 1,editor: 'textfield'}, - { text: 'Label', dataIndex: 'email', flex: 1,editor: 'textfield' }, - { text: 'Color', dataIndex: 'phone',flex: 1,editor: 'textfield' } - ], - selType: 'cellmodel', - plugins: [ - Ext.create('Ext.grid.plugin.CellEditing', { - clicksToEdit: 1 - }) - ], - height: 120, - width: 200, - renderTo: Ext.getBody() - }], + flex:4, + margin:'0 8 0 -5', + items:[this.statusGrid], }], buttons: [{ text: 'Save', handler: function() { // If the form is correctly filled, we continue + if(this.up('form').getForm().isValid()){ if(isNew){ + console.log(me.statusGrid.getStatusString()); var newColumnPrefix='added_param_id_'; var nbAddedColumn= 0; Ext.each(self.TTGrid.headerCt.getGridColumns(), function(column){ @@ -995,6 +965,7 @@ Ext.define('amdaUI.CatalogUI', { this.up('form').getForm().findField('typeColumn').getValue(), this.up('form').getForm().findField('sizeColumn').getValue(), this.up('form').getForm().findField('descriptionColumn').getValue(), + me.statusGrid.getStatusString(), function(result, e){ if(result){ me.toReconfigure = true; @@ -1008,6 +979,7 @@ Ext.define('amdaUI.CatalogUI', { var newType = null; var newSize = null; var newDescription = null; + var newStatus = null; // Check if there is modifications if(this.up('form').getForm().findField('nameColumn').getValue() != columnInfo.name){ @@ -1022,13 +994,17 @@ Ext.define('amdaUI.CatalogUI', { if(this.up('form').getForm().findField('descriptionColumn').getValue() != columnInfo.description){ newDescription = this.up('form').getForm().findField('descriptionColumn').getValue(); } + if(me.statusGrid.getStatusString() != columnInfo.status){ + newStatus = me.statusGrid.getStatusString(); + } - if(newName != null || newType != null || newSize != null || newDescription != null) + if(newName != null || newType != null || newSize != null || newDescription != null || newStatus != null) { - AmdaAction.editColumn(columnInfo.id, newName, newType, newSize, newDescription, function(result, e){ + AmdaAction.editColumn(columnInfo.id, newName, newType, newSize, newDescription, newStatus, function(result, e){ if(result){ me.toReconfigure = true; me.onAfterInit(result); + me.statusGrid.clearStore(); window.close(); } }); @@ -1046,12 +1022,15 @@ Ext.define('amdaUI.CatalogUI', { text: 'Reset', handler: function() { this.up('form').getForm().reset(); + me.statusGrid.clearStore(); + me.statusGrid.parseStatus(columnInfo.status); } }, { // To quit the window text: 'Cancel', handler: function() { + me.statusGrid.clearStore(); window.close(); } }] diff --git a/php/classes/AmdaAction.php b/php/classes/AmdaAction.php index 0607475..afb56b7 100644 --- a/php/classes/AmdaAction.php +++ b/php/classes/AmdaAction.php @@ -1674,9 +1674,9 @@ class AmdaAction return $cacheMgr->deleteColumn($id); } - public function addColumn($id, $name, $type, $size, $description){ + public function addColumn($id, $name, $type, $size, $description, $status){ $cacheMgr = new CatalogCacheMgr(); - return $cacheMgr->addColumn($id,$name, $type,$size,$description); + return $cacheMgr->addColumn($id,$name, $type,$size,$description, $status); } public function getCatColumnInfo($id){ @@ -1684,9 +1684,9 @@ class AmdaAction return $cacheMgr->getCatColumnInfo($id); } - public function editColumn($id, $name, $type, $size,$description){ + public function editColumn($id, $name, $type, $size,$description, $status){ $cacheMgr = new CatalogCacheMgr(); - return $cacheMgr->editColumn($id,$name, $type,$size,$description); + return $cacheMgr->editColumn($id,$name, $type,$size,$description, $status); } } ?> diff --git a/php/classes/CatalogCacheMgr.php b/php/classes/CatalogCacheMgr.php index 35c725a..0aaa83b 100644 --- a/php/classes/CatalogCacheMgr.php +++ b/php/classes/CatalogCacheMgr.php @@ -26,7 +26,7 @@ class CatalogCacheMgr extends TimeTableCacheMgr $this->cache = new CatalogCacheObject(); if (!empty($options['nparams'])) { for ($i = 0; $i < (int)$options['nparams']; $i++) { - $this->cache->addParameter(CatalogCacheMgr::DEFAULT_PARAM_ID_PREFIX.(string)($i+1), 'column_'.(string)($i+1), 1, 0, "", FALSE); + $this->cache->addParameter(CatalogCacheMgr::DEFAULT_PARAM_ID_PREFIX.(string)($i+1), 'column_'.(string)($i+1), 1, 0, "","", FALSE); } } else if (!empty($options['parameters'])) { @@ -45,7 +45,11 @@ class CatalogCacheMgr extends TimeTableCacheMgr if (isset($parameter['description'])) { $description = $parameter['description']; } - $this->cache->addParameter($id, $parameter['name'], intval($parameter['size']), intval($parameter['type']), $description, FALSE); + $status = ""; + if (isset($parameter['status'])) { + $status = $parameter['status']; + } + $this->cache->addParameter($id, $parameter['name'], intval($parameter['size']), intval($parameter['type']), $description, $status, FALSE); ++$index; } } @@ -74,7 +78,11 @@ class CatalogCacheMgr extends TimeTableCacheMgr if (isset($parameter['description'])) { $description = $parameter['description']; } - $this->cache->addParameter($parameter['id'], $parameter['name'], intval($parameter['size']), intval($parameter['type']), $parameter['description'], FALSE); + $status = ""; + if (isset($parameter['status'])) { + $status = $parameter['']; + } + $this->cache->addParameter($parameter['id'], $parameter['name'], intval($parameter['size']), intval($parameter['type']), $parameter['description'],$parameter['status'], FALSE); } return $result+ array('parameters' => $info['parameters']); @@ -161,11 +169,11 @@ class CatalogCacheMgr extends TimeTableCacheMgr return array('success' => $result , 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(),'parameters' => $this->cache->getParametersInfo()); } - public function addColumn($id,$name, $type,$size, $description){ + public function addColumn($id,$name, $type,$size, $description, $status){ if (!$this->loadFromFile()) return array('success' => false, 'message' => 'Cannot load cache file'); $isNew=true; - $this->cache->addParameter($id,$name, $size, $type, $description , $isNew); + $this->cache->addParameter($id,$name, $size, $type, $description, $status, $isNew); $this->saveToFile(); return array('success' => true , 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(),'parameters' => $this->cache->getParametersInfo()); } @@ -177,11 +185,11 @@ class CatalogCacheMgr extends TimeTableCacheMgr return $this->cache->getParameterInfo($id); } - public function editColumn($id,$name, $type,$size, $description){ + public function editColumn($id,$name, $type,$size, $description, $status){ if (!$this->loadFromFile()) return array('success' => false, 'message' => 'Cannot load cache file'); - $this->cache->editParameter($id,$name, $type, $size, $description); + $this->cache->editParameter($id,$name, $type, $size, $description, $status); $this->saveToFile(); return array('success' => true , 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus(),'parameters' => $this->cache->getParametersInfo()); diff --git a/php/classes/CatalogCacheObject.php b/php/classes/CatalogCacheObject.php index c9d2927..474b82e 100644 --- a/php/classes/CatalogCacheObject.php +++ b/php/classes/CatalogCacheObject.php @@ -26,7 +26,7 @@ class CatalogCacheObject extends TimeTableCacheObject return $intervalObj; } - public function addParameter($id, $name, $size, $type, $description, $isNew = false) + public function addParameter($id, $name, $size, $type, $description, $status, $isNew = false) { $this->parameters[] = array( 'id' => $id, @@ -34,6 +34,7 @@ class CatalogCacheObject extends TimeTableCacheObject 'size' => $size, 'type' => $type, 'description' => $description, + 'status' => $status ); if($isNew){ $this->isModified = $isNew; @@ -52,7 +53,7 @@ class CatalogCacheObject extends TimeTableCacheObject return false; } - public function editParameter($id, $name, $type, $size, $description) + public function editParameter($id, $name, $type, $size, $description, $status) { foreach ($this->parameters as $index=>$param){ if($id == $param['id']){ @@ -64,6 +65,8 @@ class CatalogCacheObject extends TimeTableCacheObject $this->parameters[$index]['size'] = $size; if(isset($description)) $this->parameters[$index]['description'] = $description; + if(isset($status)) + $this->parameters[$index]['status'] = $status; $this->isModified = TRUE; return true; } @@ -99,6 +102,8 @@ class CatalogCacheObject extends TimeTableCacheObject fwrite($handle,pack('L',$parameter['type'])); //Description Size fwrite($handle,pack('L',strlen($parameter['description']))); + //Status Size + fwrite($handle,pack('L',strlen($parameter['status']))); //Param Id for ($i = 0; $i < strlen($parameter['id']); ++$i) fwrite($handle,pack('C',ord($parameter['id'][$i]))); @@ -108,6 +113,9 @@ class CatalogCacheObject extends TimeTableCacheObject //Param description for ($i = 0; $i < strlen($parameter['description']); ++$i) fwrite($handle,pack('C',ord($parameter['description'][$i]))); + //Param status + for ($i = 0; $i < strlen($parameter['status']); ++$i) + fwrite($handle,pack('C',ord($parameter['status'][$i]))); } } @@ -143,6 +151,11 @@ class CatalogCacheObject extends TimeTableCacheObject return false; $descriptionlength = $res['descriptionlength']; + //Param status length + if (!$res = unpack('Lstatuslength',fread($handle,4))) + return false; + $statuslength = $res['statuslength']; + //Param Id $id = ""; for ($j = 0; $j < $idlength; ++$j) @@ -170,7 +183,16 @@ class CatalogCacheObject extends TimeTableCacheObject $description .= chr($res['description']); } - $this->addParameter($id, $name, $size, $type, $description, FALSE); + //Param description + $status = ""; + for ($j = 0; $j < $statuslength; ++$j) + { + if (!$res = unpack('Cstatus',fread($handle,1))) + return false; + $status .= chr($res['status']); + } + + $this->addParameter($id, $name, $size, $type, $description, $status, FALSE); } return true; } diff --git a/php/config.php b/php/config.php index 97470b9..dd89a76 100644 --- a/php/config.php +++ b/php/config.php @@ -200,9 +200,9 @@ $API = array( 'parseTemplatedParam' => array('len'=>1), // Furkan - New Catalog Options 'deleteColumn' => array('len'=> 1), - 'addColumn' => array('len' => 5), + 'addColumn' => array('len' => 6), 'getCatColumnInfo' => array('len' => 1), - 'editColumn' => array('len' => 5) + 'editColumn' => array('len' => 6) ) ) ); -- libgit2 0.21.2