@elderbyte/ngx-starter 16.4.3 → 16.4.4
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.
- package/esm2022/lib/common/data/filters/filter-context.mjs +4 -5
- package/esm2022/lib/components/forms/search/domain/context/search-context.mjs +27 -9
- package/esm2022/lib/components/forms/search/domain/input/search-input.mjs +1 -1
- package/esm2022/lib/components/forms/search/domain/url/elder-search-url.directive.mjs +2 -2
- package/esm2022/lib/components/forms/search/elder-search-context.directive.mjs +15 -13
- package/esm2022/lib/components/forms/search/elder-search-input.directive.mjs +11 -17
- package/fesm2022/elderbyte-ngx-starter.mjs +52 -38
- package/fesm2022/elderbyte-ngx-starter.mjs.map +1 -1
- package/lib/common/data/filters/filter-context.d.ts +1 -1
- package/lib/components/forms/search/domain/context/search-context.d.ts +5 -3
- package/lib/components/forms/search/domain/input/search-input.d.ts +0 -1
- package/lib/components/forms/search/elder-search-context.directive.d.ts +4 -3
- package/lib/components/forms/search/elder-search-input.directive.d.ts +2 -4
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { Pipe, Injectable, LOCALE_ID, Inject, NgModule, Optional, SkipSelf, Dire
|
|
|
5
5
|
import * as i1 from '@angular/platform-browser';
|
|
6
6
|
import { Duration, Period, TemporalQueries, LocalTime, Instant, LocalDate, nativeJs, ZoneId, DateTimeFormatter, convert, ZonedDateTime, Temporal } from '@js-joda/core';
|
|
7
7
|
import { LoggerFactory } from '@elderbyte/ts-logger';
|
|
8
|
-
import { timer, defer, ReplaySubject, concat, finalize, exhaustMap, BehaviorSubject,
|
|
8
|
+
import { timer, defer, ReplaySubject, concat, finalize, exhaustMap, BehaviorSubject, Subject, switchMap, of, combineLatest, EMPTY, merge, forkJoin, throwError, mergeWith, Observable, zip, mergeMap as mergeMap$1, fromEvent, combineLatestWith as combineLatestWith$1, skipUntil, NEVER } from 'rxjs';
|
|
9
9
|
import { tap, takeUntil, takeWhile, map, filter, distinctUntilChanged, debounceTime, catchError, first, take, switchMap as switchMap$1, mergeMap, expand, reduce, startWith, skip, delay, share, combineLatestWith, timeout, skipWhile } from 'rxjs/operators';
|
|
10
10
|
import * as i1$2 from '@angular/common/http';
|
|
11
11
|
import { HttpParams, HttpEventType, HttpRequest, HttpClient, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
@@ -2704,10 +2704,9 @@ class FilterContext {
|
|
|
2704
2704
|
}
|
|
2705
2705
|
return Array.from(filterMap.values());
|
|
2706
2706
|
}
|
|
2707
|
-
static
|
|
2707
|
+
static of(filters) {
|
|
2708
2708
|
const filterContext = new FilterContext();
|
|
2709
|
-
filterContext.
|
|
2710
|
-
await lastValueFrom(filterContext.filters);
|
|
2709
|
+
filterContext.replaceFilters(filters);
|
|
2711
2710
|
return filterContext;
|
|
2712
2711
|
}
|
|
2713
2712
|
/***************************************************************************
|
|
@@ -25935,6 +25934,12 @@ class SearchContext {
|
|
|
25935
25934
|
this.userFilterContext = new FilterContext();
|
|
25936
25935
|
this.forcedFilterContext = new FilterContext();
|
|
25937
25936
|
this.allFilters$ = new BehaviorSubject(undefined);
|
|
25937
|
+
/***************************************************************************
|
|
25938
|
+
* *
|
|
25939
|
+
* Public API *
|
|
25940
|
+
* *
|
|
25941
|
+
**************************************************************************/
|
|
25942
|
+
this.acceptDefaultFilters = true;
|
|
25938
25943
|
this.id = id;
|
|
25939
25944
|
this.userFilterContext.filters.pipe(combineLatestWith(this.forcedFilterContext.filters), skip(1), map(([userFilters, forcedFilters]) => FilterUtil.mergeCombine(userFilters, forcedFilters)), tap(x => this.log.debug('allFilters changed: ', x))).subscribe(merged => this.allFilters$.next(merged));
|
|
25940
25945
|
}
|
|
@@ -25947,24 +25952,36 @@ class SearchContext {
|
|
|
25947
25952
|
return this.allFilters$.pipe(filter(filters => !!filters));
|
|
25948
25953
|
}
|
|
25949
25954
|
get userFilters() {
|
|
25950
|
-
return this.userFilterContext;
|
|
25955
|
+
return this.userFilterContext.filtersSnapshot;
|
|
25956
|
+
}
|
|
25957
|
+
get userFilters$() {
|
|
25958
|
+
return this.userFilterContext.filters;
|
|
25951
25959
|
}
|
|
25952
25960
|
get forcedFilters() {
|
|
25953
|
-
return this.forcedFilterContext;
|
|
25961
|
+
return this.forcedFilterContext.filtersSnapshot;
|
|
25962
|
+
}
|
|
25963
|
+
updateDefaultFilters(filters) {
|
|
25964
|
+
// this.log.error('updateDefaultFilters, acceptDefaultFilters: ' + this.acceptDefaultFilters, filters);
|
|
25965
|
+
if (this.acceptDefaultFilters) {
|
|
25966
|
+
this.userFilterContext.updateFilters(FilterUtil.strip(filters, this.forcedFilters));
|
|
25967
|
+
}
|
|
25968
|
+
return this.acceptDefaultFilters;
|
|
25954
25969
|
}
|
|
25955
|
-
/***************************************************************************
|
|
25956
|
-
* *
|
|
25957
|
-
* Public API *
|
|
25958
|
-
* *
|
|
25959
|
-
**************************************************************************/
|
|
25960
25970
|
updateUserFilters(filters) {
|
|
25961
|
-
|
|
25971
|
+
if (filters.length > 0) {
|
|
25972
|
+
// this.log.error('updateUserFilters', filters);
|
|
25973
|
+
this.acceptDefaultFilters = false;
|
|
25974
|
+
this.userFilterContext.updateFilters(filters);
|
|
25975
|
+
}
|
|
25962
25976
|
}
|
|
25963
25977
|
replaceUserFilters(filters) {
|
|
25978
|
+
// this.log.error('replaceUserFilters', filters);
|
|
25979
|
+
this.acceptDefaultFilters = false;
|
|
25964
25980
|
this.userFilterContext.replaceFilters(filters);
|
|
25965
25981
|
}
|
|
25966
25982
|
replaceForcedFilters(filters) {
|
|
25967
25983
|
this.forcedFilterContext.replaceFilters(filters);
|
|
25984
|
+
// Maybe clean up existing user filters here
|
|
25968
25985
|
}
|
|
25969
25986
|
}
|
|
25970
25987
|
|
|
@@ -26043,7 +26060,7 @@ class ElderSearchContextDirective {
|
|
|
26043
26060
|
this.applyDefaultFiltersToSearchContext();
|
|
26044
26061
|
this.syncSearchContextToBoundFilterContext();
|
|
26045
26062
|
}
|
|
26046
|
-
|
|
26063
|
+
ngAfterViewInit() {
|
|
26047
26064
|
const searchContext = this.searchContext;
|
|
26048
26065
|
this.applySearchContextToInputs(searchContext);
|
|
26049
26066
|
this.syncSearchInputsToSearchContext();
|
|
@@ -26098,7 +26115,7 @@ class ElderSearchContextDirective {
|
|
|
26098
26115
|
this.searchContext.replaceForcedFilters(filters);
|
|
26099
26116
|
}
|
|
26100
26117
|
get forcedFilters() {
|
|
26101
|
-
return this.searchContext.forcedFilters
|
|
26118
|
+
return this.searchContext.forcedFilters;
|
|
26102
26119
|
}
|
|
26103
26120
|
get attributes() {
|
|
26104
26121
|
return this._searchInputs$.asObservable();
|
|
@@ -26146,18 +26163,21 @@ class ElderSearchContextDirective {
|
|
|
26146
26163
|
applyDefaultFiltersToSearchContext() {
|
|
26147
26164
|
const dcFilters = this.filterContext;
|
|
26148
26165
|
const searchContext = this.searchContext;
|
|
26149
|
-
if (searchContext.userFilters.
|
|
26150
|
-
|
|
26151
|
-
// Consider all filters in DC as defaults, expect for foced filters.
|
|
26152
|
-
searchContext.updateUserFilters(FilterUtil.strip(dcFilters.filtersSnapshot, this.forcedFilters));
|
|
26153
|
-
}
|
|
26166
|
+
if (searchContext.userFilters.length === 0) {
|
|
26167
|
+
this.applyAsDefaultsUntilUserAction(searchContext, dcFilters);
|
|
26154
26168
|
}
|
|
26155
26169
|
else {
|
|
26156
|
-
dcFilters.replaceFilters(searchContext.userFilters
|
|
26170
|
+
dcFilters.replaceFilters(searchContext.userFilters);
|
|
26157
26171
|
}
|
|
26158
26172
|
}
|
|
26173
|
+
applyAsDefaultsUntilUserAction(searchContext, dcFilters) {
|
|
26174
|
+
dcFilters.filters.pipe(map(filters => searchContext.updateDefaultFilters(filters)), takeWhile(acceptDefaultFilters => acceptDefaultFilters)).subscribe();
|
|
26175
|
+
}
|
|
26159
26176
|
syncSearchInputsToSearchContext() {
|
|
26160
|
-
|
|
26177
|
+
this._searchInputs$.pipe(takeUntil(this.destroy$), switchMap$1(inputs => combineLatest(inputs.map(i => i.state$))), debounceTime(5)).subscribe(states => {
|
|
26178
|
+
this._searchStates$.next(states);
|
|
26179
|
+
});
|
|
26180
|
+
const inputFilters$ = this._searchStates$.pipe(map(states => this.convertToFilters(states)), filter(filters => filters.length > 0));
|
|
26161
26181
|
inputFilters$
|
|
26162
26182
|
.pipe(takeUntil(this.destroy$), combineLatestWith(this._searchContext$))
|
|
26163
26183
|
.subscribe(([inputFilters, searchContext]) => {
|
|
@@ -26178,7 +26198,7 @@ class ElderSearchContextDirective {
|
|
|
26178
26198
|
}
|
|
26179
26199
|
}
|
|
26180
26200
|
applySearchContextToInputs(searchContext) {
|
|
26181
|
-
this.applyFiltersToInputs(searchContext.userFilters
|
|
26201
|
+
this.applyFiltersToInputs(searchContext.userFilters);
|
|
26182
26202
|
}
|
|
26183
26203
|
applyFiltersToInputs(filters) {
|
|
26184
26204
|
if (filters.length > 0) {
|
|
@@ -26414,10 +26434,12 @@ class ElderSearchInputDirective {
|
|
|
26414
26434
|
constructor(searchContext, ngModel) {
|
|
26415
26435
|
this.searchContext = searchContext;
|
|
26416
26436
|
this.ngModel = ngModel;
|
|
26417
|
-
this._state = new BehaviorSubject(SearchInputState.unknown());
|
|
26418
26437
|
this.destroy$ = new Subject();
|
|
26419
26438
|
this.log = LoggerFactory.getLogger(this.constructor.name);
|
|
26420
26439
|
this.initialValueDirective = new ElderInitialValueDirective(ngModel);
|
|
26440
|
+
this._state$ = this.buildInputStateObservable().pipe(
|
|
26441
|
+
// tap(state => this.log.error('EMIT SEARCH INPUT STATE [' + state.queryKey + ']: ' + state.queryValue + (state.pristine ? '(pristine)' : ''), state))
|
|
26442
|
+
);
|
|
26421
26443
|
}
|
|
26422
26444
|
/***************************************************************************
|
|
26423
26445
|
* *
|
|
@@ -26431,11 +26453,6 @@ class ElderSearchInputDirective {
|
|
|
26431
26453
|
ngAfterViewInit() {
|
|
26432
26454
|
this._extractedName = this.extractName();
|
|
26433
26455
|
this.log.debug(this._extractedName + "|" + this.queryKey + "|" + this.resolvePath);
|
|
26434
|
-
this.stateObservable()
|
|
26435
|
-
.subscribe(state => {
|
|
26436
|
-
// this.log.error('EMIT SEARCH INPUT STATE [' + state.queryKey + ']: ' + state.queryValue + (state.pristine ? '(pristine)' : ''), state)
|
|
26437
|
-
this.emitState(state);
|
|
26438
|
-
});
|
|
26439
26456
|
}
|
|
26440
26457
|
ngOnDestroy() {
|
|
26441
26458
|
this.destroy$.next();
|
|
@@ -26447,10 +26464,7 @@ class ElderSearchInputDirective {
|
|
|
26447
26464
|
* *
|
|
26448
26465
|
**************************************************************************/
|
|
26449
26466
|
get state$() {
|
|
26450
|
-
return this._state
|
|
26451
|
-
}
|
|
26452
|
-
get stateSnapshot() {
|
|
26453
|
-
return this._state.getValue();
|
|
26467
|
+
return this._state$;
|
|
26454
26468
|
}
|
|
26455
26469
|
get name() {
|
|
26456
26470
|
if (this.queryKey) {
|
|
@@ -26492,10 +26506,13 @@ class ElderSearchInputDirective {
|
|
|
26492
26506
|
return this.ngModel.control.valueChanges
|
|
26493
26507
|
.pipe(takeUntil(this.destroy$));
|
|
26494
26508
|
}
|
|
26495
|
-
|
|
26509
|
+
buildInputStateObservable() {
|
|
26496
26510
|
const viewStabilized$ = of('stabilized$').pipe(delay(20), first());
|
|
26497
26511
|
const inputStateChanges$ = this.valueChanges$.pipe(takeUntil(this.destroy$), map(value => this.buildInputState(value, true)), skipUntil(viewStabilized$), debounceTime(20));
|
|
26498
|
-
const startWithAsync$ = of('start').pipe(map(start =>
|
|
26512
|
+
const startWithAsync$ = of('start').pipe(map(start => {
|
|
26513
|
+
const state = this.buildInputState(this.ngModel.control.value, false);
|
|
26514
|
+
return state;
|
|
26515
|
+
}));
|
|
26499
26516
|
return concat(startWithAsync$, inputStateChanges$);
|
|
26500
26517
|
}
|
|
26501
26518
|
buildInputState(controlValue, userEvent) {
|
|
@@ -26527,9 +26544,6 @@ class ElderSearchInputDirective {
|
|
|
26527
26544
|
}
|
|
26528
26545
|
return queryValue;
|
|
26529
26546
|
}
|
|
26530
|
-
emitState(state) {
|
|
26531
|
-
this._state.next(state);
|
|
26532
|
-
}
|
|
26533
26547
|
checkAndConvertFaultyValuesToNull(value) {
|
|
26534
26548
|
let fixedValue = value;
|
|
26535
26549
|
fixedValue = this.convertEmptyArrayToNull(fixedValue);
|
|
@@ -27360,7 +27374,7 @@ class ElderSearchUrlDirective {
|
|
|
27360
27374
|
* *
|
|
27361
27375
|
**************************************************************************/
|
|
27362
27376
|
ngAfterViewInit() {
|
|
27363
|
-
this.searchContext$.pipe(takeUntil(this.destroy$), switchMap(searchContext => searchContext.userFilters
|
|
27377
|
+
this.searchContext$.pipe(takeUntil(this.destroy$), switchMap(searchContext => searchContext.userFilters$.pipe(map(filters => new ContextWithUserFilters(searchContext, filters))))).subscribe(ctxAndFilters => this.searchUrlService.updateQueryParams(ctxAndFilters.context.id, ctxAndFilters.userFilters));
|
|
27364
27378
|
}
|
|
27365
27379
|
ngOnDestroy() {
|
|
27366
27380
|
this.destroy$.next();
|