Skip to content

Commit 111622c

Browse files
authored
Signal data improvements (#927)
1 parent 1397203 commit 111622c

7 files changed

Lines changed: 334 additions & 179 deletions

File tree

signalData/resources/views/mockSignalDataWatch.html

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@
6161
}
6262
});
6363

64-
var dataRows = [],
65-
dataInputs = [];
64+
var dataRows = [], dataInputs = [];
6665

6766
Ext4.each(fileSet, function(file) {
67+
var fileName = file['FileName'];
6868
dataRows.push({
69-
Name: file.text,
70-
DataFile: SIGNAL_DATA_FILE_ROOT + file.text,
69+
Name: fileName,
70+
DataFile: SIGNAL_DATA_FILE_ROOT + fileName,
7171
TestType: 'SMP'
7272
});
7373
dataInputs.push({
74-
name: file.text,
75-
dataFileURL: file.dataFileURL
74+
name: fileName,
75+
dataFileURL: file['DataFileUrl']
7676
});
7777
});
78-
7978
run.dataRows = dataRows;
8079
run.dataInputs = dataInputs;
80+
8181
return run;
8282
}
8383

@@ -197,33 +197,24 @@
197197
{
198198
if (Ext4.isFunction(callback)) {
199199

200-
var received = 0;
201-
var newFiles = [];
202-
203-
function done(file, results)
204-
{
205-
Ext4.each(files, function(f) {
206-
if (f.text === file.text) {
207-
f['dataFileURL'] = results['DataFileUrl'];
208-
newFiles.push(f);
209-
}
210-
});
211-
received++;
212-
213-
if (received == files.length) {
214-
callback.call(scope || this, newFiles);
215-
}
216-
}
200+
var paths = [];
201+
var fileNames = [];
202+
files.forEach(function (file) {
203+
paths.push(decodeURIComponent(file.id));
204+
fileNames.push(file.text);
205+
}, this);
217206

218-
Ext4.each(files, function(file) {
219-
LABKEY.Ajax.request({
220-
url: LABKEY.ActionURL.buildURL('signaldata', 'getSignalDataResource.api'),
221-
method: 'POST',
222-
params: { path: decodeURIComponent(file.id), test: true },
223-
success: function(response) {
224-
done(file, Ext4.decode(response.responseText));
225-
}
226-
});
207+
LABKEY.Ajax.request({
208+
url: LABKEY.ActionURL.buildURL('SignalData', 'getSignalDataResource.api'),
209+
method: 'POST',
210+
jsonData: {
211+
paths : paths,
212+
files : fileNames
213+
},
214+
success: LABKEY.Utils.getCallbackWrapper(function(response) {
215+
callback.call(scope || this, response.files);
216+
}, this),
217+
scope: this
227218
});
228219
}
229220
}

signalData/resources/web/signaldata/ResultUpdate/resultupdate.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ var getResultData = function(assay) {
3434
requiredVersion: 13.2,
3535
filterArray: [LABKEY.Filter.create('RowId', LABKEY.ActionURL.getParameter('rowId'))],
3636
success: function(results){
37-
if (results.length > 0) {
38-
init(assay, results.getRow(0));
37+
if (results.rowCount > 0) {
38+
init(assay, results.rows[0]);
3939
}
4040
else {
4141
// Use an ExtJS alert instead of a raw browser alert to avoid alarming the crawler
@@ -64,12 +64,16 @@ var init = function(assay, row){
6464
LABKEY.Ajax.request({
6565
url: LABKEY.ActionURL.buildURL('SignalData', 'getSignalDataResource.api'),
6666
method: 'POST',
67-
params: {path: decodeURIComponent(file.internalId), test: true},
68-
success: function (response) {
69-
var fileResource = Ext4.decode(response.responseText);
70-
var updatedRow = setRunFields(form, fileResource);
71-
updateRunResult(updatedRow, fileResource);
67+
params: {
68+
paths: [decodeURIComponent(file.internalId)],
69+
files: [file.name]
7270
},
71+
success: LABKEY.Utils.getCallbackWrapper(function(response) {
72+
Ext4.each(response.files, function(file) {
73+
var updatedRow = setRunFields(form, file);
74+
updateRunResult(updatedRow, file);
75+
}, this);
76+
}, this),
7377
scope: this
7478
});
7579
}

signalData/resources/web/signaldata/UploadView/UploadLog.js

Lines changed: 80 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,56 @@ Ext4.define('LABKEY.SignalData.UploadLog', {
244244
if (Ext4.isFunction(callback)) {
245245
var me = this;
246246
var destination = this.fileSystem.concatPaths(this.fileSystem.getBaseURL(), targetDirectory);
247-
this.fileSystem.renamePath({
248-
source: this.getWorkingPath(),
249-
destination: destination,
250-
isFile: false,
251-
success: function () {
252-
me.resolveFileResources(targetDirectory, callback, scope, runProperties);
247+
248+
const getResourcesCallback = function(files) {
249+
if (files && files.length > 0) {
250+
// files currently exist, validate and resolve before creating the run
251+
me.resolveDataFileURL(files, callback, scope, runProperties);
253252
}
254-
});
253+
else {
254+
// files need to be moved to the target directory
255+
this.fileSystem.renamePath({
256+
source: this.getWorkingPath(),
257+
destination: destination,
258+
isFile: false,
259+
success: function () {
260+
me.resolveFileResources(targetDirectory, callback, scope, runProperties);
261+
}
262+
});
263+
}
264+
};
265+
266+
// get the list of files in the target directory (if any)
267+
this.getTargetDirResources(targetDirectory, getResourcesCallback, this);
255268
}
256269
},
257270

271+
/**
272+
* Returns the list of data files in the target directory. Uploaded run data files are moved from
273+
* a temporary location to the target directory before the run is created.
274+
*/
275+
getTargetDirResources : function (targetDirectory, callback, callbackScope) {
276+
var fileUri = this.fileSystem.concatPaths(this.fileSystem.getAbsoluteURL(), targetDirectory);
277+
LABKEY.Ajax.request({
278+
url: fileUri,
279+
method: 'GET',
280+
params: {method: 'JSON'},
281+
success: function (response) {
282+
var json = Ext4.decode(response.responseText);
283+
var files = [];
284+
if (Ext4.isDefined(json) && Ext4.isArray(json.files))
285+
files = json.files;
286+
287+
callback.call(callbackScope, files);
288+
},
289+
failure: function() {
290+
// this is normal in the case where the target directory does not yet exist or
291+
// the files have not yet been moved there
292+
callback.call(callbackScope, []);
293+
}
294+
});
295+
},
296+
258297
resolveFileResources: function (targetDirectory, callback, callbackScope, runProperties) {
259298
var fileUri = this.fileSystem.concatPaths(this.fileSystem.getAbsoluteURL(), targetDirectory);
260299
LABKEY.Ajax.request({
@@ -269,9 +308,10 @@ Ext4.define('LABKEY.SignalData.UploadLog', {
269308
}
270309
}
271310
},
272-
failure: function () {
273-
}
274-
, scope: this
311+
failure: LABKEY.Utils.getCallbackWrapper(function(json, response, opts) {
312+
LABKEY.Utils.alert('Error', 'Unable to resolve file resources : ' + response.exception);
313+
}, this, true),
314+
scope: this
275315
}, this);
276316
},
277317

@@ -281,41 +321,42 @@ Ext4.define('LABKEY.SignalData.UploadLog', {
281321
resolveDataFileURL: function (files, callback, scope, runProperties) {
282322
if (Ext4.isFunction(callback)) {
283323

284-
var received = 0;
285-
var newFiles = [];
286-
287324
var me = this;
325+
var paths = [];
326+
var fileNames = [];
327+
files.forEach(function (file) {
328+
paths.push(decodeURIComponent(file.id));
329+
fileNames.push(file.text);
330+
}, this);
288331

289-
function done(file, results) {
332+
LABKEY.Ajax.request({
333+
url: LABKEY.ActionURL.buildURL('SignalData', 'getSignalDataResource.api'),
334+
method: 'POST',
335+
jsonData: {
336+
paths : paths,
337+
files : fileNames
338+
},
339+
success: function (response) {
340+
let result = Ext4.decode(response.responseText);
341+
let store = this.getStore();
290342

291-
var store = me.getStore();
292-
var idx = store.find(me.DATA_FILE, file.text);
293-
var process = store.getAt(idx);
343+
Ext4.each(result.files, function(file) {
294344

295-
//Set upload time
296-
process.set(me.FILENAME, results[me.DATA_FILE]);
297-
process.set(me.FILE_URL, results['DataFileUrl']);
298-
process.set('file', file);
299-
newFiles.push(file);
300-
received++;
345+
var idx = store.find(this.DATA_FILE, file["FileName"]);
346+
var rec = store.getAt(idx);
301347

302-
if (received == files.length) {
303-
callback.call(scope || me, newFiles, runProperties);
304-
}
305-
}
348+
if (rec) {
349+
//Set upload time in the store record
350+
rec.set(me.FILENAME, file[this.DATA_FILE]);
351+
rec.set(me.FILE_URL, file['DataFileUrl']);
352+
rec.set('file', true);
353+
}
354+
}, this);
306355

307-
//TODO: This should be refactored to use a single ajax call for the array
308-
files.forEach(function (file) {
309-
LABKEY.Ajax.request({
310-
url: LABKEY.ActionURL.buildURL('SignalData', 'getSignalDataResource.api'),
311-
method: 'POST',
312-
params: {path: decodeURIComponent(file.id), test: true},
313-
success: function (response) {
314-
done(file, Ext4.decode(response.responseText));
315-
},
316-
scope: this
317-
});
318-
}, this);
356+
callback.call(scope || me, runProperties);
357+
},
358+
scope: this
359+
});
319360
}
320361
},
321362

signalData/resources/web/signaldata/UploadView/uploadResultFiles.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ LABKEY.SignalData.initializeDataFileUploadForm = function (metadataFormId, eleme
366366
window.location = returnUrl;
367367
},this);
368368
},
369-
failure: function(response){
370-
//TODO: Should probably do something here...
371-
}
369+
failure: LABKEY.Utils.getCallbackWrapper(function(json, response, opts) {
370+
LABKEY.Utils.alert('Error', 'Unable to save run : ' + response.exception);
371+
}, this, true)
372372
}, this);
373373
}
374374

375-
var generateAndSaveRun = function(files, fieldValues) {
375+
var generateAndSaveRun = function(fieldValues) {
376376

377377
var dataRows = [];
378378
var dataInputs = [];

0 commit comments

Comments
 (0)