15
15
*/
16
16
import { buildURL } from '../ActionURL' ;
17
17
import { request } from '../Ajax' ;
18
- import { getCallbackWrapper , getOnFailure , getOnSuccess , isObject } from '../Utils' ;
18
+ import { getCallbackWrapper , getOnFailure , getOnSuccess , isObject , RequestCallbackOptions } from '../Utils' ;
19
19
20
- import { FormWindow } from './constants' ;
21
-
22
- declare let window : FormWindow ;
23
-
24
- export interface IImportRunOptions {
20
+ export interface ImportRunOptions extends RequestCallbackOptions {
25
21
allowCrossRunFileInputs ?: boolean ;
26
22
allowLookupByAlternateKey ?: boolean ;
27
23
assayId ?: number | string ;
@@ -31,23 +27,21 @@ export interface IImportRunOptions {
31
27
comments ?: string ;
32
28
containerPath ?: string ;
33
29
dataRows ?: any [ ] ;
34
- failure ?: Function ;
35
30
files ?: any [ ] ;
36
31
forceAsync ?: boolean ;
37
32
jobDescription ?: string ;
38
33
jobNotificationProvider ?: string ;
39
34
name ?: string ;
35
+ plateMetadata ?: any ;
40
36
properties ?: any ;
41
37
reRunId ?: number | string ;
42
38
runFilePath ?: string ;
43
39
saveDataAsFile ?: boolean ;
44
- scope ?: any ;
45
- success : Function ;
46
40
workflowTask ?: number ;
47
41
}
48
42
49
- export function importRun ( options : IImportRunOptions ) : void {
50
- if ( ! window . FormData ) {
43
+ export function importRun ( options : ImportRunOptions ) : XMLHttpRequest {
44
+ if ( ! FormData ) {
51
45
throw new Error ( 'modern browser required' ) ;
52
46
}
53
47
@@ -59,7 +53,7 @@ export function importRun(options: IImportRunOptions): void {
59
53
if ( options . files ) {
60
54
for ( let i = 0 ; i < options . files . length ; i ++ ) {
61
55
const f = options . files [ i ] ;
62
- if ( f instanceof window . File ) {
56
+ if ( f instanceof File ) {
63
57
files . push ( f ) ;
64
58
} else if ( f . tagName == 'INPUT' ) {
65
59
for ( let j = 0 ; j < f . files . length ; j ++ ) {
@@ -114,25 +108,21 @@ export function importRun(options: IImportRunOptions): void {
114
108
}
115
109
116
110
if ( options . properties ) {
117
- for ( const key in options . properties ) {
118
- if ( options . properties . hasOwnProperty ( key ) ) {
119
- if ( isObject ( options . properties [ key ] ) ) {
120
- formData . append ( "properties['" + key + "']" , JSON . stringify ( options . properties [ key ] ) ) ;
121
- } else {
122
- formData . append ( "properties['" + key + "']" , options . properties [ key ] ) ;
123
- }
111
+ for ( const [ key , value ] of Object . entries ( options . properties ) ) {
112
+ if ( isObject ( value ) ) {
113
+ formData . append ( `properties['${ key } ']` , JSON . stringify ( value ) ) ;
114
+ } else {
115
+ formData . append ( `properties['${ key } ']` , options . properties [ key ] ) ;
124
116
}
125
117
}
126
118
}
127
119
128
120
if ( options . batchProperties ) {
129
- for ( const key in options . batchProperties ) {
130
- if ( options . batchProperties . hasOwnProperty ( key ) ) {
131
- if ( isObject ( options . batchProperties [ key ] ) ) {
132
- formData . append ( "batchProperties['" + key + "']" , JSON . stringify ( options . batchProperties [ key ] ) ) ;
133
- } else {
134
- formData . append ( "batchProperties['" + key + "']" , options . batchProperties [ key ] ) ;
135
- }
121
+ for ( const [ key , value ] of Object . entries ( options . batchProperties ) ) {
122
+ if ( isObject ( value ) ) {
123
+ formData . append ( `batchProperties['${ key } ']` , JSON . stringify ( value ) ) ;
124
+ } else {
125
+ formData . append ( `batchProperties['${ key } ']` , options . batchProperties [ key ] ) ;
136
126
}
137
127
}
138
128
}
@@ -152,7 +142,11 @@ export function importRun(options: IImportRunOptions): void {
152
142
}
153
143
}
154
144
155
- request ( {
145
+ if ( options . plateMetadata ) {
146
+ formData . append ( 'plateMetadata' , JSON . stringify ( options . plateMetadata ) ) ;
147
+ }
148
+
149
+ return request ( {
156
150
url : buildURL ( 'assay' , 'importRun.api' , options . containerPath ) ,
157
151
method : 'POST' ,
158
152
success : getCallbackWrapper ( getOnSuccess ( options ) , options . scope ) ,
0 commit comments