@porscheinformatik/clr-addons 13.2.1 → 13.3.1

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.
@@ -5,8 +5,8 @@ import { CommonModule, DOCUMENT } from '@angular/common';
5
5
  import * as i3$1 from '@angular/forms';
6
6
  import { FormsModule, NG_VALIDATORS, NgControl, NG_VALUE_ACCESSOR } from '@angular/forms';
7
7
  import * as i2 from '@clr/angular';
8
- import { ClarityModule, ClrFormsModule, ClrDropdown, ClrForm, ClrAlert, ClrAxis, ClrSide, ClrAlignment, ClrPopoverToggleService, ClrPopoverEventsService, ClrPopoverPositionService, ClrIconModule, ClrDropdownModule, ClrDatagridPagination } from '@clr/angular';
9
- import { Subject, BehaviorSubject, timer, asyncScheduler, interval, of, ReplaySubject, takeUntil as takeUntil$1 } from 'rxjs';
8
+ import { ClarityModule, ClrFormsModule, ClrDropdown, ClrForm, ClrAlert, ClrAxis, ClrSide, ClrAlignment, ClrPopoverToggleService, ClrPopoverEventsService, ClrPopoverPositionService, ClrIconModule, ClrDropdownModule, ClrDatagridPagination, ClrDatagridFilter } from '@clr/angular';
9
+ import { Subject, BehaviorSubject, timer, asyncScheduler, interval, of, ReplaySubject, takeUntil as takeUntil$1, delay } from 'rxjs';
10
10
  import { takeUntil, observeOn, take } from 'rxjs/operators';
11
11
  import * as i3 from '@angular/router';
12
12
  import { RouterModule } from '@angular/router';
@@ -4628,39 +4628,151 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
4628
4628
  type: Input
4629
4629
  }] } });
4630
4630
 
4631
+ const DATE_TYPE = 'date';
4631
4632
  class StatePersistenceKeyDirective {
4633
+ constructor(datagrid) {
4634
+ this.datagrid = datagrid;
4635
+ this.useLocalStoreOnly = false;
4636
+ this.destroy$ = new Subject();
4637
+ }
4632
4638
  ngAfterContentInit() {
4639
+ if (this.options.serverDriven) {
4640
+ this.init();
4641
+ }
4642
+ else {
4643
+ setTimeout(() => {
4644
+ this.init();
4645
+ });
4646
+ }
4647
+ }
4648
+ init() {
4649
+ const volatileDataState = this.getVolatileDataState();
4650
+ const localStorageState = this.getLocalStorageState();
4651
+ this.initFilter(volatileDataState);
4652
+ this.initDatagridPersister();
4633
4653
  if (this.pagination && this.pagination.page) {
4634
- /* persist page size changes in local storage */
4635
- this.pagination.page.sizeChange.subscribe(pageSize => {
4636
- let state = JSON.parse(localStorage.getItem(this.clrStatePersistenceKey));
4637
- if (!state) {
4638
- state = {};
4654
+ this.initPageSizePersister(localStorageState);
4655
+ this.initCurrentPage(volatileDataState);
4656
+ }
4657
+ }
4658
+ initPageSizePersister(savedState) {
4659
+ /* persist page size changes in local storage */
4660
+ this.pagination.page.sizeChange.pipe(takeUntil(this.destroy$)).subscribe(pageSize => {
4661
+ const state = this.getLocalStorageState();
4662
+ state.pageSize = pageSize;
4663
+ localStorage.setItem(this.options.key, JSON.stringify(state));
4664
+ });
4665
+ /* init page size of datagrid if already persisted in local storage */
4666
+ if (savedState.pageSize) {
4667
+ this.pagination.page.size = savedState.pageSize;
4668
+ }
4669
+ }
4670
+ initCurrentPage(savedState) {
4671
+ /* init current page of datagrid if already persisted */
4672
+ if (savedState === null || savedState === void 0 ? void 0 : savedState.currentPage) {
4673
+ this.pagination.page.current = savedState.currentPage;
4674
+ }
4675
+ }
4676
+ initFilter(savedState) {
4677
+ if (savedState.columns) {
4678
+ Object.keys(savedState.columns).forEach(prop => {
4679
+ const filter = this.getFilter(prop);
4680
+ if (filter) {
4681
+ const savedFilterValue = savedState.columns[prop].filterValue || {};
4682
+ Object.keys(savedFilterValue)
4683
+ .filter(valueKey => valueKey !== 'property')
4684
+ .forEach(valueKey => (filter[valueKey] = this.parseFilterValue(savedFilterValue[valueKey])));
4639
4685
  }
4640
- state.pageSize = pageSize;
4641
- localStorage.setItem(this.clrStatePersistenceKey, JSON.stringify(state));
4642
4686
  });
4643
- /* init page size of datagrid if already persisted in local storage */
4644
- const loadedState = JSON.parse(localStorage.getItem(this.clrStatePersistenceKey));
4645
- if (loadedState === null || loadedState === void 0 ? void 0 : loadedState.pageSize) {
4646
- /* postpone set size to other cycle as it is already set in this change detection cycle */
4647
- setTimeout(() => (this.pagination.page.size = loadedState.pageSize));
4648
- }
4649
4687
  }
4650
4688
  }
4689
+ initDatagridPersister() {
4690
+ // delay is needed, as onDestroy the filters emit empty values.
4691
+ // So delay it to the end of the current cycle, so the directive is also destroyed before it gets the next values
4692
+ this.datagrid.refresh.pipe(delay(0), takeUntil(this.destroy$)).subscribe(dgState => {
4693
+ var _a, _b;
4694
+ const state = this.getVolatileDataState();
4695
+ state.currentPage = (_a = dgState.page) === null || _a === void 0 ? void 0 : _a.current;
4696
+ state.columns = state.columns || {};
4697
+ Object.keys(state.columns).forEach(prop => (state.columns[prop].filterValue = undefined));
4698
+ (_b = dgState.filters) === null || _b === void 0 ? void 0 : _b.forEach(filter => {
4699
+ const property = this.getFilterPropertyName(filter);
4700
+ if (property) {
4701
+ state.columns[property] = state.columns[property] || {};
4702
+ state.columns[property].filterValue = this.enrichFilterValue(filter);
4703
+ }
4704
+ });
4705
+ (this.useLocalStoreOnly ? localStorage : sessionStorage).setItem(this.options.key, JSON.stringify(state));
4706
+ });
4707
+ }
4708
+ /**
4709
+ * Gets the state of volatile data. This can be influenced by clrUseLocalStoreOnly.
4710
+ */
4711
+ getVolatileDataState() {
4712
+ return JSON.parse((this.useLocalStoreOnly ? localStorage : sessionStorage).getItem(this.options.key)) || {};
4713
+ }
4714
+ getLocalStorageState() {
4715
+ return JSON.parse(localStorage.getItem(this.options.key)) || {};
4716
+ }
4717
+ /**
4718
+ * As a date is serialized as string, but not deserialized as date
4719
+ * we need to add some meta information to do that manually later
4720
+ */
4721
+ enrichFilterValue(filter) {
4722
+ const result = {};
4723
+ Object.keys(filter).forEach(key => (result[key] =
4724
+ filter[key] instanceof Date
4725
+ ? {
4726
+ type: DATE_TYPE,
4727
+ value: filter[key],
4728
+ }
4729
+ : filter[key]));
4730
+ return result;
4731
+ }
4732
+ /**
4733
+ * Parse filter values with meta information like date, which needs manual deserialization to a date object
4734
+ */
4735
+ parseFilterValue(value) {
4736
+ return (value === null || value === void 0 ? void 0 : value.type) === DATE_TYPE
4737
+ ? new Date(value.value)
4738
+ : value;
4739
+ }
4740
+ getFilter(prop) {
4741
+ var _a, _b;
4742
+ // get default filter or custom filter
4743
+ return (((_a = this.datagrid.columns.find(col => col.field === prop)) === null || _a === void 0 ? void 0 : _a.filter) ||
4744
+ ((_b = this.customFilters.find(filter => this.getFilterPropertyName(filter.filter) === prop)) === null || _b === void 0 ? void 0 : _b.filter));
4745
+ }
4746
+ getFilterPropertyName(filter) {
4747
+ var _a;
4748
+ // for NestedProperty we need to get the original property
4749
+ const filterWithProp = filter;
4750
+ return (((_a = filterWithProp.property) === null || _a === void 0 ? void 0 : _a.prop) || filterWithProp.property);
4751
+ }
4752
+ ngOnDestroy() {
4753
+ this.destroy$.next();
4754
+ this.destroy$.complete();
4755
+ }
4651
4756
  }
4652
- StatePersistenceKeyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: StatePersistenceKeyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
4653
- StatePersistenceKeyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: StatePersistenceKeyDirective, selector: "[clrStatePersistenceKey]", inputs: { clrStatePersistenceKey: "clrStatePersistenceKey" }, queries: [{ propertyName: "pagination", first: true, predicate: ClrDatagridPagination, descendants: true }], ngImport: i0 });
4757
+ StatePersistenceKeyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: StatePersistenceKeyDirective, deps: [{ token: i2.ClrDatagrid }], target: i0.ɵɵFactoryTarget.Directive });
4758
+ StatePersistenceKeyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: StatePersistenceKeyDirective, selector: "[clrStatePersistenceKey]", inputs: { options: ["clrStatePersistenceKey", "options"], useLocalStoreOnly: ["clrUseLocalStoreOnly", "useLocalStoreOnly"] }, queries: [{ propertyName: "pagination", first: true, predicate: ClrDatagridPagination, descendants: true }, { propertyName: "customFilters", predicate: ClrDatagridFilter, descendants: true }], ngImport: i0 });
4654
4759
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: StatePersistenceKeyDirective, decorators: [{
4655
4760
  type: Directive,
4656
4761
  args: [{
4657
4762
  selector: '[clrStatePersistenceKey]',
4658
4763
  }]
4659
- }], propDecorators: { clrStatePersistenceKey: [{
4660
- type: Input
4764
+ }], ctorParameters: function () { return [{ type: i2.ClrDatagrid }]; }, propDecorators: { options: [{
4765
+ type: Input,
4766
+ args: ['clrStatePersistenceKey']
4767
+ }], useLocalStoreOnly: [{
4768
+ type: Input,
4769
+ args: ['clrUseLocalStoreOnly']
4661
4770
  }], pagination: [{
4662
4771
  type: ContentChild,
4663
4772
  args: [ClrDatagridPagination]
4773
+ }], customFilters: [{
4774
+ type: ContentChildren,
4775
+ args: [ClrDatagridFilter, { descendants: true }]
4664
4776
  }] } });
4665
4777
 
4666
4778
  class ColumnHiddenStatePersistenceDirective {
@@ -4669,30 +4781,29 @@ class ColumnHiddenStatePersistenceDirective {
4669
4781
  this.statePersistenceKey = statePersistenceKey;
4670
4782
  this.datagrid = datagrid;
4671
4783
  this.hideableColumnDirective = hideableColumnDirective;
4784
+ this.destroy$ = new Subject();
4672
4785
  }
4673
4786
  ngOnInit() {
4674
4787
  var _a, _b;
4675
- if (((_a = this.statePersistenceKey) === null || _a === void 0 ? void 0 : _a.clrStatePersistenceKey) && ((_b = this.columnDirective) === null || _b === void 0 ? void 0 : _b.clrDgField)) {
4788
+ if (((_a = this.statePersistenceKey) === null || _a === void 0 ? void 0 : _a.options.key) && ((_b = this.columnDirective) === null || _b === void 0 ? void 0 : _b.clrDgField)) {
4676
4789
  /* set hidden states from local storage (if existing) */
4677
4790
  this.initHiddenState();
4678
4791
  /* listen to state changes and persist in local storage */
4679
- this.hideableColumnDirective.hiddenChange.subscribe(hidden => {
4792
+ this.hideableColumnDirective.hiddenChange.pipe(takeUntil(this.destroy$)).subscribe(hidden => {
4680
4793
  this.setHiddenState(hidden);
4681
4794
  });
4682
4795
  }
4683
4796
  }
4684
4797
  initHiddenState() {
4798
+ var _a;
4685
4799
  /* read grid state if existing */
4686
- const persistedGridStateJson = localStorage.getItem(this.statePersistenceKey.clrStatePersistenceKey);
4687
- if (persistedGridStateJson !== null) {
4688
- const persistedGridState = JSON.parse(persistedGridStateJson);
4689
- /* read column state if existing */
4690
- if (persistedGridState.columns && persistedGridState.columns[this.columnDirective.clrDgField]) {
4691
- /* read column hidden state if existing */
4692
- const persistedColumnHiddenState = persistedGridState.columns[this.columnDirective.clrDgField].hidden;
4693
- if (persistedColumnHiddenState !== undefined) {
4694
- this.hideableColumnDirective.clrDgHidden = persistedColumnHiddenState === true;
4695
- }
4800
+ const persistedGridState = this.readStoredState();
4801
+ /* read column state if existing */
4802
+ if ((_a = persistedGridState === null || persistedGridState === void 0 ? void 0 : persistedGridState.columns) === null || _a === void 0 ? void 0 : _a[this.columnDirective.clrDgField]) {
4803
+ /* read column hidden state if existing */
4804
+ const persistedColumnHiddenState = persistedGridState.columns[this.columnDirective.clrDgField].hidden;
4805
+ if (persistedColumnHiddenState !== undefined) {
4806
+ this.hideableColumnDirective.clrDgHidden = persistedColumnHiddenState === true;
4696
4807
  }
4697
4808
  }
4698
4809
  }
@@ -4700,11 +4811,7 @@ class ColumnHiddenStatePersistenceDirective {
4700
4811
  var _a, _b;
4701
4812
  if (!((_b = (_a = this.datagrid) === null || _a === void 0 ? void 0 : _a.detailService) === null || _b === void 0 ? void 0 : _b.isOpen)) {
4702
4813
  /* read grid state if existing */
4703
- const persistedGridStateJson = localStorage.getItem(this.statePersistenceKey.clrStatePersistenceKey);
4704
- let persistedGridState = {};
4705
- if (persistedGridStateJson !== null) {
4706
- persistedGridState = JSON.parse(persistedGridStateJson);
4707
- }
4814
+ const persistedGridState = this.readStoredState();
4708
4815
  /* read column state if existing */
4709
4816
  if (!persistedGridState.columns) {
4710
4817
  persistedGridState.columns = {};
@@ -4716,9 +4823,16 @@ class ColumnHiddenStatePersistenceDirective {
4716
4823
  }
4717
4824
  /* set column hidden state and persist in local storage */
4718
4825
  persistedColumnState.hidden = hidden;
4719
- localStorage.setItem(this.statePersistenceKey.clrStatePersistenceKey, JSON.stringify(persistedGridState));
4826
+ localStorage.setItem(this.statePersistenceKey.options.key, JSON.stringify(persistedGridState));
4720
4827
  }
4721
4828
  }
4829
+ readStoredState() {
4830
+ return JSON.parse(localStorage.getItem(this.statePersistenceKey.options.key)) || {};
4831
+ }
4832
+ ngOnDestroy() {
4833
+ this.destroy$.next();
4834
+ this.destroy$.complete();
4835
+ }
4722
4836
  }
4723
4837
  ColumnHiddenStatePersistenceDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: ColumnHiddenStatePersistenceDirective, deps: [{ token: DatagridFieldDirective, optional: true }, { token: StatePersistenceKeyDirective, optional: true }, { token: i2.ClrDatagrid }, { token: i2.ClrDatagridHideableColumn }], target: i0.ɵɵFactoryTarget.Directive });
4724
4838
  ColumnHiddenStatePersistenceDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: ColumnHiddenStatePersistenceDirective, selector: "[clrDgHideableColumn]", ngImport: i0 });
@@ -4766,6 +4880,7 @@ class ClrEnumFilterComponent {
4766
4880
  }
4767
4881
  set value(values) {
4768
4882
  this.filteredValues = values;
4883
+ this.changes.emit(true);
4769
4884
  }
4770
4885
  set clrPossibleValues(values) {
4771
4886
  this.setPossibleValues(values);
@@ -4791,6 +4906,12 @@ class ClrEnumFilterComponent {
4791
4906
  accepts(item) {
4792
4907
  return this.filteredValues.includes(item[this.property]);
4793
4908
  }
4909
+ get state() {
4910
+ return {
4911
+ property: this.property,
4912
+ value: this.filteredValues,
4913
+ };
4914
+ }
4794
4915
  ngOnDestroy() {
4795
4916
  this.destroyed$.next();
4796
4917
  this.destroyed$.complete();
@@ -4882,6 +5003,9 @@ class ClrDateFilterComponent {
4882
5003
  set property(value) {
4883
5004
  this.nestedProp = new NestedProperty(value);
4884
5005
  }
5006
+ get property() {
5007
+ return this.nestedProp.prop;
5008
+ }
4885
5009
  get maxPlaceholderValue() {
4886
5010
  return this.maxPlaceholder || this.commonStrings.keys.maxValue;
4887
5011
  }
@@ -4971,7 +5095,7 @@ class ClrDateFilterComponent {
4971
5095
  }
4972
5096
  }
4973
5097
  ClrDateFilterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: ClrDateFilterComponent, deps: [{ token: i2.ClrDatagridFilter }, { token: i2.ClrCommonStringsService }], target: i0.ɵɵFactoryTarget.Component });
4974
- ClrDateFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.8", type: ClrDateFilterComponent, selector: "clr-date-filter", inputs: { property: ["clrProperty", "property"], maxPlaceholder: ["clrFilterMaxPlaceholder", "maxPlaceholder"], minPlaceholder: ["clrFilterMinPlaceholder", "minPlaceholder"], value: ["clrFilterValue", "value"] }, outputs: { filterValueChange: "clrFilterValueChange" }, ngImport: i0, template: "<clr-date-container>\n <input\n #input_from\n type=\"date\"\n name=\"from\"\n class=\"datagrid-date-filter-input\"\n [(clrDate)]=\"from\"\n [placeholder]=\"minPlaceholderValue\"\n [attr.aria-label]=\"minPlaceholderValue\"\n />\n</clr-date-container>\n<clr-date-container>\n <input\n type=\"date\"\n name=\"to\"\n class=\"datagrid-date-filter-input\"\n [(clrDate)]=\"to\"\n [placeholder]=\"maxPlaceholderValue\"\n [attr.aria-label]=\"maxPlaceholderValue\"\n />\n</clr-date-container>\n", styles: [""], dependencies: [{ kind: "component", type: i2.ClrDateContainer, selector: "clr-date-container", inputs: ["clrPosition"] }, { kind: "directive", type: i2.ClrDateInput, selector: "[clrDate]", inputs: ["placeholder", "clrDate", "min", "max", "disabled"], outputs: ["clrDateChange"] }] });
5098
+ ClrDateFilterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.8", type: ClrDateFilterComponent, selector: "clr-date-filter", inputs: { property: ["clrProperty", "property"], maxPlaceholder: ["clrFilterMaxPlaceholder", "maxPlaceholder"], minPlaceholder: ["clrFilterMinPlaceholder", "minPlaceholder"], value: ["clrFilterValue", "value"] }, outputs: { filterValueChange: "clrFilterValueChange" }, ngImport: i0, template: "<clr-date-container>\n <input\n #input_from\n type=\"date\"\n name=\"from\"\n class=\"datagrid-date-filter-input\"\n [(clrDate)]=\"from\"\n [placeholder]=\"minPlaceholderValue\"\n [attr.aria-label]=\"minPlaceholderValue\"\n />\n</clr-date-container>\n<clr-date-container>\n <input\n type=\"date\"\n name=\"to\"\n class=\"datagrid-date-filter-input\"\n [(clrDate)]=\"to\"\n [placeholder]=\"maxPlaceholderValue\"\n [attr.aria-label]=\"maxPlaceholderValue\"\n />\n</clr-date-container>\n", styles: [""], dependencies: [{ kind: "component", type: i2.ClrDateContainer, selector: "clr-date-container", inputs: ["clrPosition"] }, { kind: "directive", type: i2.ClrDateInput, selector: "[clrDate]", inputs: ["placeholder", "clrDate", "min", "max", "disabled"], outputs: ["clrDateChange"] }, { kind: "directive", type: i2.ClrDateInputValidator, selector: "[clrDate]" }] });
4975
5099
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: ClrDateFilterComponent, decorators: [{
4976
5100
  type: Component,
4977
5101
  args: [{ selector: 'clr-date-filter', template: "<clr-date-container>\n <input\n #input_from\n type=\"date\"\n name=\"from\"\n class=\"datagrid-date-filter-input\"\n [(clrDate)]=\"from\"\n [placeholder]=\"minPlaceholderValue\"\n [attr.aria-label]=\"minPlaceholderValue\"\n />\n</clr-date-container>\n<clr-date-container>\n <input\n type=\"date\"\n name=\"to\"\n class=\"datagrid-date-filter-input\"\n [(clrDate)]=\"to\"\n [placeholder]=\"maxPlaceholderValue\"\n [attr.aria-label]=\"maxPlaceholderValue\"\n />\n</clr-date-container>\n" }]