@porscheinformatik/clr-addons 15.0.0 → 15.0.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.
@@ -1,11 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Component, NgModule, Injectable, EventEmitter, Input, Output, Directive, ViewChild, ContentChildren, TemplateRef, ViewChildren, HostBinding, ElementRef, Renderer2, forwardRef, ContentChild, HostListener, InjectionToken, Inject, Optional } from '@angular/core';
2
+ import { Component, NgModule, Injectable, EventEmitter, Input, Output, Directive, ViewChild, ContentChildren, TemplateRef, ViewChildren, HostBinding, ElementRef, Renderer2, forwardRef, ContentChild, Optional, HostListener, InjectionToken, Inject } from '@angular/core';
3
3
  import * as i1 from '@angular/common';
4
4
  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, ClrDatagridFilter } from '@clr/angular';
8
+ import { ClarityModule, ClrFormsModule, ClrDropdown, ClrForm, ClrAlert, ClrAxis, ClrSide, ClrAlignment, ClrPopoverToggleService, ClrPopoverEventsService, ClrPopoverPositionService, ClrIconModule, ClrDropdownModule, ClrDatagridSortOrder, DatagridPropertyComparator, ClrDatagridPagination, ClrDatagridFilter } from '@clr/angular';
9
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';
@@ -3068,7 +3068,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
3068
3068
  }] });
3069
3069
 
3070
3070
  /*
3071
- * Copyright (c) 2018-2022 Porsche Informatik. All Rights Reserved.
3071
+ * Copyright (c) 2018-2023 Porsche Informatik. All Rights Reserved.
3072
3072
  * This software is released under MIT license.
3073
3073
  * The full license information can be found in LICENSE in the root directory of this project.
3074
3074
  */
@@ -3151,7 +3151,7 @@ class ClrSearchField {
3151
3151
  }
3152
3152
  }
3153
3153
  }
3154
- ClrSearchField.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: ClrSearchField, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i3$1.NgControl }], target: i0.ɵɵFactoryTarget.Directive });
3154
+ ClrSearchField.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: ClrSearchField, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i3$1.NgControl, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
3155
3155
  ClrSearchField.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.1", type: ClrSearchField, selector: "[clrSearch]", host: { properties: { "class.search-input": "true" } }, ngImport: i0 });
3156
3156
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: ClrSearchField, decorators: [{
3157
3157
  type: Directive,
@@ -3159,7 +3159,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
3159
3159
  selector: '[clrSearch]',
3160
3160
  host: { '[class.search-input]': 'true' },
3161
3161
  }]
3162
- }], ctorParameters: function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i3$1.NgControl }]; } });
3162
+ }], ctorParameters: function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i3$1.NgControl, decorators: [{
3163
+ type: Optional
3164
+ }] }]; } });
3163
3165
 
3164
3166
  /*
3165
3167
  * Copyright (c) 2018-2019 Porsche Informatik. All Rights Reserved.
@@ -4649,8 +4651,10 @@ class StatePersistenceKeyDirective {
4649
4651
  const volatileDataState = this.getVolatileDataState();
4650
4652
  const localStorageState = this.getLocalStorageState();
4651
4653
  this.initFilter(volatileDataState);
4654
+ this.initSorting(localStorageState);
4652
4655
  this.initDatagridPersister();
4653
- if (this.pagination && this.pagination.page) {
4656
+ const paginationPersistenceEnabled = this.options.persistPagination ?? true;
4657
+ if (this.pagination?.page && paginationPersistenceEnabled) {
4654
4658
  this.initPageSizePersister(localStorageState);
4655
4659
  this.initCurrentPage(volatileDataState);
4656
4660
  }
@@ -4685,7 +4689,8 @@ class StatePersistenceKeyDirective {
4685
4689
  }
4686
4690
  }
4687
4691
  initFilter(savedState) {
4688
- if (savedState.columns) {
4692
+ const filterPersistenceEnabled = this.options.persistFilters ?? true;
4693
+ if (savedState.columns && filterPersistenceEnabled) {
4689
4694
  Object.keys(savedState.columns).forEach(prop => {
4690
4695
  const filter = this.getFilter(prop);
4691
4696
  if (filter) {
@@ -4697,13 +4702,40 @@ class StatePersistenceKeyDirective {
4697
4702
  });
4698
4703
  }
4699
4704
  }
4705
+ initSorting(savedState) {
4706
+ const sortPersistenceEnabled = this.options.persistSort ?? true;
4707
+ if (savedState.sortBy && sortPersistenceEnabled) {
4708
+ this.datagrid.columns.forEach(column => {
4709
+ if (this.getSortProperty(column.sortBy) === savedState.sortBy) {
4710
+ column.sortOrder = savedState.sortReverse ? ClrDatagridSortOrder.DESC : ClrDatagridSortOrder.ASC;
4711
+ }
4712
+ else {
4713
+ column.sortOrder = ClrDatagridSortOrder.UNSORTED;
4714
+ }
4715
+ });
4716
+ }
4717
+ }
4700
4718
  initDatagridPersister() {
4701
4719
  // delay is needed, as onDestroy the filters emit empty values.
4702
4720
  // So delay it to the end of the current cycle, so the directive is also destroyed before it gets the next values
4703
4721
  this.datagrid.refresh.pipe(delay(0), takeUntil(this.destroy$)).subscribe(dgState => {
4704
- const state = this.getVolatileDataState();
4722
+ this.persistFiltersAndCurrentPage(dgState);
4723
+ this.persistSorting(dgState);
4724
+ if (this.canShowPaginationDescription) {
4725
+ this.updatePaginationDescription();
4726
+ }
4727
+ });
4728
+ this.datagrid.items.change.pipe(takeUntil(this.destroy$)).subscribe(() => this.updatePaginationDescription());
4729
+ }
4730
+ persistFiltersAndCurrentPage(dgState) {
4731
+ const filterPersistenceEnabled = this.options.persistFilters ?? true;
4732
+ const paginationPersistenceEnabled = this.options.persistPagination ?? true;
4733
+ const state = this.getVolatileDataState();
4734
+ state.columns = state.columns || {};
4735
+ if (paginationPersistenceEnabled) {
4705
4736
  state.currentPage = dgState.page?.current;
4706
- state.columns = state.columns || {};
4737
+ }
4738
+ if (filterPersistenceEnabled) {
4707
4739
  Object.keys(state.columns).forEach(prop => (state.columns[prop].filterValue = undefined));
4708
4740
  dgState.filters?.forEach(filter => {
4709
4741
  const property = this.getFilterPropertyName(filter);
@@ -4712,12 +4744,17 @@ class StatePersistenceKeyDirective {
4712
4744
  state.columns[property].filterValue = this.enrichFilterValue(filter);
4713
4745
  }
4714
4746
  });
4715
- (this.useLocalStoreOnly ? localStorage : sessionStorage).setItem(this.options.key, JSON.stringify(state));
4716
- if (this.canShowPaginationDescription) {
4717
- this.updatePaginationDescription();
4718
- }
4719
- });
4720
- this.datagrid.items.change.pipe(takeUntil(this.destroy$)).subscribe(() => this.updatePaginationDescription());
4747
+ }
4748
+ (this.useLocalStoreOnly ? localStorage : sessionStorage).setItem(this.options.key, JSON.stringify(state));
4749
+ }
4750
+ persistSorting(dgState) {
4751
+ const sortPersistenceEnabled = this.options.persistSort ?? true;
4752
+ if (sortPersistenceEnabled) {
4753
+ const state = this.getLocalStorageState();
4754
+ state.sortBy = this.getSortProperty(dgState.sort?.by);
4755
+ state.sortReverse = dgState.sort?.reverse;
4756
+ localStorage.setItem(this.options.key, JSON.stringify(state));
4757
+ }
4721
4758
  }
4722
4759
  /**
4723
4760
  * Pagination description must be set by this directive,
@@ -4784,6 +4821,17 @@ class StatePersistenceKeyDirective {
4784
4821
  const filterWithProp = filter;
4785
4822
  return (filterWithProp.property?.prop || filterWithProp.property);
4786
4823
  }
4824
+ getSortProperty(sortBy) {
4825
+ if (sortBy) {
4826
+ if (typeof sortBy === 'string') {
4827
+ return sortBy;
4828
+ }
4829
+ if (sortBy instanceof DatagridPropertyComparator) {
4830
+ return sortBy.prop;
4831
+ }
4832
+ }
4833
+ return undefined;
4834
+ }
4787
4835
  ngOnDestroy() {
4788
4836
  this.destroy$.next();
4789
4837
  this.destroy$.complete();
@@ -4825,7 +4873,8 @@ class ColumnHiddenStatePersistenceDirective {
4825
4873
  this.destroy$ = new Subject();
4826
4874
  }
4827
4875
  ngOnInit() {
4828
- if (this.statePersistenceKey?.options.key && this.columnDirective?.clrDgField) {
4876
+ const persistenceEnabled = this.statePersistenceKey?.options?.persistHiddenColumns ?? true;
4877
+ if (this.statePersistenceKey?.options.key && this.columnDirective?.clrDgField && persistenceEnabled) {
4829
4878
  /* set hidden states from local storage (if existing) */
4830
4879
  this.initHiddenState();
4831
4880
  /* listen to state changes and persist in local storage */