import { Injectable } from '@angular/core' ; import { FilterType } from '@eda/services/utils/chart-utils.service' ; import { FileUtiles } from '@eda/services/utils/file-utils.service' ; import * as _ from 'lodash' ; @ Injectable ( ) export class ColumnUtilsService { constructor ( private fileUtiles ) { } public addFilter ( obj , table , column , type , selectedRange ) { const values = Object . keys ( obj ) . map ( ( key ) => { if ( ! _ . isNil ( Object . values ( obj [ key ] ) ) ) { if ( ! Array . isArray ( obj [ key ] ) ) { obj [ key ] = [ obj [ key ] ] ; } return { [ key ] : obj [ key ] } ; } } ) ; return { filter_id : this . fileUtiles . generateUUID ( ) , filter_table : table , filter_column : column , filter_type : type , filter_elements : values , selectedRange : selectedRange , isGlobal : false } ; } public handleInputTypes ( type ) { let inputType ; switch ( type ) { case 'text' : inputType = 'text' ; break ; case 'numeric' : inputType = 'number' ; break ; case 'date' : inputType = 'date' ; break ; case 'date-time' : inputType = 'datetime-local' ; break ; default : inputType = 'text' ; break ; } return inputType ; } public handleFilterChange ( filter ) { let between = false ; let value = false ; let switchBtn = false ; let limitFields = 1 ; if ( ! _ . isNil ( filter ) ) { limitFields = this . handleLimitSelectFields ( filter . value ) ; between = _ . isEqual ( filter . value , 'between' ) ; value = ! _ . isEqual ( filter . value , 'not_null' ) ; switchBtn = _ . isEqual ( filter . value , 'in' ) || _ . isEqual ( filter . value , 'not_in' ) ; } return { between , value , limitFields , switchBtn } ; } public handleValidForm ( event , filterValue , validators ) { let button = true ; if ( Object . keys ( event ) [ 0 ] === 'value1' ) { filterValue . value1 = event . value1 !== '' ? event . value1 : null ; } if ( Object . keys ( event ) [ 0 ] === 'value2' ) { filterValue . value2 = event . value2 !== '' ? event . value2 : null ; } if ( ! _ . isNil ( validators . selected ) ) { if ( ! ! validators . between ) { if ( ! _ . isNil ( filterValue . value1 ) && ! _ . isNil ( filterValue . value2 ) ) { button = false ; } else { button = true ; } } else if ( ! validators . between ) { if ( ! validators . value ) { button = false ; } else { button = _ . isNil ( filterValue . value1 ) ; } } } return button ; } public handleOrdenation ( ) { } private handleLimitSelectFields ( filter ) { if ( _ . startsWith ( filter , 'not_in' ) || _ . startsWith ( filter , 'in' ) ) { return 2 ; } else { return 1 ; } } }