diff --git a/js/app/AmdaApp.js b/js/app/AmdaApp.js index 7ea6130..0b038b8 100755 --- a/js/app/AmdaApp.js +++ b/js/app/AmdaApp.js @@ -501,8 +501,7 @@ Ext.define('amdaApp.AmdaApp', { msg += ('<b>Groups :</b> '+result['group']+'<br/>'); msg += ('<b>Email :</b> '+result['email']+'<br/>'); msg += ('<b>Registration date :</b> '+result['date']+'<br/>'); - msg += ('<b>Receive Newsletter :</b> '+(result['news'] == "1"?"true":"false")+'<br/>'); - + this.infoMsg(msg); } else diff --git a/js/app/models/Download.js b/js/app/models/Download.js index cd56f06..c853ca5 100644 --- a/js/app/models/Download.js +++ b/js/app/models/Download.js @@ -3,120 +3,117 @@ * Name : Download.js * Description : Download Request Business Object Definition * @class amdaModel.Download - * @extends amdaModel.AmdaObject - * + * @extends amdaModel.AmdaTimeObject * @author myriam * @version $Id: Download.js 2068 2014-02-06 11:27:38Z elena $ - ****************************************************************************** - * FT Id : Date : Name - Description - ****************************************************************************** - * : :15/12/2011: myriam – creation */ Ext.define('amdaModel.Download', { - extend: 'amdaModel.AmdaTimeObject', + extend: 'amdaModel.AmdaTimeObject', - 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: 'refparamSampling', type: 'boolean', defaultValue: false}, - {name: 'sampling', type: 'int', defaultValue: '600'}, - {name: 'fileprefix', type: 'string'}, - {name: 'fileformat', type: 'string'}, - {name: 'fileformatTT', type: 'string'}, - {name: 'compression', type: 'string'}, - {name: 'compressionTT', type: 'string'} + 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: 'refparamSampling', type: 'boolean', defaultValue: false}, + {name: 'sampling', type: 'int', defaultValue: '600'}, + {name: 'fileprefix', type: 'string'}, + {name: 'fileformat', type: 'string'}, + {name: 'fileformatTT', type: 'string'}, + {name: 'compression', type: 'string'}, + {name: 'compressionTT', type: 'string'} ], - + propertiesToCopy : 'id,name,downloadSrc,refparamSampling,sampling,list,timeformat,timeformatTT,structure,fileprefix,fileformat,fileformatTT,compression,compressionTT', getJsonValues : function(){ - var myValues = new Object(); - myValues.nodeType = 'download';//amdaModel.DownloadNode.nodeType; - myValues.type = this.get('type'); - myValues.downloadSrc = this.get('downloadSrc'); -//Data download - if (myValues.downloadSrc === '0') { // Data download - myValues.structure = this.get('structure'); - myValues.refparamSampling = this.get('refparamSampling'); - myValues.sampling = this.get('sampling'); - myValues.fileprefix = this.get('fileprefix'); - - myValues.timesrc = this.get('timesrc'); - // if there's at least one timeTable in case of Download data - if (this.get('timesrc') == amdaModel.AmdaTimeObject.inputTimeSrc[0] && this.get('timeTables') && this.get('timeTables').length){ - // get complete timeTables collection - var timeTables = this.get('timeTables'); - // init an empty array for timeTables - myValues.timeTables=[]; - // for each interval record - Ext.Array.each(timeTables, function(item, index, all){ - // get Json simplified value - if (!item.$className) { - myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id}; - } - // get Json simplified value - else { - myValues.timeTables[index] = item.getJsonValues(); - } - }); - } else { - myValues.startDate = this.get('startDate'); - myValues.stopDate = this.get('stopDate'); - myValues.durationDay = this.get('durationDay'); - myValues.durationHour = this.get('durationHour'); - myValues.durationMin = this.get('durationMin'); - myValues.durationSec = this.get('durationSec'); - } - - // 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.fileformat = this.get('fileformat'); - myValues.timeformat = this.get('timeformat'); - myValues.compression = this.get('compression'); - } - else if (myValues.downloadSrc === '1'){ // TT download - // if there's at least one timeTable - if (this.get('timeTables') && this.get('timeTables').length) { - var list = this.get('timeTables'); - myValues.list=[]; - - Ext.each(list, function(item, index){ - myValues.list[index]=item.get('id'); - }); - } - myValues.fileformat = this.get('fileformatTT'); - myValues.timeformat = this.get('timeformatTT'); - myValues.compression = this.get('compressionTT'); - } - else { // fits images download - myValues.list=[]; - if (this.get('list') && this.get('list').length) - Ext.each(this.get('list'), function(item, index){ - var image = new Object(); - image.name = item['name']; - image.url = item['url']; - myValues.list[index] = image; - }); - myValues.compression = this.get('compression'); - } - - myValues.leaf = true; - // myValues.nodeType = amdaModel.PlotNode.nodeType; - return myValues; - } - + var myValues = new Object(); + myValues.nodeType = 'download';//amdaModel.DownloadNode.nodeType; + myValues.type = this.get('type'); + myValues.downloadSrc = this.get('downloadSrc'); + //Data download + if (myValues.downloadSrc === '0') { // Data download + myValues.structure = this.get('structure'); + myValues.refparamSampling = this.get('refparamSampling'); + myValues.sampling = this.get('sampling'); + myValues.fileprefix = this.get('fileprefix'); + + myValues.timesrc = this.get('timesrc'); + // if there's at least one timeTable in case of Download data + if (this.get('timesrc') == amdaModel.AmdaTimeObject.inputTimeSrc[0] && this.get('timeTables') && this.get('timeTables').length){ + // get complete timeTables collection + var timeTables = this.get('timeTables'); + // init an empty array for timeTables + myValues.timeTables=[]; + // for each interval record + Ext.Array.each(timeTables, function(item, index, all){ + // get Json simplified value + if (!item.$className) { + myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id}; + } + // get Json simplified value + else { + myValues.timeTables[index] = item.getJsonValues(); + } + }); + } else { + myValues.startDate = this.get('startDate'); + myValues.stopDate = this.get('stopDate'); + myValues.durationDay = this.get('durationDay'); + myValues.durationHour = this.get('durationHour'); + myValues.durationMin = this.get('durationMin'); + myValues.durationSec = this.get('durationSec'); + } + + // 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.fileformat = this.get('fileformat'); + myValues.timeformat = this.get('timeformat'); + myValues.compression = this.get('compression'); + } + // TT download + else if (myValues.downloadSrc === '1') { + // if there's at least one timeTable + if (this.get('timeTables') && this.get('timeTables').length) { + var list = this.get('timeTables'); + myValues.list=[]; + + Ext.each(list, function(item, index){ + var tt = new Object(); + tt.name = item.get('name'); + tt.id = item.get('id'); + myValues.list[index] = tt; + }); + } + myValues.fileformat = this.get('fileformatTT'); + myValues.timeformat = this.get('timeformatTT'); + myValues.compression = this.get('compressionTT'); + } + // fits images download + else { + myValues.list=[]; + if (this.get('list') && this.get('list').length) + Ext.each(this.get('list'), function(item, index){ + var image = new Object(); + image.name = item['name']; + image.url = item['url']; + myValues.list[index] = image; + }); + myValues.compression = this.get('compression'); + } + myValues.leaf = true; + // myValues.nodeType = amdaModel.PlotNode.nodeType; + return myValues; + } }); diff --git a/js/app/models/DownloadNode.js b/js/app/models/DownloadNode.js index 5a570db..7208f78 100644 --- a/js/app/models/DownloadNode.js +++ b/js/app/models/DownloadNode.js @@ -2,17 +2,16 @@ * Project : AMDA-NG4 * Name : DownloadNode.js * @class amdaModel.DownloadNode - * @extends amdaModel.ExecutableNode + * @extends Ext.data.Model * @brief Basic Model of Node corresponding to a download request * @author Myriam * @version $Id: DownloadNode.js 2949 2015-06-23 10:25:59Z elena $ */ -//TODO amdaModel.SingletonNode class ??? + Ext.define('amdaModel.DownloadNode', { - extend: 'Ext.data.Model', - - singleton: true, + extend: 'Ext.data.Model', + singleton: true, fields:[{name : 'downloadType', type : 'string'}, {name: 'object', type: 'object'}, @@ -23,257 +22,206 @@ Ext.define('amdaModel.DownloadNode', { {name: 'jobNode', type: 'string', defaultValue: 'amdaModel.BkgJobNode'} ], - isExecutable: function(){ - return true; - }, - -//TODO MIXINS + isExecutable: function(){ + return true; + }, - getObjectCallback : function(result,remoteEvent){ - var t = remoteEvent.getTransaction(); - if (result) { - var paramObj = Ext.create(this.get('objectDataModel'), result); - // set parameter into node - this.set('object', paramObj); - var downObject = amdaModel.DownloadNode.decodeObject(); - // Edition ; - amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject)); - amdaModel.DownloadNode.editInModule(); - } - else { - // EXCEPTION : parameter not found !? - alert(t.action + "." + t.method + " : No parameter '" - +this.get('name')+"' found!"); - //TODO: adding an error log - } - }, + getObjectCallback : function(result,remoteEvent){ + var t = remoteEvent.getTransaction(); + if (result) { + var paramObj = Ext.create(this.get('objectDataModel'), result); + // set parameter into node + this.set('object', paramObj); + var downObject = amdaModel.DownloadNode.decodeObject(); + // Edition ; + amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject)); + amdaModel.DownloadNode.editInModule(); + } + else { + myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '" + +this.get('name')+"' found!"); + // EXCEPTION : parameter not found !? + } + }, - editInModule : function () { - var me = this; - myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) { - // If the node to edit is not already linked to this module - - if (module.getLinkedNode() != me) { - // set relative node into parameter Module - module.setLinkedNode(me); - } - else {// the node to edit is already edited - //TODO: TBD : message to user - //Sol1: msg alert: "warning this node is already edited! If you want to get the original, please press the 'reset' button"->'OK' - //Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your modification?"->'Confirm','Cancel' - } - // Opening parameter window - module.createWindow(); - }); - }, + editInModule : function () { + var me = this; + myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) { + // If the node to edit is not already linked to this module + if (module.getLinkedNode() != me) { + // set relative node into parameter Module + module.setLinkedNode(me); + } + else {// the node to edit is already edited + //TODO: TBD : message to user + //Sol1: msg alert: "warning this node is already edited! If you want to get the original, please press the 'reset' button"->'OK' + //Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your modification?"->'Confirm','Cancel' + } + // Opening parameter window + module.createWindow(); + }); + }, - decodeObject: function(obj) { - var myValues = new Object(); - myValues.list=[]; - - if (!obj) { - var fullObject = this.get('realLinkedNode').get('object'); - } - else { - var fullObject = obj; - } - - var i = 0; - fullObject.tabs().each(function (tab) { - tab.panels().each(function (panel) { - panel.params().each(function (param) { - myValues.list[i] = param.get('paramid'); - ++i; - }); - }); - - }); - - myValues.name = fullObject.get('name'); - myValues.timesrc = fullObject.get('timesrc'); - // if there's at least one timeTable name into 'timeTables' collection - if (myValues.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0] - && fullObject.get('timeTables') - && fullObject.get('timeTables').length ){ - // get complete timeTables collection - var timeTables = fullObject.get('timeTables'); - // init an empty array for timeTables - myValues.timeTables=[]; - // for each interval record - Ext.Array.each(timeTables, function(item, index, all){ - if (!item.$className) { - myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id}; + decodeObject: function(obj) { + var myValues = new Object(); + myValues.list=[]; + + if (!obj) { + var fullObject = this.get('realLinkedNode').get('object'); } - // get Json simplified value else { - myValues.timeTables[index] = item.getJsonValues(); + var fullObject = obj; } - }); - } else { - myValues.startDate = fullObject.get('startDate'); - myValues.stopDate = fullObject.get('stopDate'); - myValues.durationDay = fullObject.get('durationDay'); - myValues.durationHour = fullObject.get('durationHour'); - myValues.durationMin = fullObject.get('durationMin'); - myValues.durationSec = fullObject.get('durationSec'); - } - return myValues; - }, - - encodeObject: function() { - }, - -/* - * Method to parse special parameters cases with arguments (spectra && MODELS) - * TODO to rewrite with amda new kernel - */ - parseArgs: function(param) { - var name = param.name; - var args = param.downloadParamArgs; - if (args.energyMax){ - var nameToSent = name + '_' + args.energyMin + '_' + args.energyMax; - return nameToSent; - } - - if (args.PA && args.Energy){ - var nameToSent = name + '_' + args.PA + '_' + args.Energy; - return nameToSent; - } - - if (args.PA) { - var pa = args.PA - 1; - var nameToSent = name + '(' + pa + ')'; - return nameToSent; - } - - if (args.Energy) { - var en = args.Energy - 1; -//TODO temporary - if (name.substr(name.length-2, 2) == '_E') name = name.substr(0,name.length-2); - var nameToSent = name + '(' + en + ')'; - return nameToSent; - } - // T96; A2000 - if (args.SW_Monitor) { - var nameToSent = name + '_' + args.Spacecraft + '_' + args.SW_Monitor; - return nameToSent; - } - // Cain ; Morschhauser - if (args.Spacecraft && args.Sampling) { - var nameToSent = name + '_' + args.Spacecraft + '_' + args.Sampling; - return nameToSent; - } - // LATMOS - if (args.ClockAngle && args.Satellite) { - var nameToSent = name + '_' + args.Satellite + '_' + args.ClockAngle; - return nameToSent; - } - - // FMI HYBRID - if (args.Satellite && Ext.Object.getSize(args) === 1) { - var nameToSent = name + '_' + args.Satellite; - return nameToSent; - } - - }, + + var i = 0; + fullObject.tabs().each(function (tab) { + tab.panels().each(function (panel) { + panel.params().each(function (param) { + myValues.list[i] = param.get('paramid'); + ++i; + }); + }); + + }); + + myValues.name = fullObject.get('name'); + myValues.timesrc = fullObject.get('timesrc'); + // if there's at least one timeTable name into 'timeTables' collection + if (myValues.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0] + && fullObject.get('timeTables') + && fullObject.get('timeTables').length ){ + // get complete timeTables collection + var timeTables = fullObject.get('timeTables'); + // init an empty array for timeTables + myValues.timeTables=[]; + // for each interval record + Ext.Array.each(timeTables, function(item, index, all){ + if (!item.$className) { + myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id}; + } + // get Json simplified value + else { + myValues.timeTables[index] = item.getJsonValues(); + } + }); + } else { + myValues.startDate = fullObject.get('startDate'); + myValues.stopDate = fullObject.get('stopDate'); + myValues.durationDay = fullObject.get('durationDay'); + myValues.durationHour = fullObject.get('durationHour'); + myValues.durationMin = fullObject.get('durationMin'); + myValues.durationSec = fullObject.get('durationSec'); + } + return myValues; + }, + encodeObject: function() { + }, - loadJobTree : function() { - //ToDo - BRE - fix code duplication with ExecutableNode if possible - var rootNode = Ext.getCmp(amdaUI.ExplorerUI.JOB_TAB.TREE_ID).getRootNode(); - var me = this; - amdaModel.InteractiveNode.preloadNodes(rootNode, - function() - { - amdaModel.InteractiveNode.jobTreeLoaded = true; - me.realExecute(); - }); - }, + loadJobTree : function() { + //TBD - BRE - fix code duplication with ExecutableNode if possible + var rootNode = Ext.getCmp(amdaUI.ExplorerUI.JOB_TAB.TREE_ID).getRootNode(); + var me = this; + amdaModel.InteractiveNode.preloadNodes(rootNode, + function() + { + amdaModel.InteractiveNode.jobTreeLoaded = true; + me.realExecute(); + }); + }, - execute : function() { - - if (!amdaModel.ExecutableNode.jobTreeLoaded) this.loadJobTree(); - else this.realExecute(); - - }, - - - /** - * Method to execute this node - */ - realExecute : function() { - - var jsonObject = this.get('object').getJsonValues(); - if (!jsonObject.list && !jsonObject.images) { - myDesktopApp.warningMsg('Please select at least one Parameter (Get Data) or one Time Table (Get Time Table)'); - return; - } - - loadMask.show(); - AmdaAction.execute({nodeType : this.get('nodeType')}, jsonObject, function(res,e){ + execute : function() { - loadMask.hide(); + if (!amdaModel.ExecutableNode.jobTreeLoaded) this.loadJobTree(); + else this.realExecute(); + }, + +/** +* Method to execute this node +*/ + realExecute : function() { - //AKKA - Rework of the result treatment for the integration with the new kernel - if (!e.status) - { - myDesktopApp.errorMsg('Internal error during download request'); - return; - } - - if (!res.success) - { - myDesktopApp.errorMsg(res.message); - return; - } - - var newobj = this.createJobObject(res); - var newNode = Ext.create(this.get('jobNode'), - { - id : res.id, - info : res.info, - jobType : this.get('nodeType'), - processId : res.id, - text : res.name, - status : res.status, - stop : res.stop, - leaf : true, - object : newobj}); - - // new Tab - switch (res.status) - { - case amdaModel.BkgJobNode.STATUS_LIST.DONE : - // New tab, non-interactive session - var isInteractive = false; - var isNewTab = true; - newNode.createJobNode(true); - newNode.editNode(isNewTab, isInteractive); - break; - case amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS : - newNode.createJobNode(false); - break; - default: - newNode.createJobNode(true); - } - }, this ); + var jsonObject = this.get('object').getJsonValues(); + if (!jsonObject.list && !jsonObject.images) { + myDesktopApp.warningMsg('Please select at least one Parameter (Get Data) or one Time Table (Get Time Table)'); + return; + } + + loadMask.show(); + AmdaAction.execute({nodeType : this.get('nodeType')}, jsonObject, function(res,e) + { + loadMask.hide(); -}, + //AKKA - Rework of the result treatment for the integration with the new kernel + if (!e.status) + { + myDesktopApp.errorMsg('Internal error during download request'); + return; + } + + if (!res.success) + { + myDesktopApp.errorMsg(res.message); + return; + } + //TBD if such condition is OK ? + if (!res.id && res.download) { + if (res.compression) { + window.location.href = res.download; + } + else { + window.open(res.download, '_blank'); + } + return; + } + + var newobj = this.createJobObject(res); + var newNode = Ext.create(this.get('jobNode'), + { + id : res.id, + info : res.info, + jobType : this.get('nodeType'), + processId : res.id, + text : res.name, + status : res.status, + stop : res.stop, + leaf : true, + object : newobj + + }); + + // new Tab + switch (res.status) + { + case amdaModel.BkgJobNode.STATUS_LIST.DONE : + // New tab, non-interactive session + var isInteractive = false; + var isNewTab = true; + newNode.createJobNode(true); + newNode.editNode(isNewTab, isInteractive); + break; + case amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS : + newNode.createJobNode(false); + break; + default: + newNode.createJobNode(true); + } + }, this ); + }, - createJobObject: function(res) { + createJobObject: function(res) { - var obj = this.get('object').getJsonValues(); -//TODO text, name, outputName - if all is needed - //new object to attach to new bkgJobNode - -//TODO Ext.clone() + var obj = this.get('object').getJsonValues(); + //TODO text, name, outputName - if all is needed + //new object to attach to new bkgJobNode + //TODO Ext.clone() - var newobj = Ext.copyTo({}, obj, this.get('object').propertiesToCopy); - newobj.id = res.id; - newobj.resultId = res.result; - newobj.folderId = res.folder; - newobj = Ext.create(this.get('object').$className, newobj); - return newobj; + var newobj = Ext.copyTo({}, obj, this.get('object').propertiesToCopy); + newobj.id = res.id; + newobj.resultId = res.result; + newobj.folderId = res.folder; + newobj = Ext.create(this.get('object').$className, newobj); + + return newobj; } - }); diff --git a/js/app/views/DownloadUI.js b/js/app/views/DownloadUI.js index a355e7f..64aea67 100644 --- a/js/app/views/DownloadUI.js +++ b/js/app/views/DownloadUI.js @@ -23,45 +23,47 @@ Ext.define('amdaUI.DownloadUI', { //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 : [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss'], ['DD Time', 'DD Time'], ['Timestamp', 'Timestamp']], + 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); - // load object into view - if (this.object) this.loadObject(); - // - var paramArgsPlug = this.getPlugin('download-param-arguments-plugin'); - if (paramArgsPlug) - paramArgsPlug.onApply = this.onApplyParameterArgs; + // load object into view + if (this.object) this.loadObject(); + // + var paramArgsPlug = this.getPlugin('download-param-arguments-plugin'); + if (paramArgsPlug) + paramArgsPlug.onApply = this.onApplyParameterArgs; }, addTT : function(newTTName,newTTid) - { + { var tabPanel = this.formPanel.down(); var downloadSrc = tabPanel.items.indexOf(tabPanel.getActiveTab()); if (downloadSrc === 0) { - this.timeSelector.addTT(newTTName,newTTid); + this.timeSelector.addTT(newTTName,newTTid); } else { - // search for an existing record in store with this unique name - var existingIndex = this.TTGrid.store.findExact( 'name', newTTName); - // if no corresponding TT found - if (existingIndex == -1){ - // adding the time table to the TTGrid of TT download - var r = Ext.create('amdaModel.TTobject', { id: newTTid, name: newTTName }); - this.TTGrid.store.insert(this.TTGrid.store.getCount(),r); - } + // search for an existing record in store with this unique name + var existingIndex = this.TTGrid.store.findExact( 'name', newTTName); + // if no corresponding TT found + if (existingIndex == -1){ + // adding the time table to the TTGrid of TT download + var r = Ext.create('amdaModel.TTobject', { id: newTTid, name: newTTName }); + this.TTGrid.store.insert(this.TTGrid.store.getCount(),r); + } } }, addTTs : function(TTarray) { // set TTTab - this.timeSelector.setTTTab(TTarray); + this.timeSelector.setTTTab(TTarray); }, // Add TT in download TT module @@ -72,92 +74,91 @@ Ext.define('amdaUI.DownloadUI', { }, - /** - * Set Start-Stop from parameter info (Local & MyData) - */ - setTimeFromData : function(obj) { - - var dateStart = new Date(obj.start.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); - var dateStop = new Date(obj.stop.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); - - this.down('form').getForm().setValues({ startDate : dateStart, stopDate : dateStop }); - this.timeSelector.intervalSel.updateDuration(); - }, + /** + * Set Start-Stop from parameter info (Local & MyData) + */ + setTimeFromData : function(obj) { + + var dateStart = new Date(obj.start.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); + var dateStop = new Date(obj.stop.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); + + this.down('form').getForm().setValues({ startDate : dateStart, stopDate : dateStop }); + this.timeSelector.intervalSel.updateDuration(); + }, - addParam : function(paramId, isLeaf, needArgs, components) - { - // adding the parameter to the paramGrid - - var paramObj = { - paramid: paramId, - type: 0, - 'dim1-is-range': false, - 'dim1-min-range': 0., - 'dim1-max-range': 0., - 'dim1-index': '*', - 'dim2-is-range': false, - 'dim2-min-range': 0., - 'dim2-max-range': 0., - 'dim2-index': '*', - template_args: {} - }; + addParam : function(paramId, isLeaf, needArgs, components) + { + // adding the parameter to the paramGrid + var paramObj = { + paramid: paramId, + type: 0, + 'dim1-is-range': false, + 'dim1-min-range': 0., + 'dim1-max-range': 0., + 'dim1-index': '*', + 'dim2-is-range': false, + 'dim2-min-range': 0., + 'dim2-max-range': 0., + 'dim2-index': '*', + template_args: {} + }; - if (components) { - if (components['index1']) { - paramObj['dim1-index'] = components['index1']; - ++paramObj['type']; - } - - if (components['index2']) { - paramObj['dim2-index'] = components['index2']; - ++paramObj['type']; - } - } + if (components) { + if (components['index1']) { + paramObj['dim1-index'] = components['index1']; + ++paramObj['type']; + } + + if (components['index2']) { + paramObj['dim2-index'] = components['index2']; + ++paramObj['type']; + } + } - var r = Ext.create('amdaModel.DownloadParam', paramObj); - var pos = this.paramGrid.store.getCount(); - this.paramGrid.store.insert(pos,r); - this.paramGrid.getView().refresh(); - if (!isLeaf || needArgs) - this.editParameterArgs(r); - }, + var r = Ext.create('amdaModel.DownloadParam', paramObj); + var pos = this.paramGrid.store.getCount(); + this.paramGrid.store.insert(pos,r); + this.paramGrid.getView().refresh(); + if (!isLeaf || needArgs) + this.editParameterArgs(r); + }, - addParams: function(arrayParams) - { - var arrayRec = new Array(); - var index = 1; - if (arrayParams) - { - index = 0; - Ext.Array.each(arrayParams,function(item){ - if (Ext.isObject(item)) { - // for Parameter Name in Download Module - var paramObj = { - paramid: paramId, - type: 0, - 'dim1-is-range': false, - 'dim1-min-range': 0., - 'dim1-max-range': 0., - 'dim1-index': item.get('dim1'), - 'dim2-is-range': false, - 'dim2-min-range': 0., - 'dim2-max-range': 0., - 'dim2-index': item.get('dim2'), - template_args: {} - }; - - var r = Ext.create('amdaModel.DownloadParam', paramObj); - } - 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); - }, + addParams: function(arrayParams) + { + var arrayRec = new Array(); + var index = 1; + if (arrayParams) + { + index = 0; + Ext.Array.each(arrayParams,function(item){ + if (Ext.isObject(item)) { + // for Parameter Name in Download Module + var paramObj = { + paramid: paramId, + type: 0, + 'dim1-is-range': false, + 'dim1-min-range': 0., + 'dim1-max-range': 0., + 'dim1-index': item.get('dim1'), + 'dim2-is-range': false, + 'dim2-min-range': 0., + 'dim2-max-range': 0., + 'dim2-index': item.get('dim2'), + template_args: {} + }; + + var r = Ext.create('amdaModel.DownloadParam', paramObj); + } + 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) { @@ -165,7 +166,7 @@ Ext.define('amdaUI.DownloadUI', { if (index != -1) { this.paramGrid.getStore().getAt(index).set('name',newval); this.paramGrid.getStore().getAt(index).set('text',newval); - } + } }, setObject : function(obj) { @@ -176,84 +177,89 @@ Ext.define('amdaUI.DownloadUI', { /** * update this.object from form */ - updateObject : function() - { - // get the basic form - var tabPanel = this.formPanel.down(); - var downloadSrc = tabPanel.items.indexOf(tabPanel.getActiveTab()); - var basicForm = this.formPanel.getForm(); - var updateStatus = true; - var values = basicForm.getValues(); - - // data download - if (downloadSrc === 0) - { - var timeformat = basicForm.findField('timeformat').getRawValue(); - var timeSource = this.timeSelector.getActiveTimeSource(); - var structure = values.filestructure; - var sampling = values.sampling ? values.sampling : 600; - var refparamSampling = values.refparamsampling == 'on'; - var fileprefix = values.fileprefix ? values.fileprefix : ''; - var fileformat = values.fileformat; - var compression = values.compression; + updateObject : function() + { + // get the basic form + var tabPanel = this.formPanel.down(); + var downloadSrc = tabPanel.items.indexOf(tabPanel.getActiveTab()); + var basicForm = this.formPanel.getForm(); + var updateStatus = true; + var values = basicForm.getValues(); + + // data download + if (downloadSrc === 0) + { + var timeformat = basicForm.findField('timeformat').getRawValue(); + var timeSource = this.timeSelector.getActiveTimeSource(); + var structure = values.filestructure; + var sampling = values.sampling ? values.sampling : 600; + var refparamSampling = values.refparamsampling == 'on'; + var fileprefix = values.fileprefix ? values.fileprefix : ''; + var fileformat = values.fileformat; + var compression = values.compression; - var fieldsWithoutName = basicForm.getFields().items; - Ext.Array.each(fieldsWithoutName, function(item, index,allItems){ - if (!item.isValid()) { - if ((timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0]) && - ((item.name == 'startDate') || (item.name == 'stopDate') || (item.name == 'duration'))) { - updateStatus = true; - } - else { - // set update isn't allowed - updateStatus = false; - return false; - } - } - }, this); - - if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0] // timeSource 'TimeTable' - && this.timeSelector.TTGrid.getStore().count() == 0) { - myDesktopApp.warningMsg('You\'ve chosen Time Selection `by TimeTable` but no timeTable was added!' - +'<br>You must add one or choose Time Selection `by Interval`'); - updateStatus = false; - } + var fieldsWithoutName = basicForm.getFields().items; + Ext.Array.each(fieldsWithoutName, function(item, index,allItems){ + if (!item.isValid()) { + if ((timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0]) && + ((item.name == 'startDate') || (item.name == 'stopDate') || (item.name == 'duration'))) { + updateStatus = true; + } + else { + // set update isn't allowed + updateStatus = false; + return false; + } + } + }, this); + + if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0] // timeSource 'TimeTable' + && this.timeSelector.TTGrid.getStore().count() == 0) { + myDesktopApp.warningMsg('You\'ve chosen Time Selection `by TimeTable` but no timeTable was added!' + +'<br>You must add one or choose Time Selection `by Interval`'); + 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('refparamSampling', refparamSampling); - this.object.set('sampling', sampling); - this.object.set('fileprefix',fileprefix); - this.object.set('timeformat',timeformat); - this.object.set('fileformat',fileformat); - this.object.set('compression',compression); - } - } - //TT download - else - { - var timeformat = values.timeformatTT; - var compression = values.compressionTT; - var fileformat = values.fileformatTT; - this.object.set('timeTables',this.TTGrid.getStore().data.items); - this.object.set('timeformatTT',timeformat); - this.object.set('fileformatTT',fileformat); - this.object.set('compressionTT',compression); - } + 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('refparamSampling', refparamSampling); + this.object.set('sampling', sampling); + this.object.set('fileprefix',fileprefix); + this.object.set('timeformat',timeformat); + this.object.set('fileformat',fileformat); + this.object.set('compression',compression); + } + } + //TT download + else + { + var timeformat = values.timeformatTT; + var compression = values.compressionTT; + var fileformat = values.fileformatTT; + if (compression === 'none' + && this.TTGrid.getStore().count() > 1) { + myDesktopApp.warningMsg('You are going to download several time tables - select the Compression please'); + updateStatus = false; + } + this.object.set('timeTables',this.TTGrid.getStore().data.items); + this.object.set('timeformatTT',timeformat); + this.object.set('fileformatTT',fileformat); + this.object.set('compressionTT',compression); + } - this.object.set('downloadSrc',downloadSrc); - // return the update status - return updateStatus; + this.object.set('downloadSrc',downloadSrc); + // return the update status + return updateStatus; }, /** @@ -261,48 +267,48 @@ Ext.define('amdaUI.DownloadUI', { */ 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('timeformat')) + this.object.set('timeformat', this.timeformatData[0][0]); + + if (!this.object.get('timeformatTT')) + this.object.set('timeformatTT', this.timeformatTTData[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')); + 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')); }, - /** - * download method called by 'Download' button to launch the download process - */ +/** +* download method called by 'Download' button to launch the download process +*/ doDownload : function(){ var downloadModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); if (downloadModule) - downloadModule.linkedNode.execute(); - // fire execution - // this.object.fireEvent('execute',this.object.dirty); + downloadModule.linkedNode.execute(); }, - - + actionItem: function(grid, cell, cellIndex, record, row, recordIndex, e){ - if (cellIndex == 3) + + var isTimeTable = record instanceof amdaModel.TTobject; + + if ( cellIndex == 3 || ( cellIndex == 2 && isTimeTable )) grid.getStore().remove(record); - else if (cellIndex == 2) { + else if ( cellIndex == 2 ) { this.paramGrid.getView().select(row); this.editParameterArgs(record); } @@ -355,388 +361,382 @@ Ext.define('amdaUI.DownloadUI', { this.timeSelector = new amdaUI.TimeSelectorUI({id: 'downloadTimeSelector',flex: 1}); this.paramGrid = Ext.create('Ext.grid.Panel', { - flex: 2, - store : Ext.create('Ext.data.Store', { model: 'amdaModel.DownloadParam'} ), - columns: [ - { xtype: 'rownumberer', width: 20 }, - { - header: "Parameter Name", - dataIndex: 'name', - flex:1, - sortable: false, - menuDisabled : true , - renderer: function (val, meta, rec) { - return rec.getParamFullName(); - } - }, - { - menuDisabled : true, width: 30, renderer: function(){ - return'<div class="icon-parameters" style="width: 15px; height: 15px;"></div>'; - } - }, - { - menuDisabled : true, width: 30, renderer: function(){ - return'<div class="icon-remover" style="width: 15px; height: 15px;"></div>'; - } - } - ], + flex: 2, + store : Ext.create('Ext.data.Store', { model: 'amdaModel.DownloadParam'} ), + columns: [ + { xtype: 'rownumberer', width: 20 }, + { + header: "Parameter Name", + dataIndex: 'name', + flex:1, + sortable: false, + menuDisabled : true , + renderer: function (val, meta, rec) { + return rec.getParamFullName(); + } + }, + { + menuDisabled : true, width: 30, renderer: function(){ + return'<div class="icon-parameters" style="width: 15px; height: 15px;"></div>'; + } + }, + { + menuDisabled : true, width: 30, renderer: function(){ + return'<div class="icon-remover" style="width: 15px; height: 15px;"></div>'; + } + } + ], //TODO - BRE - Wait the fix for drag&drop issue - listeners : + listeners : { - render : function(o,op) - { - var me = this; - var el = me.body.dom; - var dropTarget = Ext.create('Ext.dd.DropTarget', el, { - ddGroup: 'explorerTree', - notifyEnter : function(ddSource, e, data) - { }, - notifyOver : function(ddSource, e, data) - { - if (data.records[0].data.nodeType == 'localParam' && data.records[0].get('notyet')) { - this.valid = false; - return this.dropNotAllowed; - } - if (((data.records[0].data.nodeType == 'localParam') || - (data.records[0].data.nodeType == 'remoteParam') || - (data.records[0].data.nodeType == 'remoteSimuParam') || - (data.records[0].data.nodeType == 'derivedParam') || - (data.records[0].data.nodeType == 'myDataParam') || - (data.records[0].data.nodeType == 'alias'))&& - (data.records[0].isLeaf() || data.records[0].data.isParameter) && - !data.records[0].data.disable) - { - this.valid = true; - return this.dropAllowed; - } - - this.valid = false; - return this.dropNotAllowed; - }, - notifyDrop : function(ddSource, e, data) - { - if (!this.valid) - return false; - var idToSent; - var components = null; - switch (data.records[0].data.nodeType) - { - case 'localParam' : - case 'remoteParam': - case 'remoteSimuParam': - idToSent = data.records[0].get('id'); - if (data.records[0].get('alias')!= "" ) - idToSent = "#"+data.records[0].get('alias'); - var component_info = data.records[0].get('component_info'); - if (component_info && component_info.parentId) { - //It's a component - idToSent = component_info.parentId; - components = []; - if (component_info.index1) - components['index1'] = component_info.index1; - if (component_info.index2) - components['index2'] = component_info.index2; - } - break; - case 'alias' : - idToSent = "#"+data.records[0].get('text'); - break; - case 'derivedParam' : - idToSent = "ws_"+data.records[0].get('text'); - break; - case 'myDataParam' : - idToSent = "wsd_"+data.records[0].get('text'); - break; - default : - return false; - } - var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); - if (downModule) - downModule.addParam(idToSent,data.records[0].get('leaf'), data.records[0].get('needsArgs'), components); - return true; - } - }); - } - } - + render : function(o,op) + { + var me = this; + var el = me.body.dom; + var dropTarget = Ext.create('Ext.dd.DropTarget', el, { + ddGroup: 'explorerTree', + notifyEnter : function(ddSource, e, data) + { }, + notifyOver : function(ddSource, e, data) + { + if (data.records[0].data.nodeType == 'localParam' && data.records[0].get('notyet')) { + this.valid = false; + return this.dropNotAllowed; + } + if (((data.records[0].data.nodeType == 'localParam') || + (data.records[0].data.nodeType == 'remoteParam') || + (data.records[0].data.nodeType == 'remoteSimuParam') || + (data.records[0].data.nodeType == 'derivedParam') || + (data.records[0].data.nodeType == 'myDataParam') || + (data.records[0].data.nodeType == 'alias'))&& + (data.records[0].isLeaf() || data.records[0].data.isParameter) && + !data.records[0].data.disable) + { + this.valid = true; + return this.dropAllowed; + } + + this.valid = false; + return this.dropNotAllowed; + }, + notifyDrop : function(ddSource, e, data) + { + if (!this.valid) + return false; + var idToSent; + var components = null; + switch (data.records[0].data.nodeType) + { + case 'localParam' : + case 'remoteParam': + case 'remoteSimuParam': + idToSent = data.records[0].get('id'); + if (data.records[0].get('alias')!= "" ) + idToSent = "#"+data.records[0].get('alias'); + var component_info = data.records[0].get('component_info'); + if (component_info && component_info.parentId) { + //It's a component + idToSent = component_info.parentId; + components = []; + if (component_info.index1) + components['index1'] = component_info.index1; + if (component_info.index2) + components['index2'] = component_info.index2; + } + break; + case 'alias' : + idToSent = "#"+data.records[0].get('text'); + break; + case 'derivedParam' : + idToSent = "ws_"+data.records[0].get('text'); + break; + case 'myDataParam' : + idToSent = "wsd_"+data.records[0].get('text'); + break; + default : + return false; + } + var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); + if (downModule) + downModule.addParam(idToSent,data.records[0].get('leaf'), data.records[0].get('needsArgs'), components); + return true; + } + }); + } + } }); this.paramGrid.on('cellclick', this.actionItem, this); this.TTGrid = Ext.create('Ext.grid.Panel', { - flex: 2, - store : Ext.create('Ext.data.Store', {model: 'amdaModel.TTobject'}), - columns: [ - { xtype: 'rownumberer', width: 20 }, - { header: "Time Table Name", dataIndex: 'name', flex:1, sortable: false, menuDisabled: true}, - { - menuDisabled : true, width: 30, renderer: function(){ - return '<div class="icon-remover" style="width: 15px; height: 15px;"></div>'; - } + flex: 2, + store : Ext.create('Ext.data.Store', {model: 'amdaModel.TTobject'}), + columns: [ + { xtype: 'rownumberer', width: 20 }, + { header: "Time Table Name", dataIndex: 'name', flex:1, sortable: false, menuDisabled: true}, + { + menuDisabled : true, width: 30, renderer: function(){ + return '<div class="icon-remover" style="width: 15px; height: 15px;"></div>'; + } + } + ], + listeners : + { + render : function(o,op) + { + var me = this; + var el = me.body.dom; + var dropTarget = Ext.create('Ext.dd.DropTarget', el, { + ddGroup: 'explorerTree', + notifyEnter : function(ddSource, e, data) + { + + }, + notifyOver : function(ddSource, e, data) + { + var nodeType = data.records[0].get('nodeType'); + + if ((nodeType == 'timeTable' || nodeType == 'sharedtimeTable') || + (nodeType == 'catalog' || nodeType == 'sharedCatalog') && + (data.records[0].get('leaf'))) + { + this.valid = true; + return this.dropAllowed; + } + this.valid = false; + return this.dropNotAllowed; + }, + notifyDrop : function(ddSource, e, data) + { + if (!this.valid) + return false; + var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); + if (downModule) + downModule.getUiContent().addTTdownload(data.records[0].get('text'),data.records[0].get('id')); + return true; + } + }); + } } - ], - listeners : - { - render : function(o,op) - { - var me = this; - var el = me.body.dom; - var dropTarget = Ext.create('Ext.dd.DropTarget', el, { - ddGroup: 'explorerTree', - notifyEnter : function(ddSource, e, data) - { - - }, - notifyOver : function(ddSource, e, data) - { - if ((data.records[0].get('nodeType') == 'timeTable' || data.records[0].get('nodeType') == 'sharedtimeTable') && (data.records[0].get('leaf'))) - { - this.valid = true; - return this.dropAllowed; - } - this.valid = false; - return this.dropNotAllowed; - }, - notifyDrop : function(ddSource, e, data) - { - if (!this.valid) - return false; - var downModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id); - if (downModule) - downModule.getUiContent().addTTdownload(data.records[0].get('text'),data.records[0].get('id')); - return true; - } - }); - } - } }); + this.TTGrid.on('cellclick', this.actionItem, this); this.paramPanel = { - xtype: 'container', - title: 'Get Data', - layout: { - type: 'hbox', - align : 'stretch', - defaultMargins: {top: 10, left:10, bottom: 5, right:10} - }, - items: [ - { - xtype: 'container', - flex: 2, - layout: { - type: 'vbox', - align : 'stretch' - }, - items: [ - { - xtype: 'textfield', - fieldLabel: 'Request Name', - disabled: true, - name : 'name' - }, - { - xtype: 'splitter', - flex: 0.05 - }, - this.paramGrid - ] - }, - { - xtype: 'container', - flex: 2, - defaults : { - xtype : 'combo', - labelWidth: 90, - queryMode: 'local', - editable: false - }, - layout: { - type: 'vbox', - align: 'stretch' - }, - items: [ - { - fieldLabel: 'Time Format', - name: 'timeformat', - store: this.timeformatData, - value: this.timeformatData[0] - }, - { - fieldLabel: 'File Structure', - name: 'filestructure', - store: this.filestructureData, - value: this.filestructureData[2], - listeners : { - change : { fn : this.onFileStructureChange }, - scope: this - } + xtype: 'container', + title: 'Parameters', + layout: { + type: 'hbox', + align : 'stretch', + defaultMargins: {top: 10, left:10, bottom: 5, right:10} + }, + items: [ + { + xtype: 'container', + flex: 2, + layout: { + type: 'vbox', + align : 'stretch' + }, + items: [ + { + xtype: 'textfield', + fieldLabel: 'Request Name', + disabled: true, + name : 'name' + }, + { + xtype: 'splitter', + flex: 0.05 + }, + this.paramGrid + ] + }, + { + xtype: 'container', + flex: 2, + defaults : { + xtype : 'combo', + labelWidth: 90, + queryMode: 'local', + editable: false }, - { - xtype: 'checkbox', boxLabel: 'Use first param. as reference for sampling', - boxLabelAlign: 'before', - name: 'refparamsampling', checked: false, disabled: true, - listeners : { - change : { fn : this.onRefParamSamplingChange }, - scope : this - } - }, - { - xtype: 'numberfield', name: 'sampling', - fieldLabel: 'Sampling Time', value: 600, - hideTrigger: true, editable: true, - disabled: true + layout: { + type: 'vbox', + align: 'stretch' }, - { - xtype: 'textfield', name: 'fileprefix', - fieldLabel: 'File Prefix', - disabled: false, editable: true + items: [ + { + fieldLabel: 'Time Format', + name: 'timeformat', + store: this.timeformatData, + value: this.timeformatData[0] + }, + { + fieldLabel: 'File Structure', + name: 'filestructure', + store: this.filestructureData, + value: this.filestructureData[2], + listeners : { + change : { fn : this.onFileStructureChange }, + scope: this + } + }, + { + xtype: 'checkbox', boxLabel: 'Use first param. as reference for sampling', + boxLabelAlign: 'before', + name: 'refparamsampling', checked: false, disabled: true, + listeners : { + change : { fn : this.onRefParamSamplingChange }, + scope : this + } + }, + { + xtype: 'numberfield', name: 'sampling', + fieldLabel: 'Sampling Time', value: 600, + hideTrigger: true, editable: true, + disabled: true + }, + { + xtype: 'textfield', name: 'fileprefix', + fieldLabel: 'File Prefix', + disabled: false, editable: true + }, + { + fieldLabel: 'File Format', + name: 'fileformat', + store: this.fileformatData, + value: this.fileformatData[0] + }, + { + fieldLabel: 'Compression', + name: 'compression', + store: this.filecompressData, + value: this.filecompressData[0] + }, + this.timeSelector + ] + } + ]}; + + this.ttPanel = + { + xtype: 'container', + title: 'Time Tables / Catalogs', + layout: { + type: 'hbox', + align : 'stretch', + defaultMargins: { top: 10, left:10, bottom: 5, right:10 } + }, + items: [ + this.TTGrid, + { + xtype: 'container', + flex: 2, + defaults : { + xtype : 'combo', + labelWidth: 90, + queryMode: 'local', + editable: false }, - { - fieldLabel: 'File Format', - name: 'fileformat', - store: this.fileformatData, - value: this.fileformatData[0] - }, - { - fieldLabel: 'Compression', - name: 'compression', - store: this.filecompressData, - value: this.filecompressData[0] + layout: { + type: 'vbox', + align : 'stretch' }, - this.timeSelector - ] - } - ]}; - - this.ttPanel = - { - xtype: 'container', - title: 'Get Time Table', - layout: { - type: 'hbox', - align : 'stretch', - defaultMargins: {top: 10, left:10, bottom: 5, right:10} - }, - items: [ - this.TTGrid, - { - xtype: 'container', - flex: 2, - defaults : { - xtype : 'combo', - labelWidth: 90, - queryMode: 'local', - editable: false - }, - layout: { - type: 'vbox', - align : 'stretch' - }, - items: [ - { - fieldLabel:'Time Format', - name:'timeformatTT', - store: this.timeformatData, - value: this.timeformatData[0] - }, - { - fieldLabel: 'File Format ', - name: 'fileformatTT', - store: this.fileformatTTData, - value: this.fileformatTTData[0] - }, - { - fieldLabel: 'Compression ', - name: 'compressionTT', - store: this.filecompressData, - value: this.filecompressData[0] - } - ] - } - ] - } ; + items: [{ + fieldLabel:'Time Format', + name:'timeformatTT', + store: this.timeformatTTData, + value: this.timeformatTTData[0] + }, + { + fieldLabel: 'File Format ', + name: 'fileformatTT', + store: this.fileformatTTData, + value: this.fileformatTTData[0] + }, + { + fieldLabel: 'Compression ', + name: 'compressionTT', + store: this.filecompressTT, + value: this.filecompressTT[0] + } + ]} + ] + }; this.formPanel = new Ext.form.Panel({ - layout: 'fit', - region: 'center', - bodyStyle: { background : '#dfe8f6' }, - buttonAlign: 'left', - trackResetOnLoad: true, //reset to the last loaded record - defaults: { + layout: 'fit', + region: 'center', + bodyStyle: { background : '#dfe8f6' }, + buttonAlign: 'left', + trackResetOnLoad: true, //reset to the last loaded record + defaults: { border: false - }, - items: [ - { - xtype: 'tabpanel', - activeTab : 0, - bodyStyle: { background : '#dfe8f6' }, - items: [ - this.paramPanel, - this.ttPanel - ] - } - ], - fbar: [ - { - text: 'Download', - scope : this, - handler: function(button){ - // if the return is true (object had been updated) - if(this.updateObject()){ - // launch the search process - this.doDownload(); - } - } - }, - { - 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(); - } - } - } - ] - }); - + }, + items: [{ + xtype: 'tabpanel', + activeTab : 0, + bodyStyle: { background : '#dfe8f6' }, + items: [ + this.paramPanel, + this.ttPanel + ] + }], + fbar: [ + { + text: 'Download', + scope : this, + handler: function(button){ + // if the return is true (object had been updated) + if(this.updateObject()){ + // launch the download process + this.doDownload(); + } + } + }, + { + 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 myConf = { - layout: 'border', - items: [ - this.formPanel, - { - xtype: 'panel', - region: 'south', - title: 'Information', - collapsible: true, - height: 100, - autoHide: false, - bodyStyle: 'padding:5px', - iconCls: 'icon-information', - loader: { - autoLoad: true, - url: helpDir+'downloadHOWTO' - } - - - } - ], - plugins: [ {ptype: 'paramArgumentsPlugin', pluginId: 'download-param-arguments-plugin'}] - }; - - Ext.apply (this, Ext.apply(arguments, myConf)); - } - + var myConf = { + layout: 'border', + items: [ + this.formPanel, + { + xtype: 'panel', + region: 'south', + title: 'Information', + collapsible: true, + height: 100, + autoHide: false, + bodyStyle: 'padding:5px', + iconCls: 'icon-information', + loader: { + autoLoad: true, + url: helpDir + 'downloadHOWTO' + } + } + ], + plugins: [ {ptype: 'paramArgumentsPlugin', pluginId: 'download-param-arguments-plugin'}] + }; + + Ext.apply (this, Ext.apply(arguments, myConf)); + } }); diff --git a/php/classes/AmdaAction.php b/php/classes/AmdaAction.php index 297cd5a..bad4dbe 100644 --- a/php/classes/AmdaAction.php +++ b/php/classes/AmdaAction.php @@ -596,38 +596,37 @@ class AmdaAction { } - public function getObject($id, $nodeType) { - - switch ($nodeType) { - case 'myDataParam': - case 'derivedParam' : - $objectMgr = new DerivedParamMgr($nodeType); - break; - case 'timeTable' : - case 'sharedtimeTable' : - $objectMgr = new TimeTableMgr(); - break; - case 'catalog' : - case 'sharedcatalog' : - $objectMgr = new CatalogMgr(); - break; - case 'condition' : - case 'request' : - $objectMgr = new RequestMgr($nodeType); - break; - case 'bkgWorks' : + public function getObject($id, $nodeType) { + + switch ($nodeType) { + case 'myDataParam': + case 'derivedParam' : + $objectMgr = new DerivedParamMgr($nodeType); + break; + case 'timeTable' : + case 'sharedtimeTable' : + $objectMgr = new TimeTableMgr(); + break; + case 'catalog' : + case 'sharedcatalog' : + $objectMgr = new CatalogMgr(); + break; + case 'condition' : + case 'request' : + $objectMgr = new RequestMgr($nodeType); + break; + case 'bkgWorks' : require_once(INTEGRATION_SRC_DIR."RequestManager.php"); return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO); - break; - case 'myData' : - $objectMgr = new FilesMgr(); - break; - default: - return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); - } - - return $objectMgr -> getObject($id, $nodeType); - } + break; + case 'myData' : + $objectMgr = new FilesMgr(); + break; + default: + return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); + } + return $objectMgr -> getObject($id, $nodeType); + } /* * $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType } */ @@ -846,13 +845,13 @@ class AmdaAction { return array('success' => true, 'userHost' => $dd -> getIPclient()); } - private function executeRequest($obj, $function) - { + private function executeRequest($obj, $function){ + $res = $this->checkUser($obj); if (!$res['success']) return $res; - + $requestManager = new RequestManagerClass(); try { @@ -867,14 +866,18 @@ class AmdaAction { /* * Main EXECUTE PROCEDURE */ - public function execute($node, $obj) - { + public function execute($node, $obj){ + require_once(INTEGRATION_SRC_DIR."RequestManager.php"); - if (isset($obj->action)) + + // just convert TT / Catalog + if ($obj->nodeType == "download" && $obj->downloadSrc == "1") + return $this->executeRequest($obj, FunctionTypeEnumClass::TTCONVERT); + else if (isset($obj->action)) return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION); else return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS); - } + } /* * Generate derived parameter compilation @@ -888,8 +891,8 @@ class AmdaAction { /* * Delete derived parameter compilation */ - public function compilParamDelete($obj) - { + public function compilParamDelete($obj){ + require_once(INTEGRATION_SRC_DIR."RequestManager.php"); $res = $this->checkUser($obj); @@ -1177,108 +1180,125 @@ class AmdaAction { return $res; } - public function getCrtFilterResult() - { - $filtersMgr = new FiltersMgr(); - return $filtersMgr->getCrtResult(); - } + public function getCrtFilterResult() + { + $filtersMgr = new FiltersMgr(); + return $filtersMgr->getCrtResult(); + } - public function setCrtFilterId($o) - { - $filtersMgr = new FiltersMgr(); - return $filtersMgr->setCrtId($o->id); - } + public function setCrtFilterId($o) + { + $filtersMgr = new FiltersMgr(); + return $filtersMgr->setCrtId($o->id); + } - public function resetFilter() - { - $filtersMgr = new FiltersMgr(); - $res = $filtersMgr->reset(); - return $res; - } + public function resetFilter() + { + $filtersMgr = new FiltersMgr(); + $res = $filtersMgr->reset(); + return $res; + } public function logout($isGuest) { - if ($isGuest) { - $guestMgr = new Guest($this->user); - $guestMgr->deleteGuest(); - } - else { - $myBaseMgr = new BaseManager(); - $myBaseMgr->delSimuFiles('mysimudata'); - $myBaseMgr->delSimuFiles('mywsrdata'); - - $this->cleanUserWS(); - } + if ($isGuest) { + $guestMgr = new Guest($this->user); + $guestMgr->deleteGuest(); + } + else { + $myBaseMgr = new BaseManager(); + $myBaseMgr->delSimuFiles('mysimudata'); + $myBaseMgr->delSimuFiles('mywsrdata'); + + $this->cleanUserWS(); + } return; } - public function getInfo($obj) - { - if (file_exists(HELPPATH.$obj->name)) - { - $content = file_get_contents(HELPPATH.$obj->name); - return array('success' => true, 'result' => $content); - } - return array('success' => false); - - } + public function getInfo($obj) + { + if (file_exists(HELPPATH.$obj->name)) + { + $content = file_get_contents(HELPPATH.$obj->name); + return array('success' => true, 'result' => $content); + } + return array('success' => false); + } - public function getUserInfo() - { - $dd = new UserMgr(); - return $dd->getUserInfo(); - } - - public function convertWS() - { - $dd = new UserMgr(); - return $dd->convertWS(); - } + public function getUserInfo() + { + $dd = new UserMgr(); + return $dd->getUserInfo(); + } -// $obj ={"Object":"Earth","RunCount":"2", -// "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....} - public function getRun($obj) - { + public function convertWS() + { + $dd = new UserMgr(); + return $dd->convertWS(); + } - $myBestRunsMgr = new BestRunsMgr(); - $res = $myBestRunsMgr->getRun($obj); - - return $res; - } + // $obj ={"Object":"Earth","RunCount":"2", + // "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....} + public function getRun($obj) + { + $myBestRunsMgr = new BestRunsMgr(); + $res = $myBestRunsMgr->getRun($obj); + + return $res; + } - //$obj = array of IDs - public function addRun($obj) - { - $myBestRunsMgr = new BestRunsMgr(); - $myBestRunsMgr->init(); - $myBestRunsMgr->addRuns($obj); - - $res = array('success' => true,'addedRuns' => $obj); - return $res; - } - //AKKA - New action to clean user WS - public function cleanUserWS() - { - require_once(INTEGRATION_SRC_DIR."RequestManager.php"); - return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN); - } + //$obj = array of IDs + public function addRun($obj) + { + $myBestRunsMgr = new BestRunsMgr(); + $myBestRunsMgr->init(); + $myBestRunsMgr->addRuns($obj); - public function deleteSpecialInfo($name) - { - if (file_exists(USERDIR.$name)) - unlink(USERDIR.$name); - return array('success' => true); - } + $res = array('success' => true,'addedRuns' => $obj); + return $res; + } + + //AKKA - New action to clean user WS + public function cleanUserWS() + { + $this->rrmdir(USERDIR.'DOWNLOAD.TEMP'); + + require_once(INTEGRATION_SRC_DIR."RequestManager.php"); + return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN); + } + + public function rrmdir($dir){ + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory + if ($object != "." && $object != "..") { // If object isn't a directory recall recursively this function + if (filetype($dir."/".$object) == "dir") + $this->rrmdir($dir."/".$object); + else + unlink($dir."/".$object); + } + } + reset($objects); + rmdir($dir); + } + } + + public function deleteSpecialInfo($name) + { + if (file_exists(USERDIR.$name)) + unlink(USERDIR.$name); + return array('success' => true); + } - public function interactivePlot($obj, $multiPlotState) - { - require_once(INTEGRATION_SRC_DIR."RequestManager.php"); - $inputobj = (Object)array( - 'action' => $obj, - 'multiPlotState' => $multiPlotState - ); - return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION); - } + public function interactivePlot($obj, $multiPlotState) + { + require_once(INTEGRATION_SRC_DIR."RequestManager.php"); + $inputobj = (Object)array( + 'action' => $obj, + 'multiPlotState' => $multiPlotState + ); + return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION); + } public function getParamPlotInit($obj) { diff --git a/php/classes/AmdaObjectMgr.php b/php/classes/AmdaObjectMgr.php index 5e194ee..78a2fcc 100644 --- a/php/classes/AmdaObjectMgr.php +++ b/php/classes/AmdaObjectMgr.php @@ -5,187 +5,208 @@ * */ - class AmdaObjectMgr { - - protected $xmlName, $xp; - protected $attributes, $optionalAttributes; - protected $contentRootId, $objTagName; - protected $descFileName, $resFileName; - protected $id_prefix; - protected $contentRootTag; - protected $obj, $id; - protected $types; - - public $contentDom; - public $objectDom; - - protected function __construct($xmlFile) { -// content XML +class AmdaObjectMgr { + + protected $xmlName, $xp; + protected $attributes, $optionalAttributes; + protected $contentRootId, $objTagName; + protected $descFileName, $resFileName; + protected $id_prefix; + protected $contentRootTag; + protected $obj, $id; + protected $types; + + public $contentDom; + public $objectDom; + + protected function __construct($xmlFile) { + // content XML $this->xmlName = USERWSDIR."/".$xmlFile; $this->contentDom = new DomDocument("1.0"); $this->contentDom->preserveWhiteSpace = false; $this->contentDom->formatOutput = true; if (file_exists($this->xmlName)) { - $this->contentDom -> load($this->xmlName); - $this->xp = new domxpath($this->contentDom); + $this->contentDom -> load($this->xmlName); + $this->xp = new domxpath($this->contentDom); } -// object desc XML -//TODO not used in RequestMgr + // object desc XML + //TODO not used in RequestMgr $this->objectDom = new DomDocument("1.0"); $this->objectDom->preserveWhiteSpace = false; $this->objectDom->formatOutput = true; } - private function getNewId() { - // Get all ID attributes - $elements = $this->xp->query("//".$this->objTagName."/@xml:id"); + private function getNewId() { + // Get all ID attributes + $elements = $this->xp->query("//".$this->objTagName."/@xml:id"); - // Now find New Valid ID + // Now find New Valid ID if ($elements->length > 0) { - if($elements->length > 0) for ($i = 0; $i < $elements->length; $i++) { - $id = explode('_',$elements->item($i)->nodeValue); - $idList[] = $id[1]; + if($elements->length > 0) for ($i = 0; $i < $elements->length; $i++) { + $id = explode('_',$elements->item($i)->nodeValue); + $idList[] = $id[1]; } sort($idList); for ($i = 0; $i < count($idList); $i++) { - if ($idList[$i] > $i) { - $newID = $i; - break; + if ($idList[$i] > $i) { + $newID = $i; + break; } - $newID = $i+1; - } + $newID = $i+1; + } } else - $newID = 0; - return $newID; - } + $newID = 0; + return $newID; + } protected function setId() { - $id_ = $this->getNewId(); + + $id_ = $this->getNewId(); if ($id_ === false) return false; $this->id = $this->id_prefix.$id_; + return $this->id; } protected function objectExistsByName($name){ - $this->obj = $this->xp->query("//".$this->objTagName."[@name='".$name."']"); + + $this->obj = $this->xp->query("//".$this->objTagName."[@name='".$name."']"); if ($this->obj->length != 0) return true; + return false; } protected function getObjectIdByName($name) { + $this->obj = $this->xp->query("//".$this->objTagName."[@name='".$name."']"); - if ($this->obj->length == 0) return false; - $id = $this->obj->item(0)->getAttribute('xml:id'); - if ($id) return $id; + if ($this->obj->length == 0) return false; + $id = $this->obj->item(0)->getAttribute('xml:id'); + if ($id) return $id; + return false; } protected function folderExistsByName($name){ - $this->obj = $this->xp->query("//".$this->contentRootTag."/folder[@name='".$name."']"); + + $this->obj = $this->xp->query("//".$this->contentRootTag."/folder[@name='".$name."']"); if ($this->obj->length != 0) return true; + return false; } - protected function objectExistsById($id){ + protected function objectExistsById($id){ + $this->obj = $this->contentDom->getElementById($id); if ($this->obj != null) return $this->obj; + return false; - } + } - protected function createObjectResource(){} - protected function renameInResource(){} + protected function createObjectResource(){} + protected function renameInResource(){} /* * Write Object into desc file */ protected function createObjectDescription($obj){ - $root = $this->objectDom->createElement($this->objTagName); - $root->setAttribute('xml:id',$this->id); + + $root = $this->objectDom->createElement($this->objTagName); + $root->setAttribute('xml:id',$this->id); foreach($obj as $key => $value) { - if ($key != 'id' && $key != 'leaf' && $key != 'nodeType') { - $node = $this->objectDom->createElement($key,htmlspecialchars($value)); - $root -> appendChild($node); - } + if ($key != 'id' && $key != 'leaf' && $key != 'nodeType') { + $node = $this->objectDom->createElement($key,htmlspecialchars($value)); + $root -> appendChild($node); + } } -// add Optional Attributes if they are undefined - foreach ($this->optionalAttributes as $key => $value) - if ($root->getElementsByTagName($key)->length == 0) { - $node = $this->objectDom->createElement($key,htmlspecialchars($value)); - $root -> appendChild($node); - } + // add Optional Attributes if they are undefined + foreach ($this->optionalAttributes as $key => $value) + if ($root->getElementsByTagName($key)->length == 0) { + $node = $this->objectDom->createElement($key,htmlspecialchars($value)); + $root -> appendChild($node); + } - $this->objectDom->appendChild($root); - $this->objectDom->save($this->descFileName); - } + $this->objectDom->appendChild($root); + $this->objectDom->save($this->descFileName); + } + /* * Just Save Content XML */ - protected function saveContent() { - $this->contentDom->save($this->xmlName); - } + protected function saveContent() { + + $this->contentDom->save($this->xmlName); + } /* * Add Object to Content XML */ - protected function addToContent($obj, $folder) { + protected function addToContent($obj, $folder) { - $folderToAdd = null; + $folderToAdd = null; $objList = $this->contentDom->getElementById($this->contentRootId); - $newObj = $this->contentDom->createElement($this->objTagName); - $newObj->setAttribute('xml:id',$this->id); -// object to mapped array - $obj_arr = (array)$obj; - foreach ($this->attributes as $key => $value) { - $newObj->setAttribute($key, $obj_arr[$key]); - } - if ($folder != null) - $folderToAdd = $this->contentDom->getElementById($folder); - - if ($folderToAdd) $folderToAdd -> appendChild($newObj); - else $objList -> appendChild($newObj); - + $newObj = $this->contentDom->createElement($this->objTagName); + $newObj->setAttribute('xml:id',$this->id); + // object to mapped array + $obj_arr = (array)$obj; + foreach ($this->attributes as $key => $value) { + $newObj->setAttribute($key, $obj_arr[$key]); + } + if ($folder != null) + $folderToAdd = $this->contentDom->getElementById($folder); + + if ($folderToAdd) + $folderToAdd -> appendChild($newObj); + else + $objList -> appendChild($newObj); $this->saveContent(); - } + } /* -* Delete Object From Content XML +* Delete Object From Content XML */ - protected function deleteFromContent($obj) { - $objList = $obj -> parentNode;// $this->contentDom->getElementById($this->contentRootId); - $objList -> removeChild($obj); + protected function deleteFromContent($obj) { + + $objList = $obj -> parentNode; // $this->contentDom->getElementById($this->contentRootId); + $objList -> removeChild($obj); $this->saveContent(); - } + } /* -* Create Folder +* Create Folder */ - protected function createFolder($obj){ - if ($this -> folderExistsByName($obj->name)) return array('error' => NAME_EXISTS); - $newFolder = $this->contentDom->createElement('folder'); - $id = $obj->name."_".$this->objTagName; - $newFolder -> setAttribute('xml:id',$id); - $newFolder -> setAttribute('name',$obj->name); - $objList = $this->contentDom->getElementById($obj->parent); - $objList -> appendChild($newFolder); - $this -> saveContent(); + protected function createFolder($obj){ + + if ($this -> folderExistsByName($obj->name)) + return array('error' => NAME_EXISTS); + $newFolder = $this->contentDom->createElement('folder'); + $id = $obj->name."_".$this->objTagName; + $newFolder -> setAttribute('xml:id',$id); + $newFolder -> setAttribute('name',$obj->name); + $objList = $this->contentDom->getElementById($obj->parent); + $objList -> appendChild($newFolder); + $this -> saveContent(); + return array('id' => $id); - } + } + /* * Get Folder of the object */ - protected function getObjectFolder($id) { + protected function getObjectFolder($id) { - if (!($obj = $this->objectExistsById($id))) return "NO_SUCH_ID"; - if ($obj->parentNode->tagName == 'folder') return $obj->parentNode->getAttribute('xml:id'); + if (!($obj = $this->objectExistsById($id))) + return "NO_SUCH_ID"; + if ($obj->parentNode->tagName == 'folder') + return $obj->parentNode->getAttribute('xml:id'); + return null; - - } + } protected function setAlias($chain) { @@ -195,9 +216,8 @@ foreach($listeAlias as $alias) { $chain = $aliasMgr->substrParamAlias($chain, $alias->getAttribute("xml:id"),$alias->getAttribute("name")); } - return $chain; - } + } protected function resetAlias($chain) { @@ -207,23 +227,23 @@ foreach($listeAlias as $alias) { $chain = $aliasMgr->substrAliasParam($chain, $alias->getAttribute("xml:id"),$alias->getAttribute("name")); } - return $chain; } protected function createDom() { $rootElement = $this->contentDom->createElement('ws'); - foreach ($this->types as $type) { - $contentId = $type.'-treeRootNode'; - $contentTag = $type.'List'; - $typeElement = $this->contentDom->createElement($contentTag); - $typeElement->setAttribute('xml:id', $contentId); - $rootElement->appendChild($typeElement); + foreach ($this->types as $type) { + $contentId = $type.'-treeRootNode'; + $contentTag = $type.'List'; + $typeElement = $this->contentDom->createElement($contentTag); + $typeElement->setAttribute('xml:id', $contentId); + $rootElement->appendChild($typeElement); } - $this->contentDom->appendChild($rootElement); + + $this->contentDom->appendChild($rootElement); $this->contentDom->save($this->xmlName); - } + } /***************************************************************** @@ -234,104 +254,121 @@ * Create Parameter[TT...]/Folder * create object itself, add it to content DOM */ - function createObject($p, $folder){ + function createObject($p, $folder){ - if ($p -> leaf) return $this->createParameter($p, $folder); - // else return $this->createFolder($p); -//TODO check if this is possible? - else return array('error' => 'createFolder should be called from RENAME'); + if ($p -> leaf) + return $this->createParameter($p, $folder); + // else return $this->createFolder($p); + //TODO check if this is possible? + else + return array('error' => 'createFolder should be called from RENAME'); - } + } /* * Rename Parameter[TT...]/Folder */ - function renameObject($p){ + function renameObject($p){ if (!($objToRename = $this -> objectExistsById($p->id))) { -// NO SUCH ID: leaf -> error; - if ($p->leaf) return array('error' => NO_SUCH_ID); -// NO SUCH ID: folder -> create - return $this -> createFolder($p); - } -// object was just DD in the tree : move tag in xml + // NO SUCH ID: leaf -> error; + if ($p->leaf) + return array('error' => NO_SUCH_ID); + // NO SUCH ID: folder -> create + return $this -> createFolder($p); + } + + // object was just DD in the tree : move tag in xml if ($p -> name == $p -> old_name) { - if (!($parentNode = $this->contentDom->getElementById($p -> parent))) return array('error' => NO_SUCH_PARENT_ID); - $parentNode -> appendChild($objToRename); - $this->saveContent(); - return array('id' => $p->id); - } - -// if ($this -> objectExistsByName($p->name, $this->objTagName)) return array('error' => NAME_EXISTS); -//TODO CHECK: With some PHP versions setAttribute ADD attribute - if ($objToRename->hasAttribute('name')) $objToRename->removeAttribute('name'); - $objToRename->setAttribute('name',$p->name); + if (!($parentNode = $this->contentDom->getElementById($p -> parent))) + return array('error' => NO_SUCH_PARENT_ID); + $parentNode -> appendChild($objToRename); + $this->saveContent(); + + return array('id' => $p->id); + } + + //TODO CHECK: With some PHP versions setAttribute ADD attribute + if ($objToRename->hasAttribute('name')) + $objToRename->removeAttribute('name'); + + $objToRename->setAttribute('name',$p->name); + if (!$p->leaf) { - $objToRename->removeAttribute('xml:id'); - $objToRename->setAttribute('xml:id', $p->name.'_'.$this->objTagName); - } + $objToRename->removeAttribute('xml:id'); + $objToRename->setAttribute('xml:id', $p->name.'_'.$this->objTagName); + } else - $this -> renameInResource($p->name, $p->id); + $this -> renameInResource($p->name, $p->id); $this->saveContent(); + return array('id' => $p->id); } /* * Delete Parameter[TT...]/Folder -* Delete object itself, delete from contentDOM, mark as undefined in depending objects +* Delete object itself, delete from contentDOM, mark as undefined in depending objects */ - function deleteObject($p){ - - if ($p->leaf) { -// if Parameter[TT...] - delete resources first - $isDeleted = $this->deleteParameter($p->id); - if (!($objToDelete = $this -> objectExistsById($p->id))) return array('error' => NO_SUCH_ID); - } - else { - if (!($objToDelete = $this -> objectExistsById($p->id))) return array('error' => NO_SUCH_ID); + function deleteObject($p){ + + if ($p->leaf) { + // if Parameter[TT...] - delete resources first + $isDeleted = $this->deleteParameter($p->id); + if (!($objToDelete = $this -> objectExistsById($p->id))) + return array('error' => NO_SUCH_ID); + } + else { + if (!($objToDelete = $this -> objectExistsById($p->id))) + return array('error' => NO_SUCH_ID); $folderToDelete = $objToDelete->getElementsByTagName($this->objTagName); -// delete all parameters[TT..] in folder(s) + // delete all parameters[TT..] in folder(s) foreach ($folderToDelete as $obj) { - $id = $obj->getAttribute('xml:id'); - $this->deleteParameter($id); - } - } - $this -> deleteFromContent($objToDelete); - - if ($isDeleted) return array('id' => $p->id, 'maskDeleted' => true); - else return array('id' => $p->id); - } + $id = $obj->getAttribute('xml:id'); + $this->deleteParameter($id); + } + } + + $this -> deleteFromContent($objToDelete); + + if ($isDeleted) + return array('id' => $p->id, 'maskDeleted' => true); + else + return array('id' => $p->id); + } /* * Modify Parameter[TT...]/Folder -*/ - - function modifyObject($p){ - if ($this->renameOnly($p)) { +*/ + function modifyObject($p){ + + if ($this->renameOnly($p)) { $p->leaf = 1; - return $this->renameObject($p); - } - $folder = $this->getObjectFolder($p->id); - $this->deleteObject($p); - return - $this->createObject($p, $folder); - } + return $this->renameObject($p); + } + + $folder = $this->getObjectFolder($p->id); + $this->deleteObject($p); + + return $this->createObject($p, $folder); + } - function validNameObject($p){ - if (!isset($p->name) || ($p->name == "")) - return array('valid' => false, 'error' => 'Name is required'); - if ($p->leaf) - $alreadyExist = $this -> objectExistsByName($p->name, $this->objTagName); - else - $alreadyExist = $this -> folderExistsByName($p->name); - if ($alreadyExist) - return array('valid' => false, 'error' => 'This name already exists in this subtree!'); - return array('valid' => true); - } + function validNameObject($p){ + + if (!isset($p->name) || ($p->name == "")) + return array('valid' => false, 'error' => 'Name is required'); + if ($p->leaf) + $alreadyExist = $this -> objectExistsByName($p->name, $this->objTagName); + else + $alreadyExist = $this -> folderExistsByName($p->name); + if ($alreadyExist) + return array('valid' => false, 'error' => 'This name already exists in this subtree!'); + + return array('valid' => true); + } - function getObject($id){} + function getObject($id){} } ?> diff --git a/php/classes/TimeTableMgr.php b/php/classes/TimeTableMgr.php index 3f133bf..4700222 100644 --- a/php/classes/TimeTableMgr.php +++ b/php/classes/TimeTableMgr.php @@ -54,9 +54,9 @@ class TimeTableMgr extends AmdaObjectMgr $this->contentDom->save($this->xmlName); } - /* - * rename Time Table in id.xml - */ +/* +* rename Time Table in id.xml +*/ protected function renameInResource($name, $id) { if (!file_exists(USERTTDIR.$id.'.xml')) return false; @@ -150,65 +150,9 @@ class TimeTableMgr extends AmdaObjectMgr return $inter; } - /* - * For TT download : file format in text - */ - protected function xsl2text($file,$format) - { - define("format", $format); - $xslt = new XSLTProcessor(); - - // add PHP functions to XSLT functions - $xslt -> registerPHPFunctions(); - - // Load Time table - $xml = new domDocument("1.0"); - $xml->load($file); - - // Load XSL file - $xsl = new domDocument("1.0"); - if ($format == "Y-m-dTH:i:s") $xslName = "xml2iso.xsl"; - else $xslName = "xml2all.xsl"; - $xsl->load(XMLPATH.$xslName); - - // Import XSL and write output file in text format - $xslt -> importStylesheet($xsl); - $filename = $xml->getElementsByTagName('name')->item(0)->nodeValue.".txt"; - $output=fopen(USERWORKINGDIR.$filename, "w"); - fwrite($output, trim($xslt -> transformToDoc($xml)->firstChild->wholeText)); - fclose($output); - - return USERWORKINGDIR.$filename; - } - - /* - * For TT download : file format in vot - */ - public function xsl2vot($file,$format) - { - $xslt = new XSLTProcessor(); - - // Load Time table - $xml = new domDocument("1.0"); - $xml->load($file); - - // Load XSL file - $xsl = new domDocument("1.0"); - $xsl->load(XMLPATH.'xml2vot.xsl'); - - // Import XSL and write output file in vot format - $xslt -> importStylesheet($xsl); - $vot = new domDocument("1.0"); - $vot -> loadXML($xslt -> transformToXML($xml)); - $filename = $xml->getElementsByTagName('name')->item(0)->nodeValue.".xml"; - $vot -> save(USERWORKINGDIR.$filename); - - return USERWORKINGDIR.$filename; - } - - /* - * Uploaded text file => convert to array - */ +/* +* Uploaded text file => convert to array +*/ protected function text2amda($tmp_file, $onlyDescription = false) { $suffix = explode('.', basename($tmp_file)); @@ -828,7 +772,7 @@ class TimeTableMgr extends AmdaObjectMgr chmod($dst_file_path, 0775); return TRUE; - } + } } ?> -- libgit2 0.21.2