@recursyve/nice-data-filter-kit 14.1.5 → 14.2.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.
Files changed (42) hide show
  1. package/esm2020/lib/components/nice-filter-view/components/infinite-scroll-data-view/infinite-scroll-data-view.component.mjs +2 -3
  2. package/esm2020/lib/components/nice-filter-view/directives/mat-paginator.mjs +2 -2
  3. package/esm2020/lib/components/nice-filter-view/store/nice-filter-view.query.mjs +4 -1
  4. package/esm2020/lib/components/nice-filter-view/store/nice-filter-view.service.mjs +4 -18
  5. package/esm2020/lib/components/nice-filter-view/store/nice-filter-view.store.mjs +15 -1
  6. package/esm2020/lib/directive/public-api.mjs +2 -0
  7. package/esm2020/lib/directive/selectable-list/model/load-all-entities-options.model.mjs +2 -0
  8. package/esm2020/lib/directive/selectable-list/model/selectable-list-options.model.mjs +2 -0
  9. package/esm2020/lib/directive/selectable-list/providers/preload-selected-entities.provider.mjs +10 -0
  10. package/esm2020/lib/directive/selectable-list/public-api.mjs +10 -0
  11. package/esm2020/lib/directive/selectable-list/selectable-list-checkbox.directive.mjs +122 -0
  12. package/esm2020/lib/directive/selectable-list/selectable-list-select-all.directive.mjs +48 -0
  13. package/esm2020/lib/directive/selectable-list/selectable-list.constant.mjs +3 -0
  14. package/esm2020/lib/directive/selectable-list/selectable-list.directive.mjs +38 -0
  15. package/esm2020/lib/directive/selectable-list/selectable-list.module.mjs +32 -0
  16. package/esm2020/lib/directive/selectable-list/store/selectable-list-state.service.mjs +181 -0
  17. package/esm2020/lib/directive/selectable-list/store/selectable-list.service.mjs +49 -0
  18. package/esm2020/lib/directive/selectable-list/store/selectable-list.state.mjs +2 -0
  19. package/esm2020/lib/utils/query-params.utils.mjs +2 -16
  20. package/esm2020/public-api.mjs +2 -1
  21. package/fesm2015/recursyve-nice-data-filter-kit.mjs +495 -33
  22. package/fesm2015/recursyve-nice-data-filter-kit.mjs.map +1 -1
  23. package/fesm2020/recursyve-nice-data-filter-kit.mjs +470 -36
  24. package/fesm2020/recursyve-nice-data-filter-kit.mjs.map +1 -1
  25. package/lib/components/nice-filter-view/store/nice-filter-view.query.d.ts +1 -0
  26. package/lib/components/nice-filter-view/store/nice-filter-view.service.d.ts +0 -1
  27. package/lib/components/nice-filter-view/store/nice-filter-view.store.d.ts +1 -0
  28. package/lib/directive/public-api.d.ts +1 -0
  29. package/lib/directive/selectable-list/model/load-all-entities-options.model.d.ts +4 -0
  30. package/lib/directive/selectable-list/model/selectable-list-options.model.d.ts +4 -0
  31. package/lib/directive/selectable-list/providers/preload-selected-entities.provider.d.ts +12 -0
  32. package/lib/directive/selectable-list/public-api.d.ts +9 -0
  33. package/lib/directive/selectable-list/selectable-list-checkbox.directive.d.ts +24 -0
  34. package/lib/directive/selectable-list/selectable-list-select-all.directive.d.ts +18 -0
  35. package/lib/directive/selectable-list/selectable-list.constant.d.ts +2 -0
  36. package/lib/directive/selectable-list/selectable-list.directive.d.ts +14 -0
  37. package/lib/directive/selectable-list/selectable-list.module.d.ts +12 -0
  38. package/lib/directive/selectable-list/store/selectable-list-state.service.d.ts +32 -0
  39. package/lib/directive/selectable-list/store/selectable-list.service.d.ts +23 -0
  40. package/lib/directive/selectable-list/store/selectable-list.state.d.ts +8 -0
  41. package/package.json +1 -1
  42. package/public-api.d.ts +1 -0
@@ -5,7 +5,7 @@ import * as i5$1 from '@recursyve/nice-ui-kit.v2';
5
5
  import { isNullOrUndefined, ObjectUtils, FileUtils, ArrayUtils, ExportBottomSheetComponent, NiceLoadingSpinnerModule, NiceTypeaheadModule, NiceExportBottomSheetModule } from '@recursyve/nice-ui-kit.v2';
6
6
  import * as i0 from '@angular/core';
7
7
  import { Directive, Input, NgModule, Injectable, Inject, InjectionToken, Optional, Pipe, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Output, HostListener, forwardRef, TemplateRef, ContentChild, ContentChildren, ViewChild } from '@angular/core';
8
- import { Store, StoreConfig, Query, arrayAdd, arrayUpsert, arrayRemove, EntityStore, QueryEntity } from '@datorama/akita';
8
+ import { Store, StoreConfig, Query, arrayAdd, arrayUpsert, arrayRemove, EntityStore, QueryEntity, EntityActions } from '@datorama/akita';
9
9
  import { combineLatest, Subject, firstValueFrom, of, tap } from 'rxjs';
10
10
  import { __decorate, __metadata, __awaiter, __rest } from 'tslib';
11
11
  import * as i2 from '@angular/router';
@@ -55,10 +55,11 @@ import * as i1$2 from '@ngx-translate/core';
55
55
  import { TranslateModule } from '@ngx-translate/core';
56
56
  import * as i18 from '@angular/material/badge';
57
57
  import { MatBadgeModule } from '@angular/material/badge';
58
+ import * as i1$4 from '@angular/material/checkbox';
58
59
 
59
60
  class QueryParamsUtils {
60
61
  static hasFilterParameters(params) {
61
- const keys = ["start", "length", "order", "fallbackOrder", "search", "rules"];
62
+ const keys = ["start", "length", "order", "search", "rules"];
62
63
  return Object.keys(params).some(key => keys.includes(key));
63
64
  }
64
65
  static extractFilterParameters(params) {
@@ -77,14 +78,6 @@ class QueryParamsUtils {
77
78
  delete filters.order;
78
79
  }
79
80
  }
80
- if (!isNullOrUndefined(params.fallbackOrder)) {
81
- try {
82
- filters.fallbackOrder = JSON.parse(params.fallbackOrder);
83
- }
84
- catch (e) {
85
- delete filters.fallbackOrder;
86
- }
87
- }
88
81
  if (!isNullOrUndefined(params.search)) {
89
82
  filters.search = params.search;
90
83
  }
@@ -112,12 +105,6 @@ class QueryParamsUtils {
112
105
  else {
113
106
  params.order = null;
114
107
  }
115
- if (!isNullOrUndefined(filterParameters.fallbackOrder)) {
116
- params.fallbackOrder = JSON.stringify(filterParameters.fallbackOrder);
117
- }
118
- else {
119
- params.fallbackOrder = null;
120
- }
121
108
  if (!isNullOrUndefined(filterParameters.search)) {
122
109
  params.search = filterParameters.search;
123
110
  }
@@ -2860,6 +2847,17 @@ class NiceFilterViewStore extends EntityStore {
2860
2847
  });
2861
2848
  this.remove(value[idKey]);
2862
2849
  }
2850
+ getParameters(filterParameters) {
2851
+ const { baseRules } = this.getValue();
2852
+ const parameters = Object.assign(Object.assign({}, filterParameters), { rules: (filterParameters === null || filterParameters === void 0 ? void 0 : filterParameters.rules) ? [...filterParameters.rules] : [] });
2853
+ if (baseRules === null || baseRules === void 0 ? void 0 : baseRules.length) {
2854
+ parameters.rules.push({
2855
+ condition: "and",
2856
+ rules: baseRules
2857
+ });
2858
+ }
2859
+ return parameters;
2860
+ }
2863
2861
  }
2864
2862
  NiceFilterViewStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceFilterViewStore, deps: [{ token: FILTER_VIEW_STATE }, { token: FILTER_VIEW_STORE }], target: i0.ɵɵFactoryTarget.Injectable });
2865
2863
  NiceFilterViewStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceFilterViewStore });
@@ -2892,6 +2890,9 @@ class NiceFilterViewQuery extends QueryEntity {
2892
2890
  selectFilterResult() {
2893
2891
  return this.select("filterResult");
2894
2892
  }
2893
+ getParameters() {
2894
+ return this.store.getParameters(this.store.getValue().filterParameters);
2895
+ }
2895
2896
  }
2896
2897
  NiceFilterViewQuery.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceFilterViewQuery, deps: [{ token: NiceFilterViewStore }], target: i0.ɵɵFactoryTarget.Injectable });
2897
2898
  NiceFilterViewQuery.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceFilterViewQuery });
@@ -2967,7 +2968,7 @@ class NiceFilterViewService {
2967
2968
  }
2968
2969
  try {
2969
2970
  this.store.setLoading(true);
2970
- const result = yield firstValueFrom(this.filterService.filter(this.getParameters(filterParameters)));
2971
+ const result = yield firstValueFrom(this.filterService.filter(this.store.getParameters(filterParameters)));
2971
2972
  this.store.setResult(result);
2972
2973
  }
2973
2974
  catch (e) {
@@ -2986,7 +2987,7 @@ class NiceFilterViewService {
2986
2987
  }
2987
2988
  try {
2988
2989
  this.store.setLoading(true);
2989
- const result = yield firstValueFrom(this.filterService.getFile(type, this.getParameters(filterParameters)));
2990
+ const result = yield firstValueFrom(this.filterService.getFile(type, this.store.getParameters(filterParameters)));
2990
2991
  FileUtils.downloadFile(`${downloadFileName}.${type}`, result);
2991
2992
  }
2992
2993
  catch (e) {
@@ -3005,7 +3006,7 @@ class NiceFilterViewService {
3005
3006
  }
3006
3007
  try {
3007
3008
  this.store.setLoading(true);
3008
- const result = yield firstValueFrom(this.filterService.getPrintableHtml(this.getParameters(filterParameters)));
3009
+ const result = yield firstValueFrom(this.filterService.getPrintableHtml(this.store.getParameters(filterParameters)));
3009
3010
  FileUtils.openPrintableWindow(result);
3010
3011
  }
3011
3012
  catch (e) {
@@ -3117,17 +3118,6 @@ class NiceFilterViewService {
3117
3118
  });
3118
3119
  }
3119
3120
  }
3120
- getParameters(filterParameters) {
3121
- const { baseRules } = this.store.getValue();
3122
- const parameters = Object.assign(Object.assign({}, filterParameters), { rules: (filterParameters === null || filterParameters === void 0 ? void 0 : filterParameters.rules) ? [...filterParameters.rules] : [] });
3123
- if (baseRules === null || baseRules === void 0 ? void 0 : baseRules.length) {
3124
- parameters.rules.push({
3125
- condition: "and",
3126
- rules: baseRules
3127
- });
3128
- }
3129
- return parameters;
3130
- }
3131
3121
  }
3132
3122
  NiceFilterViewService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceFilterViewService, deps: [{ token: NiceFilterViewStore }, { token: NiceFilterService }], target: i0.ɵɵFactoryTarget.Injectable });
3133
3123
  NiceFilterViewService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceFilterViewService });
@@ -3239,7 +3229,7 @@ class NiceFilterInfiniteScrollDataViewComponent {
3239
3229
  constructor(query, service) {
3240
3230
  this.query = query;
3241
3231
  this.service = service;
3242
- this.data$ = this.query.selectAll().pipe(tap(x => console.log(x)));
3232
+ this.data$ = this.query.selectAll();
3243
3233
  }
3244
3234
  loadNextPage() {
3245
3235
  return __awaiter(this, void 0, void 0, function* () {
@@ -3322,7 +3312,7 @@ class NiceFilterMatPaginatorPaginationDirective {
3322
3312
  });
3323
3313
  this.paginator.page.pipe(takeUntil(this.unsubscribeAll$)).subscribe((page) => {
3324
3314
  const { filterParameters } = this.query.getValue();
3325
- this.service.setParameters(Object.assign(Object.assign({}, filterParameters), { start: page.pageIndex, length: page.pageSize }), true);
3315
+ this.service.setParameters(Object.assign(Object.assign({}, filterParameters), { start: page.pageIndex * page.pageSize, length: page.pageSize }), true);
3326
3316
  });
3327
3317
  }
3328
3318
  ngOnDestroy() {
@@ -3698,6 +3688,478 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImpor
3698
3688
  }]
3699
3689
  }] });
3700
3690
 
3691
+ class NicePreloadSelectedEntitiesProvider {
3692
+ }
3693
+ NicePreloadSelectedEntitiesProvider.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NicePreloadSelectedEntitiesProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
3694
+ NicePreloadSelectedEntitiesProvider.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NicePreloadSelectedEntitiesProvider });
3695
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NicePreloadSelectedEntitiesProvider, decorators: [{
3696
+ type: Injectable
3697
+ }] });
3698
+
3699
+ const NICE_PRELOAD_SELECTED_ENTITIES_PROVIDER = new InjectionToken("nice_preload_selected_entities_provider");
3700
+
3701
+ class SelectableListStateService {
3702
+ constructor(store, preloadService, options) {
3703
+ this.store = store;
3704
+ this.preloadService = preloadService;
3705
+ this.options = options;
3706
+ }
3707
+ get idKey() {
3708
+ var _a, _b;
3709
+ return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.idKey) !== null && _b !== void 0 ? _b : "id";
3710
+ }
3711
+ get preloadedWindow() {
3712
+ var _a, _b;
3713
+ return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.preloadWindow) !== null && _b !== void 0 ? _b : 2;
3714
+ }
3715
+ setActive(entity) {
3716
+ this.store.setActive(entity[this.idKey]);
3717
+ }
3718
+ getIndex(identifier) {
3719
+ const { ids } = this.store.getValue();
3720
+ const index = ids.indexOf(identifier);
3721
+ return index + 1;
3722
+ }
3723
+ selectAll(options) {
3724
+ return __awaiter(this, void 0, void 0, function* () {
3725
+ if (!this.preloadService) {
3726
+ return this.store.update({
3727
+ allSelected: true
3728
+ });
3729
+ }
3730
+ const ids = yield this.preloadService.loadAllEntities(options);
3731
+ this.store.set(ids.map((id) => ({
3732
+ [this.idKey]: id,
3733
+ loaded: false
3734
+ })));
3735
+ return this.store.update({
3736
+ allSelected: true
3737
+ });
3738
+ });
3739
+ }
3740
+ select(id) {
3741
+ return __awaiter(this, void 0, void 0, function* () {
3742
+ this.store.update((state) => ({
3743
+ unselectedEntity: arrayRemove(state.unselectedEntity, id)
3744
+ }));
3745
+ if (!this.preloadService) {
3746
+ this.store.add({
3747
+ [this.idKey]: id,
3748
+ loaded: false
3749
+ });
3750
+ }
3751
+ const entity = yield this.preloadService.loadEntityById(id);
3752
+ return this.store.add(Object.assign(Object.assign({}, entity), { loaded: true }));
3753
+ });
3754
+ }
3755
+ selectEntity(entity) {
3756
+ return __awaiter(this, void 0, void 0, function* () {
3757
+ this.store.update((state) => ({
3758
+ unselectedEntity: arrayRemove(state.unselectedEntity, entity[this.idKey])
3759
+ }));
3760
+ if (!this.preloadService) {
3761
+ return this.store.upsert(entity[this.idKey], Object.assign(Object.assign({}, entity), { loaded: true }));
3762
+ }
3763
+ const preloadedEntity = yield this.preloadService.reloadEntity(entity);
3764
+ return this.store.upsert(preloadedEntity[this.idKey], Object.assign(Object.assign({}, preloadedEntity), { loaded: true }));
3765
+ });
3766
+ }
3767
+ selectManyEntities(entities) {
3768
+ return __awaiter(this, void 0, void 0, function* () {
3769
+ if (!this.preloadService) {
3770
+ return this.store.upsertMany(entities.map((entity) => (Object.assign(Object.assign({}, entity), { loaded: true }))));
3771
+ }
3772
+ const preloadedEntities = yield this.preloadService.reloadEntities(entities);
3773
+ return this.store.upsertMany(preloadedEntities.map((preloadedEntity) => (Object.assign(Object.assign({}, preloadedEntity), { loaded: true }))));
3774
+ });
3775
+ }
3776
+ unselectAll() {
3777
+ this.store.set([]);
3778
+ return this.store.update({
3779
+ allSelected: false,
3780
+ unselectedEntity: []
3781
+ });
3782
+ }
3783
+ unselect(id) {
3784
+ this.store.update((state) => ({
3785
+ unselectedEntity: arrayAdd(state.unselectedEntity, id)
3786
+ }));
3787
+ this.store.remove(id);
3788
+ }
3789
+ unselectEntity(entity) {
3790
+ this.store.update((state) => ({
3791
+ unselectedEntity: arrayAdd(state.unselectedEntity, entity[this.idKey])
3792
+ }));
3793
+ this.store.remove(entity[this.idKey]);
3794
+ }
3795
+ unselectManyEntities(entities) {
3796
+ this.store.remove(entities.map((entity) => entity[this.idKey]));
3797
+ }
3798
+ setEntities(ids, activeId) {
3799
+ return __awaiter(this, void 0, void 0, function* () {
3800
+ this.store.update({
3801
+ unselectedEntity: [],
3802
+ allSelected: false
3803
+ });
3804
+ this.store.set(ids.map((id) => ({
3805
+ [this.idKey]: id,
3806
+ loaded: false
3807
+ })));
3808
+ if (activeId) {
3809
+ this.store.setActive(activeId);
3810
+ }
3811
+ });
3812
+ }
3813
+ next() {
3814
+ return __awaiter(this, void 0, void 0, function* () {
3815
+ const { ids, active } = this.store.getValue();
3816
+ const index = ids.indexOf(active);
3817
+ yield this.loadActiveEntity(ids[index + 1], 1);
3818
+ });
3819
+ }
3820
+ previous() {
3821
+ return __awaiter(this, void 0, void 0, function* () {
3822
+ const { ids, active } = this.store.getValue();
3823
+ const index = ids.indexOf(active);
3824
+ yield this.loadActiveEntity(ids[index - 1], -1);
3825
+ });
3826
+ }
3827
+ first() {
3828
+ return __awaiter(this, void 0, void 0, function* () {
3829
+ const { ids } = this.store.getValue();
3830
+ yield this.loadActiveEntity(ids[0], 1);
3831
+ });
3832
+ }
3833
+ last() {
3834
+ return __awaiter(this, void 0, void 0, function* () {
3835
+ const { ids } = this.store.getValue();
3836
+ yield this.loadActiveEntity(ids[ids.length - 1], -1);
3837
+ });
3838
+ }
3839
+ removeActive() {
3840
+ return __awaiter(this, void 0, void 0, function* () {
3841
+ const { active, ids } = this.store.getValue();
3842
+ const index = ids.indexOf(active);
3843
+ this.store.remove(active);
3844
+ if (index === (ids.length - 1)) {
3845
+ yield this.loadActiveEntity(ids[index - 1], -1);
3846
+ }
3847
+ else {
3848
+ yield this.loadActiveEntity(ids[index + 1], 1);
3849
+ }
3850
+ });
3851
+ }
3852
+ loadActiveEntity(id, direction) {
3853
+ var _a;
3854
+ return __awaiter(this, void 0, void 0, function* () {
3855
+ try {
3856
+ this.store.setActive(id);
3857
+ const { entities } = this.store.getValue();
3858
+ if (!((_a = entities[+id + direction * this.preloadedWindow]) === null || _a === void 0 ? void 0 : _a.loaded)) {
3859
+ yield this.loadEntities(false);
3860
+ }
3861
+ }
3862
+ catch (e) {
3863
+ this.store.setError(e);
3864
+ }
3865
+ });
3866
+ }
3867
+ loadEntities(loadExtremity) {
3868
+ return __awaiter(this, void 0, void 0, function* () {
3869
+ if (!this.preloadService) {
3870
+ return;
3871
+ }
3872
+ const toLoad = this.getListIdToLoad(loadExtremity);
3873
+ if (!toLoad.length) {
3874
+ return;
3875
+ }
3876
+ const entities = yield this.preloadService.loadEntitiesById(toLoad);
3877
+ this.store.upsertMany(entities.map((entity) => (Object.assign(Object.assign({}, entity), { loaded: true }))));
3878
+ });
3879
+ }
3880
+ getListIdToLoad(loadExtremity) {
3881
+ var _a;
3882
+ const { active, ids, entities } = this.store.getValue();
3883
+ const from = ids.indexOf(active) - this.preloadedWindow > 0 ? ids.indexOf(active) - this.preloadedWindow : 0;
3884
+ const to = ids.indexOf(active) + this.preloadedWindow < ids.length - 1
3885
+ ? ids.indexOf(active) + this.preloadedWindow
3886
+ : ids.length - 1;
3887
+ const toLoad = [];
3888
+ if (loadExtremity) {
3889
+ if (ids.length <= 2) {
3890
+ return ids;
3891
+ }
3892
+ toLoad.push(ids[0], ids[ids.length - 1]);
3893
+ }
3894
+ for (let i = from; i <= to; i++) {
3895
+ if (ids[i] === null || ids[0] === undefined) {
3896
+ continue;
3897
+ }
3898
+ if (!toLoad.includes(ids[i]) && !((_a = entities[ids[i]]) === null || _a === void 0 ? void 0 : _a.loaded)) {
3899
+ toLoad.push(ids[i]);
3900
+ }
3901
+ }
3902
+ return toLoad;
3903
+ }
3904
+ }
3905
+
3906
+ class SelectableListService {
3907
+ constructor(providers) {
3908
+ this.providers = providers;
3909
+ this.stores = new Map();
3910
+ }
3911
+ createState(name, options) {
3912
+ const store = new EntityStore({ allSelected: false, unselectedEntity: [] }, { name, idKey: options === null || options === void 0 ? void 0 : options.idKey });
3913
+ const query = new QueryEntity(store);
3914
+ const state = { store, query };
3915
+ this.stores.set(name, state);
3916
+ return state;
3917
+ }
3918
+ getState(name) {
3919
+ return this.stores.get(name);
3920
+ }
3921
+ withState(stateName, options) {
3922
+ var _a;
3923
+ const provider = (_a = this.providers) === null || _a === void 0 ? void 0 : _a.find((p) => p.state === stateName);
3924
+ const state = this.getState(stateName);
3925
+ if (state) {
3926
+ return new SelectableListStateService(state.store, provider, options);
3927
+ }
3928
+ const newState = this.createState(stateName, options);
3929
+ return new SelectableListStateService(newState.store, provider, options);
3930
+ }
3931
+ query(stateName) {
3932
+ const state = this.getState(stateName);
3933
+ if (!state) {
3934
+ throw new Error("No state found");
3935
+ }
3936
+ return state.query;
3937
+ }
3938
+ }
3939
+ SelectableListService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: SelectableListService, deps: [{ token: NICE_PRELOAD_SELECTED_ENTITIES_PROVIDER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
3940
+ SelectableListService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: SelectableListService, providedIn: "root" });
3941
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: SelectableListService, decorators: [{
3942
+ type: Injectable,
3943
+ args: [{ providedIn: "root" }]
3944
+ }], ctorParameters: function () {
3945
+ return [{ type: undefined, decorators: [{
3946
+ type: Optional
3947
+ }, {
3948
+ type: Inject,
3949
+ args: [NICE_PRELOAD_SELECTED_ENTITIES_PROVIDER]
3950
+ }] }];
3951
+ } });
3952
+
3953
+ // tslint:disable-next-line:directive-class-suffix
3954
+ class NiceSelectableListDirective {
3955
+ constructor() {
3956
+ this.defaultOptions = { idKey: "id", preloadWindow: 2 };
3957
+ }
3958
+ ngOnInit() {
3959
+ if (!this.options) {
3960
+ this.options = Object.assign({}, this.defaultOptions);
3961
+ }
3962
+ }
3963
+ ngOnChanges(changes) {
3964
+ if ("options" in changes) {
3965
+ this.options = Object.assign(Object.assign({}, this.defaultOptions), changes.options.currentValue);
3966
+ }
3967
+ }
3968
+ }
3969
+ NiceSelectableListDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
3970
+ NiceSelectableListDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.3", type: NiceSelectableListDirective, selector: "[niceSelectableList]", inputs: { state: "state", options: "options" }, queries: [{ propertyName: "checkboxes", predicate: NiceSelectableListCheckboxDirective, descendants: true }], usesOnChanges: true, ngImport: i0 });
3971
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListDirective, decorators: [{
3972
+ type: Directive,
3973
+ args: [{
3974
+ selector: "[niceSelectableList]"
3975
+ }]
3976
+ }], propDecorators: { state: [{
3977
+ type: Input
3978
+ }], options: [{
3979
+ type: Input
3980
+ }], checkboxes: [{
3981
+ type: ContentChildren,
3982
+ args: [NiceSelectableListCheckboxDirective, { descendants: true }]
3983
+ }] } });
3984
+
3985
+ // tslint:disable-next-line:directive-class-suffix
3986
+ class NiceSelectableListCheckboxDirective {
3987
+ constructor(checkbox, selectableList, selectableListService) {
3988
+ this.checkbox = checkbox;
3989
+ this.selectableList = selectableList;
3990
+ this.selectableListService = selectableListService;
3991
+ this.unsubscribeAll$ = new Subject();
3992
+ }
3993
+ get currentId() {
3994
+ if (!this.selectableEntity || !this.selectableListStateService) {
3995
+ return null;
3996
+ }
3997
+ return this.selectableEntity[this.selectableListStateService.idKey];
3998
+ }
3999
+ ngOnInit() {
4000
+ this.selectableListStateService = this.selectableListService.withState(this.selectableList.state);
4001
+ this.selectableListStateQuery = this.selectableListService.query(this.selectableList.state);
4002
+ if (this.selectableEntity) {
4003
+ this.handleSelectableEntity();
4004
+ }
4005
+ if (this.selectPage) {
4006
+ this.handleSelectPage();
4007
+ }
4008
+ }
4009
+ ngOnDestroy() {
4010
+ this.unsubscribeAll$.next();
4011
+ this.unsubscribeAll$.complete();
4012
+ }
4013
+ handleSelectableEntity() {
4014
+ if (this.checkbox.checked) {
4015
+ this.selectableListStateService.selectEntity(this.selectableEntity);
4016
+ }
4017
+ if (!this.checkbox.checked && this.selectableListStateQuery.getEntity(this.currentId)) {
4018
+ this.checkbox.checked = true;
4019
+ }
4020
+ this.checkbox.change.pipe(takeUntil(this.unsubscribeAll$)).subscribe((value) => {
4021
+ if (value.checked && !this.selectableListStateQuery.getEntity(this.currentId)) {
4022
+ this.selectableListStateService.selectEntity(this.selectableEntity);
4023
+ }
4024
+ if (!value.checked && this.selectableListStateQuery.getEntity(this.currentId)) {
4025
+ this.selectableListStateService.unselectEntity(this.selectableEntity);
4026
+ }
4027
+ });
4028
+ this.selectableListStateQuery.selectEntityAction([
4029
+ EntityActions.Add,
4030
+ EntityActions.Remove,
4031
+ EntityActions.Set
4032
+ ]).pipe(takeUntil(this.unsubscribeAll$)).subscribe(({ ids, type }) => {
4033
+ const shouldTakeAction = ids.includes(this.currentId);
4034
+ if (!shouldTakeAction) {
4035
+ if (type === EntityActions.Set) {
4036
+ this.checkbox.checked = false;
4037
+ }
4038
+ return;
4039
+ }
4040
+ if (!this.checkbox.checked && (type === EntityActions.Add || type === EntityActions.Set)) {
4041
+ this.checkbox.checked = true;
4042
+ }
4043
+ if (this.checkbox.checked && type === EntityActions.Remove) {
4044
+ this.checkbox.checked = false;
4045
+ }
4046
+ });
4047
+ }
4048
+ handleSelectPage() {
4049
+ this.selectableListStateQuery.selectCount().subscribe(() => this.updateCheckboxState());
4050
+ this.selectableList.checkboxes.changes.pipe(takeUntil(this.unsubscribeAll$)).subscribe(() => this.updateCheckboxState());
4051
+ this.checkbox.change.pipe(takeUntil(this.unsubscribeAll$)).subscribe((value) => {
4052
+ for (const checkbox of this.selectableList.checkboxes) {
4053
+ if (checkbox.selectPage) {
4054
+ continue;
4055
+ }
4056
+ checkbox.checkbox.checked = value.checked;
4057
+ checkbox.checkbox.change.emit({ checked: value.checked, source: checkbox.checkbox });
4058
+ }
4059
+ });
4060
+ }
4061
+ updateCheckboxState() {
4062
+ const checkboxes = this.selectableList.checkboxes.filter((checkbox) => !checkbox.selectPage);
4063
+ if (!checkboxes.length) {
4064
+ return;
4065
+ }
4066
+ const count = this.selectableListStateQuery.getCount();
4067
+ if (!count) {
4068
+ this.checkbox.indeterminate = false;
4069
+ this.checkbox.checked = false;
4070
+ return;
4071
+ }
4072
+ if (count !== checkboxes.length) {
4073
+ this.checkbox.indeterminate = true;
4074
+ this.checkbox.checked = false;
4075
+ return;
4076
+ }
4077
+ if (count === checkboxes.length) {
4078
+ this.checkbox.checked = true;
4079
+ this.checkbox.indeterminate = false;
4080
+ }
4081
+ }
4082
+ }
4083
+ NiceSelectableListCheckboxDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListCheckboxDirective, deps: [{ token: i1$4.MatCheckbox }, { token: NiceSelectableListDirective }, { token: SelectableListService }], target: i0.ɵɵFactoryTarget.Directive });
4084
+ NiceSelectableListCheckboxDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.3", type: NiceSelectableListCheckboxDirective, selector: "mat-checkbox[niceSelectableListCheckbox]", inputs: { selectableEntity: "selectableEntity", selectPage: "selectPage" }, ngImport: i0 });
4085
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListCheckboxDirective, decorators: [{
4086
+ type: Directive,
4087
+ args: [{
4088
+ selector: "mat-checkbox[niceSelectableListCheckbox]"
4089
+ }]
4090
+ }], ctorParameters: function () { return [{ type: i1$4.MatCheckbox }, { type: NiceSelectableListDirective }, { type: SelectableListService }]; }, propDecorators: { selectableEntity: [{
4091
+ type: Input
4092
+ }], selectPage: [{
4093
+ type: Input
4094
+ }] } });
4095
+
4096
+ // tslint:disable-next-line:directive-class-suffix
4097
+ class NiceSelectableListSelectAllDirective {
4098
+ constructor(niceFilterViewQuery, selectableList, selectableListService) {
4099
+ this.niceFilterViewQuery = niceFilterViewQuery;
4100
+ this.selectableList = selectableList;
4101
+ this.selectableListService = selectableListService;
4102
+ this.action = "select";
4103
+ }
4104
+ ngOnInit() {
4105
+ this.selectableListStateService = this.selectableListService.withState(this.selectableList.state);
4106
+ this.selectableListStateQuery = this.selectableListService.query(this.selectableList.state);
4107
+ }
4108
+ onClick() {
4109
+ var _a, _b;
4110
+ if (this.action === "select") {
4111
+ const filterParameters = (_b = (_a = this.niceFilterViewQuery) === null || _a === void 0 ? void 0 : _a.getParameters()) !== null && _b !== void 0 ? _b : {};
4112
+ const query = filterParameters ? FilterUtils.parametersToRequest(filterParameters) : null;
4113
+ this.selectableListStateService.selectAll({ query });
4114
+ }
4115
+ else {
4116
+ this.selectableListStateService.unselectAll();
4117
+ }
4118
+ }
4119
+ }
4120
+ NiceSelectableListSelectAllDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListSelectAllDirective, deps: [{ token: NiceFilterViewQuery, optional: true }, { token: NiceSelectableListDirective }, { token: SelectableListService }], target: i0.ɵɵFactoryTarget.Directive });
4121
+ NiceSelectableListSelectAllDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.3", type: NiceSelectableListSelectAllDirective, selector: "button[niceSelectableListSelectAll]", inputs: { action: "action" }, host: { listeners: { "click": "onClick()" } }, ngImport: i0 });
4122
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListSelectAllDirective, decorators: [{
4123
+ type: Directive,
4124
+ args: [{
4125
+ selector: "button[niceSelectableListSelectAll]"
4126
+ }]
4127
+ }], ctorParameters: function () {
4128
+ return [{ type: NiceFilterViewQuery, decorators: [{
4129
+ type: Optional
4130
+ }] }, { type: NiceSelectableListDirective }, { type: SelectableListService }];
4131
+ }, propDecorators: { action: [{
4132
+ type: Input
4133
+ }], onClick: [{
4134
+ type: HostListener,
4135
+ args: ["click"]
4136
+ }] } });
4137
+
4138
+ class NiceSelectableListModule {
4139
+ static register(...providers) {
4140
+ return {
4141
+ ngModule: NiceSelectableListModule,
4142
+ providers: providers.map(x => ({
4143
+ provide: NICE_PRELOAD_SELECTED_ENTITIES_PROVIDER,
4144
+ useClass: x,
4145
+ multi: true
4146
+ }))
4147
+ };
4148
+ }
4149
+ }
4150
+ NiceSelectableListModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
4151
+ NiceSelectableListModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListModule, declarations: [NiceSelectableListDirective, NiceSelectableListCheckboxDirective, NiceSelectableListSelectAllDirective], exports: [NiceSelectableListDirective, NiceSelectableListCheckboxDirective, NiceSelectableListSelectAllDirective] });
4152
+ NiceSelectableListModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListModule, providers: [SelectableListService] });
4153
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: NiceSelectableListModule, decorators: [{
4154
+ type: NgModule,
4155
+ args: [{
4156
+ imports: [],
4157
+ declarations: [NiceSelectableListDirective, NiceSelectableListCheckboxDirective, NiceSelectableListSelectAllDirective],
4158
+ providers: [SelectableListService],
4159
+ exports: [NiceSelectableListDirective, NiceSelectableListCheckboxDirective, NiceSelectableListSelectAllDirective]
4160
+ }]
4161
+ }] });
4162
+
3701
4163
  class StringUtils {
3702
4164
  }
3703
4165
  // tslint:disable-next-line:max-line-length
@@ -3714,5 +4176,5 @@ String.prototype.toTableColumn = function (sortableOrOptions, nullLast) {
3714
4176
  * Generated bundle index. Do not edit.
3715
4177
  */
3716
4178
 
3717
- export { DateFilterComponent, FilterComponent, FilterGroupIconPipe, FilterOperatorTypes, FilterSelectionComponent, FilterType, FilterUtils, LayoutContent, NiceBaseFilterViewComponent, NiceBaseListButtonsDirective, NiceBaseListCardsDirective, NiceBaseListComponent, NiceBaseListCustomContentDirective, NiceBaseListDirectiveModule, NiceBaseListEmptySearchResultStateDirective, NiceBaseListEmptyStateDirective, NiceBaseListFiltersDirective, NiceBaseListModule, NiceBaseListQuery, NiceBaseListService, NiceBaseListStore, NiceBaseListTableDirective, NiceBaseListTitleDirective, NiceCustomDateAdapter, NiceFilterApi, NiceFilterCustomDataViewComponent, NiceFilterDataDirective, NiceFilterExportButtonsComponent, NiceFilterExportDirective, NiceFilterGroupService, NiceFilterInfiniteScrollDataViewComponent, NiceFilterMatPaginatorPaginationDirective, NiceFilterMatSortSortingDirective, NiceFilterMatTableViewDirective, NiceFilterQueryParamsDirective, NiceFilterSearchComponent, NiceFilterService, NiceFilterViewComponent, NiceFilterViewModule, NiceFilterViewQuery, NiceFilterViewService, NiceListState, NiceMultiStateFilterService, NiceMultiStateListComponent, NiceMultiStateListModule, NiceMultiStateListQuery, NiceMultiStateListService, NiceMultiStateListStore, NiceQueryBuilderComponent, NiceQueryBuilderModule, NiceSavedReportService, NumberFilterComponent, OrderUtils, QBFilterUtils, QueryBuilderTriggerDirective, RadioFilterComponent, RuleComponent, SelectFilterComponent, StringUtils, TableColumns, TextFilterComponent, defaultLayout, initialBaseListState, initialValue$1 as initialValue, mixinNiceFilterApi };
4179
+ export { DateFilterComponent, FilterComponent, FilterGroupIconPipe, FilterOperatorTypes, FilterSelectionComponent, FilterType, FilterUtils, LayoutContent, NiceBaseFilterViewComponent, NiceBaseListButtonsDirective, NiceBaseListCardsDirective, NiceBaseListComponent, NiceBaseListCustomContentDirective, NiceBaseListDirectiveModule, NiceBaseListEmptySearchResultStateDirective, NiceBaseListEmptyStateDirective, NiceBaseListFiltersDirective, NiceBaseListModule, NiceBaseListQuery, NiceBaseListService, NiceBaseListStore, NiceBaseListTableDirective, NiceBaseListTitleDirective, NiceCustomDateAdapter, NiceFilterApi, NiceFilterCustomDataViewComponent, NiceFilterDataDirective, NiceFilterExportButtonsComponent, NiceFilterExportDirective, NiceFilterGroupService, NiceFilterInfiniteScrollDataViewComponent, NiceFilterMatPaginatorPaginationDirective, NiceFilterMatSortSortingDirective, NiceFilterMatTableViewDirective, NiceFilterQueryParamsDirective, NiceFilterSearchComponent, NiceFilterService, NiceFilterViewComponent, NiceFilterViewModule, NiceFilterViewQuery, NiceFilterViewService, NiceListState, NiceMultiStateFilterService, NiceMultiStateListComponent, NiceMultiStateListModule, NiceMultiStateListQuery, NiceMultiStateListService, NiceMultiStateListStore, NicePreloadSelectedEntitiesProvider, NiceQueryBuilderComponent, NiceQueryBuilderModule, NiceSavedReportService, NiceSelectableListCheckboxDirective, NiceSelectableListDirective, NiceSelectableListModule, NiceSelectableListSelectAllDirective, NumberFilterComponent, OrderUtils, QBFilterUtils, QueryBuilderTriggerDirective, RadioFilterComponent, RuleComponent, SelectFilterComponent, SelectableListService, SelectableListStateService, StringUtils, TableColumns, TextFilterComponent, defaultLayout, initialBaseListState, initialValue$1 as initialValue, mixinNiceFilterApi };
3718
4180
  //# sourceMappingURL=recursyve-nice-data-filter-kit.mjs.map