@sumaris-net/ngx-components 2.6.2-rc1 → 2.6.2

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.
@@ -31503,6 +31503,8 @@ class AppAsyncTable {
31503
31503
  this.dirtySubject = new BehaviorSubject(false);
31504
31504
  this.errorSubject = new BehaviorSubject(undefined);
31505
31505
  this.selection = new SelectionModel(true, []);
31506
+ this.permanentSelection = null;
31507
+ this.permanentSelectionChangedPrevented = false;
31506
31508
  this.i18nColumnPrefix = 'COMMON.';
31507
31509
  this.autoLoad = true;
31508
31510
  this.focusFirstColumn = false;
@@ -31510,6 +31512,7 @@ class AppAsyncTable {
31510
31512
  this.confirmBeforeCancel = false;
31511
31513
  this.undoableDeletion = false;
31512
31514
  this.propagateRowError = false;
31515
+ this.permanentSelectionAllowed = false; // Allow keep selected rows over page change or sort change
31513
31516
  this.defaultPageSize = DEFAULT_PAGE_SIZE;
31514
31517
  this.defaultPageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS;
31515
31518
  this.onRefresh = new EventEmitter();
@@ -31569,6 +31572,10 @@ class AppAsyncTable {
31569
31572
  get empty() {
31570
31573
  return this.loading || this.totalRowCount === 0;
31571
31574
  }
31575
+ get selectedEntities() {
31576
+ return this.permanentSelection?.selected
31577
+ || AppTableUtils.getEntities(this.selection.selected);
31578
+ }
31572
31579
  get dirty() {
31573
31580
  return this.dirtySubject.value;
31574
31581
  }
@@ -31813,6 +31820,9 @@ class AppAsyncTable {
31813
31820
  // Listen dataSource loading events
31814
31821
  if (this._dataSource)
31815
31822
  this.listenDatasourceLoading(this._dataSource);
31823
+ // Permanent selection behavior
31824
+ if (this.permanentSelectionAllowed)
31825
+ this.initPermanentSelection();
31816
31826
  }
31817
31827
  ngAfterViewInit() {
31818
31828
  // Detect when parent ngOnInit() not call
@@ -31894,6 +31904,8 @@ class AppAsyncTable {
31894
31904
  }
31895
31905
  setFilter(filter, opts) {
31896
31906
  opts = opts || { emitEvent: true };
31907
+ // Prevent permanent selection change events
31908
+ this.permanentSelectionChangedPrevented = toBoolean(opts.permanentSelectionChangedPrevented, this.permanentSelectionChangedPrevented);
31897
31909
  if (this.saveBeforeFilter) {
31898
31910
  // if a dirty table is to be saved before filter
31899
31911
  if (this.dirty) {
@@ -32998,9 +33010,55 @@ class AppAsyncTable {
32998
33010
  def.subject.unsubscribe();
32999
33011
  }
33000
33012
  }
33013
+ /**
33014
+ * Initialize the permanent selection model
33015
+ * @protected
33016
+ */
33017
+ initPermanentSelection() {
33018
+ if (this.permanentSelection)
33019
+ throw new Error('initPermanentSelection() already called!');
33020
+ this.permanentSelection = new SelectionModel(true, []);
33021
+ // Listen sort change
33022
+ this.registerSubscription(this.onSort.subscribe(() => (this.permanentSelectionChangedPrevented = true)) // prevent selection change on sort
33023
+ );
33024
+ // Listen datasource update
33025
+ this.registerSubscription(this.dataSource.rowsSubject
33026
+ // restore the 'adding' selection (for example after a page or sort change)
33027
+ .subscribe((rows) => {
33028
+ this.permanentSelectionChangedPrevented = true;
33029
+ try {
33030
+ const permanentSelectionIds = (this.permanentSelection.selected || []).map(EntityUtils.getId);
33031
+ this.selection.setSelection(...rows.filter((row) => permanentSelectionIds.includes(AppTableUtils.getEntityId(row))));
33032
+ this.markForCheck();
33033
+ }
33034
+ finally {
33035
+ this.permanentSelectionChangedPrevented = false;
33036
+ }
33037
+ }));
33038
+ // Listen selection change
33039
+ this.registerSubscription(this.selection.changed
33040
+ .pipe(filter(() => !this.permanentSelectionChangedPrevented))
33041
+ .subscribe((selectionChange) => {
33042
+ // add to selection
33043
+ if (selectionChange.added.length) {
33044
+ this.permanentSelection.setSelection(...(this.permanentSelection.selected || [])
33045
+ // Add new elements
33046
+ .concat(...AppTableUtils.getEntities(selectionChange.added))
33047
+ // Avoid duplicated entities (Mantis #55351)
33048
+ .filter(EntityUtils.arrayDistinctFilterFn));
33049
+ }
33050
+ // remove from selection
33051
+ if (selectionChange.removed.length) {
33052
+ const removedIds = AppTableUtils.getEntityIds(selectionChange.removed);
33053
+ this.permanentSelection.setSelection(...(this.permanentSelection.selected || [])
33054
+ .filter((entity) => !removedIds.includes(entity.id)));
33055
+ }
33056
+ this.markForCheck();
33057
+ }));
33058
+ }
33001
33059
  }
33002
33060
  AppAsyncTable.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: AppAsyncTable, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
33003
- AppAsyncTable.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.3.0", type: AppAsyncTable, 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 });
33061
+ AppAsyncTable.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.3.0", type: AppAsyncTable, 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", permanentSelectionAllowed: "permanentSelectionAllowed", 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 });
33004
33062
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: AppAsyncTable, decorators: [{
33005
33063
  type: Directive
33006
33064
  }], ctorParameters: function () { return [{ type: i0.Injector }, { type: undefined }, { type: EntitiesAsyncTableDataSource }, { type: undefined }]; }, propDecorators: { settingsId: [{
@@ -33035,6 +33093,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
33035
33093
  type: Input
33036
33094
  }], propagateRowError: [{
33037
33095
  type: Input
33096
+ }], permanentSelectionAllowed: [{
33097
+ type: Input
33038
33098
  }], defaultSortBy: [{
33039
33099
  type: Input
33040
33100
  }], defaultSortDirection: [{