From f792671ae247a931f34d902e9276202b5016ef9a Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Sun, 7 Jul 2019 19:23:03 +0300 Subject: Merge from ecomp 718fd196 - Modern UI Issue-ID: VID-378 Change-Id: I2736b98426e324ec3aa233b034229ba84d99839f Signed-off-by: Ittay Stern --- .../shared/pipes/dataFilter/data-filter.pipe.ts | 42 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'vid-webpack-master/src/app/shared/pipes/dataFilter/data-filter.pipe.ts') 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 ]); } } -- cgit 1.2.3-korg