@kuzntsv/uikit 1.0.48 → 1.0.50

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,5 +1,5 @@
1
1
  import * as i0 from "@angular/core";
2
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Directive, ElementRef, HostListener, Injectable, InjectionToken, NgZone, Pipe, computed, effect, inject, input, linkedSignal, makeEnvironmentProviders, output, signal, viewChild } from "@angular/core";
2
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Directive, ElementRef, HostListener, Injectable, InjectionToken, NgZone, Pipe, computed, effect, inject, input, linkedSignal, makeEnvironmentProviders, model, output, signal, viewChild } from "@angular/core";
3
3
  import { Router, RouterLink } from "@angular/router";
4
4
  import { ReplaySubject, Subject, Subscription, filter, finalize, forkJoin, map, of, startWith, switchMap, take, tap } from "rxjs";
5
5
  import { API_NAME, AuthService, HIDE_ROLE_MARKER, NotificationService, RoleService, UIKIT_NOTIFICATION_TOKEN } from "@kuzntsv/uikit";
@@ -2636,14 +2636,8 @@ var BaseSignalFilterClass = class BaseSignalFilterClass {
2636
2636
  loaderService = inject(LoaderService);
2637
2637
  notificationService = inject(NotificationService);
2638
2638
  defaultDebounceTime = 500;
2639
- initialValues = input({}, ...ngDevMode ? [{ debugName: "initialValues" }] : /* istanbul ignore next */ []);
2639
+ filter = model({}, ...ngDevMode ? [{ debugName: "filter" }] : /* istanbul ignore next */ []);
2640
2640
  clearFilter = input(null, ...ngDevMode ? [{ debugName: "clearFilter" }] : /* istanbul ignore next */ []);
2641
- filterChange = output();
2642
- filter = linkedSignal(() => this.initialValues(), ...ngDevMode ? [{ debugName: "filter" }] : /* istanbul ignore next */ []);
2643
- subscription = new Subscription();
2644
- ngOnDestroy() {
2645
- this.subscription.unsubscribe();
2646
- }
2647
2641
  static ɵfac = i0.ɵɵngDeclareFactory({
2648
2642
  minVersion: "12.0.0",
2649
2643
  version: "22.2.2",
@@ -2658,9 +2652,9 @@ var BaseSignalFilterClass = class BaseSignalFilterClass {
2658
2652
  type: BaseSignalFilterClass,
2659
2653
  isStandalone: true,
2660
2654
  inputs: {
2661
- initialValues: {
2662
- classPropertyName: "initialValues",
2663
- publicName: "initialValues",
2655
+ filter: {
2656
+ classPropertyName: "filter",
2657
+ publicName: "filter",
2664
2658
  isSignal: true,
2665
2659
  isRequired: false,
2666
2660
  transformFunction: null
@@ -2673,7 +2667,7 @@ var BaseSignalFilterClass = class BaseSignalFilterClass {
2673
2667
  transformFunction: null
2674
2668
  }
2675
2669
  },
2676
- outputs: { filterChange: "filterChange" },
2670
+ outputs: { filter: "filterChange" },
2677
2671
  ngImport: i0
2678
2672
  });
2679
2673
  };
@@ -2684,13 +2678,16 @@ i0.ɵɵngDeclareClassMetadata({
2684
2678
  type: BaseSignalFilterClass,
2685
2679
  decorators: [{ type: Directive }],
2686
2680
  propDecorators: {
2687
- initialValues: [{
2681
+ filter: [{
2688
2682
  type: i0.Input,
2689
2683
  args: [{
2690
2684
  isSignal: true,
2691
- alias: "initialValues",
2685
+ alias: "filter",
2692
2686
  required: false
2693
2687
  }]
2688
+ }, {
2689
+ type: i0.Output,
2690
+ args: ["filterChange"]
2694
2691
  }],
2695
2692
  clearFilter: [{
2696
2693
  type: i0.Input,
@@ -2699,19 +2696,18 @@ i0.ɵɵngDeclareClassMetadata({
2699
2696
  alias: "clearFilter",
2700
2697
  required: false
2701
2698
  }]
2702
- }],
2703
- filterChange: [{
2704
- type: i0.Output,
2705
- args: ["filterChange"]
2706
2699
  }]
2707
2700
  }
2708
2701
  });
2709
2702
  var BaseSignalPageClass = class BaseSignalPageClass {
2710
2703
  dialog = inject(MatDialog);
2711
- entityType;
2712
- entityService;
2713
2704
  entityEditComponent;
2714
2705
  extraData;
2706
+ filterSchema;
2707
+ defaultFilters;
2708
+ get storagePrefix() {
2709
+ return `${this.constructor.name}_Filter_`;
2710
+ }
2715
2711
  defaultPageIndex = 0;
2716
2712
  defaultPageSize = 10;
2717
2713
  dialogEditWidth = "auto";
@@ -2728,7 +2724,6 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2728
2724
  editorRoles = [];
2729
2725
  executeRoles = [];
2730
2726
  hideRoles = [HIDE_ROLE_MARKER];
2731
- clearFilters = signal(null, ...ngDevMode ? [{ debugName: "clearFilters" }] : /* istanbul ignore next */ []);
2732
2727
  allowMultiSelect = false;
2733
2728
  selected = [];
2734
2729
  fnGetData = signal(null, ...ngDevMode ? [{ debugName: "fnGetData" }] : /* istanbul ignore next */ []);
@@ -2772,6 +2767,53 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2772
2767
  const saved = this.localStorageService.getData(this.constructor.name + "_Filters");
2773
2768
  return saved ? JSON.parse(saved) : {};
2774
2769
  }
2770
+ initFilters() {
2771
+ if (!this.filterSchema || !this.defaultFilters) return;
2772
+ const prefix = this.storagePrefix;
2773
+ const initial = { ...this.defaultFilters };
2774
+ Object.keys(this.defaultFilters).forEach((key) => {
2775
+ const storageKey = `${prefix}${key}`;
2776
+ const rawValue = this.localStorageService.getData(storageKey);
2777
+ if (rawValue !== null && rawValue !== void 0) try {
2778
+ initial[key] = JSON.parse(rawValue);
2779
+ } catch {
2780
+ initial[key] = rawValue;
2781
+ }
2782
+ });
2783
+ const validation = this.filterSchema.safeParse(initial);
2784
+ this.filters.set(validation.success ? validation.data : this.defaultFilters);
2785
+ this.trackFilterChanges();
2786
+ }
2787
+ trackFilterChanges() {
2788
+ if (!this.defaultFilters) return;
2789
+ let previousFilters = { ...this.filters() };
2790
+ effect(() => {
2791
+ const currentFilters = this.filters();
2792
+ const prefix = this.storagePrefix;
2793
+ let filterChanged = false;
2794
+ Object.keys(currentFilters).forEach((key) => {
2795
+ const prevVal = previousFilters[key];
2796
+ const currVal = currentFilters[key];
2797
+ if (prevVal !== currVal) {
2798
+ filterChanged = true;
2799
+ const storageKey = `${prefix}${String(key)}`;
2800
+ if (currVal === null || currVal === void 0 || currVal === "" || currVal === 0 || currVal === -1 || Array.isArray(currVal) && currVal.length === 0) localStorage.removeItem(storageKey);
2801
+ else this.localStorageService.saveData(storageKey, JSON.stringify(currVal));
2802
+ }
2803
+ });
2804
+ if (filterChanged) {}
2805
+ previousFilters = { ...currentFilters };
2806
+ });
2807
+ }
2808
+ clearEvent() {
2809
+ if (!this.defaultFilters) return;
2810
+ const prefix = this.storagePrefix;
2811
+ Object.keys(this.defaultFilters).forEach((key) => {
2812
+ localStorage.removeItem(`${prefix}${key}`);
2813
+ });
2814
+ this.filters.set({ ...this.defaultFilters });
2815
+ this.clearFilters.set({});
2816
+ }
2775
2817
  getInitialFilters2() {
2776
2818
  const prefix = this.constructor.name + "_Filter_";
2777
2819
  const state = {};
@@ -2789,8 +2831,8 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2789
2831
  }
2790
2832
  return state;
2791
2833
  }
2792
- filters = signal(this.getInitialFilters(), ...ngDevMode ? [{ debugName: "filters" }] : /* istanbul ignore next */ []);
2793
- filters2 = signal(this.getInitialFilters2(), ...ngDevMode ? [{ debugName: "filters2" }] : /* istanbul ignore next */ []);
2834
+ filters = signal({}, ...ngDevMode ? [{ debugName: "filters" }] : /* istanbul ignore next */ []);
2835
+ clearFilters = signal(null, ...ngDevMode ? [{ debugName: "clearFilters" }] : /* istanbul ignore next */ []);
2794
2836
  tableState = signal({
2795
2837
  sortActive: "",
2796
2838
  sortDirection: "",
@@ -2818,21 +2860,25 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2818
2860
  this.fnGetCount.set(fnGetCount);
2819
2861
  }
2820
2862
  setFilter(key, value) {
2821
- const storageKey = `${this.constructor.name}_Filter_${key}`;
2863
+ const storageKey = `${this.constructor.name}_Filter_${String(key)}`;
2822
2864
  this.tableState.update((prev) => ({
2823
2865
  ...prev,
2824
2866
  pageIndex: 0
2825
2867
  }));
2868
+ let isValueEmpty = value === null || value === void 0 || value === "" || value === "-1";
2869
+ if (Array.isArray(value) && value.length === 0) isValueEmpty = true;
2870
+ if (isValueEmpty) this.localStorageService.removeData(storageKey);
2871
+ else this.localStorageService.saveData(storageKey, JSON.stringify(value));
2826
2872
  this.filters.update((prev) => {
2827
- const next = { ...prev };
2828
- if (value === null || value === void 0 || value === "" || value === "-1") {
2873
+ if (isValueEmpty) {
2874
+ const next = { ...prev };
2829
2875
  delete next[key];
2830
- localStorage.removeItem(storageKey);
2831
- } else {
2832
- next[key] = value;
2833
- this.localStorageService.saveData(storageKey, JSON.stringify(value));
2876
+ return next;
2834
2877
  }
2835
- return next;
2878
+ return {
2879
+ ...prev,
2880
+ [key]: value
2881
+ };
2836
2882
  });
2837
2883
  }
2838
2884
  onPageChange(pageState) {
@@ -2981,21 +3027,6 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2981
3027
  this.dataResource()?.reload();
2982
3028
  this.countResource()?.reload();
2983
3029
  }
2984
- clearEvent() {
2985
- const prefix = this.constructor.name + "_Filter_";
2986
- const keysToRemove = [];
2987
- for (let i = 0; i < localStorage.length; i++) {
2988
- const key = localStorage.key(i);
2989
- if (key && key.startsWith(prefix)) keysToRemove.push(key);
2990
- }
2991
- keysToRemove.forEach((key) => localStorage.removeItem(key));
2992
- this.filters.set({});
2993
- this.tableState.update((prev) => ({
2994
- ...prev,
2995
- pageIndex: 0
2996
- }));
2997
- this.clearFilters.set({});
2998
- }
2999
3030
  onRemovalMessageChange(message) {
3000
3031
  this.removalMessage = message;
3001
3032
  }
@@ -3069,6 +3100,16 @@ i0.ɵɵngDeclareClassMetadata({
3069
3100
  decorators: [{ type: Directive }],
3070
3101
  ctorParameters: () => []
3071
3102
  });
3103
+ function cleanFilterParams(filters) {
3104
+ const cleanParams = {};
3105
+ Object.keys(filters).forEach((key) => {
3106
+ const value = filters[key];
3107
+ if (value === null || value === void 0 || value === "") return;
3108
+ if (Array.isArray(value) && value.length === 0) return;
3109
+ cleanParams[key] = value;
3110
+ });
3111
+ return cleanParams;
3112
+ }
3072
3113
  var BaseSignalServiceClass = class BaseSignalServiceClass {
3073
3114
  countRoute = "count";
3074
3115
  pageIndexParam = "page";
@@ -3141,6 +3182,41 @@ var BaseSignalServiceClass = class BaseSignalServiceClass {
3141
3182
  }
3142
3183
  });
3143
3184
  }
3185
+ getObjectsByFilterPaging(pageIndex, pageSize, sortColumn, direction, filters) {
3186
+ return httpResource(() => {
3187
+ this._refreshTrigger();
3188
+ const queryParams = { ...cleanFilterParams(filters) };
3189
+ if (pageIndex + 1) queryParams[this.pageIndexParam] = pageIndex + 1;
3190
+ if (pageSize) queryParams[this.pageSizeParam] = pageSize;
3191
+ if (sortColumn) queryParams[this.sortColumnParam] = sortColumn;
3192
+ if (direction) queryParams[this.directionParam] = direction;
3193
+ return {
3194
+ url: this.baseRoute,
3195
+ params: queryParams
3196
+ };
3197
+ }, {
3198
+ ...this.getHttpContext(),
3199
+ defaultValue: [],
3200
+ parse: (data) => {
3201
+ if (!data) return [];
3202
+ return z.array(this.schema).parse(data);
3203
+ }
3204
+ });
3205
+ }
3206
+ getObjectsCountByFilter(filters) {
3207
+ return httpResource(() => {
3208
+ this._refreshTrigger();
3209
+ const cleanFields = cleanFilterParams(filters);
3210
+ return {
3211
+ url: `${this.baseRoute}${this.countRoute}`,
3212
+ params: { ...cleanFields }
3213
+ };
3214
+ }, {
3215
+ ...this.getHttpContext(),
3216
+ defaultValue: 0,
3217
+ parse: (data) => z.coerce.number().parse(data)
3218
+ });
3219
+ }
3144
3220
  newObject(entity) {
3145
3221
  return this.http.post(this.baseRoute, entity, this.getHttpContext());
3146
3222
  }