diff --git a/js/app/controllers/EpnTapModule.js b/js/app/controllers/EpnTapModule.js index cf3f821..a3cc104 100644 --- a/js/app/controllers/EpnTapModule.js +++ b/js/app/controllers/EpnTapModule.js @@ -84,39 +84,15 @@ Ext.define('amdaDesktop.EpnTapModule', { return 'All ' + (name[name.length-1] == 's' ? name : name + 's').replace(/_/g, ' ').toLowerCase(); }, - /** - Compare two dates formated as dd/mm/yyyy and return: - - `true` if `newStrDate` is more recent than `oldStrDate`, or if `oldStrDate` is null; - - `false` if `oldStrDate` is more recent than `newStrDate`, or if `newStrDate` is null; - - `null` if a date is not well formed. - */ - isLatest: function(newStrDate, oldStrDate) { - if (newStrDate === null) { - return false; - } - if (oldStrDate === null) { - return true; - } - - var newDate = newStrDate.split('/'); - var oldDate = oldStrDate.split('/'); - - if(newDate[2]>oldDate[2]) { - return true; - } else if(newDate[2]<oldDate[2]) { - return false; - } - if(newDate[1]>oldDate[1]) { - return true; - } else if(newDate[1]<oldDate[1]) { + isDate: function(date) { + if (date === null) { return false; } - if(newDate[0]>oldDate[0]) { - return true; - } else { + var dateArr = date.split('/'); + if (dateArr.length != 3 || isNaN(parseInt(dateArr[0])) || isNaN(parseInt(dateArr[1])) || isNaN(parseInt(dateArr[2])) ) { return false; } - return null; + return true; }, /**************************** @@ -143,8 +119,6 @@ Ext.define('amdaDesktop.EpnTapModule', { this.nextPageBtn = Ext.getCmp('epnTapNextPageBtn'); this.lastPageBtn = Ext.getCmp('epnTapLastPageBtn'); - this.timeSelector.setInterval(new Date(), new Date()); // TODO: use min/max dates - this.productTypeCB.getStore().removeAll(); this.productTypeCB.getStore().add({'id': 'all', 'name': 'All data product types'}); for (var productTypeId in this.metadata) { @@ -385,10 +359,12 @@ Ext.define('amdaDesktop.EpnTapModule', { this.granulesGrid.getStore().removeAll(); var service = null; - var timeMinArr = null; - var timeMaxArr = null; - var timeMin = null; - var timeMax = null; + var newTimeMin = null; + var newTimeMax = null; + + var timeMin = Ext.Date.parse('01/01/2100', 'd/m/Y'); + var timeMax = Ext.Date.parse('01/01/1900', 'd/m/Y'); + var productType = this.productTypeCB.value; var targetClass = this.targetClassCB.value; var targetName = this.targetNameCB.value; @@ -400,13 +376,16 @@ Ext.define('amdaDesktop.EpnTapModule', { for (tn in this.metadata[dpt][tc]) { for (serv in this.metadata[dpt][tc][tn]) { service = this.metadata[dpt][tc][tn][serv]; - timeMinArr = service[1].split('/'); filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); - if (this.isLatest(service[1], timeMin)) { - timeMin = service[1]; + + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); + + if (newTimeMin !== null && newTimeMin < timeMin) { + timeMin = newTimeMin; } - if (this.isLatest(service[2], timeMax)) { - timeMax = service[2]; + if (newTimeMax !== null && newTimeMax > timeMax) { + timeMax = newTimeMax; } } } @@ -418,11 +397,14 @@ Ext.define('amdaDesktop.EpnTapModule', { for (serv in this.metadata[productType][tc][tn]) { service = this.metadata[productType][tc][tn][serv]; filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); - if (this.isLatest(service[1], timeMin)) { - timeMin = service[1]; + + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); + if (newTimeMin !== null && newTimeMin < timeMin) { + timeMin = newTimeMin; } - if (this.isLatest(service[2], timeMax)) { - timeMax = service[2]; + if (newTimeMax !== null && newTimeMax > timeMax) { + timeMax = newTimeMax; } } } @@ -432,11 +414,14 @@ Ext.define('amdaDesktop.EpnTapModule', { for (serv in this.metadata[productType][targetClass][tn]) { service = this.metadata[productType][targetClass][tn][serv]; filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); - if (this.isLatest(service[1], timeMin)) { - timeMin = service[1]; + + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); + if (newTimeMin !== null && newTimeMin < timeMin) { + timeMin = newTimeMin; } - if (this.isLatest(service[2], timeMax)) { - timeMax = service[2]; + if (newTimeMax !== null && newTimeMax > timeMax) { + timeMax = newTimeMax; } } } @@ -444,18 +429,30 @@ Ext.define('amdaDesktop.EpnTapModule', { for (serv in this.metadata[productType][targetClass][targetName]) { service = this.metadata[productType][targetClass][targetName][serv]; filterDict[serv] = service[0] + (serv in filterDict ? filterDict[serv] : 0); - if (this.isLatest(service[1], timeMin)) { - timeMin = service[1]; + + newTimeMin = Ext.Date.parse(service[1], 'd/m/Y'); + newTimeMax = Ext.Date.parse(service[2], 'd/m/Y'); + + if (newTimeMin !== null && newTimeMin < timeMin) { + timeMin = newTimeMin; } - if (this.isLatest(service[2], timeMax)) { - timeMax = service[2]; + if (newTimeMax !== null && newTimeMax > timeMax) { + timeMax = newTimeMax; } } } - console.log('times min/max: [' + timeMin + ' ; ' + timeMax + ']'); - // TODO: charger times min/max dans formulaire - // TODO: dans formulaire, mettre à jour duration avec times min/max + if (timeMin < Ext.Date.parse('01/01/1970', 'd/m/Y') ) { + console.log('warning: ', timeMin, " is a too old date, replaced by 01/01/1970."); + timeMin = Ext.Date.parse('01/01/1970', 'd/m/Y'); + } + if (timeMax > Ext.Date.parse('01/01/2099', 'd/m/Y') ) { + console.log('warning: ', timeMax, " is a too high date, replaced by 01/01/2099."); + timeMax = Ext.Date.parse('01/01/2099', 'd/m/Y'); + } + + this.timeSelector.setLimits(timeMin, timeMax); + this.timeSelector.setInterval(timeMin, timeMax); var filter = Object.keys(filterDict).map(function(key) { return [key, filterDict[key]]; diff --git a/js/app/views/IntervalUI.js b/js/app/views/IntervalUI.js index 67163b6..ac81d75 100644 --- a/js/app/views/IntervalUI.js +++ b/js/app/views/IntervalUI.js @@ -47,6 +47,24 @@ Ext.define('amdaUI.IntervalUI', { this.updateDuration(); }, + setLimits: function(minValue, maxValue) { + var form = this.findParentByType('form').getForm(); + var startField = form.findField('startDate'); + var stopField = form.findField('stopDate'); + + if (startField != null) { + startField.setMinValue(minValue); + startField.setMaxValue(maxValue); + } + + if (stopField != null) { + stopField.setMinValue(minValue); + stopField.setMaxValue(maxValue); + } + + this.updateDuration(); + }, + /** Get the start time field value. - return: A Extjs Date object representing the start time. @@ -101,8 +119,8 @@ Ext.define('amdaUI.IntervalUI', { form.findField('durationMin').setValue(Ext.String.leftPad(Math.floor(diff/60000 % 60),2,'0')); form.findField('durationSec').setValue(Ext.String.leftPad(Math.floor(diff/1000 % 60),2,'0')); - if (durationDays > 9999) { - form.findField('durationDay').markInvalid('Maximum interval is 9999 days!'); + if (durationDays > 25000) { + form.findField('durationDay').markInvalid('Maximum interval is 25000 days!'); } } @@ -219,7 +237,7 @@ Ext.define('amdaUI.IntervalUI', { items:[ { xtype: 'displayfield', labelWidth: 60, labelAlign: 'right', width: 60, fieldLabel: '<br>Duration'}, { xtype: 'component', width: 5}, - { name: 'durationDay', fieldLabel: 'Days', width: 45, maxLength: 4}, + { name: 'durationDay', fieldLabel: 'Days', width: 45, maxLength: 5}, { xtype: 'component', width: 5}, { name: 'durationHour', fieldLabel: 'Hrs'}, { xtype: 'component', width: 5}, -- libgit2 0.21.2