@sumaris-net/ngx-components 18.9.0 → 18.9.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.
- package/doc/changelog.md +7 -0
- package/esm2022/src/app/core/services/base-entity-service.class.mjs +4 -1
- package/esm2022/src/app/core/table/entities-async-table-datasource.class.mjs +29 -9
- package/esm2022/src/app/core/table/entities-table-datasource.class.mjs +42 -38
- package/esm2022/src/app/shared/services/entity-service.class.mjs +1 -1
- package/esm2022/src/app/shared/services/memory-entity-service.class.mjs +4 -1
- package/fesm2022/sumaris-net.ngx-components.mjs +73 -43
- package/fesm2022/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/core/services/base-entity-service.class.d.ts +2 -1
- package/src/app/core/table/entities-async-table-datasource.class.d.ts +22 -3
- package/src/app/core/table/entities-table-datasource.class.d.ts +22 -14
- package/src/app/shared/services/entity-service.class.d.ts +1 -0
- package/src/app/shared/services/memory-entity-service.class.d.ts +1 -0
- package/src/assets/manifest.json +1 -1
|
@@ -24427,6 +24427,9 @@ class BaseEntityService extends BaseGraphqlService {
|
|
|
24427
24427
|
defaultSortBy;
|
|
24428
24428
|
defaultSortDirection;
|
|
24429
24429
|
watchQueriesUpdatePolicy;
|
|
24430
|
+
get defaultFetchPolicy() {
|
|
24431
|
+
return this.graphql.defaultFetchPolicy;
|
|
24432
|
+
}
|
|
24430
24433
|
constructor(graphql, platform, dataType, filterType, options) {
|
|
24431
24434
|
super(graphql, environment);
|
|
24432
24435
|
this.graphql = graphql;
|
|
@@ -26966,6 +26969,9 @@ class InMemoryEntitiesService extends StartableObservableService {
|
|
|
26966
26969
|
_onSaveFn;
|
|
26967
26970
|
_equalsFn;
|
|
26968
26971
|
_filterFnFactory;
|
|
26972
|
+
get defaultFetchPolicy() {
|
|
26973
|
+
return 'cache-only';
|
|
26974
|
+
}
|
|
26969
26975
|
set value(data) {
|
|
26970
26976
|
this.setValue(data);
|
|
26971
26977
|
}
|
|
@@ -33245,21 +33251,9 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33245
33251
|
_creating = false;
|
|
33246
33252
|
_saving = false;
|
|
33247
33253
|
_fetchMoreFn = null;
|
|
33254
|
+
_waitingNetworkResult;
|
|
33248
33255
|
_stopWatchSubject = new Subject();
|
|
33249
33256
|
loadingSubject = new BehaviorSubject(undefined);
|
|
33250
|
-
/**
|
|
33251
|
-
* @deprecated Use watchAllOptions or saveAllOptions
|
|
33252
|
-
*/
|
|
33253
|
-
get serviceOptions() {
|
|
33254
|
-
return this.config.dataServiceOptions || { ...this.watchAllOptions, ...this.saveAllOptions };
|
|
33255
|
-
}
|
|
33256
|
-
/**
|
|
33257
|
-
* @deprecated Use watchAllOptions or saveAllOptions
|
|
33258
|
-
*/
|
|
33259
|
-
set serviceOptions(value) {
|
|
33260
|
-
console.warn("dataSource.serviceOptions is deprecated! Please use 'watchAllOptions' or 'saveAllOptions' instead");
|
|
33261
|
-
this.config.dataServiceOptions = value;
|
|
33262
|
-
}
|
|
33263
33257
|
get watchAllOptions() {
|
|
33264
33258
|
return this.config.watchAllOptions;
|
|
33265
33259
|
}
|
|
@@ -33283,9 +33277,8 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33283
33277
|
*
|
|
33284
33278
|
* @param dataService A service to load and save data
|
|
33285
33279
|
* @param dataType Type of data contained by the Table. If not specified, then `data` with at least one element must be specified.
|
|
33286
|
-
* @param environment
|
|
33287
33280
|
* @param validatorService Service that create instances of the FormGroup used to validate row fields.
|
|
33288
|
-
* @param
|
|
33281
|
+
* @param options Additional options
|
|
33289
33282
|
*/
|
|
33290
33283
|
constructor(dataType, dataService, validatorService, options) {
|
|
33291
33284
|
super([], dataType, validatorService, {
|
|
@@ -33299,31 +33292,21 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33299
33292
|
this._entityName = removeEnd(new dataType().__typename || 'UnknownVO', 'VO');
|
|
33300
33293
|
this._debug = options?.suppressErrors === false && !environment.production;
|
|
33301
33294
|
}
|
|
33302
|
-
/**
|
|
33303
|
-
* @deprecated use disconnect
|
|
33304
|
-
*/
|
|
33305
33295
|
ngOnDestroy() {
|
|
33306
|
-
this.
|
|
33296
|
+
this.disconnect();
|
|
33307
33297
|
}
|
|
33308
33298
|
/**
|
|
33309
33299
|
* @deprecated use disconnect
|
|
33310
33300
|
*/
|
|
33311
33301
|
close() {
|
|
33312
|
-
|
|
33313
|
-
if (this._debug)
|
|
33314
|
-
console.debug('[entities-table-datasource] Closing...');
|
|
33315
|
-
this._stopWatchSubject.next();
|
|
33316
|
-
this._stopWatchSubject.complete();
|
|
33317
|
-
this._stopWatchSubject.unsubscribe();
|
|
33318
|
-
this.loadingSubject.complete();
|
|
33319
|
-
this.loadingSubject.unsubscribe();
|
|
33320
|
-
}
|
|
33302
|
+
this.disconnect();
|
|
33321
33303
|
}
|
|
33322
33304
|
watchAll(offset, size, sortBy, sortDirection, filter) {
|
|
33323
33305
|
this._stopWatchSubject.next();
|
|
33324
33306
|
this._fetchMoreFn = null;
|
|
33325
33307
|
this.markAsLoading();
|
|
33326
|
-
|
|
33308
|
+
this._waitingNetworkResult = (this.watchAllOptions?.fetchPolicy || this.dataService?.defaultFetchPolicy) === 'cache-and-network';
|
|
33309
|
+
return this.dataService.watchAll(offset, size, sortBy, sortDirection, filter, this.watchAllOptions).pipe(catchError((err) => this.handleError(err, 'ERROR.LOAD_DATA_ERROR')), map((res) => {
|
|
33327
33310
|
if (this._saving) {
|
|
33328
33311
|
console.info(`[entities-table-datasource] Received ${this._entityName} data (from service), but still saving: skip`);
|
|
33329
33312
|
}
|
|
@@ -33334,6 +33317,8 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33334
33317
|
this.updateDatasource((res.data || []));
|
|
33335
33318
|
this._fetchMoreFn = res.fetchMore;
|
|
33336
33319
|
}
|
|
33320
|
+
// Reset _waitingNetworkResult to false
|
|
33321
|
+
this._waitingNetworkResult = false;
|
|
33337
33322
|
return res;
|
|
33338
33323
|
}),
|
|
33339
33324
|
// Stop this pipe next time we call watchAll()
|
|
@@ -33409,7 +33394,7 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33409
33394
|
}
|
|
33410
33395
|
if (this._debug)
|
|
33411
33396
|
console.debug(`[entities-table-datasource] Asking service to save this ${this._entityName} data:`, dataToSave);
|
|
33412
|
-
await this.dataService.saveAll(dataToSave, this.
|
|
33397
|
+
await this.dataService.saveAll(dataToSave, this.saveAllOptions);
|
|
33413
33398
|
if (this._debug)
|
|
33414
33399
|
console.debug(`[entities-table-datasource] Saving ${this._entityName} data [OK]`);
|
|
33415
33400
|
// 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)
|
|
@@ -33439,15 +33424,40 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33439
33424
|
//console.debug("[entities-datasource] connect");
|
|
33440
33425
|
return super.connect(collectionViewer);
|
|
33441
33426
|
}
|
|
33427
|
+
/**
|
|
33428
|
+
* Disconnects the data source, cleaning up any resources and subscriptions.
|
|
33429
|
+
*
|
|
33430
|
+
* @param {CollectionViewer} [collectionViewer] - Optional parameter representing the collection viewer to disconnect from.
|
|
33431
|
+
* @return {void} - This method does not return a value.
|
|
33432
|
+
*/
|
|
33442
33433
|
disconnect(collectionViewer) {
|
|
33443
33434
|
if (this._debug)
|
|
33444
33435
|
console.debug('[entities-table-datasource] Disconnecting...');
|
|
33445
33436
|
super.disconnect(collectionViewer);
|
|
33446
|
-
this.
|
|
33437
|
+
if (!this._stopWatchSubject.closed) {
|
|
33438
|
+
this._stopWatchSubject.next();
|
|
33439
|
+
this._stopWatchSubject.complete();
|
|
33440
|
+
this._stopWatchSubject.unsubscribe();
|
|
33441
|
+
this.loadingSubject.complete();
|
|
33442
|
+
this.loadingSubject.unsubscribe();
|
|
33443
|
+
}
|
|
33447
33444
|
}
|
|
33448
|
-
|
|
33449
|
-
|
|
33450
|
-
|
|
33445
|
+
/**
|
|
33446
|
+
* Waits for the idle state based on the provided options.
|
|
33447
|
+
*
|
|
33448
|
+
* @param {number | { debounceTimeMs?: number } & FirstOptions} [opts] Options for controlling the wait behavior.
|
|
33449
|
+
* - If a number is provided, it is treated as the debounce time in milliseconds.
|
|
33450
|
+
* - If an object is provided, it can include the following properties:
|
|
33451
|
+
* - debounceTimeMs: The debounce time in milliseconds. Defaults to 100 if not specified.
|
|
33452
|
+
* - Additional options from `FirstOptions` interface.
|
|
33453
|
+
* @return {Promise<any>} A Promise that resolves when the idle state is reached.
|
|
33454
|
+
*/
|
|
33455
|
+
waitIdle(opts) {
|
|
33456
|
+
const debounceTimeMs = typeof opts === 'number' ? opts : opts?.debounceTimeMs || 100; /* in case was not started */
|
|
33457
|
+
opts = typeof opts === 'number' ? undefined : opts;
|
|
33458
|
+
return firstFalsePromise(this.loadingSubject.asObservable().pipe(
|
|
33459
|
+
// Skip loaded event, if waiting a result from network (e.g. when fetch policy is 'cache-and-network')
|
|
33460
|
+
filter((loading) => loading || !this._waitingNetworkResult), debounceTime(debounceTimeMs)), opts);
|
|
33451
33461
|
}
|
|
33452
33462
|
confirmCreate(row) {
|
|
33453
33463
|
const confirmed = super.confirmCreate(row);
|
|
@@ -33505,7 +33515,7 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33505
33515
|
const superDelete = super.delete;
|
|
33506
33516
|
const self = this;
|
|
33507
33517
|
this.dataService
|
|
33508
|
-
.deleteAll([row.currentData], this.
|
|
33518
|
+
.deleteAll([row.currentData], this.saveAllOptions)
|
|
33509
33519
|
.catch((err) => this.handleServiceError(err))
|
|
33510
33520
|
.then(() => {
|
|
33511
33521
|
setTimeout(() => {
|
|
@@ -33522,7 +33532,7 @@ class EntitiesTableDataSource extends TableDataSource {
|
|
|
33522
33532
|
const data = this.getDataFromRows(rows);
|
|
33523
33533
|
try {
|
|
33524
33534
|
// Call service deletion
|
|
33525
|
-
await this.dataService.deleteAll(data, this.
|
|
33535
|
+
await this.dataService.deleteAll(data, this.saveAllOptions);
|
|
33526
33536
|
await sleep(300); // Wait propagation (e.g. update cache, then received update from dataService.watchAll())
|
|
33527
33537
|
// Workaround, to be sure all rows have been deleted
|
|
33528
33538
|
// Sometime, the service miss deletion, or GraphQl cache remove failed.
|
|
@@ -36099,6 +36109,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
|
|
|
36099
36109
|
_creating = false;
|
|
36100
36110
|
_saving = false;
|
|
36101
36111
|
_fetchMoreFn = null;
|
|
36112
|
+
_waitingNetworkResult;
|
|
36102
36113
|
_stopWatchSubject = new Subject();
|
|
36103
36114
|
loadingSubject = new BehaviorSubject(undefined);
|
|
36104
36115
|
get watchAllOptions() {
|
|
@@ -36124,9 +36135,8 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
|
|
|
36124
36135
|
*
|
|
36125
36136
|
* @param dataService A service to load and save data
|
|
36126
36137
|
* @param dataType Type of data contained by the Table. If not specified, then `data` with at least one element must be specified.
|
|
36127
|
-
* @param environment
|
|
36128
36138
|
* @param validatorService Service that create instances of the FormGroup used to validate row fields.
|
|
36129
|
-
* @param
|
|
36139
|
+
* @param options Additional options
|
|
36130
36140
|
*/
|
|
36131
36141
|
constructor(dataType, dataService, validatorService, options) {
|
|
36132
36142
|
super([], dataType, validatorService, {
|
|
@@ -36146,6 +36156,7 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
|
|
|
36146
36156
|
this._stopWatchSubject.next();
|
|
36147
36157
|
this._fetchMoreFn = null;
|
|
36148
36158
|
this.markAsLoading();
|
|
36159
|
+
this._waitingNetworkResult = (this.watchAllOptions?.fetchPolicy || this.dataService?.defaultFetchPolicy) === 'cache-and-network';
|
|
36149
36160
|
return this.dataService.watchAll(offset, size, sortBy, sortDirection, filter, this.watchAllOptions).pipe(catchError((err) => this.handleError(err, 'ERROR.LOAD_DATA_ERROR')), map((res) => {
|
|
36150
36161
|
if (this._saving) {
|
|
36151
36162
|
console.info(`[entities-table-datasource] Received ${this._entityName} data (from service), but still saving: skip`);
|
|
@@ -36157,6 +36168,8 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
|
|
|
36157
36168
|
this.updateDatasource((res.data || []));
|
|
36158
36169
|
this._fetchMoreFn = res.fetchMore;
|
|
36159
36170
|
}
|
|
36171
|
+
// Reset _waitingNetworkResult to false
|
|
36172
|
+
this._waitingNetworkResult = false;
|
|
36160
36173
|
return res;
|
|
36161
36174
|
}),
|
|
36162
36175
|
// Stop this pipe next time we call watchAll()
|
|
@@ -36262,13 +36275,17 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
|
|
|
36262
36275
|
//console.debug("[entities-datasource] connect");
|
|
36263
36276
|
return super.connect(collectionViewer);
|
|
36264
36277
|
}
|
|
36278
|
+
/**
|
|
36279
|
+
* Disconnects the data source, cleaning up any resources and subscriptions.
|
|
36280
|
+
*
|
|
36281
|
+
* @param {CollectionViewer} [collectionViewer] - Optional parameter representing the collection viewer to disconnect from.
|
|
36282
|
+
* @return {void} - This method does not return a value.
|
|
36283
|
+
*/
|
|
36265
36284
|
disconnect(collectionViewer) {
|
|
36266
36285
|
if (this._debug)
|
|
36267
36286
|
console.debug('[entities-table-datasource] Disconnecting...');
|
|
36268
36287
|
super.disconnect(collectionViewer);
|
|
36269
36288
|
if (!this._stopWatchSubject.closed) {
|
|
36270
|
-
if (this._debug)
|
|
36271
|
-
console.debug('[entities-table-datasource] Closing...');
|
|
36272
36289
|
this._stopWatchSubject.next();
|
|
36273
36290
|
this._stopWatchSubject.complete();
|
|
36274
36291
|
this._stopWatchSubject.unsubscribe();
|
|
@@ -36276,9 +36293,22 @@ class EntitiesAsyncTableDataSource extends AsyncTableDataSource {
|
|
|
36276
36293
|
this.loadingSubject.unsubscribe();
|
|
36277
36294
|
}
|
|
36278
36295
|
}
|
|
36279
|
-
|
|
36280
|
-
|
|
36281
|
-
|
|
36296
|
+
/**
|
|
36297
|
+
* Waits for the idle state based on the provided options.
|
|
36298
|
+
*
|
|
36299
|
+
* @param {number | { debounceTimeMs?: number } & FirstOptions} [opts] Options for controlling the wait behavior.
|
|
36300
|
+
* - If a number is provided, it is treated as the debounce time in milliseconds.
|
|
36301
|
+
* - If an object is provided, it can include the following properties:
|
|
36302
|
+
* - debounceTimeMs: The debounce time in milliseconds. Defaults to 100 if not specified.
|
|
36303
|
+
* - Additional options from `FirstOptions` interface.
|
|
36304
|
+
* @return {Promise<any>} A Promise that resolves when the idle state is reached.
|
|
36305
|
+
*/
|
|
36306
|
+
waitIdle(opts) {
|
|
36307
|
+
const debounceTimeMs = typeof opts === 'number' ? opts : opts?.debounceTimeMs || 100; /* in case was not started */
|
|
36308
|
+
opts = typeof opts === 'number' ? undefined : opts;
|
|
36309
|
+
return firstFalsePromise(this.loadingSubject.asObservable().pipe(
|
|
36310
|
+
// Skip loaded event, if waiting a result from network (e.g. when fetch policy is 'cache-and-network')
|
|
36311
|
+
filter((loading) => loading || !this._waitingNetworkResult), debounceTime(debounceTimeMs)), opts);
|
|
36282
36312
|
}
|
|
36283
36313
|
async confirmCreate(row) {
|
|
36284
36314
|
const confirmed = await super.confirmCreate(row);
|