Commit f9c8b272c6badfa4731e9c3e9e257e1348a93e60

Authored by elena
1 parent e511f2cc

edit catalog

js/app/controllers/CatalogModule.js
... ... @@ -15,6 +15,7 @@ Ext.define('amdaDesktop.CatalogModule', {
15 15 ],
16 16  
17 17 contentId : 'catalogUI',
  18 + isOperationOnShow : true,
18 19  
19 20 /**
20 21 * @cfg {String} data models
... ... @@ -30,6 +31,17 @@ Ext.define('amdaDesktop.CatalogModule', {
30 31 height: 700,
31 32 uiType : 'panelCatalog',
32 33 helpTitle : 'Help on Catalog Module',
33   - helpFile : 'catalogHelp'
34   -
  34 + helpFile : 'catalogHelp',
  35 +
  36 + operationOnShow: function() {
  37 + var obj = this.linkedNode.get('object');
  38 + if (obj && obj.get('id') == '' && !obj.get('fromPlugin')) {
  39 + Ext.Msg.prompt('Define Parameters', 'Please enter parameters number:', function(btn, text){
  40 + if (btn == 'ok'){
  41 + AmdaAction.initTTCache(this.getUiContent().isCatalog, text, this.getUiContent().onAfterInit, this.getUiContent());
  42 + }
  43 + }, this);
  44 + }
  45 +
  46 + }
35 47 });
... ...
js/app/controllers/InteractiveModule.js
... ... @@ -5,13 +5,7 @@
5 5 * @extends amdaDesktop.AmdaModule
6 6 * @brief Generic Interactive Module controller definition
7 7 * @author CDA
8   - * @version $Id: InteractiveModule.js 2109 2014-02-19 17:47:37Z elena $
9   - *******************************************************************************
10   - * FT Id : Date : Name - Description
11   - *******************************************************************************
12   - * : :08/06/2011: CDA - Migration extjs4
13   - * : :09/06/2011: elena - generic Interactive modules methods: init(), createWindow(),
14   - * createLinkedNode(), createObject() now are defined here
  8 + * @version $Id: InteractiveModule.js 2109 2014-02-19 17:47:37Z elena $
15 9 */
16 10  
17 11 Ext.define('amdaDesktop.InteractiveModule', {
... ... @@ -82,65 +76,70 @@ Ext.define('amdaDesktop.InteractiveModule', {
82 76 ],
83 77 items : [
84 78 {
85   - xtype : this.uiType,
86   - object : this.linkedNode.get('object'),
87   - id : this.contentId
  79 + xtype : this.uiType,
  80 + object : this.linkedNode.get('object'),
  81 + id : this.contentId
88 82 }
89 83 ]
90 84 });
91 85  
92 86 this.closed = false;
93 87 win.on({
94   - scope: this,
95   - // on window activation event
96   - activate: function(){
97   - // order to pin this Module with WsExplorer
98   - this.pin();
99   - },
100   - // on window closing event
101   - beforeclose: function (win, eOpts) {
102   -
103   - this.saveState();
104   -
105   - var isDirty = this.getUiContent().fclose();
106   -
107   - if (!this.closed && isDirty) {
108   - Ext.Msg.confirm('Close', 'Current window has been modified.\nDo you want to close the window ?' , function (btn, text){
109   - if (btn == 'yes'){
110   - // mark this.closed as true before the call to close() as that will fire the beforeclose event again
111   - this.closed = true;
112   - win.close();
113   - }
  88 + scope: this,
  89 + // on window activation event
  90 + activate: function(){
  91 + // order to pin this Module with WsExplorer
  92 + this.pin();
  93 + },
  94 + // on window closing event
  95 + beforeclose: function (win, eOpts) {
  96 +
  97 + this.saveState();
  98 +
  99 + var isDirty = this.getUiContent().fclose();
  100 +
  101 + if (!this.closed && isDirty) {
  102 + Ext.Msg.confirm('Close', 'Current window has been modified.\nDo you want to close the window ?' , function (btn, text){
  103 + if (btn == 'yes'){
  104 + // mark this.closed as true before the call to close() as that will fire the beforeclose event again
  105 + this.closed = true;
  106 + win.close();
  107 + }
114 108 },this);
115   - } else if (!isDirty) {
116   - this.closed = true;
117   - }
  109 + } else if (!isDirty) {
  110 + this.closed = true;
  111 + }
118 112  
119   - if (this.closed) {
120   - //remove object from linkedNode in order to minimize used memory
121   - this.linkedNode.set('object','');
122   - // unlink Node
123   - this.setLinkedNode(null);
124   - // order to unpin this Module from WsExplorer
125   - this.unpin();
126   - }
  113 + if (this.closed) {
  114 + //remove object from linkedNode in order to minimize used memory
  115 + this.linkedNode.set('object','');
  116 + // unlink Node
  117 + this.setLinkedNode(null);
  118 + // order to unpin this Module from WsExplorer
  119 + this.unpin();
  120 + }
127 121  
128   - // Don't automatically close if the form is dirty, let the call to this.close() within the confirm box close the window.
129   - return this.closed;
130   - },
131   - minimize: function (win, eOpts) {
  122 + // Don't automatically close if the form is dirty, let the call to this.close() within the confirm box close the window.
  123 + return this.closed;
  124 + },
  125 + minimize: function (win, eOpts) {
132 126 // Save form
133 127 if (this.getUiContent().formPanel)
134   - this.getUiContent().formPanel.getForm().updateRecord(this.linkedNode.get('object'));
  128 + this.getUiContent().formPanel.getForm().updateRecord(this.linkedNode.get('object'));
135 129 else
136   - this.getUiContent().items.getAt(0).getForm().updateRecord(this.linkedNode.get('object'));
  130 + this.getUiContent().items.getAt(0).getForm().updateRecord(this.linkedNode.get('object'));
137 131 // Save grids
138 132 this.getUiContent().updateObject();
139   - }
  133 + },
  134 + show: function() {
  135 + // configuration of empty catalog
  136 + if (this.isOperationOnShow)
  137 + this.operationOnShow();
  138 + }
140 139 });
141   -
142 140 } else {
143   - this.getUiContent().setObject(this.linkedNode.get('object'));
  141 + // second arg 'true' is used in CatalogUI to mark if Grid Reconfiguration is needed
  142 + this.getUiContent().setObject(this.linkedNode.get('object'), true);
144 143 }
145 144 win.show();
146 145 },
... ...
js/app/views/CatalogUI.js
... ... @@ -10,21 +10,28 @@
10 10 Ext.define('amdaUI.CatalogUI', {
11 11 extend: 'Ext.container.Container',
12 12 alias: 'widget.panelCatalog',
13   -
  13 +
  14 + requires: [
  15 + 'Ext.grid.plugin.BufferedRenderer'
  16 + ],
  17 +
14 18 isCatalog : true,
15 19  
  20 +
16 21 constructor: function(config)
17 22 {
18 23 this.init(config);
19   - this.callParent(arguments);;
  24 + this.callParent(arguments);
  25 + this.toReconfigure = true;
20 26 if (this.object) this.loadObject();
21 27 },
22 28  
23   - setObject : function (object)
24   - {
25   - // set object
26   - this.object = object;
27   -
  29 + setObject : function (object, toReconfigure)
  30 + {
  31 + if (toReconfigure)
  32 + this.toReconfigure = true;
  33 + // set object
  34 + this.object = object;
28 35 // load object into view
29 36 this.loadObject();
30 37 },
... ... @@ -77,44 +84,38 @@ Ext.define('amdaUI.CatalogUI', {
77 84 this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
78 85 },
79 86  
80   - /**
81   - * load object catalog into this view
82   - */
83   - loadObject : function()
84   - {
85   - // load object into form
86   - this.formPanel.getForm().loadRecord(this.object);
  87 +
  88 +
  89 + onAfterInit: function(result, e) {
87 90  
88   - this.status = null;
89   -
90 91 var me = this;
91 92  
92   - var onAfterInit = function(result, e)
93   - {
94   - if (!result || !result.success)
95   - {
96   - if (result.message)
97   - myDesktopApp.errorMsg(result.message);
98   - else
99   - myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
100   - return;
101   - }
102   -
  93 + if (!result || !result.success)
  94 + {
  95 + if (result.message)
  96 + myDesktopApp.errorMsg(result.message);
  97 + else
  98 + myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
  99 + return;
  100 + }
  101 +
  102 + if (me.toReconfigure)
  103 + {
103 104 var fields = [], columns = [], i = 3, width, index;
104 105  
105 106 var fieldsConfig = [{ name : 'start' },{ name : 'stop' },{ name: 'cacheId', type : 'int'},
106 107 { name: 'isNew', type : 'boolean', defaultValue: false },
107   - { name: 'isModified', type : 'boolean', defaultValue: false}
  108 + { name: 'isModified', type : 'boolean', defaultValue: false}
108 109 ];
109 110  
110 111 for (var j = 0; j < 5; j++) fields[j] = Ext.create('Ext.data.Field', fieldsConfig[j]);
111 112  
112   - columns[0] = Ext.create('Ext.grid.column.RowNumberer');
  113 + columns[0] = Ext.create('Ext.grid.column.RowNumberer');
113 114  
114 115 columns[1] = Ext.create('Ext.grid.column.Column', { text: 'Start Time', sortable : false, dataIndex: 'start',
115   - width : 120, menuDisabled: true });
  116 + width : 120, menuDisabled: true, editor : { xtype:'datefield', allowBlank:false, hideTrigger: true, format : 'Y-m-d\\TH:i:s'}});
116 117 columns[2] = Ext.create('Ext.grid.column.Column', { text: 'Stop Time', sortable : false, dataIndex: 'stop',
117   - width : 120, menuDisabled: true });
  118 + width : 120, menuDisabled: true, editor : { xtype:'datefield', allowBlank:false, hideTrigger: true, format : 'Y-m-d\\TH:i:s'}});
118 119  
119 120 Ext.Array.each(result.parameters, function(obj)
120 121 {
... ... @@ -122,12 +123,12 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
122 123 fields[i+2] = Ext.create('Ext.data.Field',{ name : index });
123 124 width = 50. * parseInt(obj.size);
124 125 columns[i] = Ext.create('Ext.grid.column.Column', { text: obj.name, sortable : false, dataIndex: index,
125   - width : width, menuDisabled: true });
  126 + width : width, menuDisabled: true, editor: 'textfield' });
126 127 i++;
127 128 });
128   -
129   -
130   -
  129 +
  130 +
  131 +
131 132 var store = Ext.create('Ext.data.Store', {
132 133 fields: fields,
133 134 autoDestroy: false,
... ... @@ -161,11 +162,11 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
161 162 // this.fireEvent("refresh");
162 163 }
163 164 }
164   - });
165   -
  165 + });
  166 +
166 167 me.TTGrid.reconfigure(store, columns);
167   -
168   - me.TTGrid.getSelectionModel().deselectAll();
  168 + }
  169 + me.TTGrid.getSelectionModel().deselectAll();
169 170 //
170 171 // // clear filters
171 172 // me.TTGrid.getStore().clearFilter(true);
... ... @@ -173,41 +174,50 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
173 174 // //clear sort
174 175 // me.TTGrid.getStore().sorters.clear();
175 176 // //me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
176   - //
  177 +
177 178 //set cache token to the Catalog object
178   - me.object.set('cacheToken', result.token);
179   - me.setParamInfo(result.parameters);
180   -
181   - me.TTGrid.getStore().load();
  179 + me.object.set('cacheToken', result.token);
  180 + me.setParamInfo(result.parameters);
  181 +
  182 + me.TTGrid.getStore().load();
182 183  
183   - me.status = result.status;
184   - };
185   -
  184 + me.status = result.status;
  185 + },
  186 +
  187 + /**
  188 + * load object catalog into this view
  189 + */
  190 + loadObject : function()
  191 + {
  192 + // load object into form
  193 + this.formPanel.getForm().loadRecord(this.object);
  194 +
  195 + this.status = null;
  196 +
186 197 if (this.object.get('fromPlugin'))
187 198 {
188 199 if (this.object.get('objFormat') && this.object.get('objFormat') != '')
189 200 {
190 201 //From uploaded file
191   - //AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), onAfterInit);
  202 + //AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), this.onAfterInit, this);
192 203 }
193 204 else
194 205 {
195   - //From tmp object (ie Search result)
196   - AmdaAction.initTTCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), this.isCatalog, onAfterInit);
  206 + //From tmp object (ie Statistics result)
  207 + AmdaAction.initTTCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), this.isCatalog, this.onAfterInit, this);
197 208 }
198 209 }
199 210 else
200 211 {
201   - var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType;
  212 + // var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType;
202 213 if (this.object.get('id') == '')
203   - {
204   - //Init empty cache
205   - AmdaAction.initTTCache(this.isCatalog, onAfterInit);
  214 + {
  215 +
206 216 }
207 217 else
208 218 {
209 219 //From existing TT file
210   - AmdaAction.initTTCacheFromTT(this.object.get('id'), 'catalog', onAfterInit);
  220 + AmdaAction.initTTCacheFromTT(this.object.get('id'), 'catalog', this.onAfterInit, this);
211 221 }
212 222 }
213 223 },
... ... @@ -221,8 +231,9 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
221 231 */
222 232 saveProcess : function(toRename)
223 233 {
224   - var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
225   -
  234 + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
  235 + // store / columns are the same - not needed to reconfigure grid
  236 + this.toReconfigure = false;
226 237 // if the name has been modified this is a creation
227 238 if (this.fclose())
228 239 {
... ... @@ -245,13 +256,26 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
245 256 }
246 257 module.linkedNode.create({callback : function() {module.linkedNode.update();}, scope : this});
247 258 } else {
248   - //update
  259 + //update
249 260 module.linkedNode.update();
250 261 }
  262 +
251 263 }
252 264 },
253 265  
254 266 /**
  267 + * overwrite metod called by Save button
  268 + */
  269 + overwriteProcess : function(btn)
  270 + {
  271 + if (btn == 'cancel') return;
  272 +
  273 + this.fieldName.clearInvalid();
  274 + this.saveProcess(true);
  275 +
  276 + },
  277 +
  278 + /**
255 279 * Check if changes were made before closing window
256 280 * @return true if changes
257 281 */
... ... @@ -263,8 +287,7 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
263 287 var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
264 288 return isDirty;
265 289 },
266   -
267   -
  290 +
268 291 init : function (config)
269 292 {
270 293 this.object = config.object;
... ... @@ -282,39 +305,97 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
282 305 return this.validFlag;
283 306 }
284 307 });
285   -
  308 +
  309 + var cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{
  310 +// clicksToEdit: 2,
  311 + onEditComplete : function(ed, value, startValue) {
  312 + var me = this,
  313 + activeColumn = me.getActiveColumn(),
  314 + context = me.context,
  315 + record;
  316 +
  317 + if (activeColumn) {
  318 + record = context.record;
  319 +
  320 + me.setActiveEditor(null);
  321 + me.setActiveColumn(null);
  322 + me.setActiveRecord(null);
  323 +
  324 + context.value = value;
  325 + if (!me.validateEdit()) {
  326 + me.editing = false;
  327 + return;
  328 + }
  329 +
  330 + // Only update the record if the new value is different than the
  331 + // startValue. When the view refreshes its el will gain focus
  332 + if (!record.isEqual(value, startValue)) {
  333 + var obj = {};
  334 +
  335 + obj['cacheId'] = record.get('cacheId');
  336 + obj['isCatalog'] = true;
  337 + obj[activeColumn.dataIndex] = value;
  338 +
  339 + //Interval is modified on the server side
  340 + me.editing = true;
  341 +
  342 + AmdaAction.modifyTTCacheInterval(obj, function (result, e) {
  343 +
  344 + var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
  345 + if (module)
  346 + module.getUiContent().status = result.status;
  347 + context.grid.getSelectionModel().deselectAll();
  348 + context.store.reload({
  349 + callback : function(records, options, success) {
  350 + context.view.bufferedRenderer.scrollTo(context.rowIdx, true, function() {
  351 + me.fireEvent('edit', me, context);
  352 + me.editing = false;
  353 + }, me);
  354 + }
  355 + });
  356 + }, this);
  357 + }
  358 + else
  359 + me.editing = false;
  360 + }
  361 + }
  362 + });
286 363  
287 364 this.TTGrid = Ext.create('Ext.grid.Panel', {
288 365 height: 530,
289 366 columns: [ ],
290 367 frame: true,
  368 + columnLines: true,
  369 + // selType: 'cellmodel',
  370 + plugins: [ cellEditing, { ptype : 'bufferedrenderer'} ],
291 371 dockedItems: [{
292 372 xtype: 'toolbar',
293 373 items: [{
294 374 iconCls: 'icon-add',
295 375 scope: this,
296 376 handler: function(){
297   - alert('NOT IMPLEMENTED YET');
298   - // cellEditing.cancelEdit();
299   - //
300   - // var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
301   - // var row = 0;
302   - // if (selection)
303   - // row = store.indexOf(selection) + 1;
304   - // this.TTGrid.getSelectionModel().deselectAll();
305   - //
306   - // var me = this;
307   - // AmdaAction.addTTCacheInterval({'index' : row}, function (result, e) {
308   - // this.status = result.status;
309   - // this.TTGrid.getStore().reload({
310   - // callback : function(records, options, success) {
311   - // me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function() {
312   - // me.TTGrid.getView().select(row);
313   - // cellEditing.startEditByPosition({row: row, column: 1});
314   - // }, me);
315   - // }
316   - // });
317   - // }, this);
  377 +
  378 + cellEditing.cancelEdit();
  379 + var store = this.TTGrid.getStore();
  380 +
  381 + var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
  382 + var row = 0;
  383 + if (selection)
  384 + row = store.indexOf(selection) + 1;
  385 + this.TTGrid.getSelectionModel().deselectAll();
  386 +
  387 + var me = this;
  388 + AmdaAction.addTTCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) {
  389 + this.status = result.status;
  390 + this.TTGrid.getStore().reload({
  391 + callback : function(records, options, success) {
  392 + me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function() {
  393 + me.TTGrid.getView().select(row);
  394 + cellEditing.startEditByPosition({row: row, column: 1});
  395 + }, me);
  396 + }
  397 + });
  398 + }, this);
318 399 }
319 400 },{
320 401 iconCls: 'icon-delete',
... ... @@ -325,8 +406,7 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
325 406 var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
326 407 if (selection)
327 408 {
328   - var rowId = selection.get('cacheId');
329   - console.log(selection);
  409 + var rowId = selection.get('cacheId');
330 410 this.TTGrid.getSelectionModel().deselectAll();
331 411 AmdaAction.removeTTCacheIntervalFromId(rowId, this.isCatalog, function (result, e) {
332 412 this.status = result.status;
... ... @@ -458,7 +538,7 @@ Ext.define(&#39;amdaUI.CatalogUI&#39;, {
458 538  
459 539 myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.visu.id, true, function (module) {
460 540  
461   - //temporary linked node - as Visu module is 'pseud' intercative - no 'save', no 'execute'
  541 + //temporary linked node - as Visu module is 'pseudo' interactive - no 'save', no 'execute'
462 542 var temporaryNode = Ext.create('amdaModel.CatalogNode', {
463 543 leaf : true
464 544 });
... ...
php/classes/AmdaAction.php
... ... @@ -937,12 +937,12 @@ class AmdaAction {
937 937 return $result;
938 938 }
939 939  
940   - public function initTTCache($isCatalog = false)
  940 + public function initTTCache($isCatalog = false, $nparams)
941 941 {
942 942 if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
943 943 else $cacheMgr = new CatalogCacheMgr();
944 944  
945   - return $cacheMgr->initTTCache();
  945 + return $cacheMgr->initTTCache($nparams);
946 946 }
947 947  
948 948  
... ... @@ -1002,7 +1002,9 @@ class AmdaAction {
1002 1002  
1003 1003 public function addTTCacheInterval($o)
1004 1004 {
1005   - $cacheMgr = new TimeTableCacheMgr();
  1005 + if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr();
  1006 + else $cacheMgr = new TimeTableCacheMgr();
  1007 +
1006 1008 return $cacheMgr->addInterval($o->index, $o->start, $o->stop);
1007 1009 }
1008 1010  
... ... @@ -1010,13 +1012,20 @@ class AmdaAction {
1010 1012 {
1011 1013 if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
1012 1014 else $cacheMgr = new TimeTableCacheMgr();
1013   -
  1015 +
1014 1016 return $cacheMgr->removeIntervalFromId($id);
1015 1017 }
1016 1018  
1017 1019 public function modifyTTCacheInterval($o)
1018 1020 {
1019   - $cacheMgr = new TimeTableCacheMgr();
  1021 + if ($o->isCatalog) {
  1022 +
  1023 + $cacheMgr = new CatalogCacheMgr();
  1024 + return $cacheMgr->modifyIntervalFromId($o);
  1025 +
  1026 + }
  1027 + else $cacheMgr = new TimeTableCacheMgr();
  1028 +
1020 1029 return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop);
1021 1030 }
1022 1031  
... ...
php/classes/CatalogCacheMgr.php
... ... @@ -226,12 +226,42 @@ class CatalogCacheObject extends TimeTableCacheObject
226 226  
227 227 return true;
228 228 }
  229 +
  230 + public function modifyIntervalFromId($obj) {
  231 +
  232 + foreach ($this->intervals as $interval)
  233 + {
  234 + if ($interval->getId() == $obj->cacheId)
  235 + {
  236 + foreach((array)$obj as $key => $val) {
  237 +
  238 + if ($key == 'start')
  239 + $interval->setStartFromISO($val);
  240 + else if ($key == 'stop')
  241 + $interval->setStopFromISO($val);
  242 + else {
  243 + if (strpos($key, 'param') === false)
  244 + continue;
  245 + $params = $interval->getParams();
  246 + $paramIndex = (int)substr($key,5);
  247 + $params[$paramIndex-2] = $val;
  248 + $interval->setParams($params);
  249 + }
  250 + }
  251 + $interval->setIsModified(true);
  252 + $this->isModified = true;
  253 + return true;
  254 + }
  255 + }
  256 +
  257 + return false;
  258 + }
229 259 }
230 260  
231 261 class CatalogCacheMgr extends TimeTableCacheMgr
232 262 {
233 263  
234   - protected static $cache_file = "cacheCat";
  264 + protected static $cache_file = "cacheCat";
235 265  
236 266 protected $ttMgr = null;
237 267 protected $cache = null;
... ... @@ -298,7 +328,7 @@ class CatalogCacheMgr extends TimeTableCacheMgr
298 328 }
299 329  
300 330 $paramHeaders = $intervals_res['parameters'];
301   -
  331 +
302 332 $this->cache->setParamsNumber(count($paramHeaders));
303 333 $this->cache->setParamsSizes($paramHeaders);
304 334 unset($intervals_res);
... ... @@ -350,6 +380,61 @@ class CatalogCacheMgr extends TimeTableCacheMgr
350 380 $this->cache->reset();
351 381  
352 382 return $this->ttMgr->saveIntervals($id, $intervals, $action);
353   - }
  383 + }
  384 +
  385 + public function addInterval($index, $start, $stop, $params) {
  386 + if (!$this->loadFromFile())
  387 + return array('success' => false, 'message' => 'Cannot load cache file');
  388 +
  389 + if (!isset($index))
  390 + $index = 0;
  391 +
  392 + if (!isset($start))
  393 + $start = date('Y-m-d\TH:i:s');
  394 +
  395 + if (!isset($stop))
  396 + $stop = date('Y-m-d\TH:i:s');
  397 +
  398 + if (!isset($params))
  399 + $params = [];
  400 +
  401 + $this->cache->addInterval($start, $stop, $params, true, $index);
  402 +
  403 + //$this->cache->updateIndexes();
  404 +
  405 + $this->saveToFile();
  406 +
  407 + return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus());
  408 + }
  409 +
  410 + public function modifyIntervalFromId($obj) {
  411 + if (!$this->loadFromFile())
  412 + return array('success' => false, 'message' => 'Cannot load cache file');
  413 +
  414 + $this->cache->modifyIntervalFromId($obj);
  415 +
  416 + $this->saveToFile();
  417 +
  418 + return array('success' => true, 'status' => $this->cache->getStatus());
  419 + }
  420 +
  421 + public function initTTCache($nparams) {
  422 + //Create new cache
  423 + $this->cache = new CatalogCacheObject();
  424 + $this->cache->setParamsNumber((int)$nparams);
  425 + $paramHeaders = array();
  426 +
  427 + for ($i = 0; $i < (int)$nparams; $i++) {
  428 + $paramHeaders[$i]['id'] = 'id_'.(string)($i+1);
  429 + $paramHeaders[$i]['name'] = 'param_'.(string)($i+1);
  430 + $paramHeaders[$i]['size'] = 1;
  431 + $paramHeaders[$i]['type'] = 'Float';
  432 +
  433 + }
  434 + $this->cache->setParamsSizes($paramHeaders);
  435 + //Save cache file
  436 + return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(),
  437 + 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders);
  438 + }
354 439 }
355 440 ?>
356 441 \ No newline at end of file
... ...
php/classes/CatalogMgr.php
... ... @@ -379,6 +379,37 @@ class CatalogMgr extends TimeTableMgr {
379 379 );
380 380  
381 381 }
382   -
  382 +
  383 +// public function modifyObject($p) {
  384 +// $folder = $this->getObjectFolder($p->id);
  385 +//
  386 +// //Copy TT in a tempory file
  387 +// $ttFilePath = USERTTDIR.$p->id.'.xml';
  388 +// $tmpFileExist = FALSE;
  389 +// if (file_exists($ttFilePath))
  390 +// $tmpFileExist = copy($ttFilePath,$ttFilePath.".tmp");
  391 +//
  392 +// //Delete TT
  393 +// $this->deleteObject($p);
  394 +//
  395 +// //Save modifications
  396 +// try {
  397 +// $result = $this->createObject($p, $folder);
  398 +// if ($result['error'])
  399 +// throw new Exception($result['error']);
  400 +// if ($tmpFileExist)
  401 +// unlink($ttFilePath.".tmp");
  402 +// return array('id' => $p->id, 'info' => $result['nbIntervals'].' intervals' );
  403 +// }
  404 +// catch (Exception $e) {
  405 +// //Restore TT file
  406 +// if ($tmpFileExist)
  407 +// {
  408 +// copy($ttFilePath.".tmp", $ttFilePath);
  409 +// unlink($ttFilePath.".tmp");
  410 +// }
  411 +// return array ('error' => $e->getMessage());
  412 +// }
  413 +// }
383 414 }
384 415 ?>
... ...