@messaia/cdk 22.0.1-rc.19 → 22.0.1-rc.21

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.
@@ -16982,7 +16982,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
16982
16982
  }] } });
16983
16983
 
16984
16984
  /**
16985
- * A generic datasource for data-table
16985
+ * @class TableDataSource
16986
+ * @description Provides a server-backed data source with filtering, sorting, pagination,
16987
+ * reloading, and row selection for an Angular Material table.
16988
+ * @template TEntity - The entity type displayed by the table.
16989
+ * @template TService - The service type used to retrieve entities.
16986
16990
  */
16987
16991
  class TableDataSource extends DataSource {
16988
16992
  service;
@@ -16990,180 +16994,176 @@ class TableDataSource extends DataSource {
16990
16994
  sorter;
16991
16995
  /**
16992
16996
  * @property _filterChange
16993
- * @description Represents a value that changes over time.
16994
- * Observers can subscribe to this BehaviorSubject to receive filter changes.
16997
+ * @description Stores and emits the current free-text filter.
16995
16998
  * @type {BehaviorSubject<string>}
16996
16999
  */
16997
17000
  _filterChange = new BehaviorSubject('');
16998
17001
  /**
16999
17002
  * @property _reloadChange
17000
- * @description Represents a value that triggers reload actions.
17001
- * It is used to notify when a reload should occur by emitting a new value.
17003
+ * @description Emits a new token whenever the table data must be reloaded.
17002
17004
  * @type {BehaviorSubject<number>}
17003
17005
  */
17004
17006
  _reloadChange = new BehaviorSubject(0);
17005
17007
  /**
17006
17008
  * @property onDataLoaded
17007
- * @description Event emitted after the data is loaded.
17008
- * It is a BehaviorSubject that holds pagination data or a null value if no data is loaded.
17009
+ * @description Emits the latest pagination response after data loads successfully.
17010
+ * The initial value is `null` until the first response is received.
17009
17011
  * @type {BehaviorSubject<Pagination<TEntity> | any>}
17010
17012
  */
17011
17013
  onDataLoaded = new BehaviorSubject(null);
17012
17014
  /**
17013
17015
  * @property selectionModel
17014
- * @description Used to power selecting one or more options from a list.
17016
+ * @description Tracks the entities selected across the table.
17015
17017
  * @type {SelectionModel<TEntity>}
17016
17018
  */
17017
17019
  selectionModel = new SelectionModel(true, []);
17018
17020
  /**
17019
17021
  * @property filter
17020
- * @description Gets the current filter applied to the data.
17022
+ * @description Gets the current free-text filter.
17021
17023
  * @type {string}
17022
17024
  */
17023
17025
  get filter() { return this._filterChange.value; }
17024
17026
  /**
17025
17027
  * @property filter
17026
- * @description Sets the filter and resets the page index if the paginator exists.
17027
- * @param {string} filter - The filter value to be applied.
17028
+ * @description Sets the free-text filter and returns pagination to the first page.
17029
+ * @param {string} filter - The filter text to apply.
17028
17030
  */
17029
17031
  set filter(filter) {
17030
- /* If paginator exists, reset the page index */
17032
+ /* Reset the paginator and cached page index before applying the filter. */
17031
17033
  if (this.paginator) {
17032
17034
  this.paginator.pageIndex = 0;
17033
17035
  this.pageIndex = 0;
17034
17036
  }
17035
- /* Trigger filter change */
17037
+ /* Publish the updated filter to connected table views. */
17036
17038
  this._filterChange.next(filter);
17037
17039
  }
17038
17040
  /**
17039
17041
  * @property onSortChange
17040
- * @description Sort change event emitter used to notify changes in sorting.
17042
+ * @description Relays changes emitted by the assigned sort controller.
17041
17043
  * @type {EventEmitter<Sort>}
17042
17044
  */
17043
17045
  onSortChange = new EventEmitter();
17044
17046
  /**
17045
17047
  * @property _sort
17046
- * @description Private instance of MatSort used to control the sorting of the table.
17047
- * @type {MatSort | null}
17048
+ * @description Stores the sort controller currently assigned to the data source.
17049
+ * @type {MatSort | undefined}
17048
17050
  */
17049
17051
  _sort = new MatSort();
17050
17052
  /**
17051
17053
  * @property sort
17052
- * @description Gets or sets the MatSort instance used to control the sorting of the table.
17053
- * Changes in sorting will trigger an update to the table’s rendered data.
17054
+ * @description Gets or sets the sort controller whose changes reload the table data.
17054
17055
  * @type {MatSort | undefined}
17055
17056
  */
17056
17057
  get sort() { return this._sort; }
17057
17058
  set sort(sort) {
17058
- /* Set the sort and subscribe to sort changes */
17059
+ /* Store the controller and relay its sort changes. */
17059
17060
  this._sort = sort;
17060
17061
  this._sort?.sortChange.subscribe(x => this.onSortChange.emit(x));
17061
17062
  }
17062
17063
  /**
17063
17064
  * @property reloadToken
17064
- * @description Gets the current reload token, used to trigger reload events.
17065
+ * @description Gets the token emitted by the most recent reload request.
17065
17066
  * @type {number}
17066
17067
  */
17067
17068
  get reloadToken() { return this._reloadChange.value; }
17068
17069
  /**
17069
17070
  * @property isConnected
17070
- * @description Flag indicating whether the data source is connected.
17071
+ * @description Indicates whether a collection viewer is connected to the data source.
17071
17072
  * @type {boolean}
17072
17073
  */
17073
17074
  isConnected = false;
17074
17075
  /**
17075
17076
  * @property includes
17076
- * @description The list of navigations to be included in the data query.
17077
+ * @description Lists the related resources to include in each data request.
17077
17078
  * @type {Array<string>}
17078
17079
  */
17079
17080
  includes = [];
17080
17081
  /**
17081
17082
  * @property path
17082
- * @description The endpoint path for the data source.
17083
+ * @description Specifies the optional service endpoint path used to retrieve data.
17083
17084
  * @type {string | undefined}
17084
17085
  */
17085
17086
  path;
17086
17087
  /**
17087
17088
  * @property projection
17088
- * @description Defines the fields to be included in the data query projection.
17089
+ * @description Specifies the fields requested from the service, either as a comma-separated
17090
+ * string or an array of field names.
17089
17091
  * @type {string | string[]}
17090
17092
  */
17091
17093
  projection = '';
17092
17094
  /**
17093
17095
  * @property items
17094
- * @description The list of items to be displayed in the data table.
17096
+ * @description Contains the entities returned for the current page.
17095
17097
  * @type {TEntity[]}
17096
17098
  */
17097
17099
  items = [];
17098
17100
  /**
17099
17101
  * @property parameters
17100
- * @description The parameters for pagination and sorting.
17102
+ * @description Contains additional parameters returned by the latest data request.
17101
17103
  * @type {any}
17102
17104
  */
17103
17105
  parameters;
17104
17106
  /**
17105
17107
  * @property facets
17106
- * @description The list of facets for filtering items.
17108
+ * @description Contains the facets returned by the latest data request.
17107
17109
  * @type {Facet[] | undefined}
17108
17110
  */
17109
17111
  facets;
17110
17112
  /**
17111
17113
  * @property fieldFilters
17112
- * @description A set of field filters applied to the data.
17114
+ * @description Contains mutable field filters applied to data requests.
17113
17115
  * @type {any}
17114
17116
  */
17115
17117
  fieldFilters = {};
17116
17118
  /**
17117
17119
  * @property fieldOperators
17118
- * @description A set of field operators used for filtering.
17120
+ * @description Contains operators associated with field-based filtering.
17119
17121
  * @type {any}
17120
17122
  */
17121
17123
  fieldOperators = {};
17122
17124
  /**
17123
17125
  * @property staticFieldFilters
17124
- * @description A set of static field filters applied to the data.
17126
+ * @description Contains persistent field filters applied to every data request.
17125
17127
  * @type {any}
17126
17128
  */
17127
17129
  staticFieldFilters = {};
17128
17130
  /**
17129
17131
  * @property pageIndex
17130
- * @description The current page index for pagination.
17132
+ * @description Stores the zero-based index of the current page.
17131
17133
  * @type {number}
17132
17134
  */
17133
17135
  pageIndex = 0;
17134
17136
  /**
17135
17137
  * @property total
17136
- * @description The current total number of items being paged.
17138
+ * @description Stores the total number of entities reported by the service.
17137
17139
  * @type {number}
17138
17140
  */
17139
17141
  total = 0;
17140
17142
  /**
17141
17143
  * @property pageSize
17142
- * @description The number of items displayed per page in the data-table.
17143
- * It controls how many records are shown on a single page.
17144
+ * @description Stores the number of entities requested per page.
17144
17145
  * @type {number}
17145
17146
  */
17146
17147
  pageSize = 15;
17147
17148
  /**
17148
17149
  * @property pageCount
17149
- * @description The total number of pages based on pagination.
17150
+ * @description Stores the total number of pages reported by the service.
17150
17151
  * @type {number}
17151
17152
  */
17152
17153
  pageCount = 0;
17153
17154
  /**
17154
17155
  * @property isLoading
17155
- * @description Flag to show the loading process when the data is being fetched.
17156
+ * @description Indicates whether a data request is currently in progress.
17156
17157
  * @type {boolean}
17157
17158
  */
17158
17159
  isLoading = false;
17159
17160
  /**
17160
17161
  * @constructor
17161
- * @description Initializes a new instance of the class and sets up the service, paginator, and sorter.
17162
- * The paginator and sorter are optional parameters used for handling pagination and sorting logic
17163
- * for the data displayed in the table.
17164
- * @param {TService} service - The service used for fetching and managing data.
17165
- * @param {MatPaginator} [paginator] - The paginator instance used for pagination functionality.
17166
- * @param {MatSort} [sorter] - The MatSort instance used for sorting functionality.
17162
+ * @description Creates a data source backed by the supplied service and optional Material
17163
+ * pagination and sorting controllers.
17164
+ * @param {TService} service - The service used to retrieve table data.
17165
+ * @param {MatPaginator} [paginator] - The controller used for server-side pagination.
17166
+ * @param {MatSort} [sorter] - The controller used for server-side sorting.
17167
17167
  */
17168
17168
  constructor(service, paginator, sorter) {
17169
17169
  super();
@@ -17173,32 +17173,33 @@ class TableDataSource extends DataSource {
17173
17173
  this.sort = sorter;
17174
17174
  }
17175
17175
  /**
17176
- * Connects a collection viewer (such as a data-table) to this data source.
17177
- * @param _ The component that exposes a view over the data provided by this
17178
- * data source.
17179
- * @returns Observable that emits a new value when the data changes.
17176
+ * @method connect
17177
+ * @description Connects a collection viewer and reloads server data when sorting,
17178
+ * pagination, filtering, or the reload token changes.
17179
+ * @param {CollectionViewer} [_] - The viewer that consumes the emitted entities.
17180
+ * @returns {Observable<TEntity[]>} An observable that emits the current page of entities.
17180
17181
  */
17181
17182
  connect(_) {
17182
17183
  this.isConnected = true;
17183
- /* A list of fields to observe */
17184
+ /* Collect every source that can trigger a data request. */
17184
17185
  const displayDataChanges = [
17185
17186
  this.onSortChange,
17186
17187
  this.paginator?.page,
17187
17188
  this._filterChange,
17188
17189
  this._reloadChange
17189
17190
  ];
17190
- /* If the user changes the sort order, reset back to the first page */
17191
+ /* Return to the first page whenever the sort order changes. */
17191
17192
  if (this.paginator) {
17192
17193
  this.onSortChange.subscribe(() => { this.paginator.pageIndex = 0; });
17193
17194
  }
17194
17195
  return merge$1(...displayDataChanges)
17195
17196
  .pipe(skip(1), switchMap$1(() => {
17196
- /* Flip flag to show that loading has begun */
17197
+ /* Mark the data source as loading before issuing the request. */
17197
17198
  this.isLoading = true;
17198
- /* Remove empty filters */
17199
+ /* Remove empty values from mutable and persistent field filters. */
17199
17200
  Utils.cleanObject(this.fieldFilters);
17200
17201
  Utils.cleanObject(this.staticFieldFilters);
17201
- /* Build parameters for the data query */
17202
+ /* Compose the service request from table state and field filters. */
17202
17203
  var params = Object.assign({
17203
17204
  includes: this.includes,
17204
17205
  projection: Array.isArray(this.projection) ? this.projection.join(',') : this.projection,
@@ -17208,12 +17209,12 @@ class TableDataSource extends DataSource {
17208
17209
  sortBy: this.sort?.active,
17209
17210
  sortOrder: this.sort?.direction
17210
17211
  }, this.fieldFilters ?? {}, this.staticFieldFilters ?? {});
17211
- /* Load data and return it */
17212
+ /* Retrieve the current page from the configured service endpoint. */
17212
17213
  return this.service.getList(Utils.cleanObject(params), this.path ?? '', { 'CheckOut': 'Yes' });
17213
17214
  }), map$1((result) => {
17214
- /* Flip flag to show that loading has finished */
17215
+ /* Clear the loading state after receiving a response. */
17215
17216
  this.isLoading = false;
17216
- /* Update pagination fields */
17217
+ /* Synchronize rows, pagination metadata, facets, and response parameters. */
17217
17218
  this.pageIndex = Math.max(Math.min(result.page - 1, result.pageCount - 1), 0);
17218
17219
  this.total = result.total;
17219
17220
  this.pageSize = result.pageSize;
@@ -17221,28 +17222,29 @@ class TableDataSource extends DataSource {
17221
17222
  this.items = result.items;
17222
17223
  this.facets = result.facets;
17223
17224
  this.parameters = result.parameters;
17224
- /* Raise onload event */
17225
+ /* Notify subscribers that the response has been applied. */
17225
17226
  this.onDataLoaded.next(result);
17226
17227
  return this.items;
17227
17228
  }), catchError(() => {
17228
- /* Flip flag to show that loading has finished */
17229
+ /* Clear the loading state and emit an empty page after a request failure. */
17229
17230
  this.isLoading = false;
17230
17231
  return of([]);
17231
17232
  }));
17232
17233
  }
17233
17234
  /**
17234
- * Disconnects a collection viewer (such as a data-table) from this data source. Can be used
17235
- * to perform any clean-up or tear-down operations when a view is being destroyed.
17236
- *
17237
- * @param _ The component that exposes a view over the data provided by this
17238
- * data source.
17235
+ * @method disconnect
17236
+ * @description Marks the data source as disconnected from its collection viewer.
17237
+ * @param {CollectionViewer} _ - The viewer that no longer consumes this data source.
17238
+ * @returns {void}
17239
17239
  */
17240
17240
  disconnect(_) {
17241
17241
  this.isConnected = false;
17242
17242
  }
17243
17243
  /**
17244
- * Reloads items
17245
- * @param clearSelection
17244
+ * @method reload
17245
+ * @description Requests fresh data and optionally clears the current row selection.
17246
+ * @param {boolean} [clearSelection=true] - Whether to clear selected entities.
17247
+ * @returns {void}
17246
17248
  */
17247
17249
  reload(clearSelection = true) {
17248
17250
  this._reloadChange.next(Math.random());
@@ -17251,21 +17253,31 @@ class TableDataSource extends DataSource {
17251
17253
  }
17252
17254
  }
17253
17255
  /**
17254
- * Clears field filters
17256
+ * @method applyFilters
17257
+ * @description Replaces the mutable field filters and requests fresh data.
17258
+ * @param {any} [newFilters={}] - The field filters to apply.
17259
+ * @returns {void}
17255
17260
  */
17256
17261
  applyFilters(newFilters = {}) {
17257
17262
  this.fieldFilters = newFilters || {};
17258
17263
  this.reload();
17259
17264
  }
17260
17265
  /**
17261
- * Clears field filters
17266
+ * @method clearFilters
17267
+ * @description Resets mutable field filters to the supplied object, or to an empty object
17268
+ * when no replacement is supplied, and requests fresh data.
17269
+ * @param {any} [newFilters={}] - Optional field filters retained after the reset.
17270
+ * @returns {void}
17262
17271
  */
17263
17272
  clearFilters(newFilters = {}) {
17264
17273
  this.fieldFilters = newFilters || {};
17265
17274
  this.reload();
17266
17275
  }
17267
17276
  /**
17268
- * Checks, whether all items are selected
17277
+ * @method isAllSelected
17278
+ * @description Determines whether the selected entity count matches the total entity count.
17279
+ * An empty selection is never considered complete.
17280
+ * @returns {boolean} `true` when every reported entity is selected; otherwise, `false`.
17269
17281
  */
17270
17282
  isAllSelected() {
17271
17283
  if (this.selectionModel.isEmpty()) {
@@ -17274,9 +17286,13 @@ class TableDataSource extends DataSource {
17274
17286
  return this.selectionModel.selected.length === this.total;
17275
17287
  }
17276
17288
  /**
17277
- * Toggles selected items
17278
- * @param checkbox
17279
- * @param predicate
17289
+ * @method toggleSelect
17290
+ * @description Clears an existing selection or selects each unlocked entity on the current
17291
+ * page that satisfies the optional predicate.
17292
+ * @param {MatCheckboxChange} checkbox - The select-all checkbox change event.
17293
+ * @param {(value: TEntity, index: number, array: TEntity[]) => unknown} [predicate] - Optional
17294
+ * condition used to choose selectable entities.
17295
+ * @returns {void}
17280
17296
  */
17281
17297
  toggleSelect(checkbox, predicate) {
17282
17298
  if (this.selectionModel.hasValue()) {
@@ -17293,11 +17309,23 @@ class TableDataSource extends DataSource {
17293
17309
  }
17294
17310
  }
17295
17311
  /**
17296
- * Get selected Items
17312
+ * @property getSelected
17313
+ * @description Maps selected entities to the values stored under the specified property key.
17314
+ * @template TType - The expected property value type.
17315
+ * @param {string} key - The entity property key to read.
17316
+ * @returns {TType[]} The selected property values.
17297
17317
  */
17298
17318
  getSelected = (key) => this.selectionModel.selected.map(x => x[key]);
17299
17319
  /**
17300
- * Get selected Items
17320
+ * @property getSelectedItems
17321
+ * @description Gets all currently selected entities.
17322
+ * @returns {TEntity[]} The selected entities.
17323
+ */
17324
+ getSelectedItems = () => this.selectionModel.selected;
17325
+ /**
17326
+ * @property getSelectedIds
17327
+ * @description Gets the numeric identifiers of all selected entities.
17328
+ * @returns {number[]} The selected entity identifiers.
17301
17329
  */
17302
17330
  getSelectedIds = () => this.getSelected('id');
17303
17331
  }