@@ -49,13 +49,14 @@ define([
49
49
id : '' , // target id
50
50
finish : null , // callback after selection
51
51
select : null , // callback after selection from suggestInput
52
- allowDataType : [ ] , // default allow data types (All)
52
+ allowDataType : [ 'DataFrame' , 'Series' , 'ndarray' , 'list' , 'dict' ] , // default allow data types
53
53
// additional options
54
54
classes : '' ,
55
55
...this . prop
56
56
}
57
57
58
58
this . state = {
59
+ filterType : 'All' ,
59
60
data : '' ,
60
61
dataType : '' ,
61
62
slicingStart : '' ,
@@ -168,11 +169,13 @@ define([
168
169
let result = true ;
169
170
// trigger change
170
171
$ ( this ) . val ( ui . item . value ) ;
172
+ $ ( this ) . attr ( 'data-type' , ui . item . dtype ) ;
171
173
$ ( this ) . trigger ( 'change' ) ;
172
174
173
175
// select event
174
- if ( typeof that . prop . select == "function" )
176
+ if ( typeof that . prop . select == "function" ) {
175
177
result = that . prop . select ( ui . item . value , ui . item ) ;
178
+ }
176
179
if ( result != undefined ) {
177
180
return result ;
178
181
}
@@ -213,7 +216,7 @@ define([
213
216
let newValue = that . generateCode ( ) ;
214
217
215
218
$ ( that . _target ) . val ( newValue ) ;
216
- $ ( that . _target ) . data ( ' type', that . state . dataType ) ;
219
+ $ ( that . _target ) . attr ( 'data- type', that . state . dataType ) ;
217
220
that . prop . finish ( newValue ) ;
218
221
that . close ( ) ;
219
222
} ) ;
@@ -225,6 +228,24 @@ define([
225
228
_bindEventForItem ( ) {
226
229
let that = this ;
227
230
231
+ // Click data type item
232
+ $ ( that . wrapSelector ( '.vp-ds-type-item' ) ) . off ( 'click' ) ;
233
+ $ ( that . wrapSelector ( '.vp-ds-type-item' ) ) . on ( 'click' , function ( ) {
234
+ $ ( that . wrapSelector ( '.vp-ds-type-item' ) ) . removeClass ( 'selected' ) ;
235
+ $ ( this ) . addClass ( 'selected' ) ;
236
+
237
+ let type = $ ( this ) . data ( 'type' ) ;
238
+ if ( type == 'All' ) {
239
+ that . renderVariableBox ( that . _varList ) ;
240
+ } else if ( type == 'Others' ) {
241
+ that . renderVariableBox ( that . _varList . filter ( obj => ! that . prop . allowDataType . includes ( obj . dtype ) ) ) ;
242
+ } else {
243
+ // filter variable list
244
+ that . renderVariableBox ( that . _varList . filter ( obj => obj . dtype == type ) ) ;
245
+ }
246
+
247
+ } ) ;
248
+
228
249
// Click variable item
229
250
$ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . off ( 'click' ) ;
230
251
// $(that.wrapSelector('.vp-ds-var-item')).on('click', function() {
@@ -233,17 +254,17 @@ define([
233
254
$ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . removeClass ( 'selected' ) ;
234
255
$ ( this ) . addClass ( 'selected' ) ;
235
256
236
- let data = $ ( this ) . find ( '.vp-ds-var-data' ) . text ( ) ;
237
- let dataType = $ ( this ) . find ( '.vp-ds-var- type') . text ( ) ;
257
+ let data = $ ( this ) . text ( ) ;
258
+ let dataType = $ ( this ) . data ( ' type') ;
238
259
that . state . data = data ;
239
260
that . state . dataType = dataType ;
240
261
241
262
// render option page
242
263
that . renderOptionPage ( ) ;
243
264
} , function ( evt ) {
244
265
// double click to select directly
245
- let data = $ ( this ) . find ( '.vp-ds-var-data' ) . text ( ) ;
246
- let dataType = $ ( this ) . find ( '.vp-ds-var- type') . text ( ) ;
266
+ let data = $ ( this ) . text ( ) ;
267
+ let dataType = $ ( this ) . data ( ' type') ;
247
268
that . state . data = data ;
248
269
that . state . dataType = dataType ;
249
270
@@ -277,10 +298,8 @@ define([
277
298
} ) ;
278
299
279
300
that . _varList = varList ;
280
-
281
-
282
-
283
- that . renderVariables ( varList ) ;
301
+
302
+ that . renderDataBox ( varList ) ;
284
303
that . _bindAutocomplete ( varList ) ;
285
304
286
305
} ) ;
@@ -329,20 +348,36 @@ define([
329
348
/** Render popup on clicking filter button */
330
349
renderPopup ( ) {
331
350
super . render ( ) ;
351
+
332
352
this . loadVariables ( ) ;
333
353
this . _bindEventForPopup ( ) ;
354
+ }
334
355
335
- //TODO:
356
+ renderDataBox ( varList ) {
357
+ let that = this ;
358
+ let varTags = new com_String ( ) ;
359
+ let types = [
360
+ 'All' ,
361
+ ...this . prop . allowDataType ,
362
+ 'Others'
363
+ ] ;
364
+ // Add Data Types to filter
365
+ types && types . forEach ( type => {
366
+ varTags . appendFormatLine ( '<div class="{0} {1}" data-type="{2}">{3}</div>'
367
+ , 'vp-ds-type-item' , ( that . state . filterType == type ? 'selected' : '' ) , type , type ) ;
368
+ } ) ;
369
+ $ ( this . wrapSelector ( '.vp-ds-type-box' ) ) . html ( varTags . toString ( ) ) ;
336
370
371
+ this . renderVariableBox ( varList ) ;
337
372
}
338
373
339
- renderVariables ( varList ) {
374
+ renderVariableBox ( varList ) {
375
+ let that = this ;
340
376
let varTags = new com_String ( ) ;
377
+ varTags = new com_String ( ) ;
341
378
varList && varList . forEach ( ( obj , idx ) => {
342
- varTags . appendFormatLine ( '<div class="{0} {1}">' , 'vp-ds-var-item' , 'vp-grid-col-p50' ) ;
343
- varTags . appendFormatLine ( '<div class="{0}">{1}</div>' , 'vp-ds-var-data' , obj . label ) ;
344
- varTags . appendFormatLine ( '<div class="{0}">{1}</div>' , 'vp-ds-var-type' , obj . dtype ) ;
345
- varTags . appendLine ( '</div>' ) ;
379
+ varTags . appendFormatLine ( '<div class="{0} {1}" title="{2}" data-type="{3}">{4}</div>'
380
+ , 'vp-ds-var-item' , ( that . state . data == obj . value ?'selected' :'' ) , obj . dtype , obj . dtype , obj . label ) ;
346
381
} ) ;
347
382
$ ( this . wrapSelector ( '.vp-ds-variable-box' ) ) . html ( varTags . toString ( ) ) ;
348
383
0 commit comments