Commit 6ab359f0d5ddfbc45da06525b14448c9cc0ec49b
1 parent
cf70da13
Exists in
master
and in
100 other branches
Cleanup model fields and columns construction in CatalogUI + fix some bugs
Showing
1 changed file
with
224 additions
and
167 deletions
Show diff stats
js/app/views/CatalogUI.js
... | ... | @@ -159,177 +159,228 @@ Ext.define('amdaUI.CatalogUI', { |
159 | 159 | |
160 | 160 | if (me.toReconfigure) |
161 | 161 | { |
162 | - var fields = [], columns = [], width, index; | |
163 | 162 | var fieldsConfig = [ |
164 | - { name : 'start', | |
165 | - type : 'date', | |
166 | - dateFormat: 'Y-m-d\\TH:i:s', | |
167 | - convert: function(value,rec) { | |
168 | - if (!Ext.isDate(value)){ | |
169 | - var valueString = new String(value); | |
170 | - return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' ')); | |
171 | - } | |
172 | - return value; | |
173 | - } | |
174 | - }, | |
175 | - { name : 'stop', | |
176 | - type : 'date', | |
177 | - dateFormat: 'Y-m-d\\TH:i:s', | |
178 | - convert: function(value,rec) { | |
179 | - if (!Ext.isDate(value)){ | |
180 | - var valueString = new String(value); | |
181 | - return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' ')); | |
182 | - } | |
183 | - return value; | |
184 | - } | |
185 | - }, | |
186 | - {name:'durationHour', | |
187 | - convert: function(value, rec){ | |
188 | - starteDate=rec.get('start') ;stopDate=rec.get('stop') ; | |
189 | - | |
190 | - d1=new Date(rec.get('start')); | |
191 | - d2=new Date(rec.get('stop')); | |
192 | - if (d1 && d2 && (d2-d1>=0)) { | |
193 | - return (d2-d1)/3600000.0; | |
194 | - } | |
195 | - }, | |
196 | - }, | |
197 | - { | |
198 | - name: 'durationMin', | |
199 | - type: 'float', | |
200 | - convert: function(value, rec){ | |
201 | - d1=new Date(rec.get('start')); | |
202 | - d2=new Date(rec.get('stop')); | |
203 | - if (d1 && d2 && (d2-d1>=0)) { | |
204 | - return (d2-d1)/60000.0; | |
205 | - } | |
206 | - }, | |
207 | - persist: false, | |
208 | - | |
209 | - }, | |
210 | - { | |
211 | - name: 'durationSec', | |
212 | - type: 'float', | |
213 | - convert: function(value, rec){ | |
214 | - d1=new Date(rec.get('start')); | |
215 | - d2=new Date(rec.get('stop')); | |
216 | - if (d1 && d2 && (d2-d1>=0)) { | |
217 | - return (d2-d1)/1000.0; | |
218 | - } | |
219 | - }, | |
220 | - persist: false, | |
221 | - | |
222 | - }, | |
223 | - { name: 'cacheId', type : 'int'}, | |
224 | - { name: 'isNew', type : 'boolean', defaultValue: false }, | |
225 | - { name: 'isModified', type : 'boolean', defaultValue: false} | |
226 | - ]; | |
227 | - | |
228 | - | |
229 | - | |
230 | - columns[0] = Ext.create('Ext.grid.column.RowNumberer', { width: 50, | |
231 | - renderer: function(value, metaData, record){ | |
232 | - var msg = record.index + 1; | |
233 | - if (record.get('isNew') || record.get('isModified')) { | |
234 | - msg += ' *'; | |
235 | - metaData.style = 'font-weight: bold' | |
236 | - } | |
237 | - return msg; | |
238 | - } | |
239 | - }); | |
240 | - columns[1] = Ext.create('Ext.grid.column.Date', { text: 'Start Time', format: 'Y-m-d\\TH:i:s', sortable : true, dataIndex: 'start', | |
241 | - width : 120, menuDisabled: false, editor : { xtype:'datefield', allowBlank:false, hideTrigger: true, format : 'Y-m-d\\TH:i:s'}}); | |
242 | - columns[2] = Ext.create('Ext.grid.column.Date', { text: 'Stop Time', format: 'Y-m-d\\TH:i:s', sortable : true, dataIndex: 'stop', | |
243 | - width : 120, menuDisabled: false, editor : { xtype:'datefield', allowBlank:false, hideTrigger: true, format : 'Y-m-d\\TH:i:s'}}); | |
244 | - columns[3] = Ext.create('Ext.grid.column.Column', { text: 'Duration (hour)', sortable : true, dataIndex: 'durationHour', | |
245 | - width : 120, menuDisabled: false, | |
246 | - hidden:true, | |
247 | - id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1', | |
248 | - renderer: function(value) { | |
249 | - return Ext.util.Format.number(value,'0.00'); | |
250 | - }, | |
251 | - listeners: { | |
252 | - beforeshow : function(){ | |
253 | - Ext.Array.each(this.ownerCt.getGridColumns(), function(item,index,all){ | |
254 | - // if item is a column to hide automatically | |
255 | - if ( Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION ) { | |
256 | - // if item isn't the column which is being declared and is not hidden | |
257 | - if ( item.id != amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1' && !item.isHidden() ){ | |
258 | - // hide this column | |
259 | - item.hide(); | |
260 | - } | |
261 | - } | |
262 | - }); | |
263 | - } | |
264 | - }}); | |
265 | - columns[4] = Ext.create('Ext.grid.column.Column', { text: 'Duration (Min)', sortable : true, dataIndex: 'durationMin', | |
266 | - width : 120, menuDisabled: false, | |
267 | - hidden:false, | |
268 | - id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2', | |
269 | - renderer: function(value) { | |
270 | - return Ext.util.Format.number(value,'0.00'); | |
271 | - }, | |
272 | - listeners: { | |
273 | - beforeshow : function(){ | |
274 | - Ext.Array.each(this.ownerCt.getGridColumns(), function(item,index,all){ | |
275 | - // if item is a column to hide automatically | |
276 | - if ( Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION ) { | |
277 | - // if item isn't the column which is being declared and is not hidden | |
278 | - if ( item.id != amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2' && !item.isHidden() ){ | |
279 | - // hide this column | |
280 | - item.hide(); | |
281 | - } | |
282 | - } | |
283 | - }); | |
284 | - } | |
285 | - }}); | |
286 | - columns[5] = Ext.create('Ext.grid.column.Column', { text: 'Duration (Sec)', sortable : true, dataIndex: 'durationSec', | |
287 | - width : 120, menuDisabled: false,hidden:true, | |
288 | - id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3', | |
289 | - renderer: function(value) { | |
290 | - return Ext.util.Format.number(value,'0.00'); | |
291 | - }, | |
292 | - listeners: { | |
293 | - beforeshow : function(){ | |
294 | - Ext.Array.each(this.ownerCt.getGridColumns(), function(item,index,all){ | |
295 | - // if item is a column to hide automatically | |
296 | - if ( Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION ) { | |
297 | - // if item isn't the column which is being declared and is not hidden | |
298 | - if ( item.id != amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3' && !item.isHidden() ){ | |
299 | - // hide this column | |
300 | - item.hide(); | |
301 | - } | |
302 | - } | |
303 | - }); | |
304 | - } | |
305 | - } | |
306 | - }); | |
163 | + { | |
164 | + name : 'start', | |
165 | + type : 'date', | |
166 | + dateFormat: 'Y-m-d\\TH:i:s', | |
167 | + convert: function(value,rec) { | |
168 | + if (!Ext.isDate(value)){ | |
169 | + var valueString = new String(value); | |
170 | + return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' ')); | |
171 | + } | |
172 | + return value; | |
173 | + } | |
174 | + }, | |
175 | + { | |
176 | + name : 'stop', | |
177 | + type : 'date', | |
178 | + dateFormat: 'Y-m-d\\TH:i:s', | |
179 | + convert: function(value,rec) { | |
180 | + if (!Ext.isDate(value)){ | |
181 | + var valueString = new String(value); | |
182 | + return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' ')); | |
183 | + } | |
184 | + return value; | |
185 | + } | |
186 | + }, | |
187 | + { | |
188 | + name:'durationHour', | |
189 | + type: 'float', | |
190 | + convert: function(value, rec){ | |
191 | + if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) { | |
192 | + return (rec.get('stop') - rec.get('start'))/3600000.0; | |
193 | + } | |
194 | + }, | |
195 | + persist: false | |
196 | + }, | |
197 | + { | |
198 | + name: 'durationMin', | |
199 | + type: 'float', | |
200 | + convert: function(value, rec){ | |
201 | + if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) { | |
202 | + return (rec.get('stop') - rec.get('start'))/60000.0; | |
203 | + } | |
204 | + }, | |
205 | + persist: false | |
206 | + }, | |
207 | + { | |
208 | + name: 'durationSec', | |
209 | + type: 'float', | |
210 | + convert: function(value, rec){ | |
211 | + if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) { | |
212 | + return (rec.get('stop') - rec.get('start'))/1000.0; | |
213 | + } | |
214 | + }, | |
215 | + persist: false | |
216 | + }, | |
217 | + { name: 'cacheId', type : 'int'}, | |
218 | + { name: 'isNew', type : 'boolean', defaultValue: false }, | |
219 | + { name: 'isModified', type : 'boolean', defaultValue: false} | |
220 | + ]; | |
307 | 221 | |
308 | - i=columns.length | |
309 | - columsTotalNumber=columns.length+2 | |
310 | - for (var j = 0; j < columsTotalNumber; j++) fields[j] = Ext.create('Ext.data.Field', fieldsConfig[j]); | |
311 | - | |
312 | - Ext.Array.each(result.parameters, function(obj) | |
313 | - { | |
314 | - index = 'param'+(i-4).toString(); | |
222 | + var updateDurationColumnsVisibility = function(columns, visibleId) { | |
223 | + Ext.Array.each(columns, function(item,index){ | |
224 | + // if item is a column to hide automatically | |
225 | + if ( Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION ) { | |
226 | + // if item isn't the column which is being declared and is not hidden | |
227 | + if ( item.id != visibleId && !item.isHidden() ){ | |
228 | + // hide this column | |
229 | + item.hide(); | |
230 | + } | |
231 | + } | |
232 | + }); | |
233 | + }; | |
315 | 234 | |
316 | - fields[i+2] = Ext.create('Ext.data.Field',{ name : index }); | |
317 | - | |
318 | - if (obj.type == 1) // dateTime | |
235 | + var columnsConfig = [ | |
319 | 236 | { |
320 | - columns[i] = Ext.create('Ext.grid.column.Column', { text: obj.name, sortable : true, dataIndex: index, | |
321 | - width : 120, menuDisabled: false, editor : { xtype:'datefield', allowBlank:false, hideTrigger: true, format : 'Y-m-d\\TH:i:s'}}); | |
237 | + xtype: 'rownumberer', | |
238 | + width: 50, | |
239 | + renderer: function(value, metaData, record){ | |
240 | + var msg = record.index + 1; | |
241 | + if (record.get('isNew') || record.get('isModified')) { | |
242 | + msg += ' *'; | |
243 | + metaData.style = 'font-weight: bold' | |
244 | + } | |
245 | + return msg; | |
246 | + } | |
247 | + }, | |
248 | + { | |
249 | + xtype: 'datecolumn', | |
250 | + text: 'Start Time', | |
251 | + format: 'Y-m-d\\TH:i:s', | |
252 | + sortable : true, | |
253 | + dataIndex: 'start', | |
254 | + width : 120, | |
255 | + menuDisabled: false, | |
256 | + editor : { | |
257 | + xtype:'datefield', | |
258 | + allowBlank:false, | |
259 | + hideTrigger: true, | |
260 | + format : 'Y-m-d\\TH:i:s' | |
261 | + } | |
262 | + }, | |
263 | + { | |
264 | + xtype: 'datecolumn', | |
265 | + text: 'Stop Time', | |
266 | + format: 'Y-m-d\\TH:i:s', | |
267 | + sortable : true, | |
268 | + dataIndex: 'stop', | |
269 | + width : 120, | |
270 | + menuDisabled: false, | |
271 | + editor : { | |
272 | + xtype:'datefield', | |
273 | + allowBlank:false, | |
274 | + hideTrigger: true, | |
275 | + format : 'Y-m-d\\TH:i:s' | |
276 | + } | |
277 | + }, | |
278 | + { | |
279 | + xtype: 'gridcolumn', | |
280 | + text: 'Duration (hour)', | |
281 | + sortable : true, | |
282 | + dataIndex: 'durationHour', | |
283 | + width : 120, | |
284 | + menuDisabled: false, | |
285 | + hidden:true, | |
286 | + id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1', | |
287 | + renderer: function(value) { | |
288 | + return Ext.util.Format.number(value,'0.00'); | |
289 | + }, | |
290 | + listeners: { | |
291 | + beforeshow : function(){ | |
292 | + updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1'); | |
293 | + } | |
294 | + } | |
295 | + }, | |
296 | + { | |
297 | + xtype: 'gridcolumn', | |
298 | + text: 'Duration (Min)', | |
299 | + sortable : true, | |
300 | + dataIndex: 'durationMin', | |
301 | + width : 120, | |
302 | + menuDisabled: false, | |
303 | + hidden:false, | |
304 | + id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2', | |
305 | + renderer: function(value) { | |
306 | + return Ext.util.Format.number(value,'0.00'); | |
307 | + }, | |
308 | + listeners: { | |
309 | + beforeshow : function(){ | |
310 | + updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2'); | |
311 | + } | |
312 | + } | |
313 | + }, | |
314 | + { | |
315 | + xtype: 'gridcolumn', | |
316 | + text: 'Duration (Sec)', | |
317 | + sortable : true, | |
318 | + dataIndex: 'durationSec', | |
319 | + width : 120, | |
320 | + menuDisabled: false, | |
321 | + hidden:true, | |
322 | + id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3', | |
323 | + renderer: function(value) { | |
324 | + return Ext.util.Format.number(value,'0.00'); | |
325 | + }, | |
326 | + listeners: { | |
327 | + beforeshow : function(){ | |
328 | + updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3'); | |
329 | + } | |
330 | + } | |
322 | 331 | } |
323 | - else | |
324 | - { | |
325 | - width = 50. * parseInt(obj.size); | |
326 | - columns[i] = Ext.create('Ext.grid.column.Column', { text: obj.name, sortable : false, dataIndex: index, | |
327 | - width : width, menuDisabled: false, editor: 'textfield' }); | |
332 | + ]; | |
333 | + | |
334 | + Ext.Array.each(result.parameters, function(obj, index) { | |
335 | + var field = { | |
336 | + name: 'param'+(index+2) | |
337 | + }; | |
338 | + var column = { | |
339 | + text: obj.name, | |
340 | + sortable : true, | |
341 | + dataIndex: 'param'+(index+2), | |
342 | + menuDisabled: false | |
343 | + }; | |
344 | + switch (obj.type) { | |
345 | + case 1: //dateTime | |
346 | + field = Ext.apply({}, field, { | |
347 | + type : 'date', | |
348 | + dateFormat: 'Y-m-d\\TH:i:s', | |
349 | + convert: function(value,rec) { | |
350 | + if (!Ext.isDate(value)){ | |
351 | + var valueString = new String(value); | |
352 | + return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' ')); | |
353 | + } | |
354 | + return value; | |
355 | + } | |
356 | + | |
357 | + }); | |
358 | + column = Ext.apply({}, column, { | |
359 | + xtype: 'datecolumn', | |
360 | + width : 120, | |
361 | + editor : { | |
362 | + xtype:'datefield', | |
363 | + allowBlank:false, | |
364 | + hideTrigger: true, | |
365 | + format : 'Y-m-d\\TH:i:s' | |
366 | + } | |
367 | + }); | |
368 | + break; | |
369 | + default: | |
370 | + field = Ext.apply({}, field, { | |
371 | + type: 'string' | |
372 | + }); | |
373 | + column = Ext.apply({}, column, { | |
374 | + width : 50. * parseInt(obj.size), | |
375 | + editor: 'textfield' | |
376 | + }); | |
328 | 377 | } |
329 | - i++; | |
378 | + fieldsConfig.push(field); | |
379 | + columnsConfig.push(column); | |
330 | 380 | }); |
381 | + | |
331 | 382 | var store = Ext.create('Ext.data.Store', { |
332 | - fields: fields, | |
383 | + fields: fieldsConfig, | |
333 | 384 | autoDestroy: false, |
334 | 385 | pageSize : 200, |
335 | 386 | buffered : true, |
... | ... | @@ -360,7 +411,7 @@ Ext.define('amdaUI.CatalogUI', { |
360 | 411 | } |
361 | 412 | }); |
362 | 413 | |
363 | - me.TTGrid.reconfigure(store, columns); | |
414 | + me.TTGrid.reconfigure(store, columnsConfig); | |
364 | 415 | } |
365 | 416 | me.TTGrid.getSelectionModel().deselectAll(); |
366 | 417 | // |
... | ... | @@ -458,7 +509,7 @@ Ext.define('amdaUI.CatalogUI', { |
458 | 509 | this.object = obj; |
459 | 510 | if (toRename) module.linkedNode.toRename = true; |
460 | 511 | } |
461 | - module.linkedNode.create(/*{callback : function() {module.linkedNode.update();}, scope : this}*/); | |
512 | + module.linkedNode.create({callback : function() {module.linkedNode.update();}, scope : this}); | |
462 | 513 | } else { |
463 | 514 | //update |
464 | 515 | module.linkedNode.update(); |
... | ... | @@ -687,11 +738,17 @@ Ext.define('amdaUI.CatalogUI', { |
687 | 738 | |
688 | 739 | Ext.Msg.prompt('Define Parameters', 'Please enter parameters number:', function(btn, text){ |
689 | 740 | if (btn == 'ok'){ |
690 | - AmdaAction.initTTCache(me.isCatalog, text, me.onAfterInit, me); | |
741 | + var nbParam = parseInt(text); | |
742 | + if ((nbParam <= 0) || (nbParam > 100)) { | |
743 | + nbParam = 1; | |
744 | + } | |
745 | + | |
746 | + obj.set('nbParameters', parseInt(text)); | |
691 | 747 | } |
692 | 748 | else { |
693 | - AmdaAction.initTTCache(me.isCatalog, 0, me.onAfterInit, me); | |
749 | + obj.set('nbParameters', 1); | |
694 | 750 | } |
751 | + me.setObject(obj,true); | |
695 | 752 | }, this); |
696 | 753 | |
697 | 754 | } | ... | ... |