@kuzntsv/uikit 1.0.36 → 1.0.38

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 * 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, take } from "rxjs";
5
- import { API_NAME, AuthService, HIDE_ROLE_MARKER, NotificationService, RoleService, UIKIT_NOTIFICATION_TOKEN } from "@kuzntsv/uikit";
4
+ import { ReplaySubject, Subject, Subscription, filter, finalize, forkJoin, map, of, startWith, switchMap, take, tap } from "rxjs";
5
+ import { API_NAME, AuthService, 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";
8
8
  import { MatAnchor, MatButton, MatIconButton } from "@angular/material/button";
@@ -28,7 +28,6 @@ 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";
32
31
  import { DomSanitizer } from "@angular/platform-browser";
33
32
  import { MatProgressSpinner } from "@angular/material/progress-spinner";
34
33
  import * as i3 from "@angular/cdk/scrolling";
@@ -2088,11 +2087,10 @@ var EntityAction;
2088
2087
  EntityAction["Delete"] = "Удаление";
2089
2088
  })(EntityAction || (EntityAction = {}));
2090
2089
  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 */ []);
2096
2094
  subscription = new Subscription();
2097
2095
  constructor() {}
2098
2096
  ngOnDestroy() {
@@ -2107,26 +2105,10 @@ var BaseFilterClass = class BaseFilterClass {
2107
2105
  target: i0.ɵɵFactoryTarget.Directive
2108
2106
  });
2109
2107
  static ɵdir = i0.ɵɵngDeclareDirective({
2110
- minVersion: "17.1.0",
2108
+ minVersion: "14.0.0",
2111
2109
  version: "22.2.2",
2112
2110
  type: BaseFilterClass,
2113
2111
  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
- },
2130
2112
  ngImport: i0
2131
2113
  });
2132
2114
  };
@@ -2136,25 +2118,7 @@ i0.ɵɵngDeclareClassMetadata({
2136
2118
  ngImport: i0,
2137
2119
  type: BaseFilterClass,
2138
2120
  decorators: [{ type: Directive }],
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
- }
2121
+ ctorParameters: () => []
2158
2122
  });
2159
2123
  var BaseNavBarMenuClass = class BaseNavBarMenuClass {
2160
2124
  roleService = inject(RoleService);
@@ -2238,6 +2202,8 @@ i0.ɵɵngDeclareClassMetadata({
2238
2202
  });
2239
2203
  var BasePageClass = class BasePageClass {
2240
2204
  dialog = inject(MatDialog);
2205
+ data = signal([], ...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
2206
+ length = signal(0, ...ngDevMode ? [{ debugName: "length" }] : /* istanbul ignore next */ []);
2241
2207
  entityService;
2242
2208
  entityType;
2243
2209
  entityEditComponent;
@@ -2257,48 +2223,14 @@ var BasePageClass = class BasePageClass {
2257
2223
  afterSaveOnEditEvent;
2258
2224
  editorRoles = [];
2259
2225
  executeRoles = [];
2260
- hideRoles = [HIDE_ROLE_MARKER];
2226
+ hideRoles = ["HIDE"];
2261
2227
  loadData$ = new Subject();
2262
2228
  loadLength$ = new Subject();
2229
+ clearFilter$ = new Subject();
2230
+ clearFilter = null;
2263
2231
  allowMultiSelect = false;
2264
2232
  selected = [];
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 */ []);
2233
+ tableState;
2302
2234
  editBtnDisabled = true;
2303
2235
  removeBtnDisabled = true;
2304
2236
  dblClickedEventEnable = true;
@@ -2306,64 +2238,60 @@ var BasePageClass = class BasePageClass {
2306
2238
  router = inject(Router);
2307
2239
  localStorageService = inject(LocalStorageService);
2308
2240
  loaderService = inject(LoaderService);
2309
- notificationService = inject(UIKIT_NOTIFICATION_TOKEN);
2241
+ notificationService = inject(NotificationService);
2310
2242
  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 */ []);
2321
2243
  constructor() {
2322
- this.tableState.set({
2244
+ this.tableState = {
2323
2245
  sortActive: this.localStorageService.getData(this.constructor.name + "SortActive") || "",
2324
2246
  sortDirection: this.localStorageService.getData(this.constructor.name + "SortDirection") || "",
2325
2247
  pageIndex: Number(this.localStorageService.getData(this.constructor.name + "PageIndex")) || this.defaultPageIndex,
2326
2248
  pageSize: Number(this.localStorageService.getData(this.constructor.name + "PageSize")) || this.defaultPageSize
2327
- });
2249
+ };
2328
2250
  }
2329
2251
  ngOnDestroy() {
2330
2252
  this.subscription.unsubscribe();
2331
2253
  }
2332
2254
  subscribeToLoadData(fnGetData, fnGetCount, fnMapEntity) {
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;
2255
+ const subs = this.loadData$.pipe(tap(() => this.loaderService.show()), switchMap(() => fnGetData()), map((v) => fnMapEntity ? 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
+ this.notificationService.error("Произошла ошибка: " + error, 0);
2264
+ }
2344
2265
  });
2345
- this.tableState.update((prev) => ({
2346
- ...prev,
2347
- pageIndex: 0
2348
- }));
2266
+ this.subscription?.add(subs);
2267
+ const subs2 = this.loadLength$.pipe(switchMap(() => fnGetCount())).subscribe({
2268
+ next: (response) => {
2269
+ this.length.set(response);
2270
+ },
2271
+ error: (error) => {
2272
+ console.log(error);
2273
+ this.notificationService.error("Произошла ошибка: " + error, 0);
2274
+ }
2275
+ });
2276
+ this.subscription?.add(subs2);
2277
+ this.loadData$.next(null);
2278
+ this.loadLength$.next(null);
2349
2279
  }
2350
2280
  onPageChange(pageState) {
2281
+ this.tableState.pageIndex = pageState.pageIndex;
2282
+ this.tableState.pageSize = pageState.pageSize;
2351
2283
  this.localStorageService.saveData(this.constructor.name + "PageIndex", pageState.pageIndex.toString());
2352
2284
  this.localStorageService.saveData(this.constructor.name + "PageSize", pageState.pageSize.toString());
2353
- this.tableState.update((prev) => ({
2354
- ...prev,
2355
- pageIndex: pageState.pageIndex,
2356
- pageSize: pageState.pageSize
2357
- }));
2285
+ this.loadData$.next(null);
2286
+ this.loadLength$.next(null);
2358
2287
  }
2359
2288
  onSortChange(sortState) {
2289
+ this.tableState.sortActive = sortState.sortActive;
2290
+ this.tableState.sortDirection = sortState.sortDirection;
2360
2291
  this.localStorageService.saveData(this.constructor.name + "SortActive", sortState.sortActive);
2361
2292
  this.localStorageService.saveData(this.constructor.name + "SortDirection", sortState.sortDirection);
2362
- this.tableState.update((prev) => ({
2363
- ...prev,
2364
- sortActive: sortState.sortActive,
2365
- sortDirection: sortState.sortDirection
2366
- }));
2293
+ this.loadData$.next(null);
2294
+ this.loadLength$.next(null);
2367
2295
  }
2368
2296
  entityFactory(type) {
2369
2297
  return new type();
@@ -2403,7 +2331,7 @@ var BasePageClass = class BasePageClass {
2403
2331
  this.afterSaveOnNewEvent(callback.bind(this), obj, result.extraData);
2404
2332
  } else {
2405
2333
  this.refreshEvent();
2406
- this.notificationService?.success("Запись добавлена.");
2334
+ this.notificationService.success("Запись добавлена.");
2407
2335
  }
2408
2336
  },
2409
2337
  error: (error) => {
@@ -2477,7 +2405,7 @@ var BasePageClass = class BasePageClass {
2477
2405
  },
2478
2406
  error: (error) => {
2479
2407
  console.log("error", error);
2480
- this.notificationService?.error("Произошла ошибка при удалении записи: " + error, 0);
2408
+ this.notificationService.error("Произошла ошибка при удалении записи: " + error, 0);
2481
2409
  }
2482
2410
  });
2483
2411
  this.subscription.add(subs);
@@ -2492,16 +2420,12 @@ var BasePageClass = class BasePageClass {
2492
2420
  }
2493
2421
  }
2494
2422
  refreshEvent() {
2495
- this.dataResource.reload();
2496
- this.countResource.reload();
2423
+ this.loadData$.next(null);
2424
+ this.loadLength$.next(null);
2497
2425
  }
2498
2426
  clearEvent() {
2499
- this.filters.set({});
2500
- this.localStorageService.saveData(this.constructor.name + "_Filters", "{}");
2501
- this.tableState.update((prev) => ({
2502
- ...prev,
2503
- pageIndex: 0
2504
- }));
2427
+ this.clearFilter$.next(null);
2428
+ this.clearFilter = {};
2505
2429
  }
2506
2430
  onRemovalMessageChange(message) {
2507
2431
  this.removalMessage = message;
@@ -2534,22 +2458,18 @@ var BasePageClass = class BasePageClass {
2534
2458
  }
2535
2459
  onMiddleButton(baseUrl, queryParamName, queryParamValue) {
2536
2460
  return ($event, item, contextMenu) => {
2537
- if (item) {
2538
- if ($event.button === 1) {
2539
- contextMenu.closeMenu();
2540
- const url = this.router.serializeUrl(queryParamName && queryParamValue ? this.router.createUrlTree([baseUrl], { queryParams: { [queryParamName]: item[queryParamValue] } }) : this.router.createUrlTree([baseUrl]));
2541
- window.open(url, "_blank");
2542
- }
2461
+ if ($event.button === 1) {
2462
+ contextMenu.closeMenu();
2463
+ const url = this.router.serializeUrl(queryParamName && queryParamValue ? this.router.createUrlTree([baseUrl], { queryParams: { [queryParamName]: item[queryParamValue] } }) : this.router.createUrlTree([baseUrl]));
2464
+ window.open(url, "_blank");
2543
2465
  }
2544
2466
  };
2545
2467
  }
2546
2468
  onActionMiddleButton(baseUrl, queryParamName, queryParamValue) {
2547
2469
  return ($event, item) => {
2548
- if (item) {
2549
- if ($event.button === 1) {
2550
- const url = this.router.serializeUrl(queryParamName && queryParamValue ? this.router.createUrlTree([baseUrl], { queryParams: { [queryParamName]: item[queryParamValue] } }) : this.router.createUrlTree([baseUrl]));
2551
- window.open(url, "_blank");
2552
- }
2470
+ if ($event.button === 1) {
2471
+ const url = this.router.serializeUrl(queryParamName && queryParamValue ? this.router.createUrlTree([baseUrl], { queryParams: { [queryParamName]: item[queryParamValue] } }) : this.router.createUrlTree([baseUrl]));
2472
+ window.open(url, "_blank");
2553
2473
  }
2554
2474
  };
2555
2475
  }