diff --git a/js/app/controllers/DownloadModule.js b/js/app/controllers/DownloadModule.js index 12f5cc4..2bd8354 100644 --- a/js/app/controllers/DownloadModule.js +++ b/js/app/controllers/DownloadModule.js @@ -60,5 +60,11 @@ Ext.define('amdaDesktop.DownloadModule', { me.getUiContent().addParameter(paramNode, true); }); } + }, + + editFromJsonData: function(jsonData) { + this.createLinkedNode(); + this.createObject(jsonData); + this.createWindow(); } }); diff --git a/js/app/controllers/PlotModule.js b/js/app/controllers/PlotModule.js index e8490cb..0bd94c1 100644 --- a/js/app/controllers/PlotModule.js +++ b/js/app/controllers/PlotModule.js @@ -300,5 +300,28 @@ Ext.define('amdaDesktop.PlotModule', { isMultiPlot : function() { return this.multiPlotWin && !this.multiPlotWin.isHidden(); + }, + + editInDownloadModule: function(plotNode) { + var plotValues = plotNode.get('object').getJsonValues(); + var downloadValues = new Object(); + downloadValues.timesrc = plotValues.timesrc; + downloadValues.startDate = plotValues.startDate; + downloadValues.stopDate = plotValues.stopDate; + downloadValues.durationDay = plotValues.durationDay; + downloadValues.durationHour = plotValues.durationHour; + downloadValues.durationMin = plotValues.durationMin; + downloadValues.durationSec = plotValues.durationSec; + if (plotValues.timeTables) + downloadValues.timeTables = plotValues.timeTables; + downloadValues.list = []; + plotNode.get('object').panels().each(function (panel) { + panel.params().each(function (param) { + downloadValues.list.push(param.getJsonValues()); + }); + }); + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id, true, function (module) { + module.editFromJsonData(downloadValues); + }); } }); diff --git a/js/app/models/Download.js b/js/app/models/Download.js index 2350a28..990b717 100644 --- a/js/app/models/Download.js +++ b/js/app/models/Download.js @@ -7,30 +7,129 @@ * @author myriam * @version $Id: Download.js 2068 2014-02-06 11:27:38Z elena $ */ - + + +Ext.define('amdaModel.DownloadConfig', { + singleton: true, + + defaultValues : { + timeformat: 'YYYY-MM-DDThh:mm:ss', + timeformatTT: 'YYYY-MM-DDThh:mm:ss', + fileformat: 'ASCII', + fileformatTT: 'text', + filecompress: 'tar+gzip', + filecompressTT: 'tar+gzip', + filestructure: '2' + }, + + timeformatData: [ + ['YYYY-MM-DDThh:mm:ss', 'YYYY-MM-DDThh:mm:ss.ms', 'ISO format with msecs'], + ['DD Time', 'YYYYDOYhhmmssms', 'Day-Of-Year, 1 Jan : DOY = 0'], + ['Timestamp', 'Seconds from 1970', 'Total of seconds from the Unix Epoch on January 1st, 1970 at UTC.'], + ['YYYY MM DD hh mm ss', 'YYYY MM DD hh mm ss ms', 'date with spaces'], + ['Timestamp-with-milliseconds', 'Seconds from 1970 with ms', 'Total of seconds from the Unix Epoch with milliseconds.'] + ], + fileformatData: [ + ['ASCII', 'ASCII'], + ['vot', 'VOTable'], + ['cdf', 'CDF'], + ['json', 'JSON'] + ], + fileformatTTData: [ + ['text', 'plain text'], + ['vot', 'VOTable'] + ], + filecompressData: [ + ['zip', 'zip'], + ['tar+gzip', 'tar+gzip'] + ], + filecompressTTData: [ + ['zip', 'zip'], + ['tar+gzip', 'tar+gzip'], + ['none', 'none'] + ], + filestructureData: [ + ['0', 'All In One File'], + ['1', 'One File Per Time Interval'], + ['2', 'One File Per Param/Interval'] + ] +}); Ext.define('amdaModel.Download', { extend: 'amdaModel.AmdaTimeObject', - + + requires: [ + "amdaModel.DownloadParam" + ], + fields : [ {name: 'type', type: 'string', defaultValue: 'Download'}, {name: 'downloadSrc', type: 'string'}, - {name: 'list', defaultValue: null }, // array of parameters - {name: 'timeformat', type: 'string'}, - {name: 'timeformatTT', type: 'string'}, - {name: 'structure', type: 'string'}, + {name: 'timeformat', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.timeformat}, + {name: 'timeformatTT', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.timeformatTT}, + {name: 'filestructure', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.filestructure}, {name: 'refparamSampling', type: 'boolean', defaultValue: false}, {name: 'separateInfoFile', type: 'boolean', defaultValue: false}, {name: 'sampling', type: 'int', defaultValue: '600'}, {name: 'scientificformat', type: 'boolean', defaultValue: true}, {name: 'fileprefix', type: 'string'}, - {name: 'fileformat', type: 'string'}, - {name: 'fileformatTT', type: 'string'}, - {name: 'compression', type: 'string'}, - {name: 'compressionTT', type: 'string'} + {name: 'fileformat', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.fileformat}, + {name: 'fileformatTT', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.fileformatTT}, + {name: 'compression', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.filecompress}, + {name: 'compressionTT', type: 'string', defaultValue: amdaModel.DownloadConfig.defaultValues.filecompressTT} + ], + + associations : [ + { + type : 'hasMany', + model : 'amdaModel.DownloadParam', + name : 'params' + } ], - propertiesToCopy : 'id,name,downloadSrc,refparamSampling,separateInfoFile,sampling,scientificformat,list,timeformat,timeformatTT,structure,fileprefix,fileformat,fileformatTT,compression,compressionTT', + propertiesToCopy : 'id,name,downloadSrc,refparamSampling,separateInfoFile,sampling,scientificformat,list,timeformat,timeformatTT,filestructure,fileprefix,fileformat,fileformatTT,compression,compressionTT', + + constructor: function(){ + var me = this; + me.callParent(arguments); + if ((arguments.length > 0) && arguments[0]) + { + if (arguments[0].list) + me.loadParams(arguments[0].list); + } + this.dirty = false; + }, + + loadParams: function(params) + { + /* Compatability mode */ + Ext.each(params, function(param, index) { + if (param.hasOwnProperty('is-init')) { + return; + } + params[index]['dim1-sum-type'] = param['dim1-is-range'] ? 1 : 0; + params[index]['dim1-min-value'] = param['dim1-min-range']; + params[index]['dim1-max-value'] = param['dim1-max-range']; + params[index]['dim2-sum-type'] = param['dim2-is-range'] ? 1 : 0; + params[index]['dim2-min-value'] = param['dim2-min-range']; + params[index]['dim2-max-value'] = param['dim2-max-range']; + params[index]['is-init'] = true; + }); + this.params().loadData(params); + }, + + isDirty : function() { + if (this.dirty) + return true; + + var d = false; + + this.params().each(function (param, index) { + if (param.dirty) + d = true; + }); + return d; + }, getJsonValues : function(){ @@ -41,7 +140,7 @@ Ext.define('amdaModel.Download', { myValues.name = this.get('name'); //Data download if (myValues.downloadSrc === '0') { // Data download - myValues.structure = this.get('structure'); + myValues.filestructure = this.get('filestructure'); myValues.refparamSampling = this.get('refparamSampling'); myValues.separateInfoFile = this.get('separateInfoFile'); myValues.scientificformat = this.get('scientificformat'); @@ -75,13 +174,10 @@ Ext.define('amdaModel.Download', { } // if there's at least one parameter - if (this.get('list') && this.get('list').length) { - var list = this.get('list'); - myValues.list=[]; - Ext.each(list, function(item, index){ - myValues.list[index] = item.getJsonValues(); - }); - } + myValues.list = [] + this.params().each(function (param, index) { + myValues.list[index] = param.getJsonValues(); + }); myValues.fileformat = this.get('fileformat'); myValues.timeformat = this.get('timeformat'); myValues.compression = this.get('compression'); diff --git a/js/app/views/AstroImagesUI.js b/js/app/views/AstroImagesUI.js index fc41b66..de8f584 100644 --- a/js/app/views/AstroImagesUI.js +++ b/js/app/views/AstroImagesUI.js @@ -38,7 +38,8 @@ Ext.define('amdaUI.AstroImagesUI', { extend: 'Ext.form.Panel', requires: [ - 'amdaUI.SendToSampButtonUI' + 'amdaUI.SendToSampButtonUI', + 'amdaModel.DownloadNode' ], // @@ -318,9 +319,13 @@ Ext.define('amdaUI.AstroImagesUI', { obj.set('compression','zip'); obj.set('list',imageList); obj.set('downloadSrc',2); - - amdaModel.DownloadNode.set('object',obj); - amdaModel.DownloadNode.execute(); + + var downloadNode = Ext.create('amdaModel.DownloadNode', { + leaf : true, + }); + + downloadNode.set('object',obj); + downloadNode.execute(); }, getAdditionalRequestConfig : function(panelId) diff --git a/js/app/views/DownloadUI.js b/js/app/views/DownloadUI.js index 01a2d54..ae1e283 100644 --- a/js/app/views/DownloadUI.js +++ b/js/app/views/DownloadUI.js @@ -16,25 +16,11 @@ Ext.define('amdaUI.DownloadUI', { 'amdaUI.TimeSelectorUI', 'amdaUI.ParamArgumentsPlug', 'amdaUI.SendToSampButtonUI', + 'amdaModel.Download', 'amdaModel.DownloadParam', 'amdaModel.RequestParamObject' ], - //Old kernel time formats - //timeformatData : [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss'], ['Y m d H i s', 'YYYY MM DD hh mm ss'], ['d m Y H i s', 'DD MM YYYY hh mm ss'], ['Y z H i s', 'YYYY DDD hh mm ss']], - //New kernel time formats - timeformatData: [['YYYY-MM-DDThh:mm:ss', 'YYYY-MM-DDThh:mm:ss.ms', 'ISO format with msecs'], - ['DD Time', 'YYYYDOYhhmmssms', 'Day-Of-Year, 1 Jan : DOY = 0'], - ['Timestamp', 'Seconds from 1970', 'Total of seconds from the Unix Epoch on January 1st, 1970 at UTC.'], - ['YYYY MM DD hh mm ss', 'YYYY MM DD hh mm ss ms', 'date with spaces'], - ['Timestamp-with-milliseconds', 'Seconds from 1970 with ms', 'Total of seconds from the Unix Epoch with milliseconds.']], - timeformatTTData: [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss']], - fileformatData: [['ASCII', 'ASCII'], ['vot', 'VOTable'], ['cdf', 'CDF'], ['json', 'JSON']], - fileformatTTData: [['text', 'plain text'], ['vot', 'VOTable']], - filecompressData: [['zip', 'zip'], ['tar+gzip', 'tar+gzip']], - filecompressTT: [['zip', 'zip'], ['tar+gzip', 'tar+gzip'], ['none', 'none']], - filestructureData: [['0', 'All In One File'], ['1', 'One File Per Time Interval'], ['2', 'One File Per Param/Interval']], - constructor: function (config) { this.init(config); this.callParent(arguments); @@ -112,26 +98,23 @@ Ext.define('amdaUI.DownloadUI', { }, saveProcess: function(toRename) { - if (this.object.dirty) - { - var downloadModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); - if (this.object.isModified('name')) { - if (this.object.get('id')) - { - var contextNode = downloadModule.linkedNode.parentNode; - downloadModule.createLinkedNode(); - downloadModule.linkedNode.set('contextNode',contextNode); - downloadModule.createObject(this.object.getJsonValues()); - var downloadObj = downloadModule.linkedNode.get('object'); - this.object = downloadObj; - if (toRename) downloadModule.linkedNode.toRename = true; - } - downloadModule.linkedNode.create(); - } - else { - downloadModule.linkedNode.set('contextNode',downloadModule.contextNode); - downloadModule.linkedNode.update(); + var downloadModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); + if (this.object.isModified('name')) { + if (this.object.get('id')) + { + var contextNode = downloadModule.linkedNode.parentNode; + downloadModule.createLinkedNode(); + downloadModule.linkedNode.set('contextNode',contextNode); + downloadModule.createObject(this.object.getJsonValues()); + var downloadObj = downloadModule.linkedNode.get('object'); + this.object = downloadObj; + if (toRename) downloadModule.linkedNode.toRename = true; } + downloadModule.linkedNode.create(); + } + else { + downloadModule.linkedNode.set('contextNode',downloadModule.contextNode); + downloadModule.linkedNode.update(); } }, @@ -219,44 +202,6 @@ Ext.define('amdaUI.DownloadUI', { this.editParameterArgs(r); }, - addParams: function (arrayParams) - { - var arrayRec = new Array(); - var index = 1; - - if (arrayParams) - { - Ext.Array.each(arrayParams, function (item) { - if (Ext.isObject(item)) { - // handel case of derived parameters - var patt_ws = new RegExp("ws_"); - var patt_wsd = new RegExp("wsd_"); - if (typeof paramId !== 'undefined' && ! patt_ws.test(item.paramid) && ! patt_wsd.test(item.paramid)) - { - // for Parameter Name in Download Module - var paramObj = amdaModel.RequestParamObject.getEmptyObj(); - paramObj.paramid = paramId; - paramObj['dim1-index'] = item.get('dim1'); - paramObj['dim2-index'] = item.get('dim2'); - - var r = Ext.create('amdaModel.DownloadParam', paramObj); - } else - { - //for download from get Data in Plot module - var r = Ext.create('amdaModel.DownloadParam', item); - } - - } else { - // for Download By Request in Operations menu - //TODO BRE - Components selection - var r = Ext.create('amdaModel.DownloadParam', {paramid: item}); - } - arrayRec.push(r); - }); - } - this.paramGrid.getStore().loadData(arrayRec); - }, - // parameter name -> alias updateConstruct: function (oldval, newval) { var index = this.paramGrid.store.findExact('name', oldval); @@ -288,7 +233,7 @@ Ext.define('amdaUI.DownloadUI', { { var timeformat = values.timeformat; var timeSource = this.timeSelector.getActiveTimeSource(); - var structure = values.filestructure; + var filestructure = values.filestructure; var sampling = values.sampling ? values.sampling : 600; var refparamSampling = values.refparamsampling == 'on'; var fileprefix = values.fileprefix ? values.fileprefix : ''; @@ -316,18 +261,23 @@ Ext.define('amdaUI.DownloadUI', { updateStatus = false; } + if (updateStatus && (this.object.params().count() == 0)) + { + myDesktopApp.warningMsg('You must define at least one parameter to download'); + updateStatus = false; + } + if (updateStatus) { /// real object update // update TimeTable object with the content of form basicForm.updateRecord(this.object); + this.object.set('timesrc', timeSource); // set valid intervals into TimeTable object if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0]) this.object.set('timeTables', this.timeSelector.TTGrid.getStore().data.items); - // set parameters - this.object.set('list', this.paramGrid.getStore().data.items); - this.object.set('structure', structure); + this.object.set('filestructure', filestructure); this.object.set('refparamSampling', refparamSampling); this.object.set('sampling', sampling); this.object.set('fileprefix', fileprefix); @@ -342,7 +292,11 @@ Ext.define('amdaUI.DownloadUI', { var timeformat = values.timeformatTT; var compression = values.compressionTT; var fileformat = values.fileformatTT; - if (compression === 'none' + if (this.TTGrid.getStore().count() == 0) { + myDesktopApp.warningMsg('You must define at least one TimeTable or Catalog to download'); + updateStatus = false; + } + else if (compression === 'none' && this.TTGrid.getStore().count() > 1) { myDesktopApp.warningMsg('You are going to download several time tables - select the Compression please'); updateStatus = false; @@ -362,31 +316,16 @@ Ext.define('amdaUI.DownloadUI', { * load this.object into form */ loadObject: function () { - - if (!this.object.get('timeformat')) - this.object.set('timeformat', this.timeformatData[0][0]); - - if (!this.object.get('timeformatTT')) - this.object.set('timeformatTT', this.timeformatData[0][0]); - - if (!this.object.get('fileformat')) - this.object.set('fileformat', this.fileformatData[0][0]); - - if (!this.object.get('fileformatTT')) - this.object.set('fileformatTT', this.fileformatTTData[0][0]); - - if (!this.object.get('compression')) - this.object.set('compression', this.filecompressData[1][0]); - - if (!this.object.get('compressionTT')) - this.object.set('compressionTT', this.filecompressData[1][0]); - // load object into form this.formPanel.getForm().loadRecord(this.object); // set object's TTs into the timeselector this.addTTs(this.object.get('timeTables')); - // set parameters - this.addParams(this.object.get('list')); + // set parameters + this.paramGrid.reconfigure(this.object.params()); + //this.paramGrid.getStore().loadData(this.object.params().data.items); + // select "Parameters" tab + var tabPanel = this.formPanel.down(); + tabPanel.setActiveTab(0); }, /** @@ -572,7 +511,7 @@ Ext.define('amdaUI.DownloadUI', { * @return false */ fclose: function () { - return false; + return this.object.isDirty(); }, init: function (config) { @@ -710,7 +649,7 @@ Ext.define('amdaUI.DownloadUI', { var storeTimeFormat = new Ext.data.ArrayStore({ fields: ['id', 'name', 'qtip'], - data: this.timeformatData + data: amdaModel.DownloadConfig.timeformatData }); this.paramPanel = new Ext.container.Container({ @@ -764,14 +703,12 @@ Ext.define('amdaUI.DownloadUI', { '<li class="x-boundlist-item" data-qtip="{qtip}">{name}</li>', '</tpl>' ] - }, - value: storeTimeFormat.first() + } }, { fieldLabel: 'File Structure', name: 'filestructure', - store: this.filestructureData, - value: this.filestructureData[2], + store: amdaModel.DownloadConfig.filestructureData, listeners: { change: {fn: this.onFileStructureChange}, scope: this @@ -811,14 +748,12 @@ Ext.define('amdaUI.DownloadUI', { { fieldLabel: 'File Format', name: 'fileformat', - store: this.fileformatData, - value: this.fileformatData[0] + store: amdaModel.DownloadConfig.fileformatData }, { fieldLabel: 'Compression', name: 'compression', - store: this.filecompressData, - value: this.filecompressData[0] + store: amdaModel.DownloadConfig.filecompressData }, this.timeSelector ] @@ -862,20 +797,17 @@ Ext.define('amdaUI.DownloadUI', { '<li class="x-boundlist-item" data-qtip="{qtip}">{name}</li>', '</tpl>' ] - }, - value: storeTimeFormat.first() + } }, { fieldLabel: 'File Format ', name: 'fileformatTT', - store: this.fileformatTTData, - value: this.fileformatTTData[0] + store: amdaModel.DownloadConfig.fileformatTTData }, { fieldLabel: 'Compression ', name: 'compressionTT', - store: this.filecompressTT, - value: this.filecompressTT[0] + store: amdaModel.DownloadConfig.filecompressTTData } ]} ] @@ -923,17 +855,11 @@ Ext.define('amdaUI.DownloadUI', { text: 'Reset', scope: this, handler: function () { - this.formPanel.getForm().reset(); - var tabPanel = this.formPanel.down(); - var downloadSrc = tabPanel.items.indexOf(tabPanel.getActiveTab()); - if (downloadSrc === 0) { - // reset parameters and Time Tables in Get Data - this.paramGrid.store.removeAll(); - this.timeSelector.TTGrid.store.removeAll(); - } else { - // reset Time Tables in Get time Table - this.TTGrid.store.removeAll(); - } + var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); + downModule.createLinkedNode(); + var obj = null; + downModule.createObject(obj); + this.setObject(downModule.linkedNode.get('object')); } }, { diff --git a/js/app/views/PlotComponents/PlotTabContent.js b/js/app/views/PlotComponents/PlotTabContent.js index 4caa53b..f4cafc4 100644 --- a/js/app/views/PlotComponents/PlotTabContent.js +++ b/js/app/views/PlotComponents/PlotTabContent.js @@ -167,9 +167,8 @@ Ext.define('amdaPlotComp.PlotTabContent', { }, getDataProcess : function() { - var downObject = amdaModel.DownloadNode.decodeObject(this.plotNode.get('object')); - amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject)); - amdaModel.DownloadNode.editInModule(); + var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id); + plotModule.editInDownloadModule(this.plotNode); }, isValidRequest : function(acceptEmptyTTList = true) { -- libgit2 0.21.2