@@ -132,7 +132,7 @@ define([
132132 // set button next to input tag
133133 var buttonTag = new com_String ( ) ;
134134 buttonTag . appendFormat ( '<button type="button" class="{0} {1} {2}">{3}</button>' ,
135- VP_DS_BTN , this . uuid , 'vp-button' , 'Edit ' ) ;
135+ VP_DS_BTN , this . uuid , 'vp-button' , 'Subset ' ) ;
136136 if ( this . pageThis ) {
137137 $ ( this . targetSelector ) . parent ( ) . append ( buttonTag . toString ( ) ) ;
138138 }
@@ -448,12 +448,7 @@ define([
448448
449449 tag . appendLine ( '<div class="vp-td-line">' ) ;
450450 tag . appendLine ( this . templateForConditionColumnInput ( colList ) ) ;
451- tag . appendFormatLine ( '<select class="{0} {1}">' , 'vp-select s' , 'vp-oper-list' ) ;
452- var operList = [ '' , '==' , '!=' , 'contains' , 'not contains' , '<' , '<=' , '>' , '>=' , 'starts with' , 'ends with' ] ;
453- operList . forEach ( oper => {
454- tag . appendFormatLine ( '<option value="{0}">{1}</option>' , oper , oper ) ;
455- } ) ;
456- tag . appendLine ( '</select>' ) ;
451+ tag . appendLine ( this . templateForConditionOperator ( '' ) ) ;
457452 tag . appendLine ( '<input class="vp-input m vp-condition" type="text" placeholder="Value"/>' ) ;
458453 tag . appendLine ( '</div>' ) ;
459454
@@ -491,6 +486,22 @@ define([
491486 tag . appendLine ( '</select>' ) ;
492487 return tag . toString ( ) ;
493488 }
489+ templateForConditionOperator ( dtype = 'object' ) {
490+ var tag = new com_String ( ) ;
491+ tag . appendFormatLine ( '<select class="{0} {1}">' , 'vp-select s' , 'vp-oper-list' ) ;
492+ var operList = [ '' , '==' , '!=' , '<' , '<=' , '>' , '>=' , 'contains' , 'not contains' , 'starts with' , 'ends with' , 'isnull()' , 'notnull()' ] ;
493+ if ( dtype == '' ) {
494+ // .index
495+ operList = [ '' , '==' , '!=' , '<' , '<=' , '>' , '>=' ] ;
496+ } else if ( dtype != 'object' ) {
497+ operList = [ '' , '==' , '!=' , '<' , '<=' , '>' , '>=' , 'isnull()' , 'notnull()' ] ;
498+ }
499+ operList . forEach ( oper => {
500+ tag . appendFormatLine ( '<option value="{0}">{1}</option>' , oper , oper ) ;
501+ } ) ;
502+ tag . appendLine ( '</select>' ) ;
503+ return tag . toString ( ) ;
504+ }
494505 templateForConditionCondInput ( category , dtype = 'object' ) {
495506 var vpCondSuggest = new SuggestInput ( ) ;
496507 vpCondSuggest . addClass ( 'vp-input m vp-condition' ) ;
@@ -1331,17 +1342,22 @@ define([
13311342 that . generateCode ( ) ;
13321343 } ) ;
13331344
1345+ // change column selection for condition page
13341346 $ ( document ) . on ( 'change' , this . wrapSelector ( '.vp-ds-cond-tbl .vp-col-list' ) , function ( ) {
13351347 var thisTag = $ ( this ) ;
13361348 var varName = that . state . pandasObject ;
13371349 var colName = $ ( this ) . find ( 'option:selected' ) . attr ( 'data-code' ) ;
13381350 var colDtype = $ ( this ) . find ( 'option:selected' ) . attr ( 'data-dtype' ) ;
13391351
1352+ var operTag = $ ( this ) . closest ( 'td' ) . find ( '.vp-oper-list' ) ;
13401353 var condTag = $ ( this ) . closest ( 'td' ) . find ( '.vp-condition' ) ;
13411354
13421355 if ( colName == '.index' ) {
13431356 // index
13441357 $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
1358+ $ ( operTag ) . replaceWith ( function ( ) {
1359+ return that . templateForConditionOperator ( '' ) ;
1360+ } ) ;
13451361 $ ( condTag ) . replaceWith ( function ( ) {
13461362 return that . templateForConditionCondInput ( [ ] , '' ) ;
13471363 } ) ;
@@ -1358,12 +1374,18 @@ define([
13581374 } else {
13591375 $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
13601376 }
1377+ $ ( operTag ) . replaceWith ( function ( ) {
1378+ return that . templateForConditionOperator ( colDtype ) ;
1379+ } ) ;
13611380 $ ( condTag ) . replaceWith ( function ( ) {
13621381 return that . templateForConditionCondInput ( category , colDtype ) ;
13631382 } ) ;
13641383 that . generateCode ( ) ;
13651384 } catch {
13661385 $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
1386+ $ ( operTag ) . replaceWith ( function ( ) {
1387+ return that . templateForConditionOperator ( colDtype ) ;
1388+ } ) ;
13671389 $ ( condTag ) . replaceWith ( function ( ) {
13681390 return that . templateForConditionCondInput ( [ ] , colDtype ) ;
13691391 } ) ;
@@ -1373,6 +1395,23 @@ define([
13731395 }
13741396 } ) ;
13751397
1398+ // change operator selection
1399+ $ ( document ) . on ( 'change' , this . wrapSelector ( '.vp-ds-cond-tbl .vp-oper-list' ) , function ( ) {
1400+ var oper = $ ( this ) . val ( ) ;
1401+ var condTag = $ ( this ) . closest ( 'td' ) . find ( '.vp-condition' ) ;
1402+ var useTextTag = $ ( this ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) ;
1403+ // var colDtype = $(this).closest('td').find('.vp-col-list option:selected').attr('data-dtype');
1404+
1405+ // if operator is isnull(), notnull(), disable condition input
1406+ if ( oper == 'isnull()' || oper == 'notnull()' ) {
1407+ $ ( condTag ) . prop ( 'disabled' , true ) ;
1408+ $ ( useTextTag ) . prop ( 'disabled' , true ) ;
1409+ } else {
1410+ $ ( condTag ) . prop ( 'disabled' , false ) ;
1411+ $ ( useTextTag ) . prop ( 'disabled' , false ) ;
1412+ }
1413+ } ) ;
1414+
13761415 // use text
13771416 $ ( document ) . on ( 'change' , this . wrapSelector ( '.vp-ds-cond-tbl .vp-cond-use-text' ) , function ( ) {
13781417 that . generateCode ( ) ;
@@ -1507,6 +1546,8 @@ define([
15071546 rowSelection . appendFormat ( '{0}.str.startswith({1})' , colValue , condValue ) ;
15081547 } else if ( oper == 'ends with' ) {
15091548 rowSelection . appendFormat ( '{0}.str.endswith({1})' , colValue , condValue ) ;
1549+ } else if ( oper == 'isnull()' || oper == 'notnull()' ) {
1550+ rowSelection . appendFormat ( '{0}.{1}' , colValue , oper ) ;
15101551 } else {
15111552 rowSelection . appendFormat ( '{0}{1}{2}' , colValue , oper != '' ?( ' ' + oper ) :'' , condValue != '' ?( ' ' + condValue ) :'' ) ;
15121553 }
@@ -1538,6 +1579,8 @@ define([
15381579 rowSelection . appendFormat ( '{0}.str.startswith({1})' , colValue , condValue ) ;
15391580 } else if ( oper == 'ends with' ) {
15401581 rowSelection . appendFormat ( '{0}.str.endswith({1})' , colValue , condValue ) ;
1582+ } else if ( oper == 'isnull()' || oper == 'notnull()' ) {
1583+ rowSelection . appendFormat ( '{0}.{1}' , colValue , oper ) ;
15411584 } else {
15421585 rowSelection . appendFormat ( '{0}{1}{2}' , colValue , oper != '' ?( ' ' + oper ) :'' , condValue != '' ?( ' ' + condValue ) :'' ) ;
15431586 }
0 commit comments