@firestitch/filter 9.8.8 → 9.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { __extends, __assign, __decorate, __metadata, __spread, __param, __values, __read } from 'tslib';
2
2
  import { Injectable, Optional, Inject, Component, ChangeDetectionStrategy, InjectionToken, ChangeDetectorRef, HostListener, Input, Injector, Directive, EventEmitter, NgZone, Output, ContentChild, TemplateRef, ViewChild, ElementRef, HostBinding, ViewEncapsulation, KeyValueDiffers, Pipe, Self, NgModule } from '@angular/core';
3
3
  import { ActivatedRoute, Router, RouterModule } from '@angular/router';
4
- import { BehaviorSubject, Subject, isObservable, of, fromEvent, merge, timer, combineLatest } from 'rxjs';
5
- import { take, takeUntil, debounceTime, tap, distinctUntilChanged, filter as filter$1, switchMap, skip, map, mapTo, startWith, delay } from 'rxjs/operators';
4
+ import { BehaviorSubject, Subject, isObservable, forkJoin, of, fromEvent, combineLatest, merge, timer } from 'rxjs';
5
+ import { tap, finalize, take, takeUntil, debounceTime, filter as filter$1, distinctUntilChanged, switchMap, skip, map, mapTo, startWith, delay } from 'rxjs/operators';
6
6
  import { isFunction, clone, isObject, isString, toString, pickBy } from 'lodash-es';
7
7
  import { Alias, Model } from 'tsmodels';
8
8
  import { filter, isEmpty, getNormalizedPath, list, remove, FsCommonModule } from '@firestitch/common';
@@ -70,6 +70,7 @@ var BaseItem = /** @class */ (function () {
70
70
  this._additionalConfig = _additionalConfig;
71
71
  this._initialized = false;
72
72
  this._pendingValues = false;
73
+ this._pendingDefaultValue = false;
73
74
  this._loading$ = new BehaviorSubject(false);
74
75
  this._value$ = new BehaviorSubject(null);
75
76
  this._valueChange$ = new Subject();
@@ -186,6 +187,13 @@ var BaseItem = /** @class */ (function () {
186
187
  enumerable: true,
187
188
  configurable: true
188
189
  });
190
+ Object.defineProperty(BaseItem.prototype, "hasPendingDefaultValue", {
191
+ get: function () {
192
+ return this._pendingDefaultValue;
193
+ },
194
+ enumerable: true,
195
+ configurable: true
196
+ });
189
197
  Object.defineProperty(BaseItem.prototype, "model", {
190
198
  get: function () {
191
199
  return this._model;
@@ -291,6 +299,15 @@ var BaseItem = /** @class */ (function () {
291
299
  enumerable: true,
292
300
  configurable: true
293
301
  });
302
+ BaseItem.prototype.loadDefaultValue = function () {
303
+ var _this = this;
304
+ return this.defaultValueFn()
305
+ .pipe(tap(function (value) {
306
+ _this.defaultValue = value;
307
+ }), finalize(function () {
308
+ _this._pendingDefaultValue = false;
309
+ }));
310
+ };
294
311
  BaseItem.prototype.initValues = function (persistedValue) {
295
312
  this._initialized = false;
296
313
  this.persistedValue = persistedValue;
@@ -354,7 +371,13 @@ var BaseItem = /** @class */ (function () {
354
371
  this.name = item.name;
355
372
  this.label = item.label;
356
373
  this.chipLabel = item.chipLabel;
357
- this.defaultValue = item.default;
374
+ if (typeof item.default === 'function') {
375
+ this._pendingDefaultValue = true;
376
+ this.defaultValueFn = item.default;
377
+ }
378
+ else {
379
+ this.defaultValue = item.default;
380
+ }
358
381
  this.change = item.change;
359
382
  this.hide = item.hide;
360
383
  this.clearAllowed = (_a = item.clear) !== null && _a !== void 0 ? _a : true;
@@ -1538,12 +1561,15 @@ var FsFilterItemsStore = /** @class */ (function () {
1538
1561
  this.sortByItem = null;
1539
1562
  this.sortDirectionItem = null;
1540
1563
  this.keywordItem = null;
1564
+ this._ready$ = new BehaviorSubject(false);
1541
1565
  this._items = [];
1542
1566
  this._visibleItems$ = new BehaviorSubject([]);
1543
1567
  this._itemsByName = new Map();
1544
1568
  this._itemsValuesLoaded = false;
1545
1569
  this._hasKeyword = false;
1546
1570
  this._itemsChange$ = new Subject();
1571
+ this._destroy$ = new Subject();
1572
+ this._lazyInit();
1547
1573
  }
1548
1574
  Object.defineProperty(FsFilterItemsStore.prototype, "items", {
1549
1575
  get: function () {
@@ -1583,8 +1609,17 @@ var FsFilterItemsStore = /** @class */ (function () {
1583
1609
  enumerable: true,
1584
1610
  configurable: true
1585
1611
  });
1612
+ Object.defineProperty(FsFilterItemsStore.prototype, "ready$", {
1613
+ get: function () {
1614
+ return this._ready$.asObservable();
1615
+ },
1616
+ enumerable: true,
1617
+ configurable: true
1618
+ });
1586
1619
  FsFilterItemsStore.prototype.ngOnDestroy = function () {
1587
1620
  this.destroyItems();
1621
+ this._destroy$.next();
1622
+ this._destroy$.complete();
1588
1623
  };
1589
1624
  FsFilterItemsStore.prototype.setConfig = function (config) {
1590
1625
  this._itemsByName.clear();
@@ -1598,8 +1633,6 @@ var FsFilterItemsStore = /** @class */ (function () {
1598
1633
  this._itemsValuesLoaded = false;
1599
1634
  if (Array.isArray(items)) {
1600
1635
  this._createItems(items);
1601
- this.updateVisibleItems();
1602
- this._setKeywordItem();
1603
1636
  }
1604
1637
  };
1605
1638
  FsFilterItemsStore.prototype.filtersClear = function () {
@@ -1638,6 +1671,25 @@ var FsFilterItemsStore = /** @class */ (function () {
1638
1671
  .filter(function (item) { return item.hasPendingValues; })
1639
1672
  .forEach(function (item) { return item.loadAsyncValues(); });
1640
1673
  };
1674
+ FsFilterItemsStore.prototype.loadAsyncDefaults = function () {
1675
+ var _this = this;
1676
+ var pendingItems = this.items
1677
+ .filter(function (item) {
1678
+ return item.hasPendingDefaultValue
1679
+ && (item.persistedValue === null || item.persistedValue === undefined);
1680
+ });
1681
+ if (pendingItems.length > 0) {
1682
+ forkJoin(pendingItems
1683
+ .map(function (item) { return item.loadDefaultValue(); }))
1684
+ .pipe(finalize(function () {
1685
+ _this._ready$.next(true);
1686
+ }), takeUntil(this._destroy$))
1687
+ .subscribe();
1688
+ }
1689
+ else {
1690
+ this._ready$.next(true);
1691
+ }
1692
+ };
1641
1693
  FsFilterItemsStore.prototype.getSort = function () {
1642
1694
  var sortBy = this.getSortByValue();
1643
1695
  sortBy = sortBy === '__all' ? null : sortBy;
@@ -1694,6 +1746,7 @@ var FsFilterItemsStore = /** @class */ (function () {
1694
1746
  item.initValues(p[item.name]);
1695
1747
  });
1696
1748
  this._createSortingItems(p);
1749
+ this.loadAsyncDefaults();
1697
1750
  this._subscribeToItemsChanges();
1698
1751
  };
1699
1752
  FsFilterItemsStore.prototype.updateItemsWithValues = function (values) {
@@ -1782,6 +1835,15 @@ var FsFilterItemsStore = /** @class */ (function () {
1782
1835
  });
1783
1836
  }
1784
1837
  };
1838
+ FsFilterItemsStore.prototype._lazyInit = function () {
1839
+ var _this = this;
1840
+ this.ready$
1841
+ .pipe(filter$1(function (state) { return state; }), takeUntil(this._destroy$))
1842
+ .subscribe(function () {
1843
+ _this.updateVisibleItems();
1844
+ _this._setKeywordItem();
1845
+ });
1846
+ };
1785
1847
  FsFilterItemsStore.prototype._createSortingItems = function (p) {
1786
1848
  var _a;
1787
1849
  if (((_a = this._config.sortValues) === null || _a === void 0 ? void 0 : _a.length) > 0) {
@@ -3239,6 +3301,13 @@ var FilterComponent = /** @class */ (function () {
3239
3301
  enumerable: true,
3240
3302
  configurable: true
3241
3303
  });
3304
+ Object.defineProperty(FilterComponent.prototype, "itemsReady$", {
3305
+ get: function () {
3306
+ return this._filterItems.ready$;
3307
+ },
3308
+ enumerable: true,
3309
+ configurable: true
3310
+ });
3242
3311
  Object.defineProperty(FilterComponent.prototype, "hasFilterChips$", {
3243
3312
  get: function () {
3244
3313
  return this._hasFilterChips$.asObservable();
@@ -3303,21 +3372,6 @@ var FilterComponent = /** @class */ (function () {
3303
3372
  _this.focus();
3304
3373
  }
3305
3374
  });
3306
- if (this.config.init) {
3307
- if (this._externalParams.pending) {
3308
- this._externalParams
3309
- .pending$
3310
- .pipe(filter$1(function (pending) {
3311
- return !pending;
3312
- }), takeUntil(this._destroy$))
3313
- .subscribe(function () {
3314
- _this.init();
3315
- });
3316
- }
3317
- else {
3318
- this.init();
3319
- }
3320
- }
3321
3375
  this._listenInternalItemsChange();
3322
3376
  this._initOverlay();
3323
3377
  };
@@ -3718,10 +3772,18 @@ var FilterComponent = /** @class */ (function () {
3718
3772
  // We may need some time to recieve external params and after that ready can be emitted
3719
3773
  FilterComponent.prototype._listenWhenFilterReady = function () {
3720
3774
  var _this = this;
3721
- this._externalParams
3722
- .pending$
3723
- .pipe(filter$1(function (value) { return !value; }), takeUntil(this._destroy$))
3775
+ combineLatest([
3776
+ this._externalParams.pending$,
3777
+ this.itemsReady$,
3778
+ ])
3779
+ .pipe(filter$1(function (_a) {
3780
+ var _b = __read(_a, 2), pendingParams = _b[0], itemsReady = _b[1];
3781
+ return !pendingParams && itemsReady;
3782
+ }), takeUntil(this._destroy$))
3724
3783
  .subscribe(function () {
3784
+ if (_this.config.init) {
3785
+ _this.init();
3786
+ }
3725
3787
  _this.ready.emit();
3726
3788
  });
3727
3789
  };
@@ -3797,7 +3859,7 @@ var FilterComponent = /** @class */ (function () {
3797
3859
  FilterComponent = __decorate([
3798
3860
  Component({
3799
3861
  selector: 'fs-filter',
3800
- template: "<ng-container *ngIf=\"hasKeyword; else noKeywordFilter\">\n <div class=\"filter-search-container\">\n <div class=\"filter-input-field\">\n <form autocomplete=\"off\" role=\"presentation\" *ngIf=\"keywordVisible$ | async\">\n <mat-form-field floatLabel=\"never\">\n <span matPrefix>\n <mat-icon matPrefix>search</mat-icon>\n </span>\n\n <input\n #searchTextInput\n matInput\n [formControl]=\"searchText\"\n [placeholder]=\"searchPlaceholder\"\n name=\"filter-input\"\n (click)=\"filterInputEvent($event)\"\n class=\"filter-input\">\n\n <a matSuffix\n *ngIf=\"searchText.value && showFilterInput && config.clear\"\n (click)=\"clearSearchText($event)\"\n href=\"javascript:void(0)\"\n class=\"clear\">\n <mat-icon>clear</mat-icon>\n </a>\n\n <a matSuffix\n (click)=\"reload($event)\"\n class=\"reload\"\n *ngIf=\"config.reload\">\n <mat-icon>refresh</mat-icon>\n </a>\n </mat-form-field>\n </form>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n <div class=\"status-actions\" *ngIf=\"keywordVisible$ | async\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n</ng-container>\n\n<ng-template #noKeywordFilter>\n <div class=\"filter-searchless-container\">\n <div class=\"status-actions\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n</ng-template>\n\n\n<ng-template #filterActions>\n <div class=\"filter-actions\">\n <ng-container *ngIf=\"hasVisibleItemOrSorting && filtersBtnVisible$ | async \">\n <button\n mat-button\n class=\"filters-button\"\n [ngClass]=\"{\n 'mat-raised-button': config.button.style == 'raised',\n 'mat-button': config.button.style == 'basic',\n 'mat-icon-button': config.button.style == 'icon'\n }\"\n (click)=\"changeVisibilityClick(!showFilterMenu, $event)\"\n type=\"button\"\n [color]=\"config.button.color\">\n <mat-icon *ngIf=\"config.button.icon\">{{config.button.icon}}</mat-icon>\n {{ config.button.label }}\n </button>\n </ng-container>\n\n <fs-filter-actions\n *ngIf=\"actionsVisible$ | async\"\n [actions]=\"actions$ | async\"\n [kebabActions]=\"menuActions$ | async\">\n </fs-filter-actions>\n </div>\n</ng-template>\n\n<ng-template #filterChips>\n <fs-filter-chips\n *ngIf=\"config.chips && hasFilterChips$ | async\"\n class=\"filter-chips\"\n [filters]=\"items\">\n </fs-filter-chips>\n</ng-template>\n\n<ng-template #statusBarContainer>\n <div class=\"status-bar\" *ngIf=\"statusBar\">\n <small><ng-container *ngTemplateOutlet=\"statusBar\"></ng-container></small>\n </div>\n</ng-template>\n",
3862
+ template: "<ng-container *ngIf=\"hasKeyword; else noKeywordFilter\">\n <div class=\"filter-search-container\">\n <div class=\"filter-input-field\">\n <form autocomplete=\"off\" role=\"presentation\" *ngIf=\"keywordVisible$ | async\">\n <mat-form-field floatLabel=\"never\">\n <span matPrefix>\n <mat-icon matPrefix>search</mat-icon>\n </span>\n\n <input\n #searchTextInput\n matInput\n [formControl]=\"searchText\"\n [placeholder]=\"searchPlaceholder\"\n name=\"filter-input\"\n (click)=\"filterInputEvent($event)\"\n class=\"filter-input\">\n\n <a matSuffix\n *ngIf=\"searchText.value && showFilterInput && config.clear\"\n (click)=\"clearSearchText($event)\"\n href=\"javascript:void(0)\"\n class=\"clear\">\n <mat-icon>clear</mat-icon>\n </a>\n\n <a matSuffix\n (click)=\"reload($event)\"\n class=\"reload\"\n *ngIf=\"config.reload\">\n <mat-icon>refresh</mat-icon>\n </a>\n </mat-form-field>\n </form>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n <div class=\"status-actions\" *ngIf=\"keywordVisible$ | async\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n</ng-container>\n\n<ng-template #noKeywordFilter>\n <div class=\"filter-searchless-container\">\n <div class=\"status-actions\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n</ng-template>\n\n\n<ng-template #filterActions>\n <div class=\"filter-actions\">\n <ng-container *ngIf=\"hasVisibleItemOrSorting && filtersBtnVisible$ | async\">\n <button\n mat-button\n class=\"filters-button\"\n [ngClass]=\"{\n 'mat-raised-button': config.button.style == 'raised',\n 'mat-button': config.button.style == 'basic',\n 'mat-icon-button': config.button.style == 'icon'\n }\"\n (click)=\"changeVisibilityClick(!showFilterMenu, $event)\"\n type=\"button\"\n [color]=\"config.button.color\">\n <mat-icon *ngIf=\"config.button.icon\">{{config.button.icon}}</mat-icon>\n {{ config.button.label }}\n </button>\n </ng-container>\n\n <fs-filter-actions\n *ngIf=\"actionsVisible$ | async\"\n [actions]=\"actions$ | async\"\n [kebabActions]=\"menuActions$ | async\">\n </fs-filter-actions>\n </div>\n</ng-template>\n\n<ng-template #filterChips>\n <fs-filter-chips\n *ngIf=\"config.chips && hasFilterChips$ | async\"\n class=\"filter-chips\"\n [filters]=\"items\">\n </fs-filter-chips>\n</ng-template>\n\n<ng-template #statusBarContainer>\n <div class=\"status-bar\" *ngIf=\"statusBar\">\n <small><ng-container *ngTemplateOutlet=\"statusBar\"></ng-container></small>\n </div>\n</ng-template>\n",
3801
3863
  encapsulation: ViewEncapsulation.None,
3802
3864
  providers: [
3803
3865
  FsFilterOverlayService,