@@ -35,20 +35,30 @@ define([
35
35
const APP_DRAGGABLE = APP_PREFIX + '-draggable' ;
36
36
37
37
/** select btns */
38
+ const APP_SELECT_ADD_ALL_BTN = APP_PREFIX + '-select-add-all-btn' ;
38
39
const APP_SELECT_ADD_BTN = APP_PREFIX + '-select-add-btn' ;
39
40
const APP_SELECT_DEL_BTN = APP_PREFIX + '-select-del-btn' ;
41
+ const APP_SELECT_DEL_ALL_BTN = APP_PREFIX + '-select-del-all-btn' ;
40
42
41
43
42
44
//========================================================================
43
45
// [CLASS] ColumnSelector
44
46
//========================================================================
45
47
class ColumnSelector {
46
48
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 = [ ] ) {
48
57
this . uuid = 'u' + vpCommon . getUUID ( ) ;
49
58
this . frameSelector = frameSelector ;
50
59
this . dataframe = dataframe ;
51
60
this . selectedList = selectedList ;
61
+ this . includeList = includeList ;
52
62
this . columnList = [ ] ;
53
63
this . pointer = { start : - 1 , end : - 1 } ;
54
64
@@ -62,8 +72,12 @@ define([
62
72
code : x . value
63
73
} ;
64
74
} ) ;
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 ( ) ;
67
81
that . bindEvent ( ) ;
68
82
that . bindDraggable ( ) ;
69
83
} ) ;
@@ -118,8 +132,14 @@ define([
118
132
tag . appendLine ( '</div>' ) ; // APP_SELECT_LEFT
119
133
// col select - buttons
120
134
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"/>' ) ;
123
143
tag . appendLine ( '</div>' ) ; // APP_SELECT_BTNS
124
144
// col select - right
125
145
tag . appendFormatLine ( '<div class="{0}">' , APP_SELECT_RIGHT ) ;
@@ -240,6 +260,16 @@ define([
240
260
}
241
261
} ) ;
242
262
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
+
243
273
// item indexing - add
244
274
$ ( this . _wrapSelector ( '.' + APP_SELECT_ADD_BTN ) ) . on ( 'click' , function ( event ) {
245
275
var selector = '.selected' ;
@@ -271,6 +301,23 @@ define([
271
301
selectedTag . removeClass ( 'selected' ) ;
272
302
that . pointer = { start : - 1 , end : - 1 } ;
273
303
} ) ;
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
+ } ) ;
274
321
}
275
322
276
323
bindDraggable ( ) {
0 commit comments