Commit 6de48c3d5701cc08f42f7b1d379f96ca8ec7fedc
1 parent
f60f0bd9
Exists in
master
and in
111 other branches
Implement data upload from a SAMP notification of a local application
Showing
5 changed files
with
130 additions
and
21 deletions
Show diff stats
js/app/controllers/InteropModule.js
... | ... | @@ -230,6 +230,12 @@ Ext.define('amdaDesktop.InteropModule', { |
230 | 230 | this.samp.sendFITS(url,name); |
231 | 231 | }, |
232 | 232 | |
233 | + loadFile: function(url,onLoad,onError) { | |
234 | + if (!this.samp) | |
235 | + return null; | |
236 | + this.samp.loadFile(url,onLoad,onError); | |
237 | + }, | |
238 | + | |
233 | 239 | loadEpnTap: function(filter) { |
234 | 240 | if(!this.epntap) { |
235 | 241 | this.epntap = Ext.create('amdaDesktop.EpnTapModule'); |
... | ... |
js/app/controllers/SampModule.js
... | ... | @@ -278,5 +278,45 @@ Ext.define('amdaDesktop.SampModule', { |
278 | 278 | receiveFile : function(clientName, url, format) |
279 | 279 | { |
280 | 280 | this.fireEvent('uploadfile',this,clientName, url, format); |
281 | - } | |
282 | -}); | |
283 | 281 | \ No newline at end of file |
282 | + }, | |
283 | + | |
284 | + loadFile : function(url, onLoad, onError) | |
285 | + { | |
286 | + if (!this.connector || !this.ready) { | |
287 | + if (onError) | |
288 | + onError("Not connected to a SAMP hub"); | |
289 | + return; | |
290 | + } | |
291 | + var proxifiedUrl = this.connector.connection.translateUrl(url); | |
292 | + var xobj = null; | |
293 | + if ((typeof XMLHttpRequest != "undefined") && (typeof FileReader != "undefined")) { | |
294 | + xobj = new XMLHttpRequest(); | |
295 | + } | |
296 | + else { | |
297 | + if (onError) | |
298 | + onError("Not supported by your browser"); | |
299 | + return; | |
300 | + } | |
301 | + xobj.open('GET', proxifiedUrl, true); | |
302 | + xobj.responseType = "blob"; | |
303 | + xobj.onload = function() { | |
304 | + var blob = xobj.response; | |
305 | + var reader = new FileReader(); | |
306 | + reader.addEventListener("load", function () { | |
307 | + if (onLoad) | |
308 | + onLoad(reader.result); | |
309 | + }, false); | |
310 | + reader.addEventListener("error", function () { | |
311 | + if (onError) | |
312 | + onError("Cannot load data received from SAMP"); | |
313 | + }, false); | |
314 | + reader.readAsText(blob,"UTF-8"); | |
315 | + }; | |
316 | + xobj.onerror = function () { | |
317 | + if (onError) | |
318 | + onError("An error occurred during the SAMP request"); | |
319 | + }; | |
320 | + xobj.send(null); | |
321 | + return true; | |
322 | + }, | |
323 | +}); | |
... | ... |
js/app/views/UploadPanelUI.js
... | ... | @@ -178,30 +178,55 @@ Ext.define('amdaUI.UploadPanelUI', { |
178 | 178 | */ |
179 | 179 | forceUpload : function (url,format,onFinish) |
180 | 180 | { |
181 | + var me = this; | |
181 | 182 | var re = /http:\/\/127.0.0.1:/; |
182 | 183 | var isRemoteUrl = !re.test(url); |
183 | 184 | |
185 | + switch (format) | |
186 | + { | |
187 | + case 'votable' : | |
188 | + this.getForm().findField('filefrmt').setValue('VOT'); | |
189 | + break; | |
190 | + case 'cdf' : | |
191 | + this.getForm().findField('filefrmt').setValue('CDF'); | |
192 | + break; | |
193 | + default : | |
194 | + myDesktopApp.errorMsg('Not supported data receive from SAMP'); | |
195 | + return; | |
196 | + } | |
197 | + | |
184 | 198 | if (!isRemoteUrl) { |
185 | - myDesktopApp.warningMsg("Cannot load data from a local application."); | |
186 | - if (onFinish) | |
187 | - onFinish(); | |
199 | + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { | |
200 | + var onError = function(error) { | |
201 | + if (error) | |
202 | + myDesktopApp.errorMsg(error); | |
203 | + else | |
204 | + myDesktopApp.errorMsg("Cannot load data from this SAMP notification"); | |
205 | + if (onFinish) | |
206 | + onFinish(); | |
207 | + }; | |
208 | + var onLoad = function(data) { | |
209 | + //Fake value for validation | |
210 | + Ext.form.field.File.superclass.setValue.call(me.getForm().findField('localFileName'), 'samp.vot'); | |
211 | + me.getForm().findField('filesrc').setValue('LOCAL'); | |
212 | + //Add data related to the samp notification | |
213 | + me.getForm().findField('sampFileName').setValue('samp.vot'); | |
214 | + me.getForm().findField('sampData').setValue(data); | |
215 | + var onFinishAll = function() { | |
216 | + me.getForm().findField('sampFileName').reset(); | |
217 | + me.getForm().findField('sampData').reset(); | |
218 | + if (onFinish) | |
219 | + onFinish(); | |
220 | + } | |
221 | + me.postUpload(onFinishAll); | |
222 | + }; | |
223 | + module.loadFile(url,onLoad,onError); | |
224 | + }); | |
188 | 225 | return; |
189 | 226 | } |
190 | 227 | |
191 | 228 | this.getForm().findField('filesrc').setValue('URL'); |
192 | 229 | this.getForm().findField('remoteFile').setValue(url); |
193 | - switch (format) | |
194 | - { | |
195 | - case 'votable' : | |
196 | - this.getForm().findField('filefrmt').setValue('VOT'); | |
197 | - break; | |
198 | - case 'cdf' : | |
199 | - this.getForm().findField('filefrmt').setValue('CDF'); | |
200 | - break; | |
201 | - default : | |
202 | - //ToDo Error - unknown format | |
203 | - return; | |
204 | - } | |
205 | 230 | this.postUpload(onFinish); |
206 | 231 | }, |
207 | 232 | |
... | ... | @@ -565,7 +590,17 @@ Ext.define('amdaUI.UploadPanelUI', { |
565 | 590 | localFile, |
566 | 591 | remoteFile, |
567 | 592 | fileFormat, |
568 | - timeFormat | |
593 | + timeFormat, | |
594 | + { | |
595 | + xtype: 'hidden', | |
596 | + name: 'sampData', | |
597 | + value: null | |
598 | + }, | |
599 | + { | |
600 | + xtype: 'hidden', | |
601 | + name: 'sampFileName', | |
602 | + value: null, | |
603 | + } | |
569 | 604 | ], |
570 | 605 | buttons: [ |
571 | 606 | { |
... | ... |
php/classes/VOTableMgr.php
... | ... | @@ -289,7 +289,8 @@ class VOTableMgr { |
289 | 289 | if (!$this->xp) |
290 | 290 | return FALSE; |
291 | 291 | |
292 | - return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime")); | |
292 | + return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime") || | |
293 | + ($field->getAttribute("ucd") == "TIME") && ($field->getAttribute("unit") == "iso-8601")); | |
293 | 294 | } |
294 | 295 | |
295 | 296 | public function getTimeFieldIndex() |
... | ... |
php/uploadFile.php
... | ... | @@ -117,6 +117,8 @@ |
117 | 117 | $nonStd = $_POST['nonstd'] ? $_POST['nonstd'] : null; |
118 | 118 | $timeLength = $_POST['timelength'] ? $_POST['timelength'] : null; |
119 | 119 | $doy = isset($_POST['doy']) ? $_POST['doy'] : null; |
120 | + $sampData = isset($_POST['sampData']) ? $_POST['sampData'] : null; | |
121 | + $sampFileName = isset($_POST['sampFileName']) ? $_POST['sampFileName'] : null; | |
120 | 122 | |
121 | 123 | $allFormats = array('fileFormat' => $fileFrmt, 'timeFormat' => $timeFrmt, 'doy' => $doy, |
122 | 124 | 'timeSampling' => $timeSmplg, 'nonStandard' => $nonStd, 'timeLength' => $timeLength); |
... | ... | @@ -127,8 +129,33 @@ |
127 | 129 | // to check ws sizw |
128 | 130 | $wsMgr = new UserMgr(); |
129 | 131 | $wsMgr->setSpecialSettings(); |
130 | - | |
131 | - if ($fromURL) | |
132 | + | |
133 | + if (isset($sampData) && !empty($sampData)) { | |
134 | + $fileMgr = new FilesMgr(); | |
135 | + $fileName = date("Y-m-d\TH:i:s").'_samp.vot'; | |
136 | + $tmpFilePath = USERTEMPDIR.$fileName; | |
137 | + file_put_contents($tmpFilePath, $sampData); | |
138 | + $fileSize = filesize($tmpFilePath); | |
139 | + | |
140 | + if ($wsMgr->getWsSize() + $fileSize > DISK_QUOTA) | |
141 | + { | |
142 | + $response = array( 'success' => false, 'error' => 'Please clean up you workspace. You are about to exceed available disk space'); | |
143 | + unlink($tmpFilePath); | |
144 | + die(json_encode($response)); | |
145 | + } | |
146 | + | |
147 | + if ($fileSize > maxSize) | |
148 | + { | |
149 | + $maxMB = maxSize/1000000; | |
150 | + $response = array( 'success' => false, 'error' => 'The uploaded file exceeds '.$maxMB.'MB'); | |
151 | + unlink($tmpFilePath); | |
152 | + die(json_encode($response)); | |
153 | + } | |
154 | + | |
155 | + $dataFilePath = USERDATADIR.$fileName; | |
156 | + rename($tmpFilePath,$dataFilePath); | |
157 | + } | |
158 | + else if ($fromURL) | |
132 | 159 | { |
133 | 160 | // url files check |
134 | 161 | if ($_POST['remoteFile']) |
... | ... |