@elderbyte/ngx-starter 22.2.2 → 22.2.3

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.
@@ -5678,71 +5678,99 @@ class DataContextLifeCycleBinding {
5678
5678
  }
5679
5679
  }
5680
5680
 
5681
- class RequiredFilterContextChangedEvent {
5682
- constructor(requiredFilters, currentFilters, isValid) {
5683
- this.requiredFilters = requiredFilters;
5684
- this.currentFilters = currentFilters;
5685
- this.isValid = isValid;
5681
+ class RequiredFilterMatcher {
5682
+ /***************************************************************************
5683
+ * *
5684
+ * Constructor *
5685
+ * *
5686
+ **************************************************************************/
5687
+ constructor(requiredFilters) {
5688
+ this.requiredKeys = new Set(requiredFilters);
5686
5689
  }
5687
- }
5688
- class RequiredFilterEvaluator {
5689
5690
  /***************************************************************************
5690
5691
  * *
5691
- * Fields *
5692
+ * Public API *
5692
5693
  * *
5693
5694
  **************************************************************************/
5694
- constructor(filterContext, requiredFilters) {
5695
- this._requiredFilters = new BehaviorSubject([]);
5696
- if (filterContext == null) {
5697
- throw new Error('filterContext must not be null!');
5698
- }
5699
- this._filterContext = filterContext;
5700
- if (requiredFilters) {
5701
- this._requiredFilters.next(requiredFilters);
5695
+ matches(currentFilters) {
5696
+ const matchedRequiredFilters = new Set();
5697
+ for (const currentFilter of currentFilters) {
5698
+ const requiredKey = this.findMatchingRequiredKey(currentFilter.key);
5699
+ if (!requiredKey) {
5700
+ continue;
5701
+ }
5702
+ if (!Filter.hasValue(currentFilter)) {
5703
+ return false;
5704
+ }
5705
+ matchedRequiredFilters.add(requiredKey);
5702
5706
  }
5703
- this.context$ = combineLatest([this._requiredFilters, this._filterContext.filters]).pipe(map(([required, currentFilters]) => this.createEvent(requiredFilters, currentFilters)));
5707
+ return this.allRequiredFiltersMatched(matchedRequiredFilters);
5704
5708
  }
5705
5709
  /***************************************************************************
5706
5710
  * *
5707
- * Properties *
5711
+ * Private methods *
5708
5712
  * *
5709
5713
  **************************************************************************/
5710
- get filterContext() {
5711
- return this._filterContext;
5714
+ findMatchingRequiredKey(currentKey) {
5715
+ if (this.requiredKeys.has(currentKey)) {
5716
+ return currentKey;
5717
+ }
5718
+ const prefix = this.getPrefix(currentKey);
5719
+ return this.requiredKeys.has(prefix) ? prefix : undefined;
5712
5720
  }
5713
- get requiredFilters$() {
5714
- return this._requiredFilters.asObservable();
5721
+ getPrefix(key) {
5722
+ const separatorIndex = key.indexOf('.');
5723
+ return separatorIndex === -1 ? key : key.slice(0, separatorIndex);
5715
5724
  }
5716
- get requiredFilters() {
5717
- return this._requiredFilters.getValue();
5725
+ allRequiredFiltersMatched(matchedRequiredFilters) {
5726
+ return matchedRequiredFilters.size === this.requiredKeys.size;
5727
+ }
5728
+ }
5729
+
5730
+ class RequiredFilterMatch {
5731
+ constructor(currentFilters, isValid) {
5732
+ this.currentFilters = currentFilters;
5733
+ this.isValid = isValid;
5734
+ }
5735
+ }
5736
+ class RequiredFilterEvaluator {
5737
+ /**
5738
+ * Observe the given filters and match them against the required filters.
5739
+ * @param filterContext
5740
+ * @param requiredFilters
5741
+ */
5742
+ static observeMatch(filterContext, requiredFilters) {
5743
+ if (filterContext == null) {
5744
+ throw new Error('filterContext must not be null!');
5745
+ }
5746
+ const evaluator = new RequiredFilterEvaluator(requiredFilters);
5747
+ return filterContext.filters.pipe(map((currentFilters) => evaluator.matchFilters(currentFilters)));
5748
+ }
5749
+ /***************************************************************************
5750
+ * *
5751
+ * Fields *
5752
+ * *
5753
+ **************************************************************************/
5754
+ constructor(requiredFilters) {
5755
+ this.someMatchRequired = (requiredFilters ?? []).map((filterGroup) => new RequiredFilterMatcher(filterGroup));
5718
5756
  }
5719
5757
  /***************************************************************************
5720
5758
  * *
5721
5759
  * Public API *
5722
5760
  * *
5723
5761
  **************************************************************************/
5762
+ matchFilters(currentFilters) {
5763
+ return new RequiredFilterMatch(currentFilters, this.allRequiredFiltersPresent(currentFilters));
5764
+ }
5724
5765
  /***************************************************************************
5725
5766
  * *
5726
5767
  * Private methods *
5727
5768
  * *
5728
5769
  **************************************************************************/
5729
- createEvent(requiredFilters, currentFilters) {
5730
- return new RequiredFilterContextChangedEvent(requiredFilters, currentFilters, this.allRequiredFiltersPresent(requiredFilters, currentFilters));
5731
- }
5732
- allRequiredFiltersPresent(requiredFilters, currentFilters) {
5733
- if (requiredFilters) {
5734
- return requiredFilters.some((filterGroup) => this.hasAllFilters(filterGroup, currentFilters));
5735
- }
5736
- return true;
5737
- }
5738
- hasAllFilters(requiredFilters, currentFilters) {
5739
- const requiredFilterSet = new Set(requiredFilters);
5740
- const currentFilterKeySet = new Set(currentFilters.map((f) => f.key));
5741
- const areAllRequiredFiltersPresent = requiredFilters.every((required) => currentFilterKeySet.has(required));
5742
- const areAllRequiredFiltersHaveValue = currentFilters
5743
- .filter((f) => requiredFilterSet.has(f.key))
5744
- .every((currentFilter) => Filter.hasValue(currentFilter));
5745
- return areAllRequiredFiltersPresent && areAllRequiredFiltersHaveValue;
5770
+ allRequiredFiltersPresent(currentFilters) {
5771
+ if (this.someMatchRequired.length === 0)
5772
+ return true;
5773
+ return this.someMatchRequired.some((groupMatcher) => groupMatcher.matches(currentFilters));
5746
5774
  }
5747
5775
  }
5748
5776
 
@@ -5812,7 +5840,7 @@ class DataContextAutoStarter extends DataContextLifeCycleBinding {
5812
5840
  * *
5813
5841
  **************************************************************************/
5814
5842
  buildRequiredFilterConditionObservable() {
5815
- return new RequiredFilterEvaluator(this._dataContext.filter, this._autoStartSpec.requiredFilters).context$.pipe(map((event) => event.isValid));
5843
+ return RequiredFilterEvaluator.observeMatch(this._dataContext.filter, this._autoStartSpec.requiredFilters).pipe(map((event) => event.isValid));
5816
5844
  }
5817
5845
  startDataContext() {
5818
5846
  this.logger.debug(this._dataContext.id + ': Auto starting ...');