@sumaris-net/ngx-components 2.4.55 → 2.4.57

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.
@@ -11463,6 +11463,15 @@ class EntityUtils {
11463
11463
  static isRemoteId(id) {
11464
11464
  return isNotNil(id) && +id >= 0;
11465
11465
  }
11466
+ static getId(entity) {
11467
+ return entity.id;
11468
+ }
11469
+ static collectById(entities) {
11470
+ return (entities || []).map(e => e.id);
11471
+ }
11472
+ static arrayDistinctFilterFn(item, index, values) {
11473
+ return values.findIndex(e => e.id === item.id) === index;
11474
+ }
11466
11475
  }
11467
11476
  EntityUtils.getPropertyByPath = getPropertyByPath;
11468
11477
 
@@ -25534,6 +25543,21 @@ class AppTableUtils {
25534
25543
  static logRowErrors(row, logPrefix) {
25535
25544
  AppFormUtils.logFormErrors(row.validator, logPrefix);
25536
25545
  }
25546
+ static getEntityId(row) {
25547
+ return EntityUtils.getId(row.currentData);
25548
+ }
25549
+ static getEntityIds(rows) {
25550
+ return (rows || [])
25551
+ .map((row) => row.currentData)
25552
+ .filter(isNotNil)
25553
+ .map(EntityUtils.getId)
25554
+ .filter(isNotNilOrNaN);
25555
+ }
25556
+ static getEntities(rows) {
25557
+ return (rows || [])
25558
+ .map((row) => row.currentData)
25559
+ .filter(isNotNil);
25560
+ }
25537
25561
  }
25538
25562
 
25539
25563
  // @dynamic
@@ -25947,6 +25971,7 @@ class AppTable {
25947
25971
  this.dirtySubject = new BehaviorSubject(false);
25948
25972
  this.errorSubject = new BehaviorSubject(undefined);
25949
25973
  this.selection = new SelectionModel(true, []);
25974
+ this.permanentSelection = null;
25950
25975
  this.editedRow = undefined;
25951
25976
  this.i18nColumnPrefix = 'COMMON.';
25952
25977
  this.autoLoad = true;
@@ -26000,18 +26025,6 @@ class AppTable {
26000
26025
  set error(error) {
26001
26026
  this.setError(error);
26002
26027
  }
26003
- /**
26004
- * @deprecated
26005
- */
26006
- get loading$() {
26007
- return this.loadingSubject.asObservable();
26008
- }
26009
- /**
26010
- * @deprecated
26011
- */
26012
- get saving$() {
26013
- return this.savingSubject.asObservable();
26014
- }
26015
26028
  get firstUserColumn() {
26016
26029
  return this.displayedColumns[RESERVED_START_COLUMNS.length];
26017
26030
  }
@@ -26033,6 +26046,10 @@ class AppTable {
26033
26046
  get empty() {
26034
26047
  return this.loading || this.totalRowCount === 0;
26035
26048
  }
26049
+ get selectedEntities() {
26050
+ return this.permanentSelection?.selected
26051
+ || AppTableUtils.getEntities(this.selection.selected);
26052
+ }
26036
26053
  get dirty() {
26037
26054
  return this.dirtySubject.value;
26038
26055
  }
@@ -26585,8 +26602,7 @@ class AppTable {
26585
26602
  isAllSelected() {
26586
26603
  // DEBUG
26587
26604
  //console.debug('isAllSelected. lengths', this.selection.selected.length, this.totalRowCount);
26588
- return this.selection.selected.length === this.totalRowCount ||
26589
- this.selection.selected.length === this.visibleRowCount;
26605
+ return this.selection.selected.length === this.visibleRowCount;
26590
26606
  }
26591
26607
  /** Selects all rows if they are not all selected; otherwise clear selection. */
26592
26608
  async masterToggle() {
@@ -26707,7 +26723,8 @@ class AppTable {
26707
26723
  // DO not update manually, because watchALl().subscribe() will update this count
26708
26724
  //this.totalRowCount -= deleteCount;
26709
26725
  //this.visibleRowCount -= deleteCount;
26710
- this.selection.clear();
26726
+ // Deselect deleted rows
26727
+ this.selection.deselect(...rows);
26711
26728
  this.editedRow = undefined;
26712
26729
  this.markAsDirty({ emitEvent: false /*markForCheck() is called just after*/ });
26713
26730
  this.markForCheck();
@@ -26771,7 +26788,6 @@ class AppTable {
26771
26788
  event.preventDefault();
26772
26789
  }
26773
26790
  this.markAsLoading();
26774
- this.selection.clear();
26775
26791
  this.openRow(row.currentData.id, row)
26776
26792
  .then(() => this.markAsLoaded())
26777
26793
  .catch(() => this.markAsLoaded());
@@ -27071,9 +27087,7 @@ class AppTable {
27071
27087
  this.onNewRow.emit(event);
27072
27088
  return true;
27073
27089
  }
27074
- return await this.router.navigate(['new'], {
27075
- relativeTo: this.route
27076
- });
27090
+ return this.navController.navigateForward(`${this.router.url}/new`);
27077
27091
  }
27078
27092
  // can be overridden to add more required columns
27079
27093
  getRequiredColumns() {
@@ -27481,6 +27495,53 @@ class AppTable {
27481
27495
  def.subject.unsubscribe();
27482
27496
  }
27483
27497
  }
27498
+ /**
27499
+ * Initialize the permanent selection model
27500
+ * @protected
27501
+ */
27502
+ initPermanentSelection() {
27503
+ if (this.permanentSelection)
27504
+ throw new Error('initPermanentSelection() already called!');
27505
+ this.permanentSelection = new SelectionModel(true, []);
27506
+ let selectionChangedPrevented = false;
27507
+ // Listen sort change
27508
+ this.registerSubscription(this.onSort.subscribe(() => (selectionChangedPrevented = true)) // prevent selection change on sort
27509
+ );
27510
+ // Listen datasource update
27511
+ this.registerSubscription(this.dataSource.rowsSubject
27512
+ // restore the 'adding' selection (for example after a page or sort change)
27513
+ .subscribe((rows) => {
27514
+ selectionChangedPrevented = true;
27515
+ try {
27516
+ const permanentSelectionIds = (this.permanentSelection.selected || []).map(EntityUtils.getId);
27517
+ this.selection.setSelection(...rows.filter((row) => permanentSelectionIds.includes(AppTableUtils.getEntityId(row))));
27518
+ this.markForCheck();
27519
+ }
27520
+ finally {
27521
+ selectionChangedPrevented = false;
27522
+ }
27523
+ }));
27524
+ // Listen selection change
27525
+ this.registerSubscription(this.selection.changed
27526
+ .pipe(filter(() => !selectionChangedPrevented))
27527
+ .subscribe((selectionChange) => {
27528
+ // add to selection
27529
+ if (selectionChange.added.length) {
27530
+ this.permanentSelection.setSelection(...(this.permanentSelection.selected || [])
27531
+ // Add new elements
27532
+ .concat(...AppTableUtils.getEntities(selectionChange.added))
27533
+ // Avoid duplicated entities (Mantis #55351)
27534
+ .filter(EntityUtils.arrayDistinctFilterFn));
27535
+ }
27536
+ // remove from selection
27537
+ if (selectionChange.removed.length) {
27538
+ const removedIds = AppTableUtils.getEntityIds(selectionChange.removed);
27539
+ this.permanentSelection.setSelection(...(this.permanentSelection.selected || [])
27540
+ .filter((entity) => !removedIds.includes(entity.id)));
27541
+ }
27542
+ this.markForCheck();
27543
+ }));
27544
+ }
27484
27545
  }
27485
27546
  AppTable.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AppTable, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
27486
27547
  AppTable.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.12", type: AppTable, inputs: { settingsId: "settingsId", debug: "debug", i18nColumnPrefix: "i18nColumnPrefix", i18nColumnSuffix: "i18nColumnSuffix", autoLoad: "autoLoad", readOnly: "readOnly", inlineEdition: "inlineEdition", focusFirstColumn: "focusFirstColumn", confirmBeforeDelete: "confirmBeforeDelete", confirmBeforeCancel: "confirmBeforeCancel", undoableDeletion: "undoableDeletion", saveBeforeDelete: "saveBeforeDelete", keepEditedRowOnSave: "keepEditedRowOnSave", saveBeforeSort: "saveBeforeSort", saveBeforeFilter: "saveBeforeFilter", propagateRowError: "propagateRowError", defaultSortBy: "defaultSortBy", defaultSortDirection: "defaultSortDirection", defaultPageSize: "defaultPageSize", defaultPageSizeOptions: "defaultPageSizeOptions", focusColumn: "focusColumn", dataSource: "dataSource", filter: "filter", disabled: "disabled", paginator: "paginator" }, outputs: { onRefresh: "onRefresh", onOpenRow: "onOpenRow", onNewRow: "onNewRow", onStartEditingRow: "onStartEditingRow", onConfirmEditCreateRow: "onConfirmEditCreateRow", onCancelOrDeleteRow: "onCancelOrDeleteRow", onBeforeDeleteRows: "onBeforeDeleteRows", onBeforeCancelRows: "onBeforeCancelRows", onBeforeSave: "onBeforeSave", onAfterDeletedRows: "onAfterDeletedRows", onSort: "onSort", onDirty: "onDirty", onError: "onError" }, viewQueries: [{ propertyName: "table", first: true, predicate: MatTable, descendants: true }, { propertyName: "childPaginator", first: true, predicate: MatPaginator, descendants: true }, { propertyName: "sort", first: true, predicate: MatSort, descendants: true }], ngImport: i0 });
@@ -28846,7 +28907,8 @@ class AppEntityEditor extends AppTabEditor {
28846
28907
  console.debug('[entity-editor] Updating route using queryParams: ', queryParams);
28847
28908
  return await this.router.navigate(['.'], {
28848
28909
  relativeTo: this.route,
28849
- queryParams: this.queryParams
28910
+ queryParams: this.queryParams,
28911
+ state: { animated: false }
28850
28912
  });
28851
28913
  }
28852
28914
  }
@@ -28859,7 +28921,8 @@ class AppEntityEditor extends AppTabEditor {
28859
28921
  queryParams: {
28860
28922
  ...this.queryParams,
28861
28923
  [this.pathIdAttribute]: futureId
28862
- }
28924
+ },
28925
+ state: { animated: false }
28863
28926
  });
28864
28927
  if (!res)
28865
28928
  return false;
@@ -28871,7 +28934,8 @@ class AppEntityEditor extends AppTabEditor {
28871
28934
  console.debug('[entity-editor] Updating route to: ' + path);
28872
28935
  return await this.router.navigate(commands, {
28873
28936
  replaceUrl: true,
28874
- queryParams: this.queryParams
28937
+ queryParams: this.queryParams,
28938
+ state: { animated: false }
28875
28939
  });
28876
28940
  }
28877
28941
  return Promise.reject('Missing page URL');