@@ -9,7 +9,7 @@ const logger = debug("redash:services:QueryResult");
9
9
const filterTypes = [ "filter" , "multi-filter" , "multiFilter" ] ;
10
10
11
11
function defer ( ) {
12
- const result = { onStatusChange : status => { } } ;
12
+ const result = { onStatusChange : ( status ) => { } } ;
13
13
result . promise = new Promise ( ( resolve , reject ) => {
14
14
result . resolve = resolve ;
15
15
result . reject = reject ;
@@ -40,13 +40,13 @@ function getColumnNameWithoutType(column) {
40
40
}
41
41
42
42
function getColumnFriendlyName ( column ) {
43
- return getColumnNameWithoutType ( column ) . replace ( / (?: ^ | \s ) \S / g, a => a . toUpperCase ( ) ) ;
43
+ return getColumnNameWithoutType ( column ) . replace ( / (?: ^ | \s ) \S / g, ( a ) => a . toUpperCase ( ) ) ;
44
44
}
45
45
46
46
const createOrSaveUrl = data => ( data . id ? `api/query_results/${ data . id } ` : "api/query_results" ) ;
47
47
const QueryResultResource = {
48
48
get : ( { id } ) => axios . get ( `api/query_results/${ id } ` ) ,
49
- post : data => axios . post ( createOrSaveUrl ( data ) , data ) ,
49
+ post : ( data ) => axios . post ( createOrSaveUrl ( data ) , data ) ,
50
50
} ;
51
51
52
52
export const ExecutionStatus = {
@@ -97,11 +97,11 @@ function handleErrorResponse(queryResult, error) {
97
97
}
98
98
99
99
function sleep ( ms ) {
100
- return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
100
+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
101
101
}
102
102
103
103
export function fetchDataFromJob ( jobId , interval = 1000 ) {
104
- return axios . get ( `api/jobs/${ jobId } ` ) . then ( data => {
104
+ return axios . get ( `api/jobs/${ jobId } ` ) . then ( ( data ) => {
105
105
const status = statuses [ data . job . status ] ;
106
106
if ( status === ExecutionStatus . WAITING || status === ExecutionStatus . PROCESSING ) {
107
107
return sleep ( interval ) . then ( ( ) => fetchDataFromJob ( data . job . id ) ) ;
@@ -146,7 +146,7 @@ class QueryResult {
146
146
// TODO: we should stop manipulating incoming data, and switch to relaying
147
147
// on the column type set by the backend. This logic is prone to errors,
148
148
// and better be removed. Kept for now, for backward compatability.
149
- each ( this . query_result . data . rows , row => {
149
+ each ( this . query_result . data . rows , ( row ) => {
150
150
forOwn ( row , ( v , k ) => {
151
151
let newType = null ;
152
152
if ( isNumber ( v ) ) {
@@ -173,7 +173,7 @@ class QueryResult {
173
173
} ) ;
174
174
} ) ;
175
175
176
- each ( this . query_result . data . columns , column => {
176
+ each ( this . query_result . data . columns , ( column ) => {
177
177
column . name = "" + column . name ;
178
178
if ( columnTypes [ column . name ] ) {
179
179
if ( column . type == null || column . type === "string" ) {
@@ -265,14 +265,14 @@ class QueryResult {
265
265
266
266
getColumnNames ( ) {
267
267
if ( this . columnNames === undefined && this . query_result . data ) {
268
- this . columnNames = this . query_result . data . columns . map ( v => v . name ) ;
268
+ this . columnNames = this . query_result . data . columns . map ( ( v ) => v . name ) ;
269
269
}
270
270
271
271
return this . columnNames ;
272
272
}
273
273
274
274
getColumnFriendlyNames ( ) {
275
- return this . getColumnNames ( ) . map ( col => getColumnFriendlyName ( col ) ) ;
275
+ return this . getColumnNames ( ) . map ( ( col ) => getColumnFriendlyName ( col ) ) ;
276
276
}
277
277
278
278
getTruncated ( ) {
@@ -286,7 +286,7 @@ class QueryResult {
286
286
287
287
const filters = [ ] ;
288
288
289
- this . getColumns ( ) . forEach ( col => {
289
+ this . getColumns ( ) . forEach ( ( col ) => {
290
290
const name = col . name ;
291
291
const type = name . split ( "::" ) [ 1 ] || name . split ( "__" ) [ 1 ] ;
292
292
if ( includes ( filterTypes , type ) ) {
@@ -302,8 +302,8 @@ class QueryResult {
302
302
}
303
303
} , this ) ;
304
304
305
- this . getRawData ( ) . forEach ( row => {
306
- filters . forEach ( filter => {
305
+ this . getRawData ( ) . forEach ( ( row ) => {
306
+ filters . forEach ( ( filter ) => {
307
307
filter . values . push ( row [ filter . name ] ) ;
308
308
if ( filter . values . length === 1 ) {
309
309
if ( filter . multiple ) {
@@ -315,8 +315,8 @@ class QueryResult {
315
315
} ) ;
316
316
} ) ;
317
317
318
- filters . forEach ( filter => {
319
- filter . values = uniqBy ( filter . values , v => {
318
+ filters . forEach ( ( filter ) => {
319
+ filter . values = uniqBy ( filter . values , ( v ) => {
320
320
if ( moment . isMoment ( v ) ) {
321
321
return v . unix ( ) ;
322
322
}
@@ -345,12 +345,12 @@ class QueryResult {
345
345
346
346
axios
347
347
. get ( `api/queries/${ queryId } /results/${ id } .json` )
348
- . then ( response => {
348
+ . then ( ( response ) => {
349
349
// Success handler
350
350
queryResult . isLoadingResult = false ;
351
351
queryResult . update ( response ) ;
352
352
} )
353
- . catch ( error => {
353
+ . catch ( ( error ) => {
354
354
// Error handler
355
355
queryResult . isLoadingResult = false ;
356
356
handleErrorResponse ( queryResult , error ) ;
@@ -362,10 +362,10 @@ class QueryResult {
362
362
loadLatestCachedResult ( queryId , parameters ) {
363
363
axios
364
364
. post ( `api/queries/${ queryId } /results` , { queryId, parameters } )
365
- . then ( response => {
365
+ . then ( ( response ) => {
366
366
this . update ( response ) ;
367
367
} )
368
- . catch ( error => {
368
+ . catch ( ( error ) => {
369
369
handleErrorResponse ( this , error ) ;
370
370
} ) ;
371
371
}
@@ -375,11 +375,11 @@ class QueryResult {
375
375
this . deferred . onStatusChange ( ExecutionStatus . LOADING_RESULT ) ;
376
376
377
377
QueryResultResource . get ( { id : this . job . query_result_id } )
378
- . then ( response => {
378
+ . then ( ( response ) => {
379
379
this . update ( response ) ;
380
380
this . isLoadingResult = false ;
381
381
} )
382
- . catch ( error => {
382
+ . catch ( ( error ) => {
383
383
if ( tryCount === undefined ) {
384
384
tryCount = 0 ;
385
385
}
@@ -394,9 +394,12 @@ class QueryResult {
394
394
} ) ;
395
395
this . isLoadingResult = false ;
396
396
} else {
397
- setTimeout ( ( ) => {
398
- this . loadResult ( tryCount + 1 ) ;
399
- } , 1000 * Math . pow ( 2 , tryCount ) ) ;
397
+ setTimeout (
398
+ ( ) => {
399
+ this . loadResult ( tryCount + 1 ) ;
400
+ } ,
401
+ 1000 * Math . pow ( 2 , tryCount )
402
+ ) ;
400
403
}
401
404
} ) ;
402
405
}
@@ -410,7 +413,7 @@ class QueryResult {
410
413
: axios . get ( `api/queries/${ query } /jobs/${ this . job . id } ` ) ;
411
414
412
415
request
413
- . then ( jobResponse => {
416
+ . then ( ( jobResponse ) => {
414
417
this . update ( jobResponse ) ;
415
418
416
419
if ( this . getStatus ( ) === "processing" && this . job . query_result_id && this . job . query_result_id !== "None" ) {
@@ -429,7 +432,7 @@ class QueryResult {
429
432
} , waitTime ) ;
430
433
}
431
434
} )
432
- . catch ( error => {
435
+ . catch ( ( error ) => {
433
436
logger ( "Connection error" , error ) ;
434
437
// TODO: use QueryResultError, or better yet: exception/reject of promise.
435
438
this . update ( {
@@ -458,14 +461,14 @@ class QueryResult {
458
461
459
462
axios
460
463
. post ( `api/queries/${ id } /results` , { id, parameters, apply_auto_limit : applyAutoLimit , max_age : maxAge } )
461
- . then ( response => {
464
+ . then ( ( response ) => {
462
465
queryResult . update ( response ) ;
463
466
464
467
if ( "job" in response ) {
465
468
queryResult . refreshStatus ( id , parameters ) ;
466
469
}
467
470
} )
468
- . catch ( error => {
471
+ . catch ( ( error ) => {
469
472
handleErrorResponse ( queryResult , error ) ;
470
473
} ) ;
471
474
@@ -488,14 +491,14 @@ class QueryResult {
488
491
}
489
492
490
493
QueryResultResource . post ( params )
491
- . then ( response => {
494
+ . then ( ( response ) => {
492
495
queryResult . update ( response ) ;
493
496
494
497
if ( "job" in response ) {
495
498
queryResult . refreshStatus ( query , parameters ) ;
496
499
}
497
500
} )
498
- . catch ( error => {
501
+ . catch ( ( error ) => {
499
502
handleErrorResponse ( queryResult , error ) ;
500
503
} ) ;
501
504
0 commit comments