@recursyve/nice-ui-kit.v2 15.0.0-beta.125 → 15.0.0-beta.126

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.
@@ -4,9 +4,9 @@ import { HttpContextToken, HttpResponse, HttpContext, HttpParams } from '@angula
4
4
  import * as i0 from '@angular/core';
5
5
  import { Injectable, NgModule, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, Output, HostBinding, InjectionToken, Directive, HostListener, forwardRef, TemplateRef, Optional, Inject, ViewChild, ContentChild, ViewChildren, Self, Pipe, ElementRef, PLATFORM_ID, ContentChildren, SimpleChange, SkipSelf } from '@angular/core';
6
6
  import { plainToInstance } from 'class-transformer';
7
- import { map, filter, takeUntil, tap, take, finalize, debounceTime as debounceTime$1, delay, switchMap } from 'rxjs/operators';
7
+ import { map, filter, takeUntil, tap, finalize, take, debounceTime as debounceTime$1, delay, switchMap as switchMap$1 } from 'rxjs/operators';
8
8
  import { __rest, __awaiter } from 'tslib';
9
- import { catchError, ReplaySubject, Subject, BehaviorSubject, mergeMap, from, isObservable, firstValueFrom, debounceTime, distinctUntilChanged, startWith, pairwise, tap as tap$1, Observable, combineLatest, defer, timer, of, fromEvent, merge as merge$1 } from 'rxjs';
9
+ import { catchError, ReplaySubject, Subject, BehaviorSubject, distinctUntilChanged, switchMap, defer, EMPTY, isObservable, mergeMap, from, firstValueFrom, debounceTime, startWith, pairwise, tap as tap$1, Observable, combineLatest, timer, of, fromEvent, merge as merge$1 } from 'rxjs';
10
10
  import { coerceBooleanProperty } from '@angular/cdk/coercion';
11
11
  import * as i2 from '@angular/common';
12
12
  import { CommonModule, DatePipe, CurrencyPipe, DOCUMENT, isPlatformServer, NgForOf, NgIf, AsyncPipe, UpperCasePipe } from '@angular/common';
@@ -35,6 +35,7 @@ import * as i1$4 from '@angular/material/input';
35
35
  import { MatInputModule } from '@angular/material/input';
36
36
  import * as i10 from '@angular/material/progress-bar';
37
37
  import { MatProgressBarModule } from '@angular/material/progress-bar';
38
+ import { fromPromise } from 'rxjs/internal/observable/innerFrom';
38
39
  import { CdkStepper, CdkStep, CdkStepperModule } from '@angular/cdk/stepper';
39
40
  import * as i1$6 from '@recursyve/ngx-form-generator';
40
41
  import { registerAsyncValidatorDecorator, AsyncValidator, NGX_FORM_GENERATOR_ASYNC_VALIDATORS, DynamicGroup } from '@recursyve/ngx-form-generator';
@@ -2709,15 +2710,23 @@ class NiceAsyncTypeaheadService {
2709
2710
  isLastPage: false,
2710
2711
  excludedIds: []
2711
2712
  });
2712
- this.loading$ = this.state$.pipe(map(x => x.loading));
2713
- this.loadingPage$ = this.state$.pipe(map(x => x.loadingPage));
2714
- this.active$ = this.state$.pipe(map(x => x.active));
2715
- this.items$ = this.state$.pipe(map(x => x.items));
2716
- this.filteredItems$ = this.state$.pipe(map(x => x.items.filter(item => !x.excludedIds.includes(item.id))));
2713
+ this.loading$ = this.state$.pipe(map(x => x.loading), distinctUntilChanged());
2714
+ this.loadingPage$ = this.state$.pipe(map(x => x.loadingPage), distinctUntilChanged());
2715
+ this.active$ = this.state$.pipe(map(x => x.active), distinctUntilChanged());
2716
+ this.items$ = this.state$.pipe(map(x => x.items), distinctUntilChanged());
2717
+ this.filteredItems$ = this.state$.pipe(map(x => x.items.filter(item => !x.excludedIds.includes(item.id))), distinctUntilChanged());
2718
+ this.requests$ = new Subject();
2717
2719
  if (!this.apis) {
2718
2720
  this.apis = [];
2719
2721
  }
2720
2722
  }
2723
+ listenForRequest() {
2724
+ this.requestsSubscription$ = this.requests$.pipe(switchMap((request) => this.sendRequest(request))).subscribe();
2725
+ }
2726
+ closeRequestSubscription() {
2727
+ var _a;
2728
+ (_a = this.requestsSubscription$) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2729
+ }
2721
2730
  initialize(resource, options) {
2722
2731
  return __awaiter(this, void 0, void 0, function* () {
2723
2732
  const { initialized } = this.state$.getValue();
@@ -2727,48 +2736,54 @@ class NiceAsyncTypeaheadService {
2727
2736
  return this.search(resource, "", options);
2728
2737
  });
2729
2738
  }
2730
- search(resource, searchQuery, options) {
2731
- return __awaiter(this, void 0, void 0, function* () {
2739
+ sendRequest(request) {
2740
+ return defer(() => {
2732
2741
  const { active, initialized } = this.state$.getValue();
2733
2742
  if (active && !initialized) {
2734
2743
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { initialized: true }));
2735
- return;
2744
+ return EMPTY;
2736
2745
  }
2737
- const api = this.apis.find(x => x.resource === resource);
2746
+ const api = this.apis.find(x => x.resource === request.resource);
2738
2747
  if (!api) {
2739
- return;
2748
+ return EMPTY;
2740
2749
  }
2741
- try {
2742
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: true, initialized: true, page: 0, isLastPage: false, searchQuery }));
2743
- const result = yield api.search(searchQuery, 0, options);
2744
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { items: result.items, page: result.nextPage ? result.nextPage : this.state$.value.page, isLastPage: !result.nextPage }));
2750
+ if (request.page === 0) {
2751
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: true, initialized: true, page: request.page, isLastPage: false, searchQuery: request.searchQuery }));
2745
2752
  }
2746
- catch (_a) { }
2747
- finally {
2748
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: false }));
2753
+ else {
2754
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loadingPage: true }));
2755
+ }
2756
+ const result = api.search(request.searchQuery, request.page, request.searchOptions);
2757
+ if (isObservable(result)) {
2758
+ return result;
2749
2759
  }
2760
+ return fromPromise(result);
2761
+ }).pipe(map((result) => {
2762
+ var _a;
2763
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { items: request.page === 0 ? result.items : [...((_a = this.state$.value.items) !== null && _a !== void 0 ? _a : []), ...result.items], page: result.nextPage ? result.nextPage : this.state$.value.page, isLastPage: !result.nextPage }));
2764
+ }), catchError(() => EMPTY), finalize(() => {
2765
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: false, loadingPage: false }));
2766
+ }));
2767
+ }
2768
+ search(resource, searchQuery, options) {
2769
+ this.requests$.next({
2770
+ resource,
2771
+ searchQuery,
2772
+ searchOptions: options,
2773
+ page: 0
2750
2774
  });
2751
2775
  }
2752
2776
  loadMore(resource, options) {
2753
- return __awaiter(this, void 0, void 0, function* () {
2754
- const { loadingPage, isLastPage } = this.state$.getValue();
2755
- if (loadingPage || isLastPage) {
2756
- return;
2757
- }
2758
- const api = this.apis.find(x => x.resource === resource);
2759
- if (!api) {
2760
- return;
2761
- }
2762
- try {
2763
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loadingPage: true }));
2764
- const { searchQuery, page, items } = this.state$.getValue();
2765
- const result = yield api.search(searchQuery, page, options);
2766
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { items: [...items, ...result.items], page: result.nextPage ? result.nextPage : this.state$.value.page, isLastPage: !result.nextPage }));
2767
- }
2768
- catch (_a) { }
2769
- finally {
2770
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loadingPage: false }));
2771
- }
2777
+ const { loadingPage, isLastPage } = this.state$.getValue();
2778
+ if (loadingPage || isLastPage) {
2779
+ return;
2780
+ }
2781
+ const { searchQuery, page } = this.state$.getValue();
2782
+ this.requests$.next({
2783
+ resource,
2784
+ page,
2785
+ searchQuery,
2786
+ searchOptions: options,
2772
2787
  });
2773
2788
  }
2774
2789
  getActive() {
@@ -2962,6 +2977,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2962
2977
  }
2963
2978
  }
2964
2979
  ngOnInit() {
2980
+ this.service.listenForRequest();
2965
2981
  if (this.ngControl) {
2966
2982
  if (this.ngControl.disabled) {
2967
2983
  this.searchControl.disable({ emitEvent: false });
@@ -2992,13 +3008,15 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2992
3008
  }
2993
3009
  }
2994
3010
  ngOnDestroy() {
3011
+ this.service.closeRequestSubscription();
2995
3012
  this.valueChangesSub$.unsubscribe();
2996
3013
  }
2997
3014
  ngOnChanges(changes) {
2998
3015
  if ("searchOptions" in changes) {
2999
3016
  const change = changes.searchOptions;
3000
3017
  if (!change.isFirstChange() && change.currentValue !== change.previousValue && this.autoReload) {
3001
- this.service.search(this.resource, "", change.currentValue).then(() => this.checkIfValueStillExist());
3018
+ this.service.search(this.resource, "", change.currentValue);
3019
+ this.service.items$.pipe(take(1)).subscribe(() => this.checkIfValueStillExist());
3002
3020
  }
3003
3021
  }
3004
3022
  if ("filterFn" in changes) {
@@ -5345,10 +5363,15 @@ class NiceControlStatusDirective {
5345
5363
  this.vcr = vcr;
5346
5364
  this.formField = formField;
5347
5365
  this.translateService = translateService;
5366
+ this.unsubscribeAll$ = new Subject();
5348
5367
  }
5349
5368
  ngAfterViewInit() {
5350
5369
  this.control = this.formField._control.ngControl;
5351
- this.control.statusChanges.subscribe(() => this.onChange());
5370
+ this.control.statusChanges.pipe(takeUntil(this.unsubscribeAll$)).subscribe(() => this.onChange());
5371
+ }
5372
+ ngOnDestroy() {
5373
+ this.unsubscribeAll$.next();
5374
+ this.unsubscribeAll$.complete();
5352
5375
  }
5353
5376
  onChange() {
5354
5377
  if (this.control.pending) {
@@ -9923,7 +9946,7 @@ class NiceSweetAlertService {
9923
9946
  }
9924
9947
  success(...args) {
9925
9948
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9926
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9949
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9927
9950
  return this.matDialog
9928
9951
  .open(this.modal, {
9929
9952
  panelClass: "nice-alert-modal",
@@ -9939,7 +9962,7 @@ class NiceSweetAlertService {
9939
9962
  }
9940
9963
  warning(...args) {
9941
9964
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9942
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9965
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9943
9966
  return this.matDialog
9944
9967
  .open(this.modal, {
9945
9968
  panelClass: "nice-alert-modal",
@@ -9955,7 +9978,7 @@ class NiceSweetAlertService {
9955
9978
  }
9956
9979
  info(...args) {
9957
9980
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9958
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9981
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9959
9982
  return this.matDialog
9960
9983
  .open(this.modal, {
9961
9984
  panelClass: "nice-alert-modal",