@unifylib/ui-lib 1.2.33 → 1.2.35

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { HostListener, Input, Inject, Component, EventEmitter, Output, Injectable, signal, ViewChild, forwardRef, Directive, model, computed, inject, effect } from '@angular/core';
2
+ import { HostListener, Input, Inject, Component, EventEmitter, Output, Injectable, signal, ViewChild, forwardRef, Directive, model, computed, inject } from '@angular/core';
3
3
  import * as i1$1 from '@angular/common';
4
4
  import { CommonModule, NgForOf, NgIf, NgClass, AsyncPipe, NgSwitch, NgTemplateOutlet, KeyValuePipe, NgSwitchCase, DatePipe, CurrencyPipe, NgStyle, formatDate, NgSwitchDefault, DecimalPipe } from '@angular/common';
5
5
  import * as i1 from '@angular/material/dialog';
@@ -3536,16 +3536,12 @@ class BaseTableComponent extends BaseUtils {
3536
3536
  this.totalRequiredCountItem = 0;
3537
3537
  this.clickRoutePage = new EventEmitter();
3538
3538
  this.sortState = {};
3539
+ this.initialDataLoadScheduled = false;
3539
3540
  this.groupNames = [];
3540
3541
  this.groupSpans = new Map();
3541
3542
  this.dataSource = new MatTableDataSource();
3542
3543
  this.columns = [];
3543
3544
  this.filterRequest = new FilterRequest();
3544
- effect(() => {
3545
- if (this.pageInfo.lazyLoadData !== true || this.enforceRefresh === true) {
3546
- this.loadData();
3547
- }
3548
- });
3549
3545
  }
3550
3546
  ngOnDestroy() {
3551
3547
  }
@@ -3617,10 +3613,16 @@ class BaseTableComponent extends BaseUtils {
3617
3613
  return this.columns.find(c => c.property === property);
3618
3614
  }
3619
3615
  getSortDirection(property) {
3620
- if (this.reportRequest?.filterRequest?.sortKey) {
3621
- return this.reportRequest.filterRequest.sortDirection === 'ASC' ? 'asc' : 'desc';
3616
+ const sortKey = this.reportRequest?.filterRequest?.sortKey;
3617
+ if (!sortKey || !this.isSortedColumn(property, sortKey)) {
3618
+ return '';
3622
3619
  }
3623
- return '';
3620
+ return this.reportRequest.filterRequest.sortDirection === 'ASC' ? 'asc' : 'desc';
3621
+ }
3622
+ isSortedColumn(property, sortKey) {
3623
+ const column = this.getColumn(property);
3624
+ const columnSortKey = column?.sortKey ?? property;
3625
+ return sortKey === columnSortKey || sortKey === property;
3624
3626
  }
3625
3627
  handleSortClick(property) {
3626
3628
  const COLUMN = this.getColumn(property);
@@ -3695,14 +3697,18 @@ class BaseTableComponent extends BaseUtils {
3695
3697
  ];
3696
3698
  }
3697
3699
  this.reportRequest.filterRequest.pageSize = this.pageSize;
3700
+ if (this.manageablePages) {
3701
+ this.syncClientDataSource();
3702
+ return;
3703
+ }
3698
3704
  if (this.separateEndpointData || !this.pageInfo.apiUri || this.pageInfo.apiUri.length === 0) {
3699
- this.dataSource.data = this.separateEndpointData;
3700
- queueMicrotask(() => this.announceTableResults());
3705
+ this.syncClientDataSource();
3706
+ return;
3701
3707
  }
3702
- else if (this.reportRequest == undefined) {
3708
+ if (this.reportRequest == undefined) {
3703
3709
  return;
3704
3710
  }
3705
- else if (!this.manageablePages) {
3711
+ if (!this.manageablePages) {
3706
3712
  this.timer = setTimeout(() => {
3707
3713
  this.reportRequest.filterRequest.pageSize = this.pageSize;
3708
3714
  this.reportRequest.filterRequest.columns = this.columns?.filter(c => FRONT_END_COLUMN_TYPES.indexOf(c.type) < 0).map(c => c.property) || [];
@@ -3731,6 +3737,11 @@ class BaseTableComponent extends BaseUtils {
3731
3737
  }, 300);
3732
3738
  }
3733
3739
  }
3740
+ syncClientDataSource() {
3741
+ const rows = this.customizedData?.data ?? this.separateEndpointData ?? [];
3742
+ this.dataSource.data = rows;
3743
+ queueMicrotask(() => this.announceTableResults());
3744
+ }
3734
3745
  announceTableResults() {
3735
3746
  const visible = this.dataSource?.data?.length ?? 0;
3736
3747
  const total = this.totalElements ?? visible;
@@ -3747,11 +3758,16 @@ class BaseTableComponent extends BaseUtils {
3747
3758
  return element.stateType;
3748
3759
  }
3749
3760
  ngOnChanges(changes) {
3750
- if (changes["customizedData"] && !changes["customizedData"].isFirstChange()) {
3751
- this.dataSource.data = changes["customizedData"].currentValue?.data || []; // Update data source with new data
3752
- this.pagesCount = this.totalPagesCount;
3753
- this.pageIndex = this.currentPageIndex;
3754
- queueMicrotask(() => this.announceTableResults());
3761
+ if (changes["customizedData"]) {
3762
+ const dataSource = changes["customizedData"].currentValue;
3763
+ if (dataSource) {
3764
+ this.dataSource = dataSource;
3765
+ }
3766
+ this.syncClientDataSource();
3767
+ if (!changes["customizedData"].isFirstChange()) {
3768
+ this.pagesCount = this.totalPagesCount;
3769
+ this.pageIndex = this.currentPageIndex;
3770
+ }
3755
3771
  }
3756
3772
  if (changes["enforceRefresh"] && !changes["enforceRefresh"].isFirstChange()) {
3757
3773
  this.loadData();
@@ -3759,6 +3775,22 @@ class BaseTableComponent extends BaseUtils {
3759
3775
  if (changes["isPending"] && !changes["isPending"].isFirstChange()) {
3760
3776
  this.loadData();
3761
3777
  }
3778
+ if (changes['pageInfo'] || changes['columns']) {
3779
+ this.scheduleInitialLoad();
3780
+ }
3781
+ }
3782
+ scheduleInitialLoad() {
3783
+ if (this.initialDataLoadScheduled || this.manageablePages) {
3784
+ return;
3785
+ }
3786
+ if (this.pageInfo.lazyLoadData === true && this.enforceRefresh !== true) {
3787
+ return;
3788
+ }
3789
+ if (!this.pageInfo?.apiUri && !this.separateEndpointData && !this.customizedData) {
3790
+ return;
3791
+ }
3792
+ this.initialDataLoadScheduled = true;
3793
+ queueMicrotask(() => this.loadData());
3762
3794
  }
3763
3795
  getCroppedText(elementValue, subWidth = 20) {
3764
3796
  return elementValue && elementValue.length > subWidth ? elementValue.substring(0, subWidth) + "..." : elementValue;
@@ -3958,6 +3990,9 @@ class BaseTableComponent extends BaseUtils {
3958
3990
  this.reportRequest.filterRequest.sortDirection = $event.direction === 'asc' ? 'ASC' : 'DESC';
3959
3991
  this.reportRequest.filterRequest.pageIndex = 0;
3960
3992
  this.selectedColumn.emit($event);
3993
+ if (this.manageablePages) {
3994
+ return;
3995
+ }
3961
3996
  this.loadData();
3962
3997
  }
3963
3998
  shouldShowButton(element) {
@@ -4008,7 +4043,6 @@ class BaseTableComponent extends BaseUtils {
4008
4043
  }
4009
4044
  hasFiltersApplied() {
4010
4045
  return (this.advancedAppliedFilter && this.advancedAppliedFilter.length > 0) ||
4011
- (this.filters && this.filters.length > 0) ||
4012
4046
  (this.pendingFilters && this.pendingFilters.length > 0);
4013
4047
  }
4014
4048
  getDisplaySvgPath() {