@elderbyte/ngx-starter 16.3.1 → 16.3.2

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.
@@ -25825,52 +25825,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.11", ngImpo
25825
25825
  type: Input
25826
25826
  }] } });
25827
25827
 
25828
- class SearchFilterContext {
25829
- /***************************************************************************
25830
- * *
25831
- * Constructor *
25832
- * *
25833
- **************************************************************************/
25834
- constructor() {
25835
- /***************************************************************************
25836
- * *
25837
- * Private methods *
25838
- * *
25839
- **************************************************************************/
25840
- this._filterContext$ = new BehaviorSubject(null);
25841
- this.initialFilterContext = new FilterContext();
25842
- this.log = LoggerFactory.getLogger(this.constructor.name);
25843
- }
25844
- /***************************************************************************
25845
- * *
25846
- * Properties *
25847
- * *
25848
- **************************************************************************/
25849
- get filterContext() {
25850
- return this._filterContext$.getValue();
25851
- }
25852
- get initialFilters$() {
25853
- return this.initialFilterContext.filters
25854
- .pipe(startWith(this.initialFilterContext.filtersSnapshot));
25855
- }
25856
- get filters() {
25857
- return this.filterContext.filters;
25858
- }
25859
- /***************************************************************************
25860
- * *
25861
- * Public Api *
25862
- * *
25863
- **************************************************************************/
25864
- init(ctx, forcedFilters) {
25865
- this._filterContext$.next(ctx);
25866
- this.initialFilterContext.updateFilters(ctx.filtersSnapshot);
25867
- this.initialFilterContext.updateFilters(forcedFilters);
25868
- }
25869
- addInitialFilters(filters) {
25870
- this.initialFilterContext.updateFilters(filters);
25871
- }
25872
- }
25873
-
25874
25828
  /**
25875
25829
  * The search container manages a group of search-inputs
25876
25830
  * and holds their values in a central search model.
@@ -25887,7 +25841,7 @@ class ElderSearchContextDirective {
25887
25841
  this.destroy$ = new Subject$1();
25888
25842
  this._searchInputs$ = new BehaviorSubject$1([]);
25889
25843
  this._searchStates$ = new BehaviorSubject$1([]);
25890
- this._searchFilterContext = new SearchFilterContext();
25844
+ this._filterContext$ = new BehaviorSubject$1(null);
25891
25845
  }
25892
25846
  /***************************************************************************
25893
25847
  * *
@@ -25916,7 +25870,7 @@ class ElderSearchContextDirective {
25916
25870
  }
25917
25871
  }
25918
25872
  ngAfterViewInit() {
25919
- this.subscribeInitialFilters();
25873
+ this.applyModelToInputs();
25920
25874
  }
25921
25875
  ngOnDestroy() {
25922
25876
  this.destroy$.next();
@@ -25930,21 +25884,21 @@ class ElderSearchContextDirective {
25930
25884
  set filterContext(value) {
25931
25885
  let context;
25932
25886
  if (value) {
25933
- if (typeof value !== 'string') {
25887
+ if (typeof value !== "string") {
25934
25888
  context = value;
25935
25889
  }
25936
25890
  else {
25937
- this.log.warn('Illegal value provided for property filterContext: ', JSON.stringify(value));
25938
- throw new Error('Illegal value provided for property filterContext! ' + value);
25891
+ this.log.warn("Illegal value provided for property filterContext: ", JSON.stringify(value));
25892
+ throw new Error("Illegal value provided for property filterContext! " + value);
25939
25893
  }
25940
25894
  }
25941
25895
  else {
25942
25896
  context = FilterContext.empty();
25943
25897
  }
25944
- this._searchFilterContext.init(context, this.forcedFilters);
25898
+ this._filterContext$.next(context);
25945
25899
  }
25946
25900
  get filterContext() {
25947
- return this.searchFilterContext.filterContext;
25901
+ return this._filterContext$.getValue();
25948
25902
  }
25949
25903
  /**
25950
25904
  * Forced filters are always merged into the final FilterContext.
@@ -25970,9 +25924,6 @@ class ElderSearchContextDirective {
25970
25924
  get statesSnapshot() {
25971
25925
  return this._searchStates$.getValue();
25972
25926
  }
25973
- get searchFilterContext() {
25974
- return this._searchFilterContext;
25975
- }
25976
25927
  /**
25977
25928
  * Returns the current user touched attributes. (ignoring fallbacks)
25978
25929
  */
@@ -25988,7 +25939,7 @@ class ElderSearchContextDirective {
25988
25939
  * Register a new search name in this container
25989
25940
  */
25990
25941
  register(searchInput) {
25991
- this.log.debug('Registering search input [' + searchInput.name + ']');
25942
+ this.log.debug("Registering search input [" + searchInput.name + "]");
25992
25943
  const current = this._searchInputs$.getValue();
25993
25944
  this._searchInputs$.next([...current, searchInput]);
25994
25945
  }
@@ -26004,14 +25955,27 @@ class ElderSearchContextDirective {
26004
25955
  * Private *
26005
25956
  * *
26006
25957
  **************************************************************************/
26007
- subscribeInitialFilters() {
26008
- this.searchFilterContext.initialFilters$.pipe(takeUntil(this.destroy$), combineLatestWith(this._searchInputs$)).subscribe(([initialFilters, searchInputs]) => {
26009
- searchInputs.forEach(input => {
26010
- const filter = this.findFilterForInput(input, initialFilters);
26011
- if (filter) {
26012
- input.applyInitialValue(filter.value);
26013
- }
26014
- });
25958
+ applyModelToInputs() {
25959
+ this.log.warn('applyModelToInputs', {
25960
+ filterSnapshot: this._filterContext$.getValue().filtersSnapshot,
25961
+ forcedFilters: this.forcedFilters
25962
+ });
25963
+ const mergedFilters = this.mergeFilters(this._filterContext$.getValue().filtersSnapshot, this.forcedFilters);
25964
+ this.applyFiltersToInputs(mergedFilters);
25965
+ }
25966
+ mergeFilters(filtersA, filtersB) {
25967
+ const mergeContext = new FilterContext();
25968
+ mergeContext.updateFilters(filtersA);
25969
+ mergeContext.mergeFilters(filtersB);
25970
+ return mergeContext.filtersSnapshot;
25971
+ }
25972
+ applyFiltersToInputs(filters) {
25973
+ this.log.warn('applyFiltersToInputs', filters);
25974
+ this._searchInputs$.getValue().forEach(input => {
25975
+ const filter = this.findFilterForInput(input, filters);
25976
+ if (filter) {
25977
+ input.applyInitialValue(filter.value);
25978
+ }
26015
25979
  });
26016
25980
  }
26017
25981
  findFilterForInput(input, filters) {
@@ -26033,12 +25997,12 @@ class ElderSearchContextDirective {
26033
25997
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.11", ngImport: i0, type: ElderSearchContextDirective, decorators: [{
26034
25998
  type: Directive,
26035
25999
  args: [{
26036
- selector: '[elderSearchContext]',
26037
- exportAs: 'elderSearchContext'
26000
+ selector: "[elderSearchContext]",
26001
+ exportAs: "elderSearchContext"
26038
26002
  }]
26039
26003
  }], propDecorators: { filterContext: [{
26040
26004
  type: Input,
26041
- args: ['elderSearchContext']
26005
+ args: ["elderSearchContext"]
26042
26006
  }], forcedFilters: [{
26043
26007
  type: Input
26044
26008
  }] } });
@@ -26134,7 +26098,7 @@ class ElderInitialValueDirective {
26134
26098
  **************************************************************************/
26135
26099
  constructor(ngModel) {
26136
26100
  //TODO: The debounce time is a hacky workaround, find a proper way to set initial value.
26137
- // Currently two way binding ngModel deosnt work.
26101
+ // ngModel regular and two way binding differ in initial value, which led to this solution
26138
26102
  this.ngModel = ngModel;
26139
26103
  /***************************************************************************
26140
26104
  * *
@@ -26145,18 +26109,15 @@ class ElderInitialValueDirective {
26145
26109
  this.initialValue$ = new BehaviorSubject(null);
26146
26110
  this.destroy$ = new Subject();
26147
26111
  this.initialDone$ = new Subject();
26148
- this.isInitial = true;
26149
26112
  const ngModelValue$ = of("dummy")
26150
26113
  .pipe(delay(10), map(() => this.ngModel.model));
26151
26114
  ngModelValue$
26152
- .pipe(combineLatestWith$1(this.initialValue$), takeUntil(this.initialDone$), takeUntil(this.destroy$)).subscribe({
26153
- next: ([ngModelValue, initialValue]) => {
26154
- if (initialValue) {
26155
- ngModel.control.setValue(initialValue);
26156
- }
26157
- this.initialDone$.next();
26158
- this.initialDone$.complete();
26115
+ .pipe(combineLatestWith$1(this.initialValue$), takeUntil(this.initialDone$), takeUntil(this.destroy$)).subscribe(([ngModelValue, initialValue]) => {
26116
+ if (initialValue) {
26117
+ ngModel.control.setValue(initialValue);
26159
26118
  }
26119
+ this.initialDone$.next();
26120
+ this.initialDone$.complete();
26160
26121
  });
26161
26122
  // this.ngModelValue = this.ngModel.model;
26162
26123
  // ngModel.control.valueChanges
@@ -26193,9 +26154,7 @@ class ElderInitialValueDirective {
26193
26154
  **************************************************************************/
26194
26155
  get valueChanges$() {
26195
26156
  return this.ngModel.control.valueChanges
26196
- .pipe(takeUntil(this.destroy$)
26197
- //filter(value => this.filterInitialValue(value))
26198
- );
26157
+ .pipe(takeUntil(this.destroy$));
26199
26158
  }
26200
26159
  applyInitialValue(value) {
26201
26160
  this.initialValue$.next(value);
@@ -26204,18 +26163,6 @@ class ElderInitialValueDirective {
26204
26163
  this.destroy$.next();
26205
26164
  this.destroy$.complete();
26206
26165
  }
26207
- /***************************************************************************
26208
- * *
26209
- * Private methods *
26210
- * *
26211
- **************************************************************************/
26212
- filterInitialValue(value) {
26213
- if (this.isInitial && this.ngModelValue$ === value) {
26214
- this.isInitial = false;
26215
- return false;
26216
- }
26217
- return true;
26218
- }
26219
26166
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.11", ngImport: i0, type: ElderInitialValueDirective, deps: [{ token: i3.NgModel, host: true }], target: i0.ɵɵFactoryTarget.Directive }); }
26220
26167
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.11", type: ElderInitialValueDirective, selector: "[elderInitialValue]", exportAs: ["elderInitialValue"], ngImport: i0 }); }
26221
26168
  }
@@ -26252,10 +26199,13 @@ class ElderSearchInputDirective {
26252
26199
  * Life Cycle *
26253
26200
  * *
26254
26201
  **************************************************************************/
26255
- ngAfterViewInit() {
26202
+ ngOnInit() {
26256
26203
  this._extractedName = this.extractName();
26257
- this.log.debug(this.extractName() + "|" + this.queryKey + "|" + this.resolvePath);
26258
26204
  this.searchContext.register(this);
26205
+ }
26206
+ ngAfterViewInit() {
26207
+ this._extractedName = this.extractName();
26208
+ this.log.debug(this._extractedName + "|" + this.queryKey + "|" + this.resolvePath);
26259
26209
  this.stateObservable().subscribe(state => {
26260
26210
  this.emitState(state);
26261
26211
  });
@@ -26911,71 +26861,101 @@ class ElderSearchContextFilters {
26911
26861
  }
26912
26862
 
26913
26863
  class ElderSearchUrlBindingService {
26864
+ /***************************************************************************
26865
+ * *
26866
+ * Constructor *
26867
+ * *
26868
+ **************************************************************************/
26914
26869
  constructor(router, route) {
26915
26870
  this.router = router;
26916
26871
  this.route = route;
26917
- //A search param has following structure: search-[searchContextId]-[filterId]=[value]
26872
+ //A search param has following structure: q-[searchContextId]-[filterId]=[value]
26918
26873
  //Example: search-browser1-hasStarted=true
26919
- this._searchMap$ = new BehaviorSubject$1(new Map());
26874
+ /***************************************************************************
26875
+ * *
26876
+ * Fields *
26877
+ * *
26878
+ **************************************************************************/
26879
+ this.log = LoggerFactory.getLogger(this.constructor.name);
26880
+ this._searchMap$ = new BehaviorSubject$1({
26881
+ value: new Map(),
26882
+ emit: true
26883
+ });
26920
26884
  this._initialSearchMap$ = new BehaviorSubject$1(new Map());
26921
26885
  this.searchParamPrefix = "q";
26922
26886
  this.unsubscribe$ = new Subject();
26923
26887
  this.router.events.pipe(first()).subscribe(() => {
26924
26888
  this.handleSearchParameters(this.route.snapshot.queryParams);
26925
26889
  });
26926
- this._searchMap$.pipe(takeUntil(this.unsubscribe$)).subscribe(searchMap => {
26890
+ this._searchMap$.pipe(filter(searchMapUpdate => searchMapUpdate.emit), takeUntil(this.unsubscribe$)).subscribe(searchMapUpdate => {
26891
+ this.log.warn("SET URL");
26892
+ const searchMap = searchMapUpdate.value;
26927
26893
  const resetParams = this.resetSearchParams();
26928
26894
  const queryParams = { ...resetParams, ...this.buildQueryParams(searchMap) };
26895
+ this.log.warn("searchMap :", searchMap);
26896
+ this.log.warn("queryParams :", queryParams);
26929
26897
  this.router.navigate([], {
26930
- relativeTo: this.route,
26931
26898
  queryParams: queryParams,
26932
26899
  replaceUrl: true,
26933
26900
  queryParamsHandling: "merge"
26934
26901
  });
26935
26902
  });
26903
+ this.router.events.subscribe((event) => this.log.warn("Type: " + event.constructor?.name, event));
26936
26904
  }
26937
- resetSearchParams() {
26938
- let params = { ...this.route.snapshot.queryParams };
26939
- const searchParams = this.extractSearchParameters(params);
26940
- for (const searchParam of searchParams) {
26941
- params[searchParam] = null;
26942
- }
26943
- return params;
26944
- }
26945
- buildQueryParams(searchMap) {
26946
- const params = {};
26947
- for (const searchContextId of searchMap.keys()) {
26948
- const filters = searchMap.get(searchContextId).filters;
26949
- for (const filter of filters.values()) {
26950
- params[`${this.searchParamPrefix}-${searchContextId}-${filter.key}`] = this.convertValueToArrayOrSingleValue(filter.value);
26951
- }
26952
- }
26953
- return params;
26954
- }
26955
- convertValueToArrayOrSingleValue(value) {
26956
- return Array.isArray(value) ? `(${value.toString()})` : value;
26905
+ /***************************************************************************
26906
+ * *
26907
+ * Life Cycle *
26908
+ * *
26909
+ **************************************************************************/
26910
+ ngOnDestroy() {
26911
+ this.unsubscribe$.next();
26912
+ this.unsubscribe$.complete();
26957
26913
  }
26914
+ /***************************************************************************
26915
+ * *
26916
+ * Properties *
26917
+ * *
26918
+ **************************************************************************/
26958
26919
  get initialSearchMap$() {
26959
26920
  return this._initialSearchMap$;
26960
26921
  }
26922
+ /***************************************************************************
26923
+ * *
26924
+ * Public API *
26925
+ * *
26926
+ **************************************************************************/
26961
26927
  updateFiltersForContext(searchContextId, filters) {
26962
- const searchMap = this._searchMap$.getValue();
26928
+ const searchMapUpdate = this._searchMap$.getValue();
26929
+ const searchMap = searchMapUpdate.value;
26963
26930
  const filtersMap = new Map(filters
26964
26931
  .filter(filter => filter.value != null)
26965
26932
  .map(filter => {
26966
26933
  return [filter.key, filter];
26967
26934
  }));
26968
26935
  searchMap.set(searchContextId, new ElderSearchContextFilters(searchContextId, filtersMap));
26969
- this._searchMap$.next(searchMap);
26936
+ this._searchMap$.next({ value: searchMap, emit: true });
26937
+ }
26938
+ resetFilterForContext(contextId) {
26939
+ const searchMapUpdate = this._searchMap$.getValue();
26940
+ const searchMap = searchMapUpdate.value;
26941
+ if (searchMap.has(contextId)) {
26942
+ searchMap.delete(contextId);
26943
+ this._searchMap$.next({ value: searchMap, emit: false });
26944
+ }
26970
26945
  }
26946
+ /***************************************************************************
26947
+ * *
26948
+ * Private methods *
26949
+ * *
26950
+ **************************************************************************/
26971
26951
  handleSearchParameters(params) {
26972
26952
  const searchParamKeys = this.extractSearchParameters(params);
26973
26953
  const searchMap = this.buildSearchContextMap(params, searchParamKeys);
26974
- this._searchMap$.next(searchMap);
26954
+ this._searchMap$.next({ value: searchMap, emit: true });
26975
26955
  this._initialSearchMap$.next(searchMap);
26976
26956
  }
26977
26957
  extractSearchParameters(params) {
26978
- return Object.getOwnPropertyNames(params).filter(param => param.startsWith(this.searchParamPrefix));
26958
+ return Object.getOwnPropertyNames(params).filter(param => param.startsWith(this.searchParamPrefix + "-"));
26979
26959
  }
26980
26960
  buildSearchContextMap(params, searchParamKeys) {
26981
26961
  const searchMap = new Map();
@@ -27024,9 +27004,26 @@ class ElderSearchUrlBindingService {
27024
27004
  convertValueToArray(value) {
27025
27005
  return value.slice(1).slice(0, -1).split(",");
27026
27006
  }
27027
- ngOnDestroy() {
27028
- this.unsubscribe$.next();
27029
- this.unsubscribe$.complete();
27007
+ resetSearchParams() {
27008
+ let params = { ...this.route.snapshot.queryParams };
27009
+ const searchParams = this.extractSearchParameters(params);
27010
+ for (const searchParam of searchParams) {
27011
+ params[searchParam] = null;
27012
+ }
27013
+ return params;
27014
+ }
27015
+ buildQueryParams(searchMap) {
27016
+ const params = {};
27017
+ for (const searchContextId of searchMap.keys()) {
27018
+ const filters = searchMap.get(searchContextId).filters;
27019
+ for (const filter of filters.values()) {
27020
+ params[`${this.searchParamPrefix}-${searchContextId}-${filter.key}`] = this.convertValueToArrayOrSingleValue(filter.value);
27021
+ }
27022
+ }
27023
+ return params;
27024
+ }
27025
+ convertValueToArrayOrSingleValue(value) {
27026
+ return Array.isArray(value) ? `(${value.toString()})` : value;
27030
27027
  }
27031
27028
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.11", ngImport: i0, type: ElderSearchUrlBindingService, deps: [{ token: i1$3.Router }, { token: i1$3.ActivatedRoute }], target: i0.ɵɵFactoryTarget.Injectable }); }
27032
27029
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.11", ngImport: i0, type: ElderSearchUrlBindingService, providedIn: "root" }); }
@@ -27067,12 +27064,15 @@ class ElderSearchContextUrlBindingDirective {
27067
27064
  ngAfterViewInit() {
27068
27065
  if (this._urlBinding) {
27069
27066
  this.urlBindingService.initialSearchMap$.pipe(first(), takeUntil(this._unsubscribe$), filter(searchMap => searchMap.has(this._urlBinding)), map(searchMap => searchMap.get(this._urlBinding)), map(filterMap => Array.from(filterMap.filters.values()))).subscribe(filters => {
27070
- this.searchContext.searchFilterContext.addInitialFilters(filters);
27067
+ this.searchContext.filterContext.updateFilters(filters);
27068
+ this.searchContext.applyModelToInputs();
27069
+ // this.searchContext.searchFilterContext.addInitialFilters(filters)
27071
27070
  });
27072
- this.searchContext.searchFilterContext.filters.pipe(takeUntil(this._unsubscribe$)).subscribe(filters => this.urlBindingService.updateFiltersForContext(this._urlBinding, filters));
27071
+ this.searchContext.filterContext.filters.pipe(takeUntil(this._unsubscribe$)).subscribe(filters => this.urlBindingService.updateFiltersForContext(this._urlBinding, filters));
27073
27072
  }
27074
27073
  }
27075
27074
  ngOnDestroy() {
27075
+ this.urlBindingService.resetFilterForContext(this._urlBinding);
27076
27076
  this._unsubscribe$.next();
27077
27077
  this._unsubscribe$.complete();
27078
27078
  }