4
4
5
5
import { take , fork , cancel } from 'redux-saga/effects' ;
6
6
import { get , set , unset , has , isEmpty , isUndefined , uniqueId , cloneDeep , omit , omitBy , isNil , isPlainObject , isArray , padEnd } from 'lodash' ;
7
+ import Enum from 'enum' ;
7
8
8
9
import * as TblCntlr from './TablesCntlr.js' ;
9
10
import { SortInfo , SORT_ASC , UNSORTED } from './SortInfo.js' ;
@@ -17,10 +18,13 @@ import {ServerParams} from '../data/ServerParams.js';
17
18
import { doUpload } from '../ui/FileUpload.jsx' ;
18
19
import { dispatchAddSaga } from '../core/MasterSaga.js' ;
19
20
21
+ export const COL_TYPE = new Enum ( [ 'NUMBER' , 'TEXT' ] ) ;
20
22
export const MAX_ROW = Math . pow ( 2 , 31 ) - 1 ;
21
23
/* TABLE_REQUEST should match QueryUtil on the server-side */
22
24
23
25
const LSSTQueryPID = 'LSSTCataLogSearch' ;
26
+
27
+
24
28
/**
25
29
* @public
26
30
*/
@@ -928,6 +932,31 @@ export function watchTableChanges(tbl_id, actions, callback) {
928
932
return ( ) => stopWatching = true ;
929
933
}
930
934
935
+
936
+ /**
937
+ * @summary returns the columns array of the given table.
938
+ * @param {TableModel } tableModel
939
+ * @returns {Array<TableColumn> }
940
+ */
941
+ export function getColumns ( tableModel ) {
942
+ return get ( tableModel , 'tableData.columns' , [ ] ) ;
943
+ }
944
+
945
+ /**
946
+ * @summary returns only the visible columns matching the given type.
947
+ * @param {Array<TableColumn> } tblColumns
948
+ * @param {COL_TYPE } type one of predefined COL_TYPE('NUMBER' | 'TEXT'). defaults to 'NUMBER'.
949
+ * @returns {Array<TableColumn> }
950
+ */
951
+ export function getColsByType ( tblColumns = [ ] , type = COL_TYPE . NUMBER ) {
952
+ const charTypes = [ 'char' , 'c' , 's' , 'str' ] ;
953
+ const numTypes = [ 'double' , 'd' , 'long' , 'l' , 'int' , 'i' , 'float' , 'f' ] ;
954
+ const matcher = type === COL_TYPE . TEXT ? charTypes : numTypes ;
955
+ return tblColumns . filter ( ( col ) => get ( col , 'visibility' ) !== 'hidden' && matcher . includes ( col . type ) ) ;
956
+ }
957
+
958
+
959
+
931
960
/*-------------------------------------private------------------------------------------------*/
932
961
/**
933
962
* this saga watches for table update and invoke the given callback when
@@ -955,83 +984,3 @@ function* doOnTblLoaded({tbl_id, callback}) {
955
984
}
956
985
callback && callback ( getTblInfoById ( tbl_id ) ) ;
957
986
}
958
-
959
-
960
-
961
- /**
962
- * Returns only numerical column names form raw lc table
963
- * @param {Object } rawTbl
964
- * @returns {string[] } - array of table columns objects
965
- */
966
- export function getOnlyNumericalColNames ( rawTbl ) {
967
- const cols = get ( rawTbl , [ 'tableData' , 'columns' ] ) ;
968
- const colType = getColumnTypes ( cols , 'numeric' ) ;
969
- return get ( rawTbl , [ 'tableData' , 'columns' ] ) . reduce ( ( prev , col ) => {
970
- if ( ( colType . includes ( col . type ) ) ) {
971
- prev . push ( col . name ) ;
972
- }
973
- return prev ;
974
- } , [ ] ) ;
975
- }
976
-
977
-
978
- /**
979
- * @summary get column names from the column of string or char type
980
- * @param {Array } tblColumns
981
- * @returns {Array }
982
- */
983
- export function getStringColNames ( tblColumns ) {
984
- const CharTypes = [ 'char' , 'c' , 's' , 'str' ] ;
985
-
986
- return isEmpty ( tblColumns ) ? [ ] :
987
- tblColumns . filter ( ( tblCol ) => ( get ( tblCol , 'visibility' , '' ) !== 'hidden' ) )
988
- . filter ( ( tblCol ) => ( CharTypes . includes ( tblCol . type ) ) )
989
- . map ( ( tblCol ) => ( tblCol . name ) ) ;
990
- }
991
-
992
- /**
993
- * @summary get column names from the column of numeric type
994
- * @param {Array } tblColumns
995
- * @returns {Array }
996
- */
997
- export function getNumericColNames ( tblColumns ) {
998
- const NumTypes = [ 'double' , 'd' , 'long' , 'l' , 'int' , 'i' , 'float' , 'f' ] ;
999
-
1000
- return isEmpty ( tblColumns ) ? [ ] :
1001
- tblColumns . filter ( ( tblCol ) => ( get ( tblCol , 'visibility' , '' ) !== 'hidden' ) )
1002
- . filter ( ( tblCol ) => ( NumTypes . includes ( tblCol . type ) ) )
1003
- . map ( ( tblCol ) => ( tblCol . name ) ) ;
1004
- }
1005
-
1006
- export function getColNames ( tblColumns , colTypes ) {
1007
- return isEmpty ( tblColumns ) ?[ ] :
1008
- tblColumns . reduce ( ( prev , col ) => {
1009
- if ( colTypes && colTypes . includes ( col . type ) ) {
1010
- prev . push ( col . name ) ;
1011
- }
1012
- else {
1013
- prev . push ( col . name ) ;
1014
- }
1015
- return prev ;
1016
- } , [ ] ) ;
1017
- }
1018
-
1019
- export function getColumnTypes ( cols , type = undefined ) {
1020
- // const cols = get(tblModel, ['tableData', 'columns']);
1021
- var types = [ ] ;
1022
- for ( let i = 0 ; i < cols . length ; i ++ ) {
1023
- if ( types . indexOf ( cols [ i ] . type ) > - 1 ) continue ;
1024
- if ( ! has ( cols [ i ] , 'visibility' ) || get ( cols [ i ] , 'visibility' ) !== 'hidden' ) {
1025
- if ( ! type || type === 'numeric' ) {
1026
- if ( cols [ i ] . type !== 'char' && cols [ i ] . type . toLowerCase ( ) !== 'string' ) {
1027
- types [ i ] = cols [ i ] . type ;
1028
- }
1029
- }
1030
- else {
1031
- types [ i ] = cols [ i ] . type ;
1032
- }
1033
- }
1034
- }
1035
- return types ;
1036
-
1037
- }
0 commit comments