Commit 72195d652f5b15a25a6f6ff63c8920ad7af653ae
1 parent
73a466f0
Exists in
master
and in
111 other branches
Automatically set times min/max values.
Showing
2 changed files
with
73 additions
and
58 deletions
Show diff stats
js/app/controllers/EpnTapModule.js
... | ... | @@ -84,39 +84,15 @@ Ext.define('amdaDesktop.EpnTapModule', { |
84 | 84 | return 'All ' + (name[name.length-1] == 's' ? name : name + 's').replace(/_/g, ' ').toLowerCase(); |
85 | 85 | }, |
86 | 86 | |
87 | - /** | |
88 | - Compare two dates formated as dd/mm/yyyy and return: | |
89 | - - `true` if `newStrDate` is more recent than `oldStrDate`, or if `oldStrDate` is null; | |
90 | - - `false` if `oldStrDate` is more recent than `newStrDate`, or if `newStrDate` is null; | |
91 | - - `null` if a date is not well formed. | |
92 | - */ | |
93 | - isLatest: function(newStrDate, oldStrDate) { | |
94 | - if (newStrDate === null) { | |
95 | - return false; | |
96 | - } | |
97 | - if (oldStrDate === null) { | |
98 | - return true; | |
99 | - } | |
100 | - | |
101 | - var newDate = newStrDate.split('/'); | |
102 | - var oldDate = oldStrDate.split('/'); | |
103 | - | |
104 | - if(newDate[2]>oldDate[2]) { | |
105 | - return true; | |
106 | - } else if(newDate[2]<oldDate[2]) { | |
107 | - return false; | |
108 | - } | |
109 | - if(newDate[1]>oldDate[1]) { | |
110 | - return true; | |
111 | - } else if(newDate[1]<oldDate[1]) { | |
87 | + isDate: function(date) { | |
88 | + if (date === null) { | |
112 | 89 | return false; |
113 | 90 | } |
114 | - if(newDate[0]>oldDate[0]) { | |
115 | - return true; | |
116 | - } else { | |
91 | + var dateArr = date.split('/'); | |
92 | + if (dateArr.length != 3 || isNaN(parseInt(dateArr[0])) || isNaN(parseInt(dateArr[1])) || isNaN(parseInt(dateArr[2])) ) { | |
117 | 93 | return false; |
118 | 94 | } |
119 | - return null; | |
95 | + return true; | |
120 | 96 | }, |
121 | 97 | |
122 | 98 | /**************************** |
... | ... | @@ -143,8 +119,6 @@ Ext.define('amdaDesktop.EpnTapModule', { |
143 | 119 | this.nextPageBtn = Ext.getCmp('epnTapNextPageBtn'); |
144 | 120 | this.lastPageBtn = Ext.getCmp('epnTapLastPageBtn'); |
145 | 121 | |
146 | - this.timeSelector.setInterval(new Date(), new Date()); // TODO: use min/max dates | |
147 | - | |
148 | 122 | this.productTypeCB.getStore().removeAll(); |
149 | 123 | this.productTypeCB.getStore().add({'id': 'all', 'name': 'All data product types'}); |
150 | 124 | for (var productTypeId in this.metadata) { |
... | ... | @@ -385,10 +359,12 @@ Ext.define('amdaDesktop.EpnTapModule', { |
385 | 359 | this.granulesGrid.getStore().removeAll(); |
386 | 360 | |
387 | 361 | var service = null; |
388 | - var timeMinArr = null; | |
389 | - var timeMaxArr = null; | |
390 | - var timeMin = null; | |
391 | - var timeMax = null; | |
362 | + var newTimeMin = null; | |
363 | + var newTimeMax = null; | |
364 | + | |
365 | + var timeMin = Ext.Date.parse('01/01/2100', 'd/m/Y'); | |
366 | + var timeMax = Ext.Date.parse('01/01/1900', 'd/m/Y'); | |
367 | + | |
392 | 368 | var productType = this.productTypeCB.value; |
393 | 369 | var targetClass = this.targetClassCB.value; |
394 | 370 | var targetName = this.targetNameCB.value; |
... | ... | @@ -400,13 +376,16 @@ Ext.define('amdaDesktop.EpnTapModule', { |
400 | 376 | for (tn in this.metadata[dpt][tc]) { |
401 | 377 | for (serv in this.metadata[dpt][tc][tn]) { |
402 | 378 | service = this.metadata[dpt][tc][tn][serv]; |
403 | - timeMinArr = service[1].split('/'); | |
404 | 379 | filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); |
405 | - if (this.isLatest(service[1], timeMin)) { | |
406 | - timeMin = service[1]; | |
380 | + | |
381 | + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); | |
382 | + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); | |
383 | + | |
384 | + if (newTimeMin !== null && newTimeMin < timeMin) { | |
385 | + timeMin = newTimeMin; | |
407 | 386 | } |
408 | - if (this.isLatest(service[2], timeMax)) { | |
409 | - timeMax = service[2]; | |
387 | + if (newTimeMax !== null && newTimeMax > timeMax) { | |
388 | + timeMax = newTimeMax; | |
410 | 389 | } |
411 | 390 | } |
412 | 391 | } |
... | ... | @@ -418,11 +397,14 @@ Ext.define('amdaDesktop.EpnTapModule', { |
418 | 397 | for (serv in this.metadata[productType][tc][tn]) { |
419 | 398 | service = this.metadata[productType][tc][tn][serv]; |
420 | 399 | filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); |
421 | - if (this.isLatest(service[1], timeMin)) { | |
422 | - timeMin = service[1]; | |
400 | + | |
401 | + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); | |
402 | + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); | |
403 | + if (newTimeMin !== null && newTimeMin < timeMin) { | |
404 | + timeMin = newTimeMin; | |
423 | 405 | } |
424 | - if (this.isLatest(service[2], timeMax)) { | |
425 | - timeMax = service[2]; | |
406 | + if (newTimeMax !== null && newTimeMax > timeMax) { | |
407 | + timeMax = newTimeMax; | |
426 | 408 | } |
427 | 409 | } |
428 | 410 | } |
... | ... | @@ -432,11 +414,14 @@ Ext.define('amdaDesktop.EpnTapModule', { |
432 | 414 | for (serv in this.metadata[productType][targetClass][tn]) { |
433 | 415 | service = this.metadata[productType][targetClass][tn][serv]; |
434 | 416 | filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); |
435 | - if (this.isLatest(service[1], timeMin)) { | |
436 | - timeMin = service[1]; | |
417 | + | |
418 | + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); | |
419 | + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); | |
420 | + if (newTimeMin !== null && newTimeMin < timeMin) { | |
421 | + timeMin = newTimeMin; | |
437 | 422 | } |
438 | - if (this.isLatest(service[2], timeMax)) { | |
439 | - timeMax = service[2]; | |
423 | + if (newTimeMax !== null && newTimeMax > timeMax) { | |
424 | + timeMax = newTimeMax; | |
440 | 425 | } |
441 | 426 | } |
442 | 427 | } |
... | ... | @@ -444,18 +429,30 @@ Ext.define('amdaDesktop.EpnTapModule', { |
444 | 429 | for (serv in this.metadata[productType][targetClass][targetName]) { |
445 | 430 | service = this.metadata[productType][targetClass][targetName][serv]; |
446 | 431 | filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); |
447 | - if (this.isLatest(service[1], timeMin)) { | |
448 | - timeMin = service[1]; | |
432 | + | |
433 | + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); | |
434 | + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); | |
435 | + | |
436 | + if (newTimeMin !== null && newTimeMin < timeMin) { | |
437 | + timeMin = newTimeMin; | |
449 | 438 | } |
450 | - if (this.isLatest(service[2], timeMax)) { | |
451 | - timeMax = service[2]; | |
439 | + if (newTimeMax !== null && newTimeMax > timeMax) { | |
440 | + timeMax = newTimeMax; | |
452 | 441 | } |
453 | 442 | } |
454 | 443 | } |
455 | 444 | |
456 | - console.log('times min/max: [' + timeMin + ' ; ' + timeMax + ']'); | |
457 | - // TODO: charger times min/max dans formulaire | |
458 | - // TODO: dans formulaire, mettre à jour duration avec times min/max | |
445 | + if (timeMin < Ext.Date.parse('01/01/1970', 'd/m/Y') ) { | |
446 | + console.log('warning: ', timeMin, " is a too old date, replaced by 01/01/1970."); | |
447 | + timeMin = Ext.Date.parse('01/01/1970', 'd/m/Y'); | |
448 | + } | |
449 | + if (timeMax > Ext.Date.parse('01/01/2099', 'd/m/Y') ) { | |
450 | + console.log('warning: ', timeMax, " is a too high date, replaced by 01/01/2099."); | |
451 | + timeMax = Ext.Date.parse('01/01/2099', 'd/m/Y'); | |
452 | + } | |
453 | + | |
454 | + this.timeSelector.setLimits(timeMin, timeMax); | |
455 | + this.timeSelector.setInterval(timeMin, timeMax); | |
459 | 456 | |
460 | 457 | var filter = Object.keys(filterDict).map(function(key) { |
461 | 458 | return [key, filterDict[key]]; | ... | ... |
js/app/views/IntervalUI.js
... | ... | @@ -47,6 +47,24 @@ Ext.define('amdaUI.IntervalUI', { |
47 | 47 | this.updateDuration(); |
48 | 48 | }, |
49 | 49 | |
50 | + setLimits: function(minValue, maxValue) { | |
51 | + var form = this.findParentByType('form').getForm(); | |
52 | + var startField = form.findField('startDate'); | |
53 | + var stopField = form.findField('stopDate'); | |
54 | + | |
55 | + if (startField != null) { | |
56 | + startField.setMinValue(minValue); | |
57 | + startField.setMaxValue(maxValue); | |
58 | + } | |
59 | + | |
60 | + if (stopField != null) { | |
61 | + stopField.setMinValue(minValue); | |
62 | + stopField.setMaxValue(maxValue); | |
63 | + } | |
64 | + | |
65 | + this.updateDuration(); | |
66 | + }, | |
67 | + | |
50 | 68 | /** |
51 | 69 | Get the start time field value. |
52 | 70 | - return: A Extjs Date object representing the start time. |
... | ... | @@ -101,8 +119,8 @@ Ext.define('amdaUI.IntervalUI', { |
101 | 119 | form.findField('durationMin').setValue(Ext.String.leftPad(Math.floor(diff/60000 % 60),2,'0')); |
102 | 120 | form.findField('durationSec').setValue(Ext.String.leftPad(Math.floor(diff/1000 % 60),2,'0')); |
103 | 121 | |
104 | - if (durationDays > 9999) { | |
105 | - form.findField('durationDay').markInvalid('Maximum interval is 9999 days!'); | |
122 | + if (durationDays > 25000) { | |
123 | + form.findField('durationDay').markInvalid('Maximum interval is 25000 days!'); | |
106 | 124 | } |
107 | 125 | } |
108 | 126 | |
... | ... | @@ -219,7 +237,7 @@ Ext.define('amdaUI.IntervalUI', { |
219 | 237 | items:[ |
220 | 238 | { xtype: 'displayfield', labelWidth: 60, labelAlign: 'right', width: 60, fieldLabel: '<br>Duration'}, |
221 | 239 | { xtype: 'component', width: 5}, |
222 | - { name: 'durationDay', fieldLabel: 'Days', width: 45, maxLength: 4}, | |
240 | + { name: 'durationDay', fieldLabel: 'Days', width: 45, maxLength: 5}, | |
223 | 241 | { xtype: 'component', width: 5}, |
224 | 242 | { name: 'durationHour', fieldLabel: 'Hrs'}, |
225 | 243 | { xtype: 'component', width: 5}, | ... | ... |