UNPKG

@firestitch/filter

Version:
1,256 lines (1,250 loc) 166 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/forms'), require('@angular/material'), require('@angular/flex-layout'), require('@firestitch/datepicker'), require('@firestitch/chip'), require('@firestitch/label'), require('@firestitch/autocomplete'), require('@firestitch/autocomplete-chips'), require('@angular/common'), require('@angular/router'), require('@firestitch/store'), require('tsmodels'), require('rxjs/internal/util/isObservable'), require('date-fns'), require('lodash-es'), require('@firestitch/scroll'), require('@angular/cdk/portal'), require('@angular/cdk/overlay'), require('rxjs'), require('rxjs/operators'), require('@firestitch/common'), require('@firestitch/date'), require('@angular/core')) : typeof define === 'function' && define.amd ? define('@firestitch/filter', ['exports', '@angular/forms', '@angular/material', '@angular/flex-layout', '@firestitch/datepicker', '@firestitch/chip', '@firestitch/label', '@firestitch/autocomplete', '@firestitch/autocomplete-chips', '@angular/common', '@angular/router', '@firestitch/store', 'tsmodels', 'rxjs/internal/util/isObservable', 'date-fns', 'lodash-es', '@firestitch/scroll', '@angular/cdk/portal', '@angular/cdk/overlay', 'rxjs', 'rxjs/operators', '@firestitch/common', '@firestitch/date', '@angular/core'], factory) : (factory((global.firestitch = global.firestitch || {}, global.firestitch.filter = {}),global.ng.forms,global.ng.material,global.ng['flex-layout'],global.datepicker,global.chip,global.label,global.autocomplete,global.autocompleteChips,global.ng.common,global.ng.router,global.store,global.tsmodels,global.rxjs['internal/util/isObservable'],global.dateFns,global.lodashEs,global.scroll,global.ng.cdk.portal,global.ng.cdk.overlay,global.rxjs,global.rxjs.operators,global.common$1,global.date,global.ng.core)); }(this, (function (exports,forms,material,flexLayout,datepicker,chip,label,autocomplete,autocompleteChips,common,router,store,tsmodels,isObservable,dateFns,lodashEs,scroll,portal,overlay,rxjs,operators,common$1,date,core) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ var ItemType = { Text: 'text', Select: 'select', Range: 'range', Date: 'date', DateTime: 'datetime', DateRange: 'daterange', DateTimeRange: 'datetimerange', AutoComplete: 'autocomplete', AutoCompleteChips: 'autocompletechips', Checkbox: 'checkbox', Chips: 'chips', Keyword: 'keyword', }; var FsFilterConfigItem = /** @class */ (function (_super) { __extends(FsFilterConfigItem, _super); function FsFilterConfigItem(_configItem, _config, _route, _persists) { if (_configItem === void 0) { _configItem = {}; } var _this = _super.call(this) || this; _this._configItem = _configItem; _this._config = _config; _this._route = _route; _this._persists = _persists; _this.initialLoading = false; _this.valueChanged = false; _this._pendingValues = false; _this._fromJSON(_configItem); return _this; } Object.defineProperty(FsFilterConfigItem.prototype, "hasPendingValues", { get: /** * @return {?} */ function () { return this._pendingValues; }, enumerable: true, configurable: true }); Object.defineProperty(FsFilterConfigItem.prototype, "model", { get: /** * @return {?} */ function () { return this._model; }, set: /** * @param {?} val * @return {?} */ function (val) { this._model = val; this.checkIfValueChanged(); }, enumerable: true, configurable: true }); Object.defineProperty(FsFilterConfigItem.prototype, "values", { get: /** * @return {?} */ function () { return this._values; }, set: /** * @param {?} values * @return {?} */ function (values) { this._values = values; this.sanitize(); }, enumerable: true, configurable: true }); /** * @param {?} data * @return {?} */ FsFilterConfigItem.prototype._fromJSON = /** * @param {?} data * @return {?} */ function (data) { _super.prototype._fromJSON.call(this, data); if (this.name && lodashEs.isObject(this.name)) { this.names = this.name; this.name = Object.keys(this.names).join('-'); } if (this._config.persist) { /** @type {?} */ var persisted = this._persists[this._config.persist.name].data; if (persisted[this.name]) { this.parseAndSetValue(persisted[this.name]); } } this.sanitize(); }; /** * @return {?} */ FsFilterConfigItem.prototype.initValues = /** * @return {?} */ function () { if (lodashEs.isFunction(this._configItem.values) && !this.isTypeAutocomplete() && !this.isTypeAutocompleteChips()) { /** @type {?} */ var obj = this._configItem.values(); this.values = obj; if (isObservable.isObservable(obj)) { this._pendingValues = true; } } else { this.values = this._configItem.values; } }; /** * @param {?} value * @return {?} */ FsFilterConfigItem.prototype.updateValue = /** * @param {?} value * @return {?} */ function (value) { var _this = this; var _a; switch (this.type) { case ItemType.Select: { if (value === '__all' || value === null) { this.model = value; return; } /** @type {?} */ var valueExists = null; /** @type {?} */ var isolated = null; if (this.multiple) { isolated = this.isolate && Array.isArray(value) && value[0] === this.isolate.value; valueExists = Array.isArray(this.values) ? value.every(( /** * @param {?} val * @return {?} */function (val) { return _this.values.find(( /** * @param {?} valueItem * @return {?} */function (valueItem) { return valueItem.value === val; })); })) || isolated : false; } else { valueExists = Array.isArray(this.values) ? this.values.some(( /** * @param {?} valueItem * @return {?} */function (valueItem) { return valueItem.value === value; })) : false; } if (valueExists) { this.model = value; if (this.isolate) { this.isolate.enabled = isolated; } return; } } break; case ItemType.Range: { this.model = lodashEs.isObject(value) ? __assign({}, this.model, value) : {}; } break; case ItemType.Chips: { this.model = []; } break; case ItemType.Date: case ItemType.DateTime: { this.model = value; } break; case ItemType.AutoCompleteChips: { if (Array.isArray(value)) { (_a = this.model).push.apply(_a, __spread(value)); } else if (lodashEs.isObject(value)) { this.model.push(value); } else { this.model = []; } } break; default: { this.model = value; } } }; /** * @param {?=} reload * @return {?} */ FsFilterConfigItem.prototype.loadValues = /** * @param {?=} reload * @return {?} */ function (reload) { var _this = this; if (reload === void 0) { reload = true; } if (reload || (!this.initialLoading && this.hasPendingValues)) { this.initialLoading = true; if (lodashEs.isFunction(this._configItem.values) && !this.isTypeAutocomplete() && !this.isTypeAutocompleteChips()) { /** @type {?} */ var obj = this._configItem.values(); if (isObservable.isObservable(obj)) { // Clear out values so the interfaces go into a loading state this.values = []; obj .pipe(operators.take(1), operators.takeUntil(this._config.destroy$)) .subscribe(( /** * @param {?} values * @return {?} */function (values) { _this.values = values; _this._pendingValues = false; _this.initialLoading = false; _this.validateModel(); })); } else { this.values = obj; } } } }; /** * @return {?} */ FsFilterConfigItem.prototype.clear = /** * @return {?} */ function () { this.valueChanged = false; this.model = undefined; this.selectedValue = ''; switch (this.type) { case ItemType.AutoComplete: { this.model = null; this.search = ''; } break; case ItemType.AutoCompleteChips: case ItemType.Chips: { this.model = []; this.search = ''; } break; case ItemType.Checkbox: { this.model = false; } break; case ItemType.Select: { if (this.multiple) { this.model = []; } else { this.model = Array.isArray(this.values) && this.values.some(( /** * @param {?} val * @return {?} */function (val) { return val.value === '__all'; })) ? '__all' : null; } if (this.isolate) { this.isolate.enabled = false; } } break; case ItemType.Range: { this.model = {}; } break; case ItemType.Text: case ItemType.Keyword: { this.model = ''; } break; case ItemType.Date: case ItemType.DateTime: { this.model = null; } break; } }; /** * @return {?} */ FsFilterConfigItem.prototype.checkIfValueChanged = /** * @return {?} */ function () { switch (this.type) { case ItemType.AutoCompleteChips: { this.valueChanged = this.model && this.model.length; } break; case ItemType.Checkbox: { this.valueChanged = this.model && this.model !== false; } break; case ItemType.Select: { if (this.multiple) { this.valueChanged = this.model && this.model.length; } else { /** @type {?} */ var hasAllOption = Array.isArray(this.values) && this.values.some(( /** * @param {?} val * @return {?} */function (val) { return val.value === '__all'; })); if (hasAllOption && this.model && this.model !== '__all') { this.valueChanged = true; } else { this.valueChanged = !!this.model; } } } break; case ItemType.Range: { if (this.model && Object.keys(this.model).length > 0) { this.valueChanged = true; } } break; case ItemType.Text: case ItemType.Keyword: { this.valueChanged = this.model && this.model !== ''; } break; case ItemType.AutoComplete: case ItemType.Date: case ItemType.DateTime: { this.valueChanged = !!this.model; } break; default: { this.valueChanged = false; } } }; /** * @param {?} value * @return {?} */ FsFilterConfigItem.prototype.parseAndSetValue = /** * @param {?} value * @return {?} */ function (value) { if (value) { if (this.isTypeDateRange() || this.isTypeDateTimeRange()) { value.from = value.from ? date.toUTC(value.from) : null; value.to = value.to ? date.toUTC(value.to) : null; } else if (this.isTypeDate() || this.isTypeDateTime()) { if (!dateFns.isDate(value) || !dateFns.isValid(value)) { value = dateFns.parse(value, 'yyyy-MM-dd\'T\'HH:mm:ssxxxxx', new Date()); } } else if (this.isTypeCheckbox() && this.checked !== undefined) { value = value == this.checked; } else if (this.isTypeSelect() && this.multiple) { value = lodashEs.clone(value); } else if (this.isTypeSelect() || this.isTypeAutocomplete()) { value = +value; } } this.model = value; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeAutocomplete = /** * @return {?} */ function () { return this.type === ItemType.AutoComplete; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeAutocompleteChips = /** * @return {?} */ function () { return this.type === ItemType.AutoCompleteChips; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeChips = /** * @return {?} */ function () { return this.type === ItemType.Chips; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeCheckbox = /** * @return {?} */ function () { return this.type === ItemType.Checkbox; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeSelect = /** * @return {?} */ function () { return this.type === ItemType.Select; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeDate = /** * @return {?} */ function () { return this.type === ItemType.Date; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeDateRange = /** * @return {?} */ function () { return this.type === ItemType.DateRange; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeDateTimeRange = /** * @return {?} */ function () { return this.type === ItemType.DateTimeRange; }; /** * @return {?} */ FsFilterConfigItem.prototype.isTypeDateTime = /** * @return {?} */ function () { return this.type === ItemType.DateTime; }; /** * @return {?} */ FsFilterConfigItem.prototype.sanitize = /** * @return {?} */ function () { switch (this.type) { case ItemType.Text: case ItemType.Keyword: break; case ItemType.Select: { this.sanitizeSelect(); } break; case ItemType.Chips: { this.sanitizeChips(); } break; case ItemType.Range: { this.sanitizeRange(); } break; case ItemType.Checkbox: { this.sanitizeCheckbox(); } break; } if (this.model === undefined) { if (this.isTypeCheckbox()) { this.model = this.checked == this.defaultValue; } else { this.model = this.defaultValue; } } if (this.model === undefined) { if (this.isTypeCheckbox()) { this.model = false; } else if (this.isTypeSelect()) { if (this.multiple) { if (!Array.isArray(this.defaultValue)) { this.model = []; } } else { if (this.defaultValue === undefined) { this.model = '__all'; } } } else if (this.isTypeAutocompleteChips() || this.isTypeChips()) { this.model = []; } } }; /** * @return {?} */ FsFilterConfigItem.prototype.validateModel = /** * @return {?} */ function () { var _this = this; if (this.isTypeSelect()) { if (this.multiple) { this.model = lodashEs.filter(this.model || [], ( /** * @param {?} item * @return {?} */function (item) { return _this.values.find(( /** * @param {?} value * @return {?} */function (value) { return value.value === item; })); })); } else { /** @type {?} */ var exists = this.modelValueExists(this.values); if (!exists) { this.model = '__all'; } } } }; /** * @private * @param {?} values * @return {?} */ FsFilterConfigItem.prototype.modelValueExists = /** * @private * @param {?} values * @return {?} */ function (values) { for (var i = 0; i < values.length; i++) { if (values[i].value === this.model) { return true; } if (values[i][this.children]) { /** @type {?} */ var model = this.modelValueExists(values[i][this.children]); if (model) { return true; } } } return false; }; /** * @private * @return {?} */ FsFilterConfigItem.prototype.sanitizeSelect = /** * @private * @return {?} */ function () { if (!Array.isArray(this.values)) { this.values = []; } if (this.isolate) { for (var index in this.values) { if (this.values.hasOwnProperty(index)) { if (!this.values[index]) { continue; } if (this.values[index].value == this.isolate.value) { this.values.splice(index, 1); } } } if (Array.isArray(this.model)) { if (this.model.length == this.values.length) { this.model = null; this.isolate.enabled = false; } else if (this.model[0] == this.isolate.value) { this.isolate.enabled = true; } } } }; /** * @private * @return {?} */ FsFilterConfigItem.prototype.sanitizeChips = /** * @private * @return {?} */ function () { var _this = this; if (!Array.isArray(this.values)) { this.values = []; } if (this.model && Array.isArray(this.model) && this.values.length) { if (Number.isInteger(this.model[0])) { this.model = this.model.map(( /** * @param {?} id * @return {?} */function (id) { return _this.values.find(( /** * @param {?} value * @return {?} */function (value) { return value.value === id; })); })); } } }; /** * @private * @return {?} */ FsFilterConfigItem.prototype.sanitizeCheckbox = /** * @private * @return {?} */ function () { this.checked = this.checked ? lodashEs.toString(this.checked) : true; this.unchecked = this.unchecked ? lodashEs.toString(this.unchecked) : false; this.defaultValue = this.defaultValue === undefined ? this.unchecked : lodashEs.toString(this.defaultValue); }; /** * @private * @return {?} */ FsFilterConfigItem.prototype.sanitizeRange = /** * @private * @return {?} */ function () { if (!this.placeholder) { this.placeholder = ['Min', 'Max']; } if (!this.model) { this.model = {}; } }; __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "name", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "type", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "label", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "chipLabel", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "children", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Boolean) ], FsFilterConfigItem.prototype, "multiple", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "groups", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Boolean) ], FsFilterConfigItem.prototype, "wait", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "query", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "values$", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "selectedValue", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "isolate", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "names", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Boolean) ], FsFilterConfigItem.prototype, "primary", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "search", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "unchecked", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "checked", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "alias", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "placeholder", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", Function) ], FsFilterConfigItem.prototype, "change", void 0); __decorate([ tsmodels.Alias(), __metadata("design:type", String) ], FsFilterConfigItem.prototype, "prefix", void 0); __decorate([ tsmodels.Alias('default'), __metadata("design:type", Object) ], FsFilterConfigItem.prototype, "defaultValue", void 0); return FsFilterConfigItem; }(tsmodels.Model)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var SORT_BY_FIELD = 'system_sort_by'; /** @type {?} */ var SORT_DIRECTION_FIELD = 'system_sort_direction'; var FsFilterConfig = /** @class */ (function (_super) { __extends(FsFilterConfig, _super); function FsFilterConfig(data) { if (data === void 0) { data = {}; } var _this = _super.call(this) || this; _this.load = true; _this.persist = false; _this.inline = false; _this.autofocus = false; _this.chips = false; _this.sortValues = null; _this.sort = null; _this.sortDirection = null; _this.queryParam = false; _this.namespace = 'filter'; _this.items = []; _this.sortByItem = null; _this.sortDirectionItem = null; _this.keywordFilter = false; _this.nonKeywordFilters = false; _this._filtersNames = []; _this._destroy$ = new rxjs.Subject(); _this._fromJSON(data); return _this; } Object.defineProperty(FsFilterConfig.prototype, "destroy$", { get: /** * @return {?} */ function () { return this._destroy$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} items * @param {?} route * @param {?} persists * @return {?} */ FsFilterConfig.prototype.initItems = /** * @param {?} items * @param {?} route * @param {?} persists * @return {?} */ function (items, route, persists) { var _this = this; if (items && Array.isArray(items)) { this.items = items.map(( /** * @param {?} item * @param {?} index * @return {?} */function (item, index) { if (index === 0 && item.type === ItemType.Text) { item.type = ItemType.Keyword; } if (item && item.name && _this._filtersNames.indexOf(item.name) === -1) { _this._filtersNames.push(item.name); return new FsFilterConfigItem(item, _this, route, persists); } else { throw Error('Filter init error. Items name must be unique.'); } })); // After all the items have been created and added to this.items initalize the values // This is important if some item default values are dependent on others this.items.map(( /** * @param {?} item * @return {?} */function (item) { item.initValues(); return item; })); } this.initSorting(route, persists); this.keywordFilter = !!this.items.find(( /** * @param {?} e * @return {?} */function (e) { return ItemType.Keyword === e.type; })); this.nonKeywordFilters = !!this.items.find(( /** * @param {?} e * @return {?} */function (e) { return ItemType.Keyword !== e.type; })); }; /** * @param {?} name * @return {?} */ FsFilterConfig.prototype.getItem = /** * @param {?} name * @return {?} */ function (name) { return this.items.find(( /** * @param {?} item * @return {?} */function (item) { return item.name === name; })); }; /** * @param {?} route * @param {?} persists * @return {?} */ FsFilterConfig.prototype.initSorting = /** * @param {?} route * @param {?} persists * @return {?} */ function (route, persists) { if (this.sortValues) { /** @type {?} */ var sortByItem = { name: SORT_BY_FIELD, type: ItemType.Select, label: 'Sort By', values: this.sortValues }; if (this.sort && this.sort.value) { sortByItem['default'] = this.sort.value; } this.sortByItem = new FsFilterConfigItem(sortByItem, this, route, persists); /** @type {?} */ var sortDirectionItem = { name: SORT_DIRECTION_FIELD, type: ItemType.Select, label: 'Sort Direction', values: [ { name: 'Ascending', value: 'asc' }, { name: 'Descending', value: 'desc' } ] }; if (this.sort && this.sort.direction) { sortDirectionItem['default'] = this.sort.direction; } this.sortDirectionItem = new FsFilterConfigItem(sortDirectionItem, this, route, persists); } }; /** * @return {?} */ FsFilterConfig.prototype.updateModelValues = /** * @return {?} */ function () { this.items.forEach(( /** * @param {?} filter * @return {?} */function (filter) { filter.model = lodashEs.clone(filter.model); })); if (this.sortByItem) { this.sortByItem.model = lodashEs.clone(this.sortByItem.model); } if (this.sortDirectionItem) { this.sortDirectionItem.model = lodashEs.clone(this.sortDirectionItem.model); } }; /** * @param {?=} opts * @return {?} */ FsFilterConfig.prototype.gets = /** * @param {?=} opts * @return {?} */ function (opts) { if (opts === void 0) { opts = {}; } var e_1, _a; /** @type {?} */ var query = {}; try { for (var _b = __values(this.items), _c = _b.next(); !_c.done; _c = _b.next()) { var filter = _c.value; /** @type {?} */ var value = lodashEs.clone(filter.model); if (filter.type == ItemType.Select) { if (filter.multiple) { if (filter.isolate) { if (!Array.isArray(filter.model) || !filter.model.length) { value = common$1.list(filter.values, 'value'); } } if (filter.model && filter.model.indexOf('__all') > -1) { value = null; } } else { if (filter.isolate) { if (filter.model == '__all') { value = common$1.list(filter.values, 'value'); } } else { if (filter.model == '__all') { value = null; } } } } else if (filter.type == ItemType.AutoCompleteChips || filter.type === ItemType.Chips) { if (Array.isArray(filter.model) && filter.model.length && !opts.expand) { value = common$1.list(filter.model, 'value'); } } else if (filter.type == ItemType.Checkbox) { value = filter.model ? filter.checked : filter.unchecked; } // @TODO if (common$1.isEmpty(value, { zero: true })) { continue; } if (filter.type == ItemType.Date || filter.type == ItemType.DateTime) { if (value && dateFns.isValid(value) && dateFns.isDate(value)) { value = date.simpleFormat(value); } } else if (filter.type == ItemType.DateRange || filter.type == ItemType.DateTimeRange) { /** @type {?} */ var from = value.from; /** @type {?} */ var to = value.to; value = {}; if (from) { value.from = dateFns.format(from, 'yyyy-MM-dd\THH:mm:ssxxxxx'); } if (to) { value.to = dateFns.format(to, 'yyyy-MM-dd\THH:mm:ssxxxxx'); } } else if (filter.type == ItemType.AutoComplete) { if (common$1.isEmpty(filter.model.value, { zero: true })) { continue; } value = opts.expand ? filter.model : filter.model.value; } if (lodashEs.isObject(filter.names) && opts.names !== false) { for (var key in filter.names) { if (value[filter.names[key]]) { query[key] = value[filter.names[key]]; } } } else { query[filter.name] = value; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } if (opts.flatten) { for (var name_1 in query) { if (Array.isArray(query[name_1])) { query[name_1] = query[name_1].join(','); } } } return query; }; /** * @return {?} */ FsFilterConfig.prototype.getSort = /** * @return {?} */ function () { /** @type {?} */ var sortBy = this.getSortByValue(); sortBy = sortBy === '__all' ? null : sortBy; /** @type {?} */ var sortDirection = this.getSortDirectionValue(); sortDirection = sortDirection === '__all' ? null : sortDirection; return { value: sortBy, direction: sortDirection, }; }; /** * @return {?} */ FsFilterConfig.prototype.getSortByValue = /** * @return {?} */ function () { return this.sortByItem ? this.sortByItem.model : null; }; /** * @return {?} */ FsFilterConfig.prototype.getSortDirectionValue = /** * @return {?} */ function () { return this.sortDirectionItem ? this.sortDirectionItem.model : null; }; /** * @param {?} sort * @return {?} */ FsFilterConfig.prototype.updateSort = /** * @param {?} sort * @return {?} */ function (sort) { if (sort.sortBy) { this.sortByItem.model = sort.sortBy; } if (sort.sortDirection) { this.sortDirectionItem.model = sort.sortDirection; } }; /** * @return {?} */ FsFilterConfig.prototype.getFilledItems = /** * @return {?} */ function () { return this.items.reduce(( /** * @param {?} acc * @param {?} filter * @return {?} */function (acc, filter) { switch (filter.type) { case ItemType.Select: { /** @type {?} */ var multipleIsoldated = filter.multiple && filter.isolate && Array.isArray(filter.model) && filter.model.length && filter.model.indexOf('__all') === -1; /** @type {?} */ var multipleHasSelectedValues = filter.multiple && Array.isArray(filter.model) && filter.model.length && filter.model.indexOf('__all') === -1; /** @type {?} */ var selectedValues = !filter.multiple && filter.model && filter.model !== '__all'; if (multipleIsoldated || multipleHasSelectedValues || selectedValues) { acc.push(filter);