@kuzntsv/uikit 1.0.42 → 1.0.44

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.
@@ -29,7 +29,6 @@ import { MatDivider } from "@angular/material/divider";
29
29
  import { MatMenu, MatMenuContent, MatMenuItem, MatMenuTrigger } from "@angular/material/menu";
30
30
  import { MatToolbar } from "@angular/material/toolbar";
31
31
  import z, { z as z$1 } from "zod";
32
- import { rxResource } from "@angular/core/rxjs-interop";
33
32
  import { DomSanitizer } from "@angular/platform-browser";
34
33
  import { MatProgressSpinner } from "@angular/material/progress-spinner";
35
34
  import * as i3 from "@angular/cdk/scrolling";
@@ -2296,9 +2295,6 @@ var BasePageClass = class BasePageClass {
2296
2295
  this.loadData$.next(null);
2297
2296
  this.loadLength$.next(null);
2298
2297
  }
2299
- entityFactory(type) {
2300
- return new type();
2301
- }
2302
2298
  onSelectionChange(selected) {
2303
2299
  this.selected = selected;
2304
2300
  this.editBtnDisabledUpdate(this.selected);
@@ -2732,48 +2728,37 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2732
2728
  editorRoles = [];
2733
2729
  executeRoles = [];
2734
2730
  hideRoles = [HIDE_ROLE_MARKER];
2735
- loadData$ = new Subject();
2736
- loadLength$ = new Subject();
2737
2731
  clearFilters = signal(null, ...ngDevMode ? [{ debugName: "clearFilters" }] : /* istanbul ignore next */ []);
2738
2732
  allowMultiSelect = false;
2739
2733
  selected = [];
2740
2734
  fnGetData = signal(null, ...ngDevMode ? [{ debugName: "fnGetData" }] : /* istanbul ignore next */ []);
2741
2735
  fnGetCount = signal(null, ...ngDevMode ? [{ debugName: "fnGetCount" }] : /* istanbul ignore next */ []);
2742
2736
  fnMapEntity = signal(void 0, ...ngDevMode ? [{ debugName: "fnMapEntity" }] : /* istanbul ignore next */ []);
2743
- dataResource = rxResource({
2744
- params: () => {
2745
- const fetchFn = this.fnGetData();
2746
- if (!fetchFn) return null;
2747
- return {
2748
- fetchFn,
2749
- state: this.tableState(),
2750
- mapFn: this.fnMapEntity()
2751
- };
2752
- },
2753
- stream: ({ params, abortSignal }) => {
2754
- if (!params) return of([]);
2755
- this.loaderService.show();
2756
- return params.fetchFn().pipe(map((v) => params.mapFn && Array.isArray(v) ? v.map(params.mapFn()) : v), finalize(() => {
2757
- this.loaderService.hide();
2758
- }));
2759
- }
2760
- });
2761
- countResource = rxResource({
2762
- params: () => {
2763
- const fetchCountFn = this.fnGetCount();
2764
- if (!fetchCountFn) return null;
2765
- return {
2766
- fetchCountFn,
2767
- state: this.tableState()
2768
- };
2769
- },
2770
- stream: ({ params }) => {
2771
- if (!params) return of(0);
2772
- return params.fetchCountFn();
2773
- }
2774
- });
2775
- data = computed(() => this.dataResource.value() || [], ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
2776
- length = computed(() => this.countResource.value() || 0, ...ngDevMode ? [{ debugName: "length" }] : /* istanbul ignore next */ []);
2737
+ dataResource = computed(() => {
2738
+ const fetchFn = this.fnGetData();
2739
+ if (!fetchFn) return null;
2740
+ this.tableState();
2741
+ this.filters();
2742
+ return fetchFn();
2743
+ }, ...ngDevMode ? [{ debugName: "dataResource" }] : /* istanbul ignore next */ []);
2744
+ countResource = computed(() => {
2745
+ const fetchCountFn = this.fnGetCount();
2746
+ if (!fetchCountFn) return null;
2747
+ this.filters();
2748
+ return fetchCountFn();
2749
+ }, ...ngDevMode ? [{ debugName: "countResource" }] : /* istanbul ignore next */ []);
2750
+ data = computed(() => {
2751
+ const rawData = this.dataResource()?.value() || [];
2752
+ const mapFn = this.fnMapEntity();
2753
+ if (mapFn && Array.isArray(rawData)) return rawData.map(mapFn());
2754
+ return rawData;
2755
+ }, ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
2756
+ length = computed(() => this.countResource()?.value() || 0, ...ngDevMode ? [{ debugName: "length" }] : /* istanbul ignore next */ []);
2757
+ isLoading = computed(() => {
2758
+ const dataLoading = this.dataResource()?.isLoading() ?? false;
2759
+ const countLoading = this.countResource()?.isLoading() ?? false;
2760
+ return dataLoading || countLoading;
2761
+ }, ...ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []);
2777
2762
  editBtnDisabled = true;
2778
2763
  removeBtnDisabled = true;
2779
2764
  dblClickedEventEnable = true;
@@ -2819,6 +2804,10 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2819
2804
  pageIndex: Number(this.localStorageService.getData(this.constructor.name + "PageIndex")) || this.defaultPageIndex,
2820
2805
  pageSize: Number(this.localStorageService.getData(this.constructor.name + "PageSize")) || this.defaultPageSize
2821
2806
  });
2807
+ effect(() => {
2808
+ if (this.isLoading()) this.loaderService.show();
2809
+ else this.loaderService.hide();
2810
+ });
2822
2811
  }
2823
2812
  ngOnDestroy() {
2824
2813
  this.subscription.unsubscribe();
@@ -2830,6 +2819,10 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2830
2819
  }
2831
2820
  setFilter(key, value) {
2832
2821
  const storageKey = `${this.constructor.name}_Filter_${key}`;
2822
+ this.tableState.update((prev) => ({
2823
+ ...prev,
2824
+ pageIndex: 0
2825
+ }));
2833
2826
  this.filters.update((prev) => {
2834
2827
  const next = { ...prev };
2835
2828
  if (value === null || value === void 0 || value === "" || value === "-1") {
@@ -2841,10 +2834,6 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2841
2834
  }
2842
2835
  return next;
2843
2836
  });
2844
- this.tableState.update((prev) => ({
2845
- ...prev,
2846
- pageIndex: 0
2847
- }));
2848
2837
  }
2849
2838
  onPageChange(pageState) {
2850
2839
  this.localStorageService.saveData(this.constructor.name + "PageIndex", pageState.pageIndex.toString());
@@ -2864,9 +2853,6 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2864
2853
  sortDirection: sortState.sortDirection
2865
2854
  }));
2866
2855
  }
2867
- entityFactory(type) {
2868
- return new type();
2869
- }
2870
2856
  onSelectionChange(selected) {
2871
2857
  this.selected = selected;
2872
2858
  this.editBtnDisabledUpdate(this.selected);
@@ -2991,8 +2977,8 @@ var BaseSignalPageClass = class BaseSignalPageClass {
2991
2977
  }
2992
2978
  }
2993
2979
  refreshEvent() {
2994
- this.dataResource.reload();
2995
- this.countResource.reload();
2980
+ this.dataResource()?.reload();
2981
+ this.countResource()?.reload();
2996
2982
  }
2997
2983
  clearEvent() {
2998
2984
  const prefix = this.constructor.name + "_Filter_";
@@ -3095,7 +3081,10 @@ var BaseSignalServiceClass = class BaseSignalServiceClass {
3095
3081
  this._refreshTrigger.update((v) => v + 1);
3096
3082
  }
3097
3083
  getObjects() {
3098
- return httpResource(() => ({ url: this.baseRoute }), {
3084
+ return httpResource(() => {
3085
+ this._refreshTrigger();
3086
+ return { url: this.baseRoute };
3087
+ }, {
3099
3088
  ...this.getHttpContext(),
3100
3089
  parse: (data) => {
3101
3090
  if (!data) return [];
@@ -3105,19 +3094,31 @@ var BaseSignalServiceClass = class BaseSignalServiceClass {
3105
3094
  }
3106
3095
  getObject(id) {
3107
3096
  const idSignal = typeof id === "function" ? id : () => id;
3108
- return httpResource(() => `${this.baseRoute}${idSignal()}`, {
3097
+ return httpResource(() => {
3098
+ this._refreshTrigger();
3099
+ const currentId = idSignal();
3100
+ if (currentId === null || currentId === void 0) return;
3101
+ return { url: `${this.baseRoute}${currentId}` };
3102
+ }, {
3109
3103
  ...this.getHttpContext(),
3110
- parse: (data) => data ? new this.entityType(data).deserialize(data) : null
3104
+ parse: (data) => {
3105
+ if (!data) return null;
3106
+ return this.schema.parse(data);
3107
+ }
3111
3108
  });
3112
3109
  }
3113
3110
  getCount() {
3114
- return httpResource(() => ({ url: `${this.baseRoute}${this.countRoute}` }), {
3111
+ return httpResource(() => {
3112
+ this._refreshTrigger();
3113
+ return { url: `${this.baseRoute}${this.countRoute}` };
3114
+ }, {
3115
3115
  ...this.getHttpContext(),
3116
- parse: (data) => Number(data)
3116
+ parse: (data) => z.coerce.number().parse(data)
3117
3117
  });
3118
3118
  }
3119
3119
  getObjectsByPaging(pageIndex, pageSize, sortColumn, direction) {
3120
3120
  return httpResource(() => {
3121
+ this._refreshTrigger();
3121
3122
  const queryParams = {};
3122
3123
  if (pageIndex() + 1) queryParams[this.pageIndexParam] = pageIndex() + 1;
3123
3124
  if (pageSize()) queryParams[this.pageSizeParam] = pageSize();
@@ -3129,35 +3130,18 @@ var BaseSignalServiceClass = class BaseSignalServiceClass {
3129
3130
  };
3130
3131
  }, {
3131
3132
  ...this.getHttpContext(),
3132
- parse: (data) => Array.isArray(data) ? data.map((item) => new this.entityType(item).deserialize(item)) : []
3133
+ parse: (data) => {
3134
+ if (!data) return [];
3135
+ return z.array(this.schema).parse(data);
3136
+ }
3133
3137
  });
3134
3138
  }
3135
3139
  newObject(entity) {
3136
3140
  return this.http.post(this.baseRoute, entity, this.getHttpContext());
3137
3141
  }
3138
- create(dto) {
3139
- return httpResource(() => ({
3140
- url: this.baseRoute,
3141
- method: "POST",
3142
- body: dto
3143
- }), {
3144
- ...this.getHttpContext(),
3145
- parse: (data) => this.schema.parse(data)
3146
- });
3147
- }
3148
3142
  editObject(entity) {
3149
3143
  return this.http.put(this.baseRoute + entity.id, entity, this.getHttpContext());
3150
3144
  }
3151
- update(id, dto) {
3152
- return httpResource(() => ({
3153
- url: `${this.baseRoute}/${id}`,
3154
- method: "PUT",
3155
- body: dto
3156
- }), {
3157
- ...this.getHttpContext(),
3158
- parse: (data) => this.schema.parse(data)
3159
- });
3160
- }
3161
3145
  deleteObject(entity) {
3162
3146
  return this.http.delete(this.baseRoute + entity.id, this.getHttpContext()).pipe(tap(() => this.refresh()));
3163
3147
  }