@sumaris-net/ngx-components 18.12.10 → 18.12.11

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.
@@ -33757,11 +33757,11 @@ class EntitiesTableDataSource extends TableDataSource {
33757
33757
  _entityName;
33758
33758
  _debug = false;
33759
33759
  _creating = false;
33760
- _saving = false;
33761
33760
  _fetchMoreFn = null;
33762
33761
  _waitingNetworkResult;
33763
33762
  _stopWatchSubject = new Subject();
33764
33763
  loadingSubject = new BehaviorSubject(undefined);
33764
+ savingSubject = new BehaviorSubject(false);
33765
33765
  get watchAllOptions() {
33766
33766
  return this.config.watchAllOptions;
33767
33767
  }
@@ -33775,10 +33775,13 @@ class EntitiesTableDataSource extends TableDataSource {
33775
33775
  this.config.saveAllOptions = value;
33776
33776
  }
33777
33777
  get loaded() {
33778
- return this.loadingSubject.value === false; // Should be false when undefined (initial state)
33778
+ return this.loadingSubject.getValue() === false; // Should be false when undefined (initial state)
33779
33779
  }
33780
33780
  get loading() {
33781
- return this.loadingSubject.value !== false; // Should be true when undefined (initial state)
33781
+ return this.loadingSubject.getValue() !== false; // Should be true when undefined (initial state)
33782
+ }
33783
+ get saving() {
33784
+ return this.savingSubject.getValue();
33782
33785
  }
33783
33786
  /**
33784
33787
  * Creates a new TableDataSource instance, that can be used as datasource of `@angular/cdk` data-table.
@@ -33803,19 +33806,13 @@ class EntitiesTableDataSource extends TableDataSource {
33803
33806
  ngOnDestroy() {
33804
33807
  this.disconnect();
33805
33808
  }
33806
- /**
33807
- * @deprecated use disconnect
33808
- */
33809
- close() {
33810
- this.disconnect();
33811
- }
33812
33809
  watchAll(offset, size, sortBy, sortDirection, filter) {
33813
33810
  this._stopWatchSubject.next();
33814
33811
  this._fetchMoreFn = null;
33815
33812
  this.markAsLoading();
33816
33813
  this._waitingNetworkResult = (this.watchAllOptions?.fetchPolicy || this.dataService?.defaultFetchPolicy) === 'cache-and-network';
33817
33814
  return this.dataService.watchAll(offset, size, sortBy, sortDirection, filter, this.watchAllOptions).pipe(catchError((err) => this.handleError(err, 'ERROR.LOAD_DATA_ERROR')), map((res) => {
33818
- if (this._saving) {
33815
+ if (this.saving) {
33819
33816
  console.info(`[entities-table-datasource] Received ${this._entityName} data (from service), but still saving: skip`);
33820
33817
  }
33821
33818
  else {
@@ -33851,12 +33848,11 @@ class EntitiesTableDataSource extends TableDataSource {
33851
33848
  return false;
33852
33849
  }
33853
33850
  // Saving twice (should never occur)
33854
- if (this._saving) {
33851
+ if (this.saving) {
33855
33852
  console.warn(`[entities-table-datasource] Trying to save ${this._entityName} rows twice. Skip`);
33856
33853
  return false;
33857
33854
  }
33858
- this._saving = true;
33859
- this.markAsLoading();
33855
+ this.markAsSaving();
33860
33856
  const onlyDirtyRows = this.config.saveOnlyDirtyRows;
33861
33857
  try {
33862
33858
  if (this._debug)
@@ -33906,7 +33902,7 @@ class EntitiesTableDataSource extends TableDataSource {
33906
33902
  if (this._debug)
33907
33903
  console.debug(`[entities-table-datasource] Saving ${this._entityName} data [OK]`);
33908
33904
  // LP 23/03/2021: update datasource is necessary but can be changed to a refetch() on QueryRef (must be created and registered in GraphqlService.watchQuery)
33909
- this.updateDatasource(data, { emitEvent: false });
33905
+ this.updateDatasource(data);
33910
33906
  return true;
33911
33907
  }
33912
33908
  catch (error) {
@@ -33915,8 +33911,7 @@ class EntitiesTableDataSource extends TableDataSource {
33915
33911
  throw error;
33916
33912
  }
33917
33913
  finally {
33918
- this._saving = false;
33919
- this.markAsLoaded();
33914
+ this.markAsSaved();
33920
33915
  }
33921
33916
  }
33922
33917
  updateDatasource(data, opts) {
@@ -33981,7 +33976,7 @@ class EntitiesTableDataSource extends TableDataSource {
33981
33976
  const confirmed = super.confirmEdit(row);
33982
33977
  if (!confirmed)
33983
33978
  return false;
33984
- if (row.editing && row.validator) {
33979
+ if (row.validator?.enabled) {
33985
33980
  console.warn('[entities-table-datasource] Row still has {editing: true} after confirmEdit()! Force editing to false');
33986
33981
  row.validator.disable({ onlySelf: true, emitEvent: false });
33987
33982
  }
@@ -33991,7 +33986,7 @@ class EntitiesTableDataSource extends TableDataSource {
33991
33986
  const editing = super.startEdit(row);
33992
33987
  if (!editing)
33993
33988
  return false;
33994
- if (!row.editing && row.validator) {
33989
+ if (row.validator?.disabled) {
33995
33990
  console.warn('[entities-table-datasource] Row still has {editing: false} after startEdit()! Force editing');
33996
33991
  row.validator.enable({ onlySelf: true, emitEvent: false });
33997
33992
  }
@@ -34020,8 +34015,6 @@ class EntitiesTableDataSource extends TableDataSource {
34020
34015
  return;
34021
34016
  }
34022
34017
  this.markAsLoading();
34023
- const superDelete = super.delete;
34024
- const self = this;
34025
34018
  this.dataService
34026
34019
  .deleteAll([row.currentData], this.saveAllOptions)
34027
34020
  .catch((err) => this.handleServiceError(err))
@@ -34030,7 +34023,7 @@ class EntitiesTableDataSource extends TableDataSource {
34030
34023
  // make sure row has been deleted (because GrapQHl cache remove can failed)
34031
34024
  const present = this.getRow(id) === row;
34032
34025
  if (present)
34033
- superDelete.call(self, id);
34026
+ super.delete(id);
34034
34027
  this.markAsLoaded();
34035
34028
  }, 300);
34036
34029
  });
@@ -34041,19 +34034,18 @@ class EntitiesTableDataSource extends TableDataSource {
34041
34034
  try {
34042
34035
  // Call service deletion
34043
34036
  await this.dataService.deleteAll(data, this.saveAllOptions);
34044
- await sleep(300); // Wait propagation (e.g. update cache, then received update from dataService.watchAll())
34037
+ // Wait propagation (e.g. update cache, then received update from dataService.watchAll())
34038
+ await sleep(500);
34045
34039
  // Workaround, to be sure all rows have been deleted
34046
34040
  // Sometime, the service miss deletion, or GraphQl cache remove failed.
34047
- // In this case, apply missing deletion using the super.delete() function
34041
+ // In this case, apply missing deletion using the parent delete() function
34048
34042
  const rowNotDeleted = this.getRows().filter((row) => rows.includes(row));
34049
34043
  if (isNotEmptyArray(rowNotDeleted)) {
34050
- const superDelete = super.delete;
34051
- const self = this;
34052
34044
  console.warn(`[entities-table-datasource] Force deletion of ${rowNotDeleted.length} rows! Please check that data service update the cache, after deletion`);
34053
- rowNotDeleted
34054
- // Start at the end
34055
- .sort((a, b) => (a.id > b.id ? -1 : 1))
34056
- .forEach((r) => superDelete.call(self, r.id));
34045
+ // Start at the end
34046
+ for (const r of rowNotDeleted.sort((a, b) => (a.id > b.id ? -1 : 1))) {
34047
+ super.delete(r.id);
34048
+ }
34057
34049
  }
34058
34050
  }
34059
34051
  catch (err) {
@@ -34068,13 +34060,13 @@ class EntitiesTableDataSource extends TableDataSource {
34068
34060
  return super.getRow(id);
34069
34061
  }
34070
34062
  getRows() {
34071
- return this.rowsSubject.getValue();
34063
+ return this.rowsSubject.getValue() || [];
34072
34064
  }
34073
34065
  hasSomeEditingRow() {
34074
- return (this.rowsSubject.value || []).some((row) => row.editing);
34066
+ return this.getRows().some((row) => row.editing);
34075
34067
  }
34076
34068
  hasSomeDirtyRow() {
34077
- return (this.rowsSubject.value || []).some((row) => row.dirty);
34069
+ return this.getRows().some((row) => row.dirty);
34078
34070
  }
34079
34071
  async createNew(insertAt, opts = { editing: true }) {
34080
34072
  // Avoid multiple call (only one editing row is allowed)
@@ -34138,6 +34130,16 @@ class EntitiesTableDataSource extends TableDataSource {
34138
34130
  this.loadingSubject.next(false);
34139
34131
  }
34140
34132
  }
34133
+ markAsSaving() {
34134
+ if (this.savingSubject.value !== true) {
34135
+ this.savingSubject.next(true);
34136
+ }
34137
+ }
34138
+ markAsSaved() {
34139
+ if (this.savingSubject.value !== false) {
34140
+ this.savingSubject.next(false);
34141
+ }
34142
+ }
34141
34143
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EntitiesTableDataSource, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
34142
34144
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: EntitiesTableDataSource, usesInheritance: true, ngImport: i0 });
34143
34145
  }
@@ -36623,11 +36625,11 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36623
36625
  _entityName;
36624
36626
  _debug = false;
36625
36627
  _creating = false;
36626
- _saving = false;
36627
36628
  _fetchMoreFn = null;
36628
36629
  _waitingNetworkResult;
36629
36630
  _stopWatchSubject = new Subject();
36630
36631
  loadingSubject = new BehaviorSubject(undefined);
36632
+ savingSubject = new BehaviorSubject(false);
36631
36633
  get watchAllOptions() {
36632
36634
  return this.config.watchAllOptions;
36633
36635
  }
@@ -36641,10 +36643,13 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36641
36643
  this.config.saveAllOptions = value;
36642
36644
  }
36643
36645
  get loaded() {
36644
- return this.loadingSubject.value === false; // Should be false when undefined (initial state)
36646
+ return this.loadingSubject.getValue() === false; // Should be false when undefined (initial state)
36645
36647
  }
36646
36648
  get loading() {
36647
- return this.loadingSubject.value !== false; // Should be true when undefined (initial state)
36649
+ return this.loadingSubject.getValue() !== false; // Should be true when undefined (initial state)
36650
+ }
36651
+ get saving() {
36652
+ return this.savingSubject.getValue();
36648
36653
  }
36649
36654
  /**
36650
36655
  * Creates a new TableDataSource instance, that can be used as datasource of `@angular/cdk` data-table.
@@ -36674,7 +36679,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36674
36679
  this.markAsLoading();
36675
36680
  this._waitingNetworkResult = (this.watchAllOptions?.fetchPolicy || this.dataService?.defaultFetchPolicy) === 'cache-and-network';
36676
36681
  return this.dataService.watchAll(offset, size, sortBy, sortDirection, filter, this.watchAllOptions).pipe(catchError((err) => this.handleError(err, 'ERROR.LOAD_DATA_ERROR')), map((res) => {
36677
- if (this._saving) {
36682
+ if (this.saving) {
36678
36683
  console.info(`[entities-table-datasource] Received ${this._entityName} data (from service), but still saving: skip`);
36679
36684
  }
36680
36685
  else {
@@ -36710,12 +36715,11 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36710
36715
  return false;
36711
36716
  }
36712
36717
  // Saving twice (should never occur)
36713
- if (this._saving) {
36718
+ if (this.saving) {
36714
36719
  console.warn(`[entities-table-datasource] Trying to save ${this._entityName} rows twice. Skip`);
36715
36720
  return false;
36716
36721
  }
36717
- this._saving = true;
36718
- this.markAsLoading();
36722
+ this.markAsSaving();
36719
36723
  const onlyDirtyRows = this.config.saveOnlyDirtyRows;
36720
36724
  try {
36721
36725
  if (this._debug)
@@ -36765,7 +36769,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36765
36769
  if (this._debug)
36766
36770
  console.debug(`[entities-table-datasource] Saving ${this._entityName} data [OK]`);
36767
36771
  // LP 23/03/2021: update datasource is necessary but can be changed to a refetch() on QueryRef (must be created and registered in GraphqlService.watchQuery)
36768
- this.updateDatasource(data, { emitEvent: false });
36772
+ this.updateDatasource(data);
36769
36773
  return true;
36770
36774
  }
36771
36775
  catch (error) {
@@ -36774,8 +36778,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36774
36778
  throw error;
36775
36779
  }
36776
36780
  finally {
36777
- this._saving = false;
36778
- this.markAsLoaded();
36781
+ this.markAsSaved();
36779
36782
  }
36780
36783
  }
36781
36784
  updateDatasource(data, opts) {
@@ -36834,7 +36837,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36834
36837
  console.warn('[entities-table-datasource] Row still has {editing: true} after confirmCreate()! Force editing to false');
36835
36838
  row.validator.disable({ onlySelf: true, emitEvent: false });
36836
36839
  }
36837
- return confirmed;
36840
+ return true;
36838
36841
  }
36839
36842
  async confirmEdit(row) {
36840
36843
  const confirmed = await super.confirmEdit(row);
@@ -36850,7 +36853,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36850
36853
  const editing = await super.startEdit(row);
36851
36854
  if (!editing)
36852
36855
  return false;
36853
- if (!row.editing && row.validator) {
36856
+ if (row.validator?.disabled) {
36854
36857
  console.warn('[entities-table-datasource] Row still has {editing: false} after startEdit()! Force editing');
36855
36858
  row.validator.enable({ onlySelf: true, emitEvent: false });
36856
36859
  }
@@ -36925,7 +36928,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
36925
36928
  return super.getRow(id);
36926
36929
  }
36927
36930
  getRows() {
36928
- return this.rowsSubject.value || [];
36931
+ return this.rowsSubject.getValue() || [];
36929
36932
  }
36930
36933
  getEditingRows() {
36931
36934
  return this.getRows().filter((row) => row.editing);
@@ -37002,6 +37005,16 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
37002
37005
  this.loadingSubject.next(false);
37003
37006
  }
37004
37007
  }
37008
+ markAsSaving() {
37009
+ if (this.savingSubject.value !== true) {
37010
+ this.savingSubject.next(true);
37011
+ }
37012
+ }
37013
+ markAsSaved() {
37014
+ if (this.savingSubject.value !== false) {
37015
+ this.savingSubject.next(false);
37016
+ }
37017
+ }
37005
37018
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: EntitiesAsyncTableDataSource, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
37006
37019
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: EntitiesAsyncTableDataSource, usesInheritance: true, ngImport: i0 });
37007
37020
  }