@kuzntsv/uikit 1.0.34 → 1.0.36

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,7 +1,7 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Directive, ElementRef, HostListener, Injectable, InjectionToken, NgZone, Pipe, computed, effect, inject, input, linkedSignal, makeEnvironmentProviders, output, signal, viewChild } from "@angular/core";
3
3
  import { Router, RouterLink } from "@angular/router";
4
- import { ReplaySubject, Subject, Subscription, filter, finalize, forkJoin, map, of, startWith, switchMap, take, tap } from "rxjs";
4
+ import { ReplaySubject, Subject, Subscription, filter, finalize, forkJoin, map, of, startWith, take } from "rxjs";
5
5
  import { API_NAME, AuthService, HIDE_ROLE_MARKER, NotificationService, RoleService, UIKIT_NOTIFICATION_TOKEN } from "@kuzntsv/uikit";
6
6
  import * as i1$1 from "@angular/forms";
7
7
  import { FormControl, FormGroup, FormsModule, NgControl, ReactiveFormsModule, Validators } from "@angular/forms";
@@ -28,6 +28,7 @@ import { MatTooltip, MatTooltipModule } from "@angular/material/tooltip";
28
28
  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
+ import { rxResource } from "@angular/core/rxjs-interop";
31
32
  import { DomSanitizer } from "@angular/platform-browser";
32
33
  import { MatProgressSpinner } from "@angular/material/progress-spinner";
33
34
  import * as i3 from "@angular/cdk/scrolling";
@@ -2087,10 +2088,11 @@ var EntityAction;
2087
2088
  EntityAction["Delete"] = "Удаление";
2088
2089
  })(EntityAction || (EntityAction = {}));
2089
2090
  var BaseFilterClass = class BaseFilterClass {
2090
- localStorageService = inject(LocalStorageService);
2091
2091
  loaderService = inject(LoaderService);
2092
2092
  notificationService = inject(NotificationService);
2093
2093
  defaultDebounceTime = 500;
2094
+ filters = input({}, ...ngDevMode ? [{ debugName: "filters" }] : /* istanbul ignore next */ []);
2095
+ clearFilters = input(null, ...ngDevMode ? [{ debugName: "clearFilters" }] : /* istanbul ignore next */ []);
2094
2096
  subscription = new Subscription();
2095
2097
  constructor() {}
2096
2098
  ngOnDestroy() {
@@ -2105,10 +2107,26 @@ var BaseFilterClass = class BaseFilterClass {
2105
2107
  target: i0.ɵɵFactoryTarget.Directive
2106
2108
  });
2107
2109
  static ɵdir = i0.ɵɵngDeclareDirective({
2108
- minVersion: "14.0.0",
2110
+ minVersion: "17.1.0",
2109
2111
  version: "22.2.2",
2110
2112
  type: BaseFilterClass,
2111
2113
  isStandalone: true,
2114
+ inputs: {
2115
+ filters: {
2116
+ classPropertyName: "filters",
2117
+ publicName: "filters",
2118
+ isSignal: true,
2119
+ isRequired: false,
2120
+ transformFunction: null
2121
+ },
2122
+ clearFilters: {
2123
+ classPropertyName: "clearFilters",
2124
+ publicName: "clearFilters",
2125
+ isSignal: true,
2126
+ isRequired: false,
2127
+ transformFunction: null
2128
+ }
2129
+ },
2112
2130
  ngImport: i0
2113
2131
  });
2114
2132
  };
@@ -2118,7 +2136,25 @@ i0.ɵɵngDeclareClassMetadata({
2118
2136
  ngImport: i0,
2119
2137
  type: BaseFilterClass,
2120
2138
  decorators: [{ type: Directive }],
2121
- ctorParameters: () => []
2139
+ ctorParameters: () => [],
2140
+ propDecorators: {
2141
+ filters: [{
2142
+ type: i0.Input,
2143
+ args: [{
2144
+ isSignal: true,
2145
+ alias: "filters",
2146
+ required: false
2147
+ }]
2148
+ }],
2149
+ clearFilters: [{
2150
+ type: i0.Input,
2151
+ args: [{
2152
+ isSignal: true,
2153
+ alias: "clearFilters",
2154
+ required: false
2155
+ }]
2156
+ }]
2157
+ }
2122
2158
  });
2123
2159
  var BaseNavBarMenuClass = class BaseNavBarMenuClass {
2124
2160
  roleService = inject(RoleService);
@@ -2202,8 +2238,6 @@ i0.ɵɵngDeclareClassMetadata({
2202
2238
  });
2203
2239
  var BasePageClass = class BasePageClass {
2204
2240
  dialog = inject(MatDialog);
2205
- data = signal([], ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
2206
- length = signal(0, ...ngDevMode ? [{ debugName: "length" }] : /* istanbul ignore next */ []);
2207
2241
  entityService;
2208
2242
  entityType;
2209
2243
  entityEditComponent;
@@ -2226,11 +2260,45 @@ var BasePageClass = class BasePageClass {
2226
2260
  hideRoles = [HIDE_ROLE_MARKER];
2227
2261
  loadData$ = new Subject();
2228
2262
  loadLength$ = new Subject();
2229
- clearFilter$ = new Subject();
2230
- clearFilter = null;
2231
2263
  allowMultiSelect = false;
2232
2264
  selected = [];
2233
- tableState;
2265
+ fnGetData = signal(null, ...ngDevMode ? [{ debugName: "fnGetData" }] : /* istanbul ignore next */ []);
2266
+ fnGetCount = signal(null, ...ngDevMode ? [{ debugName: "fnGetCount" }] : /* istanbul ignore next */ []);
2267
+ fnMapEntity = signal(void 0, ...ngDevMode ? [{ debugName: "fnMapEntity" }] : /* istanbul ignore next */ []);
2268
+ dataResource = rxResource({
2269
+ params: () => {
2270
+ const fetchFn = this.fnGetData();
2271
+ if (!fetchFn) return null;
2272
+ return {
2273
+ fetchFn,
2274
+ state: this.tableState(),
2275
+ mapFn: this.fnMapEntity()
2276
+ };
2277
+ },
2278
+ stream: ({ params, abortSignal }) => {
2279
+ if (!params) return of([]);
2280
+ this.loaderService.show();
2281
+ return params.fetchFn().pipe(map((v) => params.mapFn && Array.isArray(v) ? v.map(params.mapFn()) : v), finalize(() => {
2282
+ this.loaderService.hide();
2283
+ }));
2284
+ }
2285
+ });
2286
+ countResource = rxResource({
2287
+ params: () => {
2288
+ const fetchCountFn = this.fnGetCount();
2289
+ if (!fetchCountFn) return null;
2290
+ return {
2291
+ fetchCountFn,
2292
+ state: this.tableState()
2293
+ };
2294
+ },
2295
+ stream: ({ params }) => {
2296
+ if (!params) return of(0);
2297
+ return params.fetchCountFn();
2298
+ }
2299
+ });
2300
+ data = computed(() => this.dataResource.value() || [], ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
2301
+ length = computed(() => this.countResource.value() || 0, ...ngDevMode ? [{ debugName: "length" }] : /* istanbul ignore next */ []);
2234
2302
  editBtnDisabled = true;
2235
2303
  removeBtnDisabled = true;
2236
2304
  dblClickedEventEnable = true;
@@ -2240,59 +2308,62 @@ var BasePageClass = class BasePageClass {
2240
2308
  loaderService = inject(LoaderService);
2241
2309
  notificationService = inject(UIKIT_NOTIFICATION_TOKEN);
2242
2310
  subscription = new Subscription();
2311
+ filters = signal(() => {
2312
+ const saved = this.localStorageService.getData(this.constructor.name + "_Filters");
2313
+ return saved ? JSON.parse(saved) : {};
2314
+ }, ...ngDevMode ? [{ debugName: "filters" }] : /* istanbul ignore next */ []);
2315
+ tableState = signal({
2316
+ sortActive: "",
2317
+ sortDirection: "",
2318
+ pageIndex: this.defaultPageIndex,
2319
+ pageSize: this.defaultPageSize
2320
+ }, ...ngDevMode ? [{ debugName: "tableState" }] : /* istanbul ignore next */ []);
2243
2321
  constructor() {
2244
- this.tableState = {
2322
+ this.tableState.set({
2245
2323
  sortActive: this.localStorageService.getData(this.constructor.name + "SortActive") || "",
2246
2324
  sortDirection: this.localStorageService.getData(this.constructor.name + "SortDirection") || "",
2247
2325
  pageIndex: Number(this.localStorageService.getData(this.constructor.name + "PageIndex")) || this.defaultPageIndex,
2248
2326
  pageSize: Number(this.localStorageService.getData(this.constructor.name + "PageSize")) || this.defaultPageSize
2249
- };
2327
+ });
2250
2328
  }
2251
2329
  ngOnDestroy() {
2252
2330
  this.subscription.unsubscribe();
2253
2331
  }
2254
2332
  subscribeToLoadData(fnGetData, fnGetCount, fnMapEntity) {
2255
- const subs = this.loadData$.pipe(tap(() => this.loaderService.show()), switchMap(() => fnGetData()), map((v) => fnMapEntity && Array.isArray(v) ? v.map(fnMapEntity()) : v)).subscribe({
2256
- next: (response) => {
2257
- this.data.set(response || []);
2258
- this.loaderService.hide();
2259
- },
2260
- error: (error) => {
2261
- this.loaderService.hide();
2262
- console.log(error);
2263
- const errorMessage = error.message || error;
2264
- this.notificationService?.error("Произошла ошибка: " + errorMessage, 0);
2265
- }
2333
+ this.fnMapEntity.set(fnMapEntity);
2334
+ this.fnGetData.set(fnGetData);
2335
+ this.fnGetCount.set(fnGetCount);
2336
+ }
2337
+ setFilter(key, value) {
2338
+ this.filters.update((prev) => {
2339
+ const next = { ...prev };
2340
+ if (value === null || value === void 0 || value === "" || value === "-1") delete next[key];
2341
+ else next[key] = value;
2342
+ this.localStorageService.saveData(this.constructor.name + "_Filters", JSON.stringify(next));
2343
+ return next;
2266
2344
  });
2267
- this.subscription?.add(subs);
2268
- const subs2 = this.loadLength$.pipe(switchMap(() => fnGetCount())).subscribe({
2269
- next: (response) => {
2270
- this.length.set(response);
2271
- },
2272
- error: (error) => {
2273
- console.log(error);
2274
- this.notificationService.error("Произошла ошибка: " + error, 0);
2275
- }
2276
- });
2277
- this.subscription?.add(subs2);
2278
- this.loadData$.next(null);
2279
- this.loadLength$.next(null);
2345
+ this.tableState.update((prev) => ({
2346
+ ...prev,
2347
+ pageIndex: 0
2348
+ }));
2280
2349
  }
2281
2350
  onPageChange(pageState) {
2282
- this.tableState.pageIndex = pageState.pageIndex;
2283
- this.tableState.pageSize = pageState.pageSize;
2284
2351
  this.localStorageService.saveData(this.constructor.name + "PageIndex", pageState.pageIndex.toString());
2285
2352
  this.localStorageService.saveData(this.constructor.name + "PageSize", pageState.pageSize.toString());
2286
- this.loadData$.next(null);
2287
- this.loadLength$.next(null);
2353
+ this.tableState.update((prev) => ({
2354
+ ...prev,
2355
+ pageIndex: pageState.pageIndex,
2356
+ pageSize: pageState.pageSize
2357
+ }));
2288
2358
  }
2289
2359
  onSortChange(sortState) {
2290
- this.tableState.sortActive = sortState.sortActive;
2291
- this.tableState.sortDirection = sortState.sortDirection;
2292
2360
  this.localStorageService.saveData(this.constructor.name + "SortActive", sortState.sortActive);
2293
2361
  this.localStorageService.saveData(this.constructor.name + "SortDirection", sortState.sortDirection);
2294
- this.loadData$.next(null);
2295
- this.loadLength$.next(null);
2362
+ this.tableState.update((prev) => ({
2363
+ ...prev,
2364
+ sortActive: sortState.sortActive,
2365
+ sortDirection: sortState.sortDirection
2366
+ }));
2296
2367
  }
2297
2368
  entityFactory(type) {
2298
2369
  return new type();
@@ -2421,12 +2492,16 @@ var BasePageClass = class BasePageClass {
2421
2492
  }
2422
2493
  }
2423
2494
  refreshEvent() {
2424
- this.loadData$.next(null);
2425
- this.loadLength$.next(null);
2495
+ this.dataResource.reload();
2496
+ this.countResource.reload();
2426
2497
  }
2427
2498
  clearEvent() {
2428
- this.clearFilter$.next(null);
2429
- this.clearFilter = {};
2499
+ this.filters.set({});
2500
+ this.localStorageService.saveData(this.constructor.name + "_Filters", "{}");
2501
+ this.tableState.update((prev) => ({
2502
+ ...prev,
2503
+ pageIndex: 0
2504
+ }));
2430
2505
  }
2431
2506
  onRemovalMessageChange(message) {
2432
2507
  this.removalMessage = message;