@@ -35,20 +35,30 @@ define([
3535 const APP_DRAGGABLE = APP_PREFIX + '-draggable' ;
3636
3737 /** select btns */
38+ const APP_SELECT_ADD_ALL_BTN = APP_PREFIX + '-select-add-all-btn' ;
3839 const APP_SELECT_ADD_BTN = APP_PREFIX + '-select-add-btn' ;
3940 const APP_SELECT_DEL_BTN = APP_PREFIX + '-select-del-btn' ;
41+ const APP_SELECT_DEL_ALL_BTN = APP_PREFIX + '-select-del-all-btn' ;
4042
4143
4244 //========================================================================
4345 // [CLASS] ColumnSelector
4446 //========================================================================
4547 class ColumnSelector {
4648
47- constructor ( frameSelector , dataframe , selectedList = [ ] ) {
49+ /**
50+ *
51+ * @param {string } frameSelector query for parent component
52+ * @param {string } dataframe dataframe variable name
53+ * @param {Array<string> } selectedList
54+ * @param {Array<string> } includeList
55+ */
56+ constructor ( frameSelector , dataframe , selectedList = [ ] , includeList = [ ] ) {
4857 this . uuid = 'u' + vpCommon . getUUID ( ) ;
4958 this . frameSelector = frameSelector ;
5059 this . dataframe = dataframe ;
5160 this . selectedList = selectedList ;
61+ this . includeList = includeList ;
5262 this . columnList = [ ] ;
5363 this . pointer = { start : - 1 , end : - 1 } ;
5464
@@ -62,8 +72,12 @@ define([
6272 code : x . value
6373 } ;
6474 } ) ;
65- that . columnList = colList ;
66- that . load ( colList ) ;
75+ if ( includeList && includeList . length > 0 ) {
76+ that . columnList = colList . filter ( col => includeList . includes ( col . code ) ) ;
77+ } else {
78+ that . columnList = colList ;
79+ }
80+ that . load ( ) ;
6781 that . bindEvent ( ) ;
6882 that . bindDraggable ( ) ;
6983 } ) ;
@@ -118,8 +132,14 @@ define([
118132 tag . appendLine ( '</div>' ) ; // APP_SELECT_LEFT
119133 // col select - buttons
120134 tag . appendFormatLine ( '<div class="{0}">' , APP_SELECT_BTN_BOX ) ;
121- tag . appendFormatLine ( '<button type="button" class="{0}">{1}</button>' , APP_SELECT_ADD_BTN , '<img src="/nbextensions/visualpython/resource/arrow_right.svg"/></i>' ) ;
122- tag . appendFormatLine ( '<button type="button" class="{0}">{1}</button>' , APP_SELECT_DEL_BTN , '<img src="/nbextensions/visualpython/resource/arrow_left.svg"/>' ) ;
135+ tag . appendFormatLine ( '<button type="button" class="{0}" title="{1}">{2}</button>'
136+ , APP_SELECT_ADD_ALL_BTN , 'Add all columns' , '<img src="/nbextensions/visualpython/resource/arrow_right_double.svg"/></i>' ) ;
137+ tag . appendFormatLine ( '<button type="button" class="{0}" title="{1}">{2}</button>'
138+ , APP_SELECT_ADD_BTN , 'Add selected columns' , '<img src="/nbextensions/visualpython/resource/arrow_right.svg"/></i>' ) ;
139+ tag . appendFormatLine ( '<button type="button" class="{0}" title="{1}">{2}</button>'
140+ , APP_SELECT_DEL_BTN , 'Remove selected columns' , '<img src="/nbextensions/visualpython/resource/arrow_left.svg"/>' ) ;
141+ tag . appendFormatLine ( '<button type="button" class="{0}" title="{1}">{2}</button>'
142+ , APP_SELECT_DEL_ALL_BTN , 'Remove all columns' , '<img src="/nbextensions/visualpython/resource/arrow_left_double.svg"/>' ) ;
123143 tag . appendLine ( '</div>' ) ; // APP_SELECT_BTNS
124144 // col select - right
125145 tag . appendFormatLine ( '<div class="{0}">' , APP_SELECT_RIGHT ) ;
@@ -240,6 +260,16 @@ define([
240260 }
241261 } ) ;
242262
263+ // item indexing - add all
264+ $ ( this . _wrapSelector ( '.' + APP_SELECT_ADD_ALL_BTN ) ) . on ( 'click' , function ( event ) {
265+ $ ( that . _wrapSelector ( '.' + APP_SELECT_BOX + '.left .' + APP_SELECT_ITEM ) ) . appendTo (
266+ $ ( that . _wrapSelector ( '.' + APP_SELECT_BOX + '.right' ) )
267+ ) ;
268+ $ ( that . _wrapSelector ( '.' + APP_SELECT_ITEM ) ) . addClass ( 'added' ) ;
269+ $ ( that . _wrapSelector ( '.' + APP_SELECT_ITEM + '.selected' ) ) . removeClass ( 'selected' ) ;
270+ that . pointer = { start : - 1 , end : - 1 } ;
271+ } ) ;
272+
243273 // item indexing - add
244274 $ ( this . _wrapSelector ( '.' + APP_SELECT_ADD_BTN ) ) . on ( 'click' , function ( event ) {
245275 var selector = '.selected' ;
@@ -271,6 +301,23 @@ define([
271301 selectedTag . removeClass ( 'selected' ) ;
272302 that . pointer = { start : - 1 , end : - 1 } ;
273303 } ) ;
304+
305+ // item indexing - delete all
306+ $ ( this . _wrapSelector ( '.' + APP_SELECT_DEL_ALL_BTN ) ) . on ( 'click' , function ( event ) {
307+ var targetBoxQuery = that . _wrapSelector ( '.' + APP_SELECT_BOX + '.left' ) ;
308+ $ ( that . _wrapSelector ( '.' + APP_SELECT_BOX + '.right .' + APP_SELECT_ITEM ) ) . appendTo (
309+ $ ( targetBoxQuery )
310+ ) ;
311+ // sort
312+ $ ( targetBoxQuery + ' .' + APP_SELECT_ITEM ) . sort ( function ( a , b ) {
313+ return ( $ ( b ) . data ( 'idx' ) ) < ( $ ( a ) . data ( 'idx' ) ) ? 1 : - 1 ;
314+ } ) . appendTo (
315+ $ ( targetBoxQuery )
316+ ) ;
317+ $ ( that . _wrapSelector ( '.' + APP_SELECT_ITEM ) ) . removeClass ( 'added' ) ;
318+ $ ( that . _wrapSelector ( '.' + APP_SELECT_ITEM + '.selected' ) ) . removeClass ( 'selected' ) ;
319+ that . pointer = { start : - 1 , end : - 1 } ;
320+ } ) ;
274321 }
275322
276323 bindDraggable ( ) {
0 commit comments