ngx-easy-table
Version:
Angular easy table
112 lines • 8.31 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import { Pipe } from '@angular/core';
import { FiltersService } from '../services/filters.service';
var SearchPipe = /** @class */ (function () {
function SearchPipe() {
this.filters = {};
}
/**
* @param {?} array
* @param {?} filter
* @param {?} filteredCountSubject
* @param {?=} config
* @return {?}
*/
SearchPipe.prototype.transform = /**
* @param {?} array
* @param {?} filter
* @param {?} filteredCountSubject
* @param {?=} config
* @return {?}
*/
function (array, filter, filteredCountSubject, config) {
var _this = this;
filteredCountSubject.next(0);
if (typeof array === 'undefined') {
return;
}
if (typeof filter === 'undefined') {
filteredCountSubject.next(array.length);
return array;
}
filter.forEach((/**
* @param {?} f
* @return {?}
*/
function (f) {
_this.filters[f.key] = f.value.toString().toLocaleLowerCase();
if (Object.keys(f).length === 0 || f.value === '') {
delete _this.filters[f.key];
}
}));
if (config && config.groupRows) {
return array.map((/**
* @param {?} arr
* @return {?}
*/
function (arr) { return _this.filterGroup(arr, filteredCountSubject); }));
}
return this.filterGroup(array, filteredCountSubject);
};
/**
* @private
* @param {?} array
* @param {?} filteredCountSubject
* @return {?}
*/
SearchPipe.prototype.filterGroup = /**
* @private
* @param {?} array
* @param {?} filteredCountSubject
* @return {?}
*/
function (array, filteredCountSubject) {
var _this = this;
/** @type {?} */
var arr = array.filter((/**
* @param {?} obj
* @return {?}
*/
function (obj) {
return Object.keys(_this.filters).every((/**
* @param {?} c
* @return {?}
*/
function (c) {
/** @type {?} */
var split = c.split('.');
/** @type {?} */
var val = FiltersService.getPath(split, obj);
/** @type {?} */
var element = (typeof val === 'object') ? JSON.stringify(val) : val.toString().toLocaleLowerCase();
/** @type {?} */
var strings = _this.filters[c].split(',');
return strings.some((/**
* @param {?} string
* @return {?}
*/
function (string) { return element.indexOf(string.trim()) > -1; }));
}));
}));
filteredCountSubject.next(arr.length);
return arr;
};
SearchPipe.decorators = [
{ type: Pipe, args: [{
name: 'search',
},] }
];
return SearchPipe;
}());
export { SearchPipe };
if (false) {
/**
* @type {?}
* @private
*/
SearchPipe.prototype.filters;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VhcmNoLXBpcGUuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9uZ3gtZWFzeS10YWJsZS8iLCJzb3VyY2VzIjpbImxpYi9waXBlcy9zZWFyY2gtcGlwZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsT0FBTyxFQUFFLElBQUksRUFBaUIsTUFBTSxlQUFlLENBQUM7QUFDcEQsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBSTdEO0lBQUE7UUFLVSxZQUFPLEdBQThCLEVBQUUsQ0FBQztJQW9DbEQsQ0FBQzs7Ozs7Ozs7SUFsQ0MsOEJBQVM7Ozs7Ozs7SUFBVCxVQUFVLEtBQVksRUFBRSxNQUE2QyxFQUFFLG9CQUFxQyxFQUFFLE1BQWU7UUFBN0gsaUJBbUJDO1FBbEJDLG9CQUFvQixDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUM3QixJQUFJLE9BQU8sS0FBSyxLQUFLLFdBQVcsRUFBRTtZQUNoQyxPQUFPO1NBQ1I7UUFDRCxJQUFJLE9BQU8sTUFBTSxLQUFLLFdBQVcsRUFBRTtZQUNqQyxvQkFBb0IsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLE1BQU0sQ0FBQyxDQUFDO1lBQ3hDLE9BQU8sS0FBSyxDQUFDO1NBQ2Q7UUFDRCxNQUFNLENBQUMsT0FBTzs7OztRQUFDLFVBQUMsQ0FBQztZQUNmLEtBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxLQUFLLENBQUMsU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