@@ -49,13 +49,14 @@ define([
4949 id : '' , // target id
5050 finish : null , // callback after selection
5151 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
5353 // additional options
5454 classes : '' ,
5555 ...this . prop
5656 }
5757
5858 this . state = {
59+ filterType : 'All' ,
5960 data : '' ,
6061 dataType : '' ,
6162 slicingStart : '' ,
@@ -168,11 +169,13 @@ define([
168169 let result = true ;
169170 // trigger change
170171 $ ( this ) . val ( ui . item . value ) ;
172+ $ ( this ) . attr ( 'data-type' , ui . item . dtype ) ;
171173 $ ( this ) . trigger ( 'change' ) ;
172174
173175 // select event
174- if ( typeof that . prop . select == "function" )
176+ if ( typeof that . prop . select == "function" ) {
175177 result = that . prop . select ( ui . item . value , ui . item ) ;
178+ }
176179 if ( result != undefined ) {
177180 return result ;
178181 }
@@ -213,7 +216,7 @@ define([
213216 let newValue = that . generateCode ( ) ;
214217
215218 $ ( that . _target ) . val ( newValue ) ;
216- $ ( that . _target ) . data ( ' type', that . state . dataType ) ;
219+ $ ( that . _target ) . attr ( 'data- type', that . state . dataType ) ;
217220 that . prop . finish ( newValue ) ;
218221 that . close ( ) ;
219222 } ) ;
@@ -225,6 +228,24 @@ define([
225228 _bindEventForItem ( ) {
226229 let that = this ;
227230
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+
228249 // Click variable item
229250 $ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . off ( 'click' ) ;
230251 // $(that.wrapSelector('.vp-ds-var-item')).on('click', function() {
@@ -233,17 +254,17 @@ define([
233254 $ ( that . wrapSelector ( '.vp-ds-var-item' ) ) . removeClass ( 'selected' ) ;
234255 $ ( this ) . addClass ( 'selected' ) ;
235256
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') ;
238259 that . state . data = data ;
239260 that . state . dataType = dataType ;
240261
241262 // render option page
242263 that . renderOptionPage ( ) ;
243264 } , function ( evt ) {
244265 // 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') ;
247268 that . state . data = data ;
248269 that . state . dataType = dataType ;
249270
@@ -277,10 +298,8 @@ define([
277298 } ) ;
278299
279300 that . _varList = varList ;
280-
281-
282-
283- that . renderVariables ( varList ) ;
301+
302+ that . renderDataBox ( varList ) ;
284303 that . _bindAutocomplete ( varList ) ;
285304
286305 } ) ;
@@ -329,20 +348,36 @@ define([
329348 /** Render popup on clicking filter button */
330349 renderPopup ( ) {
331350 super . render ( ) ;
351+
332352 this . loadVariables ( ) ;
333353 this . _bindEventForPopup ( ) ;
354+ }
334355
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 ( ) ) ;
336370
371+ this . renderVariableBox ( varList ) ;
337372 }
338373
339- renderVariables ( varList ) {
374+ renderVariableBox ( varList ) {
375+ let that = this ;
340376 let varTags = new com_String ( ) ;
377+ varTags = new com_String ( ) ;
341378 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 ) ;
346381 } ) ;
347382 $ ( this . wrapSelector ( '.vp-ds-variable-box' ) ) . html ( varTags . toString ( ) ) ;
348383
0 commit comments