diff options
author | Ittay Stern <ittay.stern@att.com> | 2019-07-07 19:23:03 +0300 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-07-08 16:13:43 +0300 |
commit | f792671ae247a931f34d902e9276202b5016ef9a (patch) | |
tree | 6104971e8074c9a3d720836276ff18619719ec02 /vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts | |
parent | fc62274e8d15964d63c62bf0e2f4abc040252ee9 (diff) |
Merge from ecomp 718fd196 - Modern UI
Issue-ID: VID-378
Change-Id: I2736b98426e324ec3aa233b034229ba84d99839f
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts')
-rw-r--r-- | vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts b/vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts index 4b4f1a5bc..7418d8f28 100644 --- a/vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts +++ b/vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts @@ -9,22 +9,33 @@ import * as _ from 'lodash'; }) export class DataFilterPipe implements PipeTransform { - transform(items: any, searchStr: string, keys?: string[][]): any { + transform(items: any, searchStr: string, keys?: string[][], types ?: string[]): any { if (items != null && items.length > 0 && !_.isNil(searchStr)) { let ans = []; if (_.isNil(keys) || keys.length === 0) { keys = Object.keys(items[0]).map((key)=> new Array(key) ); } + for (const item of items) { + let index = 0; for(const key of keys) { - - let val: string = DataFilterPipe.getDeepObjectValueByKeys(item, key); - if (!_.isNil(val) && val.toLowerCase().includes(searchStr.toLowerCase())) { - ans.push(item); - break; + if(types && types[index] === 'LIST'){ + let listVal: string[] = DataFilterPipe.getDeepObjectValueByKeysInList(item, key); + if (!_.isNil(listVal) && listVal.filter((val) => val.toLowerCase().includes(searchStr.toLowerCase())).length > 0) { + ans.push(item); + break; + } + }else { + let val: string = DataFilterPipe.getDeepObjectValueByKeys(item, key); + if (!_.isNil(val) && val.toLowerCase().includes(searchStr.toLowerCase())) { + ans.push(item); + break; + } } + index++; } + } return ans; } @@ -42,6 +53,23 @@ export class DataFilterPipe implements PipeTransform { for(let i = 1; i < keys.length ; i++){ obj = obj[keys[i]]; } - return obj.toString(); + return _.isNil(obj) ? null : obj.toString(); + } + + + /********************************************************************** + get values from obj data by array of keys. + @keys: all table column and keys + @rowData : row data + ************************************************************************/ + static getDeepObjectValueByKeysInList(rowData: any , keys: string[]) : string[] { + let obj = rowData[keys[0]]; + if(_.isNil(obj)) { + return obj; + } + for(let i = 1; i < keys.length-1 ; i++){ + obj = obj[keys[i]]; + } + return _.isNil(obj) ? [] : _.map(obj, keys[keys.length -1 ]); } } |