@recursyve/nice-ui-kit.v2 14.0.0-beta.125 → 14.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,8 +4,8 @@ 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';
8
- 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';
7
+ import { map, filter, takeUntil, tap, finalize, take, debounceTime as debounceTime$1, delay, switchMap as switchMap$1 } from 'rxjs/operators';
8
+ 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';
9
9
  import { coerceBooleanProperty } from '@angular/cdk/coercion';
10
10
  import * as i2 from '@angular/common';
11
11
  import { CommonModule, DatePipe, CurrencyPipe, DOCUMENT, isPlatformServer, NgForOf, NgIf, AsyncPipe, UpperCasePipe } from '@angular/common';
@@ -34,6 +34,7 @@ import * as i1$5 from '@angular/material/input';
34
34
  import { MatInputModule } from '@angular/material/input';
35
35
  import * as i10 from '@angular/material/progress-bar';
36
36
  import { MatProgressBarModule } from '@angular/material/progress-bar';
37
+ import { fromPromise } from 'rxjs/internal/observable/innerFrom';
37
38
  import { CdkStepper, CdkStep, CdkStepperModule } from '@angular/cdk/stepper';
38
39
  import * as i1$6 from '@recursyve/ngx-form-generator';
39
40
  import { registerAsyncValidatorDecorator, AsyncValidator, NGX_FORM_GENERATOR_ASYNC_VALIDATORS, DynamicGroup } from '@recursyve/ngx-form-generator';
@@ -2690,15 +2691,22 @@ class NiceAsyncTypeaheadService {
2690
2691
  isLastPage: false,
2691
2692
  excludedIds: []
2692
2693
  });
2693
- this.loading$ = this.state$.pipe(map(x => x.loading));
2694
- this.loadingPage$ = this.state$.pipe(map(x => x.loadingPage));
2695
- this.active$ = this.state$.pipe(map(x => x.active));
2696
- this.items$ = this.state$.pipe(map(x => x.items));
2697
- this.filteredItems$ = this.state$.pipe(map(x => x.items.filter(item => !x.excludedIds.includes(item.id))));
2694
+ this.loading$ = this.state$.pipe(map(x => x.loading), distinctUntilChanged());
2695
+ this.loadingPage$ = this.state$.pipe(map(x => x.loadingPage), distinctUntilChanged());
2696
+ this.active$ = this.state$.pipe(map(x => x.active), distinctUntilChanged());
2697
+ this.items$ = this.state$.pipe(map(x => x.items), distinctUntilChanged());
2698
+ this.filteredItems$ = this.state$.pipe(map(x => x.items.filter(item => !x.excludedIds.includes(item.id))), distinctUntilChanged());
2699
+ this.requests$ = new Subject();
2698
2700
  if (!this.apis) {
2699
2701
  this.apis = [];
2700
2702
  }
2701
2703
  }
2704
+ listenForRequest() {
2705
+ this.requestsSubscription$ = this.requests$.pipe(switchMap((request) => this.sendRequest(request))).subscribe();
2706
+ }
2707
+ closeRequestSubscription() {
2708
+ this.requestsSubscription$?.unsubscribe();
2709
+ }
2702
2710
  async initialize(resource, options) {
2703
2711
  const { initialized } = this.state$.getValue();
2704
2712
  if (initialized) {
@@ -2706,74 +2714,76 @@ class NiceAsyncTypeaheadService {
2706
2714
  }
2707
2715
  return this.search(resource, "", options);
2708
2716
  }
2709
- async search(resource, searchQuery, options) {
2710
- const { active, initialized } = this.state$.getValue();
2711
- if (active && !initialized) {
2712
- this.state$.next({
2713
- ...this.state$.value,
2714
- initialized: true
2715
- });
2716
- return;
2717
- }
2718
- const api = this.apis.find(x => x.resource === resource);
2719
- if (!api) {
2720
- return;
2721
- }
2722
- try {
2723
- this.state$.next({
2724
- ...this.state$.value,
2725
- loading: true,
2726
- initialized: true,
2727
- page: 0,
2728
- isLastPage: false,
2729
- searchQuery
2730
- });
2731
- const result = await api.search(searchQuery, 0, options);
2717
+ sendRequest(request) {
2718
+ return defer(() => {
2719
+ const { active, initialized } = this.state$.getValue();
2720
+ if (active && !initialized) {
2721
+ this.state$.next({
2722
+ ...this.state$.value,
2723
+ initialized: true
2724
+ });
2725
+ return EMPTY;
2726
+ }
2727
+ const api = this.apis.find(x => x.resource === request.resource);
2728
+ if (!api) {
2729
+ return EMPTY;
2730
+ }
2731
+ if (request.page === 0) {
2732
+ this.state$.next({
2733
+ ...this.state$.value,
2734
+ loading: true,
2735
+ initialized: true,
2736
+ page: request.page,
2737
+ isLastPage: false,
2738
+ searchQuery: request.searchQuery
2739
+ });
2740
+ }
2741
+ else {
2742
+ this.state$.next({
2743
+ ...this.state$.value,
2744
+ loadingPage: true
2745
+ });
2746
+ }
2747
+ const result = api.search(request.searchQuery, request.page, request.searchOptions);
2748
+ if (isObservable(result)) {
2749
+ return result;
2750
+ }
2751
+ return fromPromise(result);
2752
+ }).pipe(map((result) => {
2732
2753
  this.state$.next({
2733
2754
  ...this.state$.value,
2734
- items: result.items,
2755
+ items: request.page === 0 ? result.items : [...(this.state$.value.items ?? []), ...result.items],
2735
2756
  page: result.nextPage ? result.nextPage : this.state$.value.page,
2736
2757
  isLastPage: !result.nextPage
2737
2758
  });
2738
- }
2739
- catch { }
2740
- finally {
2759
+ }), catchError(() => EMPTY), finalize(() => {
2741
2760
  this.state$.next({
2742
2761
  ...this.state$.value,
2743
- loading: false
2762
+ loading: false,
2763
+ loadingPage: false
2744
2764
  });
2745
- }
2765
+ }));
2746
2766
  }
2747
- async loadMore(resource, options) {
2767
+ search(resource, searchQuery, options) {
2768
+ this.requests$.next({
2769
+ resource,
2770
+ searchQuery,
2771
+ searchOptions: options,
2772
+ page: 0
2773
+ });
2774
+ }
2775
+ loadMore(resource, options) {
2748
2776
  const { loadingPage, isLastPage } = this.state$.getValue();
2749
2777
  if (loadingPage || isLastPage) {
2750
2778
  return;
2751
2779
  }
2752
- const api = this.apis.find(x => x.resource === resource);
2753
- if (!api) {
2754
- return;
2755
- }
2756
- try {
2757
- this.state$.next({
2758
- ...this.state$.value,
2759
- loadingPage: true
2760
- });
2761
- const { searchQuery, page, items } = this.state$.getValue();
2762
- const result = await api.search(searchQuery, page, options);
2763
- this.state$.next({
2764
- ...this.state$.value,
2765
- items: [...items, ...result.items],
2766
- page: result.nextPage ? result.nextPage : this.state$.value.page,
2767
- isLastPage: !result.nextPage
2768
- });
2769
- }
2770
- catch { }
2771
- finally {
2772
- this.state$.next({
2773
- ...this.state$.value,
2774
- loadingPage: false
2775
- });
2776
- }
2780
+ const { searchQuery, page } = this.state$.getValue();
2781
+ this.requests$.next({
2782
+ resource,
2783
+ page,
2784
+ searchQuery,
2785
+ searchOptions: options,
2786
+ });
2777
2787
  }
2778
2788
  getActive() {
2779
2789
  return this.state$.value.active;
@@ -2983,6 +2993,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2983
2993
  return this.service.getInitialized();
2984
2994
  }
2985
2995
  ngOnInit() {
2996
+ this.service.listenForRequest();
2986
2997
  if (this.ngControl) {
2987
2998
  if (this.ngControl.disabled) {
2988
2999
  this.searchControl.disable({ emitEvent: false });
@@ -3013,13 +3024,15 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3013
3024
  }
3014
3025
  }
3015
3026
  ngOnDestroy() {
3027
+ this.service.closeRequestSubscription();
3016
3028
  this.valueChangesSub$.unsubscribe();
3017
3029
  }
3018
3030
  ngOnChanges(changes) {
3019
3031
  if ("searchOptions" in changes) {
3020
3032
  const change = changes.searchOptions;
3021
3033
  if (!change.isFirstChange() && change.currentValue !== change.previousValue && this.autoReload) {
3022
- this.service.search(this.resource, "", change.currentValue).then(() => this.checkIfValueStillExist());
3034
+ this.service.search(this.resource, "", change.currentValue);
3035
+ this.service.items$.pipe(take(1)).subscribe(() => this.checkIfValueStillExist());
3023
3036
  }
3024
3037
  }
3025
3038
  if ("filterFn" in changes) {
@@ -5354,10 +5367,15 @@ class NiceControlStatusDirective {
5354
5367
  this.vcr = vcr;
5355
5368
  this.formField = formField;
5356
5369
  this.translateService = translateService;
5370
+ this.unsubscribeAll$ = new Subject();
5357
5371
  }
5358
5372
  ngAfterViewInit() {
5359
5373
  this.control = this.formField._control.ngControl;
5360
- this.control.statusChanges.subscribe(() => this.onChange());
5374
+ this.control.statusChanges.pipe(takeUntil(this.unsubscribeAll$)).subscribe(() => this.onChange());
5375
+ }
5376
+ ngOnDestroy() {
5377
+ this.unsubscribeAll$.next();
5378
+ this.unsubscribeAll$.complete();
5361
5379
  }
5362
5380
  onChange() {
5363
5381
  if (this.control.pending) {
@@ -9889,7 +9907,7 @@ class NiceSweetAlertService {
9889
9907
  }
9890
9908
  success(...args) {
9891
9909
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9892
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9910
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9893
9911
  return this.matDialog
9894
9912
  .open(this.modal, {
9895
9913
  panelClass: "nice-alert-modal",
@@ -9905,7 +9923,7 @@ class NiceSweetAlertService {
9905
9923
  }
9906
9924
  warning(...args) {
9907
9925
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9908
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9926
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9909
9927
  return this.matDialog
9910
9928
  .open(this.modal, {
9911
9929
  panelClass: "nice-alert-modal",
@@ -9921,7 +9939,7 @@ class NiceSweetAlertService {
9921
9939
  }
9922
9940
  info(...args) {
9923
9941
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9924
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9942
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9925
9943
  return this.matDialog
9926
9944
  .open(this.modal, {
9927
9945
  panelClass: "nice-alert-modal",