@porscheinformatik/clr-addons 13.2.1 → 13.3.0

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,7 +5,7 @@ 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';
8
+ import { ClarityModule, ClrFormsModule, ClrDropdown, ClrForm, ClrAlert, ClrAxis, ClrSide, ClrAlignment, ClrPopoverToggleService, ClrPopoverEventsService, ClrPopoverPositionService, ClrIconModule, ClrDropdownModule, ClrDatagridPagination, ClrDatagridFilter } from '@clr/angular';
9
9
  import { Subject, BehaviorSubject, timer, asyncScheduler, interval, of, ReplaySubject, takeUntil as takeUntil$1 } from 'rxjs';
10
10
  import { takeUntil, observeOn, take } from 'rxjs/operators';
11
11
  import * as i3 from '@angular/router';
@@ -4628,39 +4628,149 @@ 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
+ this.datagrid.refresh.pipe(takeUntil(this.destroy$)).subscribe(dgState => {
4691
+ var _a, _b;
4692
+ const state = this.getVolatileDataState();
4693
+ state.currentPage = (_a = dgState.page) === null || _a === void 0 ? void 0 : _a.current;
4694
+ state.columns = state.columns || {};
4695
+ Object.keys(state.columns).forEach(prop => (state.columns[prop].filterValue = undefined));
4696
+ (_b = dgState.filters) === null || _b === void 0 ? void 0 : _b.forEach(filter => {
4697
+ const property = this.getFilterPropertyName(filter);
4698
+ if (property) {
4699
+ state.columns[property] = state.columns[property] || {};
4700
+ state.columns[property].filterValue = this.enrichFilterValue(filter);
4701
+ }
4702
+ });
4703
+ (this.useLocalStoreOnly ? localStorage : sessionStorage).setItem(this.options.key, JSON.stringify(state));
4704
+ });
4705
+ }
4706
+ /**
4707
+ * Gets the state of volatile data. This can be influenced by clrUseLocalStoreOnly.
4708
+ */
4709
+ getVolatileDataState() {
4710
+ return JSON.parse((this.useLocalStoreOnly ? localStorage : sessionStorage).getItem(this.options.key)) || {};
4711
+ }
4712
+ getLocalStorageState() {
4713
+ return JSON.parse(localStorage.getItem(this.options.key)) || {};
4714
+ }
4715
+ /**
4716
+ * As a date is serialized as string, but not deserialized as date
4717
+ * we need to add some meta information to do that manually later
4718
+ */
4719
+ enrichFilterValue(filter) {
4720
+ const result = {};
4721
+ Object.keys(filter).forEach(key => (result[key] =
4722
+ filter[key] instanceof Date
4723
+ ? {
4724
+ type: DATE_TYPE,
4725
+ value: filter[key],
4726
+ }
4727
+ : filter[key]));
4728
+ return result;
4729
+ }
4730
+ /**
4731
+ * Parse filter values with meta information like date, which needs manual deserialization to a date object
4732
+ */
4733
+ parseFilterValue(value) {
4734
+ return (value === null || value === void 0 ? void 0 : value.type) === DATE_TYPE
4735
+ ? new Date(value.value)
4736
+ : value;
4737
+ }
4738
+ getFilter(prop) {
4739
+ var _a, _b;
4740
+ // get default filter or custom filter
4741
+ return (((_a = this.datagrid.columns.find(col => col.field === prop)) === null || _a === void 0 ? void 0 : _a.filter) ||
4742
+ ((_b = this.customFilters.find(filter => this.getFilterPropertyName(filter.filter) === prop)) === null || _b === void 0 ? void 0 : _b.filter));
4743
+ }
4744
+ getFilterPropertyName(filter) {
4745
+ var _a;
4746
+ // for NestedProperty we need to get the original property
4747
+ const filterWithProp = filter;
4748
+ return (((_a = filterWithProp.property) === null || _a === void 0 ? void 0 : _a.prop) || filterWithProp.property);
4749
+ }
4750
+ ngOnDestroy() {
4751
+ this.destroy$.next();
4752
+ this.destroy$.complete();
4753
+ }
4651
4754
  }
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 });
4755
+ StatePersistenceKeyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: StatePersistenceKeyDirective, deps: [{ token: i2.ClrDatagrid }], target: i0.ɵɵFactoryTarget.Directive });
4756
+ 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
4757
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: StatePersistenceKeyDirective, decorators: [{
4655
4758
  type: Directive,
4656
4759
  args: [{
4657
4760
  selector: '[clrStatePersistenceKey]',
4658
4761
  }]
4659
- }], propDecorators: { clrStatePersistenceKey: [{
4660
- type: Input
4762
+ }], ctorParameters: function () { return [{ type: i2.ClrDatagrid }]; }, propDecorators: { options: [{
4763
+ type: Input,
4764
+ args: ['clrStatePersistenceKey']
4765
+ }], useLocalStoreOnly: [{
4766
+ type: Input,
4767
+ args: ['clrUseLocalStoreOnly']
4661
4768
  }], pagination: [{
4662
4769
  type: ContentChild,
4663
4770
  args: [ClrDatagridPagination]
4771
+ }], customFilters: [{
4772
+ type: ContentChildren,
4773
+ args: [ClrDatagridFilter, { descendants: true }]
4664
4774
  }] } });
4665
4775
 
4666
4776
  class ColumnHiddenStatePersistenceDirective {
@@ -4669,30 +4779,29 @@ class ColumnHiddenStatePersistenceDirective {
4669
4779
  this.statePersistenceKey = statePersistenceKey;
4670
4780
  this.datagrid = datagrid;
4671
4781
  this.hideableColumnDirective = hideableColumnDirective;
4782
+ this.destroy$ = new Subject();
4672
4783
  }
4673
4784
  ngOnInit() {
4674
4785
  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)) {
4786
+ 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
4787
  /* set hidden states from local storage (if existing) */
4677
4788
  this.initHiddenState();
4678
4789
  /* listen to state changes and persist in local storage */
4679
- this.hideableColumnDirective.hiddenChange.subscribe(hidden => {
4790
+ this.hideableColumnDirective.hiddenChange.pipe(takeUntil(this.destroy$)).subscribe(hidden => {
4680
4791
  this.setHiddenState(hidden);
4681
4792
  });
4682
4793
  }
4683
4794
  }
4684
4795
  initHiddenState() {
4796
+ var _a;
4685
4797
  /* 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
- }
4798
+ const persistedGridState = this.readStoredState();
4799
+ /* read column state if existing */
4800
+ if ((_a = persistedGridState === null || persistedGridState === void 0 ? void 0 : persistedGridState.columns) === null || _a === void 0 ? void 0 : _a[this.columnDirective.clrDgField]) {
4801
+ /* read column hidden state if existing */
4802
+ const persistedColumnHiddenState = persistedGridState.columns[this.columnDirective.clrDgField].hidden;
4803
+ if (persistedColumnHiddenState !== undefined) {
4804
+ this.hideableColumnDirective.clrDgHidden = persistedColumnHiddenState === true;
4696
4805
  }
4697
4806
  }
4698
4807
  }
@@ -4700,11 +4809,7 @@ class ColumnHiddenStatePersistenceDirective {
4700
4809
  var _a, _b;
4701
4810
  if (!((_b = (_a = this.datagrid) === null || _a === void 0 ? void 0 : _a.detailService) === null || _b === void 0 ? void 0 : _b.isOpen)) {
4702
4811
  /* 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
- }
4812
+ const persistedGridState = this.readStoredState();
4708
4813
  /* read column state if existing */
4709
4814
  if (!persistedGridState.columns) {
4710
4815
  persistedGridState.columns = {};
@@ -4716,9 +4821,16 @@ class ColumnHiddenStatePersistenceDirective {
4716
4821
  }
4717
4822
  /* set column hidden state and persist in local storage */
4718
4823
  persistedColumnState.hidden = hidden;
4719
- localStorage.setItem(this.statePersistenceKey.clrStatePersistenceKey, JSON.stringify(persistedGridState));
4824
+ localStorage.setItem(this.statePersistenceKey.options.key, JSON.stringify(persistedGridState));
4720
4825
  }
4721
4826
  }
4827
+ readStoredState() {
4828
+ return JSON.parse(localStorage.getItem(this.statePersistenceKey.options.key)) || {};
4829
+ }
4830
+ ngOnDestroy() {
4831
+ this.destroy$.next();
4832
+ this.destroy$.complete();
4833
+ }
4722
4834
  }
4723
4835
  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
4836
  ColumnHiddenStatePersistenceDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.8", type: ColumnHiddenStatePersistenceDirective, selector: "[clrDgHideableColumn]", ngImport: i0 });
@@ -4766,6 +4878,7 @@ class ClrEnumFilterComponent {
4766
4878
  }
4767
4879
  set value(values) {
4768
4880
  this.filteredValues = values;
4881
+ this.changes.emit(true);
4769
4882
  }
4770
4883
  set clrPossibleValues(values) {
4771
4884
  this.setPossibleValues(values);
@@ -4791,6 +4904,12 @@ class ClrEnumFilterComponent {
4791
4904
  accepts(item) {
4792
4905
  return this.filteredValues.includes(item[this.property]);
4793
4906
  }
4907
+ get state() {
4908
+ return {
4909
+ property: this.property,
4910
+ value: this.filteredValues,
4911
+ };
4912
+ }
4794
4913
  ngOnDestroy() {
4795
4914
  this.destroyed$.next();
4796
4915
  this.destroyed$.complete();
@@ -4882,6 +5001,9 @@ class ClrDateFilterComponent {
4882
5001
  set property(value) {
4883
5002
  this.nestedProp = new NestedProperty(value);
4884
5003
  }
5004
+ get property() {
5005
+ return this.nestedProp.prop;
5006
+ }
4885
5007
  get maxPlaceholderValue() {
4886
5008
  return this.maxPlaceholder || this.commonStrings.keys.maxValue;
4887
5009
  }
@@ -4971,7 +5093,7 @@ class ClrDateFilterComponent {
4971
5093
  }
4972
5094
  }
4973
5095
  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"] }] });
5096
+ 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
5097
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: ClrDateFilterComponent, decorators: [{
4976
5098
  type: Component,
4977
5099
  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" }]