@@ -50,14 +50,17 @@ const local = {
5050} ;
5151export default local ;
5252
53- export const COL_TYPE = new Enum ( [ 'ALL' , 'NUMBER' , 'TEXT' , 'INT' , 'FLOAT' ] ) ;
53+ const TEXT = [ 'char' , 'c' , 's' , 'str' ] ;
54+ const INT = [ 'long' , 'l' , 'int' , 'i' ] ;
55+ const FLOAT = [ 'double' , 'd' , 'float' , 'f' ] ;
56+ const BOOL = [ 'boolean' , 'bool' ] ;
57+ const DATE = [ 'date' ] ;
58+ const NUMBER = [ ...INT , ...FLOAT ] ;
59+ const USE_STRING = [ ...TEXT , ...DATE ] ;
60+
61+ // export const COL_TYPE = new Enum(['ALL', 'NUMBER', 'TEXT', 'INT', 'FLOAT']);
62+ export const COL_TYPE = new Enum ( { ANY :[ ] , TEXT , INT , FLOAT , BOOL , DATE , NUMBER , USE_STRING } ) ;
5463
55- const colTypes = {
56- [ COL_TYPE . TEXT ] : [ 'char' , 'c' , 's' , 'str' ] ,
57- [ COL_TYPE . INT ] : [ 'long' , 'l' , 'int' , 'i' ] ,
58- [ COL_TYPE . FLOAT ] : [ 'double' , 'd' , 'float' , 'f' ] ,
59- [ COL_TYPE . NUMBER ] : [ 'long' , 'l' , 'int' , 'i' , 'double' , 'd' , 'float' , 'f' ] ,
60- } ;
6164
6265/**
6366 * @param {TableColumn } col
@@ -67,7 +70,7 @@ const colTypes = {
6770export function isColumnType ( col = { } , type ) {
6871 const flg = '_t-' + type . key ; // for efficiency
6972 if ( ! has ( col , flg ) ) {
70- col [ flg ] = ! colTypes [ type ] || isOfType ( col . type , type ) ;
73+ col [ flg ] = isOfType ( col . type , type ) ;
7174 }
7275 return col [ flg ] ;
7376}
@@ -79,7 +82,7 @@ export function isColumnType(col={}, type) {
7982 * @returns {boolean }
8083 */
8184export function isOfType ( s , type ) {
82- return colTypes [ type ] . includes ( s ) ;
85+ return type === COL_TYPE . ANY || COL_TYPE [ type ] . value . includes ( s ) ;
8386}
8487
8588export function isClientTable ( tbl_id ) {
@@ -1244,13 +1247,13 @@ export function monitorChanges(actions, accept, callback, watcherId) {
12441247 * @summary returns the non-hidden columns of the given table. If type is given, it
12451248 * will only return columns that match type.
12461249 * @param {TableModel } tableModel
1247- * @param {COL_TYPE } type one of predefined COL_TYPE. defaults to 'ALL '.
1250+ * @param {COL_TYPE } type one of predefined COL_TYPE. defaults to 'ANY '.
12481251 * @returns {Array<TableColumn> }
12491252 * @public
12501253 * @memberof firefly.util.table
12511254 * @func getColumns
12521255 */
1253- export function getColumns ( tableModel , type = COL_TYPE . ALL ) {
1256+ export function getColumns ( tableModel , type = COL_TYPE . ANY ) {
12541257 return getColsByType ( getAllColumns ( tableModel ) , type ) ;
12551258}
12561259
@@ -1269,10 +1272,10 @@ export function getAllColumns(tableModel) {
12691272/**
12701273 * @summary returns only the non-hidden columns matching the given type.
12711274 * @param {Array<TableColumn> } tblColumns
1272- * @param {COL_TYPE } type one of predefined COL_TYPE. defaults to 'ALL '.
1275+ * @param {COL_TYPE } type one of predefined COL_TYPE. defaults to 'ANY '.
12731276 * @returns {Array<TableColumn> }
12741277 */
1275- export function getColsByType ( tblColumns = [ ] , type = COL_TYPE . ALL ) {
1278+ export function getColsByType ( tblColumns = [ ] , type = COL_TYPE . ANY ) {
12761279 return tblColumns . filter ( ( col ) =>
12771280 get ( col , 'visibility' ) !== 'hidden' &&
12781281 isColumnType ( col , type ) ) ;
0 commit comments