@@ -19,8 +19,9 @@ define([
19
19
'vp_base/js/com/com_util' ,
20
20
'vp_base/js/com/component/PopupComponent' ,
21
21
'vp_base/js/com/component/SuggestInput' ,
22
- 'vp_base/js/com/component/VarSelector'
23
- ] , function ( frameHtml , frameCss , com_String , com_util , PopupComponent , SuggestInput , VarSelector ) {
22
+ 'vp_base/js/com/component/VarSelector' ,
23
+ 'vp_base/js/m_apps/Subset'
24
+ ] , function ( frameHtml , frameCss , com_String , com_util , PopupComponent , SuggestInput , VarSelector , Subset ) {
24
25
25
26
/**
26
27
* Frame
@@ -61,6 +62,10 @@ define([
61
62
'bool' , 'str'
62
63
] ;
63
64
65
+ // Add/Replace - subset
66
+ this . subsetCm = null ;
67
+ this . subsetEditor = null ;
68
+
64
69
this . loading = false ;
65
70
66
71
this . _addCodemirror ( 'previewCode' , this . wrapSelector ( '#vp_fePreviewCode' ) , 'readonly' ) ;
@@ -581,6 +586,9 @@ define([
581
586
// render variable list
582
587
// get prevvalue
583
588
var prevValue = that . state . originObj ;
589
+ if ( varList && varList . length > 0 && prevValue == '' ) {
590
+ prevValue = varList [ 0 ] . varName ;
591
+ }
584
592
// replace
585
593
that . renderVariableList ( varList , prevValue ) ;
586
594
$ ( that . wrapSelector ( '#vp_feVariable' ) ) . trigger ( 'change' ) ;
@@ -610,6 +618,9 @@ define([
610
618
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'value' , 'Value' ) ;
611
619
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'calculation' , 'Calculation' ) ;
612
620
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'replace' , 'Replace' ) ;
621
+ if ( type == 'column' || type == 'replace' ) {
622
+ content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'subset' , 'Subset' ) ;
623
+ }
613
624
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'apply' , 'Apply' ) ;
614
625
content . appendLine ( '</select></td></tr>' ) ;
615
626
content . appendLine ( '</table>' ) ;
@@ -656,8 +667,25 @@ define([
656
667
content . appendFormatLine ( '<div class="{0} {1} {2}" style="display: none;">' , 'vp-inner-popup-tab' , 'replace' , 'vp-scrollbar' ) ;
657
668
content . appendLine ( this . renderReplacePage ( ) ) ;
658
669
content . appendLine ( '</div>' ) ; // end of vp-inner-popup-tab replace
659
-
660
- // tab 4. apply
670
+
671
+ // tab 4. subset
672
+ if ( type == 'column' || type == 'replace' ) {
673
+ content . appendFormatLine ( '<div class="{0} {1}" style="display: none;">' , 'vp-inner-popup-tab' , 'subset' ) ;
674
+ content . appendLine ( '<table class="vp-tbl-gap5"><colgroup><col width="80px"><col width="*"></colgroup>' ) ;
675
+
676
+ content . appendLine ( '<tr><td colspan="2">' ) ;
677
+ content . appendLine ( '<div class="vp-fr-subset-box">' ) ;
678
+ content . appendLine ( '<textarea class="vp-input vp-inner-popup-subset"></textarea>' ) ;
679
+ content . appendLine ( '</div>' ) ;
680
+ content . appendLine ( '</td></tr>' ) ;
681
+
682
+ content . appendLine ( '<tr><th><label>Value</label></th>' ) ;
683
+ content . appendFormatLine ( '<td><input type="text" class="{0}"/>' , 'vp-inner-popup-input3' ) ;
684
+ content . appendFormatLine ( '<label><input type="checkbox" class="{0}" checked/><span>{1}</span></label>' , 'vp-inner-popup-istext3' , 'Text' ) ;
685
+ content . appendLine ( '</td></tr></table>' ) ;
686
+ content . appendLine ( '</div>' ) ; // end of vp-inner-popup-tab subset
687
+ }
688
+ // tab 5. apply
661
689
content . appendFormatLine ( '<div class="{0} {1}" style="display: none;">' , 'vp-inner-popup-tab' , 'apply' ) ;
662
690
content . appendLine ( '<table class="vp-tbl-gap5"><colgroup><col width="80px"><col width="*"></colgroup>' ) ;
663
691
content . appendLine ( '<tr><th><label>Column</label></th>' ) ;
@@ -668,6 +696,9 @@ define([
668
696
content . appendLine ( '</tr></table>' ) ;
669
697
content . appendLine ( '</div>' ) ; // end of vp-inner-popup-tab apply
670
698
content . appendLine ( '</div>' ) ; // end of vp-inner-popup-addpage
699
+
700
+ // set content
701
+ $ ( this . wrapSelector ( '.vp-inner-popup-body' ) ) . html ( content . toString ( ) ) ;
671
702
return content . toString ( ) ;
672
703
}
673
704
@@ -695,10 +726,13 @@ define([
695
726
} ) ;
696
727
content . appendLine ( '</table>' ) ;
697
728
content . appendLine ( '</div>' ) ;
729
+
730
+ // set content
731
+ $ ( this . wrapSelector ( '.vp-inner-popup-body' ) ) . html ( content . toString ( ) ) ;
698
732
return content . toString ( ) ;
699
733
}
700
734
701
- renderReplacePage = function ( ) {
735
+ renderReplacePage ( ) {
702
736
var content = new com_String ( ) ;
703
737
content . appendFormatLine ( '<label><input type="checkbox" class="{0}"/><span>{1}</span></label>' , 'vp-inner-popup-use-regex' , 'Use Regular Expression' ) ;
704
738
content . appendLine ( '<br/><br/>' ) ;
@@ -711,7 +745,7 @@ define([
711
745
return content . toString ( ) ;
712
746
}
713
747
714
- renderReplaceInput = function ( index ) {
748
+ renderReplaceInput ( index ) {
715
749
var content = new com_String ( ) ;
716
750
content . appendLine ( '<tr>' ) ;
717
751
content . appendLine ( '<td>' ) ;
@@ -727,7 +761,7 @@ define([
727
761
return content . toString ( ) ;
728
762
}
729
763
730
- renderAsType = function ( ) {
764
+ renderAsType ( ) {
731
765
var astypeList = this . astypeList ;
732
766
var content = new com_String ( ) ;
733
767
content . appendFormatLine ( '<div class="{0}">' , 'vp-inner-popup-astype' ) ;
@@ -750,18 +784,52 @@ define([
750
784
} ) ;
751
785
content . appendLine ( '</tbody></table>' ) ;
752
786
content . append ( '</div>' ) ;
787
+
788
+ // set content
789
+ $ ( this . wrapSelector ( '.vp-inner-popup-body' ) ) . html ( content . toString ( ) ) ;
753
790
return content . toString ( ) ;
754
791
}
755
792
756
- openInputPopup = function ( type , width = 400 , height = 400 ) {
793
+ openInputPopup ( type , width = 400 , height = 400 ) {
757
794
var title = '' ;
758
795
var content = '' ;
759
796
let size = { width : width , height : height } ;
797
+ let that = this ;
760
798
761
799
switch ( parseInt ( type ) ) {
762
800
case FRAME_EDIT_TYPE . ADD_COL :
763
801
title = 'Add Column' ;
764
802
content = this . renderAddPage ( 'column' , 'Column Name' ) ;
803
+
804
+ // bind codemirror
805
+ this . subsetCm = this . initCodemirror ( {
806
+ key : 'vp-inner-popup-subset' ,
807
+ selector : this . wrapSelector ( '.vp-inner-popup-subset' ) ,
808
+ type : 'readonly'
809
+ } ) ;
810
+ // set subset
811
+ this . subsetEditor = new Subset ( {
812
+ pandasObject : this . state . tempObj ,
813
+ config : { name : 'Subset' } } ,
814
+ {
815
+ useInputVariable : true ,
816
+ useInputColumns : true ,
817
+ targetSelector : this . wrapSelector ( '.vp-inner-popup-subset' ) ,
818
+ pageThis : this ,
819
+ allowSubsetTypes : [ 'iloc' , 'loc' ] ,
820
+ beforeOpen : function ( subsetThis ) {
821
+ let contentState = that . getPopupContent ( type ) ;
822
+ let name = com_util . convertToStr ( contentState . name , contentState . nameastext ) ;
823
+ subsetThis . state . selectedColumns = [ name ] ;
824
+ } ,
825
+ finish : function ( code ) {
826
+ that . subsetCm . setValue ( code ) ;
827
+ that . subsetCm . save ( ) ;
828
+ setTimeout ( function ( ) {
829
+ that . subsetCm . refresh ( ) ;
830
+ } , 1 ) ;
831
+ }
832
+ } ) ;
765
833
break ;
766
834
case FRAME_EDIT_TYPE . ADD_ROW :
767
835
title = 'Add Row' ;
@@ -775,6 +843,34 @@ define([
775
843
title = 'Replace' ;
776
844
// content = this.renderReplacePage();
777
845
content = this . renderAddPage ( 'replace' , 'Column' ) ;
846
+
847
+ // bind codemirror
848
+ this . subsetCm = this . initCodemirror ( {
849
+ key : 'vp-inner-popup-subset' ,
850
+ selector : this . wrapSelector ( '.vp-inner-popup-subset' ) ,
851
+ type : 'readonly'
852
+ } ) ;
853
+ // set subset
854
+ this . subsetEditor = new Subset ( {
855
+ pandasObject : this . state . tempObj ,
856
+ config : { name : 'Subset' } } ,
857
+ {
858
+ useInputVariable : true ,
859
+ useInputColumns : true ,
860
+ targetSelector : this . wrapSelector ( '.vp-inner-popup-subset' ) ,
861
+ pageThis : this ,
862
+ allowSubsetTypes : [ 'iloc' , 'loc' ] ,
863
+ beforeOpen : function ( subsetThis ) {
864
+ subsetThis . state . selectedColumns = that . state . selected . map ( col => col . code ) ;
865
+ } ,
866
+ finish : function ( code ) {
867
+ that . subsetCm . setValue ( code ) ;
868
+ that . subsetCm . save ( ) ;
869
+ setTimeout ( function ( ) {
870
+ that . subsetCm . refresh ( ) ;
871
+ } , 1 ) ;
872
+ }
873
+ } ) ;
778
874
break ;
779
875
case FRAME_EDIT_TYPE . AS_TYPE :
780
876
title = 'Convert type' ;
@@ -789,15 +885,10 @@ define([
789
885
790
886
// set size
791
887
$ ( this . wrapSelector ( '.vp-inner-popup-box' ) ) . css ( size ) ;
792
-
793
- // set content
794
- $ ( this . wrapSelector ( '.vp-inner-popup-body' ) ) . html ( content ) ;
795
888
796
889
// bindEventForAddPage
797
890
this . bindEventForPopupPage ( ) ;
798
891
799
- let that = this ;
800
-
801
892
// set column list
802
893
vpKernel . getColumnList ( this . state . tempObj ) . then ( function ( resultObj ) {
803
894
let { result } = resultObj ;
@@ -865,6 +956,10 @@ define([
865
956
} ) ;
866
957
}
867
958
}
959
+ } else if ( tab == 'subset' ) {
960
+ content [ 'subset' ] = this . subsetCm ?this . subsetCm . getValue ( ) :'' ;
961
+ content [ 'value' ] = $ ( this . wrapSelector ( '.vp-inner-popup-input3' ) ) . val ( ) ;
962
+ content [ 'valueastext' ] = $ ( this . wrapSelector ( '.vp-inner-popup-istext3' ) ) . prop ( 'checked' ) ;
868
963
} else if ( tab == 'apply' ) {
869
964
content [ 'column' ] = $ ( this . wrapSelector ( '.vp-inner-popup-apply-column' ) ) . val ( ) ;
870
965
content [ 'apply' ] = $ ( this . wrapSelector ( '.vp-inner-popup-apply-lambda' ) ) . val ( ) ;
@@ -1094,12 +1189,12 @@ define([
1094
1189
var tab = content . addtype ;
1095
1190
if ( tab == 'value' ) {
1096
1191
var value = com_util . convertToStr ( content . value , content . valueastext ) ;
1097
- code . appendFormat ( "{0}[{1}] = {2}" , tempObj , name , value ) ;
1192
+ code . appendFormat ( "{0}[[ {1}] ] = {2}" , tempObj , name , value ) ;
1098
1193
} else if ( tab == 'calculation' ) {
1099
1194
var { var1col, oper, var2col } = content ;
1100
1195
var var1code = tempObj + "['" + var1col + "']" ;
1101
1196
var var2code = tempObj + "['" + var2col + "']" ;
1102
- code . appendFormat ( '{0}[{1}] = {2} {3} {4}' , tempObj , name , var1code , oper , var2code ) ;
1197
+ code . appendFormat ( '{0}[[ {1}] ] = {2} {3} {4}' , tempObj , name , var1code , oper , var2code ) ;
1103
1198
} else if ( tab == 'replace' ) {
1104
1199
var replaceStr = new com_String ( ) ;
1105
1200
var useRegex = content [ 'useregex' ] ;
@@ -1122,8 +1217,11 @@ define([
1122
1217
code . append ( ', regex=True' ) ;
1123
1218
}
1124
1219
code . append ( ')' ) ;
1220
+ } else if ( tab == 'subset' ) {
1221
+ var value = com_util . convertToStr ( content . value , content . valueastext ) ;
1222
+ code . appendFormat ( "{0} = {1}" , content . subset , value ) ;
1125
1223
} else if ( tab == 'apply' ) {
1126
- code . appendFormat ( "{0}[{1}] = {2}[{3}].apply({4})" , tempObj , name , tempObj , content . column , content . apply ) ;
1224
+ code . appendFormat ( "{0}[[ {1}] ] = {2}[{3}].apply({4})" , tempObj , name , tempObj , content . column , content . apply ) ;
1127
1225
}
1128
1226
break ;
1129
1227
case FRAME_EDIT_TYPE . ADD_ROW :
@@ -1335,6 +1433,21 @@ define([
1335
1433
$ ( this . wrapSelector ( com_util . formatString ( '.{0}' , VP_FE_MENU_BOX ) ) ) . hide ( ) ;
1336
1434
}
1337
1435
1436
+ hide ( ) {
1437
+ super . hide ( ) ;
1438
+ this . subsetEditor && this . subsetEditor . hide ( ) ;
1439
+ }
1440
+
1441
+ close ( ) {
1442
+ super . close ( ) ;
1443
+ this . subsetEditor && this . subsetEditor . close ( ) ;
1444
+ }
1445
+
1446
+ remove ( ) {
1447
+ super . remove ( ) ;
1448
+ this . subsetEditor && this . subsetEditor . remove ( ) ;
1449
+ }
1450
+
1338
1451
}
1339
1452
1340
1453
const VP_FE_BTN = 'vp-fe-btn' ;
0 commit comments