@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,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$5 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';
@@ -2707,15 +2708,23 @@ class NiceAsyncTypeaheadService {
2707
2708
  isLastPage: false,
2708
2709
  excludedIds: []
2709
2710
  });
2710
- this.loading$ = this.state$.pipe(map(x => x.loading));
2711
- this.loadingPage$ = this.state$.pipe(map(x => x.loadingPage));
2712
- this.active$ = this.state$.pipe(map(x => x.active));
2713
- this.items$ = this.state$.pipe(map(x => x.items));
2714
- this.filteredItems$ = this.state$.pipe(map(x => x.items.filter(item => !x.excludedIds.includes(item.id))));
2711
+ this.loading$ = this.state$.pipe(map(x => x.loading), distinctUntilChanged());
2712
+ this.loadingPage$ = this.state$.pipe(map(x => x.loadingPage), distinctUntilChanged());
2713
+ this.active$ = this.state$.pipe(map(x => x.active), distinctUntilChanged());
2714
+ this.items$ = this.state$.pipe(map(x => x.items), distinctUntilChanged());
2715
+ this.filteredItems$ = this.state$.pipe(map(x => x.items.filter(item => !x.excludedIds.includes(item.id))), distinctUntilChanged());
2716
+ this.requests$ = new Subject();
2715
2717
  if (!this.apis) {
2716
2718
  this.apis = [];
2717
2719
  }
2718
2720
  }
2721
+ listenForRequest() {
2722
+ this.requestsSubscription$ = this.requests$.pipe(switchMap((request) => this.sendRequest(request))).subscribe();
2723
+ }
2724
+ closeRequestSubscription() {
2725
+ var _a;
2726
+ (_a = this.requestsSubscription$) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2727
+ }
2719
2728
  initialize(resource, options) {
2720
2729
  return __awaiter(this, void 0, void 0, function* () {
2721
2730
  const { initialized } = this.state$.getValue();
@@ -2725,48 +2734,54 @@ class NiceAsyncTypeaheadService {
2725
2734
  return this.search(resource, "", options);
2726
2735
  });
2727
2736
  }
2728
- search(resource, searchQuery, options) {
2729
- return __awaiter(this, void 0, void 0, function* () {
2737
+ sendRequest(request) {
2738
+ return defer(() => {
2730
2739
  const { active, initialized } = this.state$.getValue();
2731
2740
  if (active && !initialized) {
2732
2741
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { initialized: true }));
2733
- return;
2742
+ return EMPTY;
2734
2743
  }
2735
- const api = this.apis.find(x => x.resource === resource);
2744
+ const api = this.apis.find(x => x.resource === request.resource);
2736
2745
  if (!api) {
2737
- return;
2746
+ return EMPTY;
2738
2747
  }
2739
- try {
2740
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: true, initialized: true, page: 0, isLastPage: false, searchQuery }));
2741
- const result = yield api.search(searchQuery, 0, options);
2742
- 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 }));
2748
+ if (request.page === 0) {
2749
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: true, initialized: true, page: request.page, isLastPage: false, searchQuery: request.searchQuery }));
2743
2750
  }
2744
- catch (_a) { }
2745
- finally {
2746
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: false }));
2751
+ else {
2752
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loadingPage: true }));
2753
+ }
2754
+ const result = api.search(request.searchQuery, request.page, request.searchOptions);
2755
+ if (isObservable(result)) {
2756
+ return result;
2747
2757
  }
2758
+ return fromPromise(result);
2759
+ }).pipe(map((result) => {
2760
+ var _a;
2761
+ 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 }));
2762
+ }), catchError(() => EMPTY), finalize(() => {
2763
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: false, loadingPage: false }));
2764
+ }));
2765
+ }
2766
+ search(resource, searchQuery, options) {
2767
+ this.requests$.next({
2768
+ resource,
2769
+ searchQuery,
2770
+ searchOptions: options,
2771
+ page: 0
2748
2772
  });
2749
2773
  }
2750
2774
  loadMore(resource, options) {
2751
- return __awaiter(this, void 0, void 0, function* () {
2752
- const { loadingPage, isLastPage } = this.state$.getValue();
2753
- if (loadingPage || isLastPage) {
2754
- return;
2755
- }
2756
- const api = this.apis.find(x => x.resource === resource);
2757
- if (!api) {
2758
- return;
2759
- }
2760
- try {
2761
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loadingPage: true }));
2762
- const { searchQuery, page, items } = this.state$.getValue();
2763
- const result = yield api.search(searchQuery, page, options);
2764
- 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 }));
2765
- }
2766
- catch (_a) { }
2767
- finally {
2768
- this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loadingPage: false }));
2769
- }
2775
+ const { loadingPage, isLastPage } = this.state$.getValue();
2776
+ if (loadingPage || isLastPage) {
2777
+ return;
2778
+ }
2779
+ const { searchQuery, page } = this.state$.getValue();
2780
+ this.requests$.next({
2781
+ resource,
2782
+ page,
2783
+ searchQuery,
2784
+ searchOptions: options,
2770
2785
  });
2771
2786
  }
2772
2787
  getActive() {
@@ -2960,6 +2975,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2960
2975
  return this.service.getInitialized();
2961
2976
  }
2962
2977
  ngOnInit() {
2978
+ this.service.listenForRequest();
2963
2979
  if (this.ngControl) {
2964
2980
  if (this.ngControl.disabled) {
2965
2981
  this.searchControl.disable({ emitEvent: false });
@@ -2990,13 +3006,15 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2990
3006
  }
2991
3007
  }
2992
3008
  ngOnDestroy() {
3009
+ this.service.closeRequestSubscription();
2993
3010
  this.valueChangesSub$.unsubscribe();
2994
3011
  }
2995
3012
  ngOnChanges(changes) {
2996
3013
  if ("searchOptions" in changes) {
2997
3014
  const change = changes.searchOptions;
2998
3015
  if (!change.isFirstChange() && change.currentValue !== change.previousValue && this.autoReload) {
2999
- this.service.search(this.resource, "", change.currentValue).then(() => this.checkIfValueStillExist());
3016
+ this.service.search(this.resource, "", change.currentValue);
3017
+ this.service.items$.pipe(take(1)).subscribe(() => this.checkIfValueStillExist());
3000
3018
  }
3001
3019
  }
3002
3020
  if ("filterFn" in changes) {
@@ -5352,10 +5370,15 @@ class NiceControlStatusDirective {
5352
5370
  this.vcr = vcr;
5353
5371
  this.formField = formField;
5354
5372
  this.translateService = translateService;
5373
+ this.unsubscribeAll$ = new Subject();
5355
5374
  }
5356
5375
  ngAfterViewInit() {
5357
5376
  this.control = this.formField._control.ngControl;
5358
- this.control.statusChanges.subscribe(() => this.onChange());
5377
+ this.control.statusChanges.pipe(takeUntil(this.unsubscribeAll$)).subscribe(() => this.onChange());
5378
+ }
5379
+ ngOnDestroy() {
5380
+ this.unsubscribeAll$.next();
5381
+ this.unsubscribeAll$.complete();
5359
5382
  }
5360
5383
  onChange() {
5361
5384
  if (this.control.pending) {
@@ -9911,7 +9934,7 @@ class NiceSweetAlertService {
9911
9934
  }
9912
9935
  success(...args) {
9913
9936
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9914
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9937
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9915
9938
  return this.matDialog
9916
9939
  .open(this.modal, {
9917
9940
  panelClass: "nice-alert-modal",
@@ -9927,7 +9950,7 @@ class NiceSweetAlertService {
9927
9950
  }
9928
9951
  warning(...args) {
9929
9952
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9930
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9953
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9931
9954
  return this.matDialog
9932
9955
  .open(this.modal, {
9933
9956
  panelClass: "nice-alert-modal",
@@ -9943,7 +9966,7 @@ class NiceSweetAlertService {
9943
9966
  }
9944
9967
  info(...args) {
9945
9968
  const [titleKey, messageKey, buttonsKey, params] = this.transformArgs(args);
9946
- return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap(([title, message, buttons]) => {
9969
+ return this.getTranslations(titleKey, messageKey, buttonsKey, params).pipe(switchMap$1(([title, message, buttons]) => {
9947
9970
  return this.matDialog
9948
9971
  .open(this.modal, {
9949
9972
  panelClass: "nice-alert-modal",